Assert Failhttp://assertfail.gewalli.se/
Assert Failen-usTue, 30 Oct 2018 09:40:00 +0000Tue, 30 Oct 2018 09:40:00 +0000Is there a value in having diversity when it comes to solutions?http://assertfail.gewalli.se/2018/10/26/Is-there-a-value-in-having-diversity-when-it-comes-to-solutions.html
Fri, 26 Oct 2018 11:01:51 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2018/10/26/Is-there-a-value-in-having-diversity-when-it-comes-to-solutions<ul>
<li>Monoculture in agriculture has some definite downsides (lack of resilience, soil depletion, over reliance on fertilizer)</li>
<li>Monoculture in buildings can cause people to feel lost. Once you move in, you want to change your house to fit your family and your interests.</li>
</ul>
<p>A suburb that started out with lots of very similar houses can end up with divergent colors, additions suited for different people, gardens with personal style. This should not be seen as a negative thing, it shows the history of the area and give a sense of identity to the neighborhood.</p>
<p>In programming we often have a drive towards standardization.</p>
<ul>
<li>perhaps in order to increase the industrial or engineering nature of it?</li>
<li>To make it easy to get people from other teams to understand the code due to similarities in style</li>
</ul>
<h2 id="having-different-stylesarchitecturesprogramming-language">Having different styles/architectures/programming language?</h2>
<p>Since different software components suite different purposes, they should have style suited for different application / purpose.
When you use components from different companies and open source initiatives, they will not fit your style: they can help you deliver, so don’t ignore things that don’t fit your style (since they can help you deliver).</p>
<h3 id="one-language-to-rule-them-all">One language to rule them all</h3>
<p>There is talk about having a single language for frontend and backend. This type of talk has been going on for as long as I’ve been a developer. I’ve worked in such solutions: C#, Java or C++ as the single language. I’ve seen JavaScript on both client and server. This can be very helpful for people starting out. They use the same language that they are very familiar with in both settings. For one team this can be a good thing and help them deliver.</p>
<p>However compiling Java or C# to JavaScript have had some interesting challenges. The debugging experience, error handling, diagnosing errors. Source maps and other tools have helped make this less of an issue. Though since most frontend web libraries are written in JavaScript, it is often better to be familiar with JavaScript.</p>
<p>Writing JavaScript on the backend has had some challences. The developers I’ve worked with have had it easier to work with C# (when it comes to deliver stable features). For simple services, JavaScript can be a good choice. There are also more mature libraries for Java and C# that fits more of server side development (for historical reasons).</p>
<p>Limiting yourself to one language also means limiting your recruitment base. Once people have started working, they usually pick up the other commonly used languages (in order to be able to modify other parts).</p>
<h2 id="hiring-different-style-of-programmers">Hiring different style of programmers</h2>
<p>Developers will find their own style of coding as they mature. Different people will work in different ways. Some write text then code, some draw diagrams then code, some tests then code, et.c.. When you hire people, most probably they will not be familiar with your domain and your standards. Just because they are not familiar with your preferred style, they can still prove useful (to your organization).</p>
<h3 id="consider-frontend-vs-backend">Consider frontend vs backend</h3>
<p>When I started out, I didn’t hear about this distinction, while today it’s a big division. JavaScript was a loathed niche language. I think the primary reasons was that it was very difficulty to write working code. One big reason was due to browser differences between versions and vendors. Another reason was that linters was not in use. There are some gotchas that can be difficult to track down (unless you use linter). Then came jQuery (to smooth out the differences). Then came browser standardization.</p>
<p>Note however, if you write mobile apps or desktop applications, you can do that fully in C#.</p>
<h3 id="hiring-people">Hiring people</h3>
<p>How do you hire ok frontend web people? You go with JavaScript (since that’s the mainstream web frontend language right now).</p>
<p>How do you hire ok backend people? You go with Java, Python, C# or even PHP (since they are the mainstream backend languages right now).</p>
<p>How do you find great developers? One way is to go a bit niche. Interested developers will want to learn new things. If you have ‘cool’ tech you can attract some of these guys.</p>
<h4 id="niche-language">Niche language:</h4>
<ul>
<li>possible to hire great developers who have sought out the language in order to level up</li>
<li>harder to convince other people that they can work in such a language</li>
</ul>
<h4 id="very-common-language">very common language:</h4>
<ul>
<li>easier to recruit people directly from school (since it’s common, schools target the language)</li>
<li>easier to recruit people from other parts of the industry</li>
<li>normal people, going to work and then going home, also called 9-5:ers or <a href="https://www.hanselman.com/blog/DarkMatterDevelopersTheUnseen99.aspx">dark matter developers</a></li>
</ul>
<h2 id="where-should-you-have-homogeneity">Where should you have homogeneity?</h2>
<p>You need people to make sure that components (libraries/services) have internally uniform style. Having a good structure will make it easier to read the code. What kind of structure? I would say that it depends on the project and people working on it.</p>
Why I prefer React over Angularhttp://assertfail.gewalli.se/2018/09/09/Why-I-prefer-React-over-Angular.html
Sun, 09 Sep 2018 08:18:42 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2018/09/09/Why-I-prefer-React-over-Angular<ul>
<li>React has a smaller scope than Angular.</li>
<li>I’ve found that my coworkers have an easier time grokking React than Angular: React contains fewer concepts than Angular.</li>
<li>Angular can sometimes make implementation of custom behaviors require a lot of deep knownledge (of Angular). For instance when implementing a custom dropdown or a checkbox.</li>
<li>If you are cheeky, you could say:
<blockquote>
<p>Angular is a somewhat over engineered platform, while React is sometimes used to create over engineered apps.</p>
</blockquote>
</li>
</ul>
<p>My personal opinion is that as long as you can use the existing behavior of the standard components (buttons, checkboxes, dropdowns et.c.), Angular can be a good choice. I’ve yet to have been in a situation where management will settle on not implementing something just because it will create additional complexity: Why my feeling is that if you are given the choice, you should go for React.</p>
<p>I’ve used knockout for several years as well (and still like it as a library). My biggest issue is that I’ve found that the documentation (and the API) leads people into using computed properties when they don’t need to. I would say that knockout is more well thought out than Angular (due to the smaller scope of the project). Due to the popularity of React compared to Knockout, I would guess that React would be a more natural choice.</p>
f# 2 years laterhttp://assertfail.gewalli.se/2018/09/08/fsharp-2-years-later.html
Sat, 08 Sep 2018 19:30:26 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2018/09/08/fsharp-2-years-later<h2 id="whats-the-lure-of-f">What’s the lure of f#?</h2>
<p>The main lure of f# is that it’s a surprisingly competent <a href="https://en.wikipedia.org/wiki/ML_(programming_language)">ML</a> style language that transcends some of the limitations of <a href="https://en.wikipedia.org/wiki/Common_Intermediate_Language">CIL</a>.</p>
<p>From my point of view, the main distinguishing feature for f# is <a href="https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/statically-resolved-type-parameters">Statically Resolved Type Parameters</a>. It’s a feature you don’t want to see in business code (same as reflection in c#), but something that enables libraries to take f# to <a href="https://github.com/fsprojects/FSharpPlus">the next level</a>. Compare this to <a href="http://learnyouahaskell.com/types-and-typeclasses">type classes</a> in Haskell and what is called <a href="https://v1.realworldocaml.org/v1/en/html/functors.html">functors</a> in OCaml.</p>
<h2 id="what-has-delighted-me">What has delighted me?</h2>
<ul>
<li>The editor tooling for f# has grown more stable.</li>
<li>That f# has another perspective (compared to c#).</li>
<li>Type providers can simplify one-off “scripting”.</li>
</ul>
<h2 id="what-has-been-annoying">What has been annoying?</h2>
<p>Personally most of the pain points have been in dealing with .net core.</p>
<ul>
<li>Type providers have recently (2018/05/08) <a href="https://blogs.msdn.microsoft.com/dotnet/2018/05/08/f-language-and-tools-update-for-visual-studio-2017-version-15-7/">been fixed to work in .net core</a>.</li>
<li>Using libraries intended to be consumed in c# that uses <code class="highlighter-rouge">Microsoft.Extensions.DependencyInjection</code> and <code class="highlighter-rouge">Microsoft.Extensions.Options</code> requires ceremony to use.</li>
</ul>
<p>These are minor things. For the most part I don’t need dependency injection heavy code in the f# I’ve been writing.</p>
What about Identity Server?http://assertfail.gewalli.se/2018/09/06/What-about-Identity-Server.html
Thu, 06 Sep 2018 05:52:29 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2018/09/06/What-about-Identity-Server<h1 id="so-what-has-been-my-experience-using-identity-server">So what has been my experience using <a href="https://github.com/IdentityServer/IdentityServer4">Identity Server</a>?</h1>
<p>I’ve (and others in my team) have worked on a project using Identity Server 4 since early 2017.</p>
<h2 id="what-lead-us-there">What lead us there?</h2>
<p>The main reason why we started to consider it was due to the main business goals:</p>
<ul>
<li>To have a JWT provider that enables a single page application to communicate with a plethora of micro services</li>
<li>To use an existing solutions. The reasoning being that if the company used existing software, that would create a dependency on that software instead of senior developers.</li>
<li>To have a single provider of identity and accounts.</li>
<li>To have the provider of identity and accounts as a micro service.</li>
</ul>
<p>We noticed that asp.net identity together with Identity Server satisfies a lot of the specific business requirements.</p>
<h2 id="initial-experience">Initial experience</h2>
<p>We got something working quite fast that satisfied the requirements. We had an login, authentication and OAuth solution within days.</p>
<h2 id="what-happened-next">What happened next</h2>
<p>Our first stumbling block was that there was a need for a JSON API to use with a backoffice GUI that needed to be able to display accounts. Part of the trouble was that we needed mixed authentication: JWT and cookies. That turned out to be somewhat difficult with asp.net core mvc 1, but we eventually solved it. In asp.net core mvc 2 this has become much easier to configure.</p>
<p>Our next stumbling block was that there was a requirement that we could have a sign in flow from the single page application without disrupting the shopping experience. That requirement turned out to be more difficult to satisfy than the other requirements. In order to satisfy that we needed to dive deep into Identity Server in order to bend the opinions of Identity Server to the requirements.</p>
<h2 id="conclusions">Conclusions</h2>
<p>In hindsight, building such a solution on Identity Server turned out to be something of a mistake. My best bet right now is that Identity Server is more useful for server to server communication or when you want an OAUTH provider (and you are OK with the opinions of Identity Server). Another alternative is to relax one of the above requirements and use the Identity Server <code class="highlighter-rouge">site</code> as API gateway to internal services.</p>
<p>Another approach would have been sign JWT tokens directly without going through Identity Server. The tokens returned to the user could then have been validated by the services. The CTO at that time expressed a wish for the developers to use OAuth in order to be ready for native app development and to use an industry standard instead of something more homegrown.</p>
Working on dotnet core on Mac OS X part 2http://assertfail.gewalli.se/2018/09/05/Working-on-dotnet-core-on-Mac-OS-X-part-2.html
Wed, 05 Sep 2018 18:48:47 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2018/09/05/Working-on-dotnet-core-on-Mac-OS-X-part-2<p>After writing the <a href="http://assertfail.gewalli.se/2018/02/17/Working-on-dotnet-core-on-Mac-OS-X.html">previous post</a> about getting some of the infrastructure working for non Windows, I’ve seen better ways of getting it to work. In particular we have seen the use of <a href="https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/netfx.props">netfx.props</a> as seen in <a href="https://github.com/fsprojects/FSharp.TypeProviders.SDK">FSharp.TypeProviders.SDK</a>. Then you add the following to your csproj or fsproj file:</p>
<pre><code class="language-XML">&lt;Project Sdk="Microsoft.NET.Sdk"&gt;
&lt;Import Project="..\netfx.props" /&gt;
</code></pre>
<p>as can be seen in <a href="https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/src/FSharp.TypeProviders.SDK.fsproj">FSharp.TypeProviders.SDK.fsproj</a>.</p>
What makes for happy c#?http://assertfail.gewalli.se/2018/03/16/What-makes-for-happy-c.html
Fri, 16 Mar 2018 10:51:45 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2018/03/16/What-makes-for-happy-c<p>One of the questions I’ve started asking myself is what makes for happy C#? After a few years getting a bit more understanding of ML like languages like F# I’ve started to realise that C# is not built to write the kind of code that you write in an ML. Instead, you are happier when you embrace the Ruby-like patterns in C#. If you look at C# sort of like a typed Ruby like language: Object orientation, mutability first and meta programming using reflection. When you see that this is shared between the two languages then more things make sense. I’ve noticed that good Ruby code translates very easily to good C# (although <a href="https://github.com/wallymathieu/csharp_ukanren">not always</a>). Same is not true for good F# or Haskell.</p>
<p>Good Ruby code tries to keep a nice clean programming surface for the user (of a library).</p>
<p>Ruby is very object oriented. C# shares this trait since it is very adamant in that you need to have a class in order to have any code. Extension methods can be used to make a sort of monkey patching in C#. Monkey patching in Ruby can be dangerous, but applied right can help clean up your code. Same is true for extension methods. I would call a nice extension method to be polite: It only uses the extended type and any parameters sent in.</p>
<h2 id="architecture-that-fits-c-and-ruby">Architecture that fits C# and Ruby</h2>
<p>Having smaller libraries with their own solution means that it’s easier for people to reason about the code. There are some downsides of this approach though: You need to keep libraries in lockstep when introducing breaking changes during a larger refactoring. You need to be careful about what kind of public API surface you accidentally introduce. It’s easy to introduce leaky concepts (concepts and abstracts that require you to write code to deal with a specific concept in many different places).</p>
<p>Writing micro services is another way of splitting up your code base. However, you need to know when it’s worth putting something in a separate library and when it’s useful to have it in a service. A service can easily introduce latency and give you bad performance. If you try to follow <a href="https://martinfowler.com/bliki/BoundedContext.html">Marint Fowlers advice</a> and apply that to your microservices, you can have relatively separate services (that they don’t cause performance issues because of hard coupling requiring many buss events or http calls to complete actions).</p>
<p>Having relatively small services (but not to small), means that it can be easier to reason about mutable first procedural code. I find it very difficult to try to reason about large a large code base with mutable instances.</p>
<h2 id="deviations">Deviations</h2>
<p>Since we have static analysis available through the compiler, we can use that to define value types and wrap strings, ints, et.c. when dealing with many different small id-types or values that are easy to mix up. I.e. value types of a single value. In Haskell you call this a <a href="https://wiki.haskell.org/Newtype">Newtype</a>. In c# you need to do a bit <a href="https://github.com/NewtonsoftJsonExt/Saithe/blob/master/CSharpTypes/ProductId.cs">more work</a>. If you have many of these types, you might want to create a <a href="https://en.wikipedia.org/wiki/Text_Template_Transformation_Toolkit">t4-template</a> for it. In Ruby you would (due to the dynamic nature of the language) not need a template for it.</p>
Working on dotnet core on Mac OS Xhttp://assertfail.gewalli.se/2018/02/17/Working-on-dotnet-core-on-Mac-OS-X.html
Sat, 17 Feb 2018 12:13:55 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2018/02/17/Working-on-dotnet-core-on-Mac-OS-X<p>One thing I neglegted to mention was that there isn’t really out of the box editor support for targeting both <code class="highlighter-rouge">net45</code> and <code class="highlighter-rouge">netstandard1.6</code> (or higher versions).</p>
<p>My standard workaround for this have been to only target netstandard1.6 or lower for most of the relevant assemblies that I work on a day to day basis on. This works for most of the internal libraries since we deploy either <code class="highlighter-rouge">netcoreapp1.1</code> or <code class="highlighter-rouge">netcoreapp2.0</code> to Azure.</p>
<p>For libraries that are supposed to be <a href="https://github.com/gusty/FSharpPlus/blob/master/src/FSharpPlus/FSharpPlus.fsproj#L4">consumed by a wider set</a> that has been a bit of a pain to edit on Mac OS X.</p>
<p>If you try to open a .net core project that uses paket, the workaround to edit projects in Visual Studio for Mac is to <a href="https://developercommunity.visualstudio.com/content/problem/189500/visual-studio-for-mac-can-not-build-net-core-proje.html?childToView=191340">disable automatic package restore</a>.</p>
<p>The final workaround to be able to work <code class="highlighter-rouge">net45</code> and <code class="highlighter-rouge">netstandard1.6</code> dotnet core project on Mac OS X is to apply <a href="https://github.com/enricosada/dotnet-proj-info/blob/master/.travis.yml#L6-L8">@enricosada’s fix</a> to <code class="highlighter-rouge">.bash_profile</code>:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">export </span><span class="nv">FrameworkPathOverride</span><span class="o">=</span><span class="k">$(</span>dirname <span class="k">$(</span>which mono<span class="k">))</span>/../lib/mono/4.5/
</code></pre></div></div>
<p>This has made it possible to open for instance <a href="https://github.com/giraffe-fsharp/Giraffe">Giraffe</a> without doing any <a href="https://github.com/wallymathieu/Giraffe/tree/mono">other workaround</a> to have it working.</p>
Dotnet core a year laterhttp://assertfail.gewalli.se/2018/01/19/Dotnet-core-a-year-later.html
Fri, 19 Jan 2018 20:21:06 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2018/01/19/Dotnet-core-a-year-later<p>We asked the other developers in December 2016 what they wanted to work on. They said that they wanted to work on <a href="https://github.com/dotnet/core/blob/master/release-notes/1.0/1.0.0.md">dotnet core</a> and <a href="https://github.com/aspnet/Mvc">MVC</a>. I was a bit hesitant at first since that would imply using something relatively new to base the business on. <a href="https://github.com/tfsjohan">A cowoker</a> at the time did inject that he was using it in production already.</p>
<p>It has been an interesting journey. From json + xproj to a new csproj format. The nice thing about the new format is that it includes packages in the csproj. The file format has been cleaned up (so that we no longer need to use <a href="http://assertfail.gewalli.se/2016/10/04/Common-csproj-issues-that-can-be-detected-automatically.html">albacore</a>). Using NuGet is less painful compared to previously (I feel less of a need for <a href="fsprojects.github.io/Paket/">paket</a> but NuGet still have catching up to do). Though, there is still a bit of weirdness that make it difficult for people. I’m helping a dev get into asp.net Mvc 2. Due to lots of different blogs about asp.net Mvc, asp.net Mvc Core 1, asp.net Mvc Core 2. This is similar to what we see on for instance differences between different minor versions of Angular. As the documentation for Mvc on microsoft sites is quite good, it becomes less of an issue than for NG.</p>
<p>We have used <a href="https://docs.microsoft.com/en-us/ef/core/">EF Core 1-2</a>. I’ve previously used <a href="http://nhibernate.info/">NHibernate</a>. EF does not perform as well as NHibernate but is easier to start out with. I wish we had used <a href="https://github.com/StackExchange/Dapper">Dapper</a> since it’s easier to get performant and having to write SQL discourages the use of more complicated schemas. EF migrations doesn’t feel as elegant as some of the other <a href="https://github.com/fluentmigrator/fluentmigrator">migration frameworks</a>, it does however work well enough due to the fact that it can be used on the command line.</p>
<p>What has worked well has been to use <a href="https://github.com/domaindrivendev/Swashbuckle.AspNetCore">Swashbuckle.AspNetCore</a>. It helps with keeping documentation in sync and cuts down on the need for hand written API cruft.</p>
<p>A lot of the API’s have been improved in asp.net core. Default dependency injection and logging abstraction, et.c. has made the c# code more pleasant to work with. That the configuration is using dependency injection instead of global values makes it easier to reason about configuration.</p>
Running dotnet core 1.1 on appveyor and travishttp://assertfail.gewalli.se/2017/01/29/Running-dotnet-core-11-on-appveyor-and-travis.html
Sun, 29 Jan 2017 08:05:29 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2017/01/29/Running-dotnet-core-11-on-appveyor-and-travis<p>I wanted to see the state of EntityFramework on core. Turns out that it works on other platforms than Windows! NHibernate worked on mono as well as Windows, and now Entity Framework has caught up with that. However, EF Core is still somewhat limited as a ORM. This should not matter much if you are writing relatively simple SQL (LINQ) and have few relationships (so that you have less of a need for more advanced constructs). Many business apps do fall into this category if the requirements are made simple and clear (one source of complexity is fuzzy requirements leading to confused code).</p>
<h2 id="appveyor">appveyor</h2>
<p>Running .net core on appveyor turned out to be quite easy. They have already installed .net core 1.1 on their servers. All you need to do is to run the dotnet commands.</p>
<h2 id="net-core-official-travis-documentation">.net core official .travis documentation</h2>
<p>The first thing I tried was to try out a configuration based on the <a href="https://docs.travis-ci.com/user/languages/csharp/#Choosing-runtime-and-version-to-test-against">travis documentation</a> about running .net core on travis. This should work for a 1.0.0 version, however, I had depencies on core 1.1.0. Note that this type of configuration is also used by <a href="https://github.com/dotnet/docs/blob/master/.travis.yml">Enrico Sada in the dotnet docs</a>:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ dotnet test
Project Tests (.NETCoreApp,Version=v1.1) was previously compiled. Skipping compilation.
The specified framework 'Microsoft.NETCore.App', version '1.1.0' was not found.
- Check application dependencies and target a framework version installed at:
/usr/share/dotnet/shared/Microsoft.NETCore.App
- The following versions are installed:
1.0.0
- Alternatively, install the framework version '1.1.0'.
</code></pre></div></div>
<h2 id="trying-other-versions-of-dotnet-core-on-travis">Trying other versions of dotnet core on travis</h2>
<p>I tried with a later travis dotnet version:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dotnet: 1.0.0-preview2.1-003155
</code></pre></div></div>
<p>This resulted in:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>$ dotnet test
Project Tests (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
The specified framework 'Microsoft.NETCore.App', version '1.1.0' was not found.
- Check application dependencies and target a framework version installed at:
/usr/share/dotnet/shared/Microsoft.NETCore.App
- The following versions are installed:
1.1.0-preview1-001100-00
- Alternatively, install the framework version '1.1.0'.
</code></pre></div></div>
<h2 id="trying-the-scripts-from-ef-core">Trying the scripts from EF Core</h2>
<p>I tried to run a setup based on the <a href="https://github.com/aspnet/EntityFramework/blob/dev/.travis.yml">.travis.yml in the EF repository</a>. The scripts failed while running locally, so I abandonded that attempt early (perhaps they need environment in the repository that I’m missing).</p>
<h2 id="trying-out-scripts-from-blog">Trying out scripts from blog</h2>
<p>I tried running scripts found on <a href="http://andrewlock.net/adding-travis-ci-to-a-net-core-app/">Andrew Locks blog</a>. These failed with:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/home/travis/build/wallymathieu/entity-framework-studies/.dotnetcli/sdk/1.0.0-rc4-004706/NuGet.targets(210,5): warning MSB3202: The project file "/home/travis/build/wallymathieu/entity-framework-studies/Web/Web.xsproj" was not found. [/home/travis/build/wallymathieu/entity-framework-studies/entity-framework-studies.sln]
/home/travis/build/wallymathieu/entity-framework-studies/.dotnetcli/sdk/1.0.0-rc4-004706/NuGet.targets(210,5): warning MSB3202: The project file "/home/travis/build/wallymathieu/entity-framework-studies/Tests/Tests.xsproj" was not found. [/home/travis/build/wallymathieu/entity-framework-studies/entity-framework-studies.sln]
/home/travis/build/wallymathieu/entity-framework-studies/.dotnetcli/sdk/1.0.0-rc4-004706/NuGet.targets(97,5): warning : Unable to find a project to restore! [/home/travis/build/wallymathieu/entity-framework-studies/entity-framework-studies.sln]
</code></pre></div></div>
<p>and</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/home/travis/build/wallymathieu/entity-framework-studies/Tests/Tests.xproj(7,3): error MSB4019: The imported project "/home/travis/build/wallymathieu/entity-framework-studies/.dotnetcli/sdk/1.0.0-rc4-004706/Microsoft/VisualStudio/v14.0/DotNet/Microsoft.DotNet.Props" was not found. Confirm that the path in the &lt;Import&gt; declaration is correct, and that the file exists on disk.
</code></pre></div></div>
<p>Probably due to being for a previous version of dotnet core.</p>
<h2 id="trying-out-install-instructions">Trying out install instructions</h2>
<p>Instead of trying out travis specific instructions I tried to copy the <a href="https://www.microsoft.com/net/core#linuxubuntu">instructions found for installing net core on ubuntu</a>. Since these instructions are probably maintained, they worked without a glitch. I ended up with this version of .travis.yml:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>language: csharp
sudo: required
dist: trusty
addons:
apt:
packages:
- gettext
- libcurl4-openssl-dev
- libicu-dev
- libssl-dev
- libunwind8
- zlib1g
env:
global:
- DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
- DOTNET_CLI_TELEMETRY_OPTOUT: 1
mono:
- latest
os:
- linux
before_install:
- sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" &gt; /etc/apt/sources.list.d/dotnetdev.list'
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
- sudo apt-get update
install:
- sudo apt-get install dotnet-dev-1.0.0-preview2.1-003177
script:
- dotnet restore
...
</code></pre></div></div>
<h2 id="update">Update</h2>
<p>Note that the version I referenced while trying out the install documentation is higher than the version I tried out. Trimming the yml resulted in the following travis yml:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>language: csharp
sudo: false
dist: trusty
dotnet: 1.0.0-preview2.1-003177
mono:
- latest
os:
- linux
script:
...
</code></pre></div></div>
The usefulness of generalized regular expressionshttp://assertfail.gewalli.se/2016/10/12/The-usefulness-of-generalized-regular-expressions.html
Wed, 12 Oct 2016 18:30:07 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2016/10/12/The-usefulness-of-generalized-regular-expressions<p>It’s not obvious at first thought that there are applications for generalized regular expression engines. During my career, the regular kind has been the most prevalent kind. For certain problems, there is a simple pattern matching, that regular expressions excel at. For instance, in the case when you have a matrix with relatively regular content, it can be thought of as a general type of expressions. I’ve created the library <a href="https://github.com/wallymathieu/Zander">Zander</a> to help with that type of problem.</p>
Should you work with old technologies?http://assertfail.gewalli.se/2016/08/15/Should-you-work-with-old-technologies.html
Mon, 15 Aug 2016 05:49:37 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2016/08/15/Should-you-work-with-old-technologies<h2 id="why-should-a-coder-avoid-old-technologies">Why should a coder avoid old technologies?</h2>
<h3 id="large-complicated-systems-are-often-written-in-older-technologies">Large complicated systems are often written in older technologies</h3>
<p>Newer technologies can mean assignments with fewer lines of code and more greenfield development. Since the amount of code is proportional to the amount of time and people spent working on that code. Greenfield development is easier than working with millions of lines of code. It can however be an interesting challange to <a href="https://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052">rewrite an older system</a>.</p>
<h3 id="market-value">Market value.</h3>
<p>In order to sell consulting services, many people will push for new tech.</p>
<p>Since the market value of a coder is related to experience with the current technologies in use, knowing and working with new technologies is a good policy to stay competitive. This means that even regular employees will push for new technologies.</p>
<p>New tech may shift how you develop. For instance javascript performance improvements have made it feasible to run more logic browser side, causing a drive towards writing code more like regular server side code using ko, angular, react et.c.. Virtual machines performance that is close to native performance (<a href="https://en.wikipedia.org/wiki/Java_virtual_machine">JVM</a>, <a href="https://en.wikipedia.org/wiki/Common_Language_Runtime">CLR</a>) and the use of GC can simplify a lot of code (easier to work with) and create demand for different skills.</p>
<h3 id="writing-new-libraries">Writing new libraries</h3>
<p>Working in mature technologies can mean that the trailblazers have solved many of the problems. What’s left is to try to get patches for potentially unmaintained libraries. If you are one of the trailblazers you can increase your market value by providing a library that many people use (thus people get to know your name). You will need to market the library in order to gain attract developers to write pull requests and contribute issues. Good way of marketing a library is to present it during meetups or conferences.</p>
<h2 id="why-should-a-coder-avoid-untested-technologies">Why should a coder avoid untested technologies?</h2>
<h3 id="stability">Stability</h3>
<p>New code without tests or insufficient test coverage has a greater probability of bugs. As development of new things progress, the API’s will change until they mature. The maintainers may wish to iron out quirks from the API’s.</p>
<h3 id="learning-overhead">Learning overhead</h3>
<p>If the new technology is radically different from the old (angular vs jQuery), the amount of time spent learning impacts your ability to deliver. This cost can be sufficiently small if you know that you will have a lot of things to deliver (i.e. you know that you will spend enough time on the code). In order to avoid information overload you might want to have a mixture of known and unknown. Some developers are better at grokking new libraries and languages than others, but you still need to think about the team.</p>
<h3 id="trailblazer-moving-on-to-greener-pastures">Trailblazer moving on to greener pastures</h3>
<p>A trailblazer might want to move on to the next language after creating a few new library. Or if the technology becomes somewhat popular (without people that want to help out) the maintainer might not have enough time on their hands to support the library. This means that some libraries might become abandoned. Talk with the original author, sometimes they can be convinced to pass on the keys to NuGet, github et.c. as long as you are willing to help maintain the lib and review pull requests.</p>
What does technical debt mean for a project?http://assertfail.gewalli.se/2016/07/02/What-does-technical-debt-mean-for-a-project.html
Sat, 02 Jul 2016 06:20:29 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2016/07/02/What-does-technical-debt-mean-for-a-project<p>Technical debt is a concept that suggests that the cost of developing software has been postponed. For instance it can be the conscious act of delivering features while taking shortcuts (in order to get them delivered at a certain date).</p>
<h2 id="cost-in-time-related-to-technical-debt">Cost in time related to technical debt</h2>
<p>When changing a component, the amount of bugs introduced is often related to technical debt of that components. Higher technical debt means greater likelihood of bugs.</p>
<p>The time to resolve various issues is related to the technical debt. Technical debt will express itself in the sense that some tasks that should be simple to complete take a lot of time to finish.</p>
<p>Estimation: There is a risk that after something looks implemented, there are Y number of bugs to be found. It may mean that after one task seems to be done, issues and bugs related to the component will crop up where each issue take on average X amount of time to resolve.</p>
<p>If nothing is done to pay off technical debt, you have a situation where after an issue A1 you have Y bugs. Each bug takes an average X amount of time to resolve. After each bugfix there is a risk of a new bug. Since the technical debt is not repaid, we see that the average time X will increase. It means that you have a similar situation as when a person with a loan allows the interest rate to accumulate (ie debt increases).</p>
<h2 id="how-do-you-achieve-profitability-in-a-project-with-high-technical-debt">How do you achieve profitability in a project with high technical debt?</h2>
<p>Lower customer requirements in existing parts of the system. If you lack people that can hold off customer demands for changes in existing parts (requirements that entail greater complexity), customer requirements will drive increased costs.</p>
<p>Build separate modules where technical debt can be kept low. However, this can mean that the greatest cost (time spent) will be related to integration code (code to connect between things) between to connect modules of low technical debt with modules of high technical debt. However as long as you avoid changing modules with high technical debt, you can avoid cost increases.</p>
<p>Hire people that take a long term view (see the section about how to handle technical debt) in order to pay of the loan over time. Together with the developers, make sure that they create a long term plan for how to reduce the debt.</p>
<h2 id="what-does-technical-debt-mean-for-people-working-in-the-project">What does technical debt mean for people working in the project?</h2>
<p>The complexity and difficulties to deliver, can along with demands for quick deliveries create severe stress: Morality is reduced. This means that the probability of people leaving the project increases. The likelihood that people within the project burnout increases. What does this cost? <a href="http://www.dn.se/ekonomi/400-000-kronor-kostnaden-for-en-utbrand-medarbetare/">According to DN</a>, it can end up at about 400 000 SEK (ca 40 000 EUR).</p>
<h2 id="how-do-you-handle-technical-debt">How do you handle technical debt?</h2>
<ul>
<li>Doing code reviews with experienced developers</li>
<li>Automatic testing to reduce the likelihood of regression</li>
<li>Requirements management: ensure that the requirements reduce complexity (eg by having a dialogue to arrive at simpler solutions)</li>
<li>By identifying the problem through different tools and working to isolate or remove the parts of the code that need to be changed due to customer requirements</li>
<li><a href="http://martinfowler.com/books/refactoring.html">Refactor</a> parts that are covered by tests</li>
<li>Create new modules that <a href="http://www.martinfowler.com/bliki/StranglerApplication.html">strangle old parts of the system</a></li>
</ul>
<h3 id="how-do-you-identify-the-problem">How do you identify the problem?</h3>
<p>Static code analysis can help identify problem areas. For example .net are:</p>
<ul>
<li><a href="http://www.ndepend.com/">NDepend</a></li>
<li><a href="http://www.sonarqube.org/">sonarqube</a> is able to analyse c# code (with some effort).</li>
<li><a href="https://www.jetbrains.com/resharper/features/command-line.html">Resharper</a></li>
<li>Selected rules in StyleCop</li>
</ul>
<p>Test coverage percentage can give you a picture of the areas where changes have higher probability of regression (ie can result in extra work).</p>
Common enterprise architectureshttp://assertfail.gewalli.se/2016/06/03/Common-enterprise-architectures.html
Fri, 03 Jun 2016 18:24:52 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2016/06/03/Common-enterprise-architectures<p>Some patterns I’ve usually encountered while working code bases written by .net developers. You can also read more on <a href="https://msdn.microsoft.com/en-us/library/ee658117.aspx">msdn</a>.</p>
<h2 id="domain-driven-design-inspired"><a href="https://en.wikipedia.org/wiki/Domain-driven_design">Domain driven design</a> inspired</h2>
<p>Usually you find classes with postfix name like:</p>
<ul>
<li>Repository : List like interface for working with persisted data. Usually state of fetched objects is tracked, so you can do <code class="highlighter-rouge">customerContext.Save()</code> to persist changes to objects.</li>
<li><a href="https://en.wikipedia.org/wiki/Service_(systems_architecture)">Service</a></li>
</ul>
<h3 id="related-concepts">Related concepts</h3>
<p>People are often confused by “Unit of work” also mentioned in connection to these patterns. Many OR-mappers implement the repository pattern. Popular libraries include <a href="http://www.asp.net/entity-framework">Entity Framework</a>, <a href="http://nhibernate.info/">NHibernate</a> and <a href="https://ravendb.net/">RavenDB</a> (library and database).</p>
<h3 id="key-concept">Key concept</h3>
<p>The key point of DDD is ubiquitous Language. Being able to have roughly the same type of concepts as the users can be very helpful.</p>
<h2 id="dal"><a href="https://msdn.microsoft.com/en-us/library/ee658127.aspx">DAL</a></h2>
<p>This type of architecture is quite simple. The main benefit of it is that it’s easy for people to grok. This type of architecture is not as popular anymore because it increases the amount of code you have to write.</p>
<ul>
<li>Manager : An object that does things by using other managers and accesses the data using DAL</li>
<li>DAL : Data access layer. State for fetched objects is not tracked. You have to make the DAL aware of changes <code class="highlighter-rouge">customerDAL.Update(customer);</code></li>
<li>DTO : Data transfer object.</li>
</ul>
<p>In this type of architecture it’s not uncommon to have an additional layer in the database implemented by stored procedures.</p>
<h2 id="message-queue--service-bus">Message queue &amp; Service Bus</h2>
<p>Popular choices I’ve encountered are <a href="https://en.wikipedia.org/wiki/RabbitMQ">RabbitMQ</a> and <a href="https://en.wikipedia.org/wiki/Microsoft_Message_Queuing">MSMQ</a>. A popular library is <a href="https://github.com/MassTransit/MassTransit">MassTransit</a>.</p>
<p>Provides a way to lower cohesion between components. Can also be helpful if you want to <a href="http://www.rabbitmq.com/tutorials/tutorial-two-python.html">distribute work</a>.</p>
Merging in svnhttp://assertfail.gewalli.se/2016/05/29/Merging-in-svn.html
Sun, 29 May 2016 11:46:21 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2016/05/29/Merging-in-svn<p>While working as a consultant at a company that uses svn, I needed to keep a branch in sync with the master branch. This turns out to be a lot of work.</p>
<p>Problem was that it was not possible to just clone the repository using git svn. The clone failed after a while (I think due to the long connection time). First you might want to read up on it from <a href="http://andy.delcambre.com/2008/03/04/git-svn-workflow.html">this blog post</a>.</p>
<p>The command I used was something like:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git svn clone -r 10327 --username=oskar.gewalli http://company.com/scm/svn/Project project --stdlayout --prefix=svn/
</code></pre></div></div>
<p>In order to fetch changes I did:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git svn rebase
</code></pre></div></div>
<p>And to push changes:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git svn dcommit
</code></pre></div></div>
<p>Since I could not clone the repository and get the full branches, I had to add branches manually. It took little bit of work but was described on <a href="http://stackoverflow.com/questions/296975/how-do-i-tell-git-svn-about-a-remote-branch-created-after-i-fetched-the-repo">stackoverflow</a>.</p>
<p>The value of this work is that merging branches is far easier in git compared to svn.</p>
Going deeper into angularhttp://assertfail.gewalli.se/2016/04/12/Going-deeper-into-angular.html
Tue, 12 Apr 2016 17:32:58 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2016/04/12/Going-deeper-into-angular<p>After getting to know details about ng for the last months, I’ve come to appreciate some of the features of angular. You can write quite clean looking code if you know enough ng. From my personal point of preference, <a href="https://docs.angularjs.org/api/ng/type/$rootScope.Scope">“scope”</a> is a bit all over the place. I remember using angular for small project in 2012 not thinking much of it (angularjs shines for projects with a limited complexity).</p>
<h3 id="before-trying-to-write-an-angular-app">Before trying to write an angular app</h3>
<p>In order to get sort of a grasp of it there are things that you should read like <a href="https://github.com/johnpapa/angular-styleguide/tree/master/a1#controlleras-view-syntax">ng patterns</a>. Some of these things won’t make sense until you understood some ng weirdness:
<a href="http://jimhoskins.com/2012/12/14/nested-scopes-in-angularjs.html">nested scopes in angularjs</a>
You may also need read up on the opposition: <a href="https://larseidnes.com/2014/11/05/angularjs-the-bad-parts/">angularjs the bad parts</a>.</p>
<h3 id="understanding-angularjs">Understanding angularjs</h3>
<p>Once you have read these things, you should be able to make some sense of the <a href="https://github.com/angular/angular.js">ng1</a> and <a href="https://github.com/angular/angular">ng2</a> code bases. There is quite a lot of documentation mixed in with the source (used to generate the api docs). It’s probably better to start to read the code from the point of the api docs (if you know what area you’re interested in), since <a href="https://github.com/angular/angular.js/blob/a4e60cb6970d8b6fa9e0af4b9f881ee3ba7fdc99/src/ngCookies/cookieStore.js">some of the code</a> has more documentation than code. If you are planning to write something bigger (&gt;10k lines) in typescript, it can be worth to take a look at the ng2 code base since it’s an open source example of a large typescript code base and <a href="https://github.com/angular/angular/blob/df1f78e302e75244a71045e02ec76b7a7d8b8e8f/modules/angular2/src/common/directives.ts">scripting language usage of files</a>.</p>
<h3 id="the-future">The future</h3>
<p>There is a lot of focus on <a href="https://docs.angularjs.org/guide/component">components</a> in angular2. In earlier versions (prior to ng 1.5) you can achieve similar type of code by creating directives composed of template and controller.</p>
<p>My guess is that angularjs will have a sort of stable position (but it’s definatelly not hip anymore).</p>
Clean your work area!http://assertfail.gewalli.se/2016/01/24/Clean-your-work-area.html
Sun, 24 Jan 2016 06:34:44 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2016/01/24/Clean-your-work-area<p>When in the kitchen, how are you behaving to old dishes? Do you make space in order to have space to cook the food? After finished cooking the food, do you leave dirty dishes to the next day?</p>
<p>I’ve worked in a couple school kitchen. When I worked, it would be in the form:</p>
<ul>
<li>make sure that there are nothing cluttering the kitchen that shouldn’t be there</li>
<li>make sure that the kitchen is clean</li>
<li>prepare food and put food and milk in place for the children</li>
<li>do dishes</li>
<li>clean up the kitchen</li>
</ul>
<p>I’ve worked a few months in a mechanical workshop. My boss told me how to work:</p>
<ul>
<li>make sure that the area where you are going to work is uncluttered and clean</li>
<li>work</li>
<li>make sure to put back all the tools</li>
<li>put any unused materials back to storage</li>
<li>clean up the work area</li>
</ul>
<p>My grandfather (engineer and architect) told me how to behave in his workshop:</p>
<ul>
<li>clean up the table, make sure you have space to work</li>
<li>work</li>
<li>clean up the table</li>
</ul>
<p>In his mind, if you go for lunch, then work is considered finished (so you need to clean up before going to lunch).</p>
<p>In software development it’s not unusual to try to ignore the cleaning part of the job. Why is this considered OK? Will the job be easier if you have to slog through:</p>
<ul>
<li>commented out code</li>
<li>comments that are unmaintained</li>
<li>debug code</li>
<li>dead code</li>
<li>uncommunicative function names</li>
</ul>
<p>and the list goes on.</p>
<p>Why do you avoid to follow even the boy scout rule of leaving it a little better than you found it? Perhaps it’s because you have no sense of <a href="http://blog.codinghorror.com/code-smells/">code smell</a>? Perhaps it’s because you’re stressed? You’re a junior developer?</p>
<p>The thing about code is that once you have a clean working area (clean part of the code base where you are working), is that changes and additions will become easier to implement. Fewer things to keep in mind will keep your <a href="https://en.wikipedia.org/wiki/The_Magical_Number_Seven,_Plus_or_Minus_Two">working memory</a> focused.</p>
Divide and conquerhttp://assertfail.gewalli.se/2016/01/16/Divide-and-conquer.html
Sat, 16 Jan 2016 12:06:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2016/01/16/Divide-and-conquer<p>This approach to programming is not only useful for algorithms, it’s also a recurring architectural theme. The current versin is called microservices. In unix you have the small command line tools that does one thing well. On a smaller scale it’s about splitting your code inte several files and then folders. When you have identified a need for a library you might create a nuget, gem, maven or npm package (see <a href="http://www.modulecounts.com/">modulecount</a>).</p>
Inheritance in javascripthttp://assertfail.gewalli.se/2015/12/11/Inheritance-in-javascript.html
Fri, 11 Dec 2015 16:06:44 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/12/11/Inheritance-in-javascript<h1 id="how-do-you-inherit-from-a-class-in-javascript">How do you inherit from a “class” in javascript</h1>
<p>Especially if you have a class that is a mix of constructor function and prototype methods and properties.</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="s2">"use strict"</span><span class="p">;</span>
<span class="kd">function</span> <span class="nx">getSeq</span><span class="p">(</span><span class="nx">start</span><span class="p">){</span>
<span class="k">return</span> <span class="kd">function</span> <span class="nx">next</span><span class="p">(){</span>
<span class="k">return</span> <span class="nx">start</span><span class="o">++</span><span class="p">;</span>
<span class="p">};</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">getId</span> <span class="o">=</span> <span class="nx">getSeq</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
<span class="kd">function</span> <span class="nx">Mammal</span><span class="p">(</span><span class="nx">name</span><span class="p">){</span>
<span class="kd">var</span> <span class="nb">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
<span class="kd">var</span> <span class="nx">id</span> <span class="o">=</span> <span class="nx">getId</span><span class="p">();</span> <span class="c1">// private variable </span>
<span class="k">this</span><span class="p">.</span><span class="nx">getId</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span>
<span class="k">return</span> <span class="nx">id</span><span class="p">;</span>
<span class="p">};</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">'name'</span><span class="p">,</span> <span class="p">{</span> <span class="c1">// we want name to be mutable</span>
<span class="na">get</span><span class="p">:</span><span class="kd">function</span> <span class="p">(){</span> <span class="k">return</span> <span class="nx">name</span><span class="p">;</span> <span class="p">},</span>
<span class="na">set</span><span class="p">:</span><span class="kd">function</span> <span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span> <span class="nx">name</span> <span class="o">=</span> <span class="nx">value</span><span class="p">;</span> <span class="p">}</span>
<span class="p">});</span>
<span class="k">this</span><span class="p">.</span><span class="nx">_old_name</span> <span class="o">=</span> <span class="nx">name</span><span class="p">;</span> <span class="c1">// this value will be immutable</span>
<span class="c1">// we want for the object to implement the same interface</span>
<span class="c1">// this is a way to make objects more like java or c# objects</span>
<span class="nb">Object</span><span class="p">.</span><span class="nx">freeze</span><span class="p">(</span><span class="k">this</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">Mammal</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">says</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span> <span class="c1">// but we can still add functions by adding to the prototype</span>
<span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">saying</span> <span class="o">||</span> <span class="s1">''</span><span class="p">;</span>
<span class="p">};</span>
</code></pre></div></div>
<h2 id="some-notes-about-the-above-code">Some notes about the above code</h2>
<p>We (me and <a href="https://github.com/2hdddg/">Peter Wilhelmsson</a>) have found that the usage of “use strict” together with Object.freeze and Object.defineProperty can some javascript confusion (accidentally setting a new variable when you want to set an existing, hard to find initialization of objects). Usually as with many old languages with many features (c++, perl) you should choose a subset of that language to simplify for other developers.</p>
<p>By modifying the prototype you can always add methods even if the object itself is frozen.</p>
<h2 id="how-do-you-create-an-instance-of-this-class">How do you create an instance of this “class”?</h2>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">var</span> <span class="nx">m</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Mammal</span><span class="p">(</span><span class="s1">'Missan'</span><span class="p">);</span>
</code></pre></div></div>
<h2 id="how-do-we-inherit-from-this-class">How do we inherit from this “class”?</h2>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="s2">"use strict"</span><span class="p">;</span>
<span class="kd">function</span> <span class="nx">Feline</span><span class="p">(</span><span class="nx">name</span><span class="p">){</span>
<span class="kd">var</span> <span class="nb">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">saying</span> <span class="o">=</span> <span class="s1">''</span>
<span class="c1">// the last thing we do is call the base class in order to inherit and freeze this class</span>
<span class="nx">Mammal</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span><span class="nx">name</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">Feline</span><span class="p">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">Mammal</span><span class="p">.</span><span class="nx">prototype</span><span class="p">);</span> <span class="c1">// we want the methods and properties added through prototype</span>
<span class="nx">Feline</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="kd">constructor</span> <span class="o">=</span> <span class="nx">Feline</span><span class="p">;</span> <span class="c1">// but still have the correct constructor</span>
<span class="kd">function</span> <span class="nx">Cat</span><span class="p">(</span><span class="nx">name</span><span class="p">){</span>
<span class="kd">var</span> <span class="nb">self</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
<span class="nx">Feline</span><span class="p">.</span><span class="nx">apply</span><span class="p">(</span><span class="k">this</span><span class="p">,</span><span class="kr">arguments</span><span class="p">);</span>
<span class="p">}</span>
<span class="nx">Cat</span><span class="p">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">(</span><span class="nx">Feline</span><span class="p">.</span><span class="nx">prototype</span><span class="p">);</span>
<span class="nx">Cat</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="kd">constructor</span> <span class="o">=</span> <span class="nx">Cat</span><span class="p">;</span>
</code></pre></div></div>
<h2 id="naming-of-javascript-classes">Naming of javascript classes</h2>
<p>Note that when you write:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">namespace</span><span class="p">.</span><span class="nx">Name</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(){</span> <span class="p">}</span>
</code></pre></div></div>
<p>This becomes an anonymous function (in many browsers). In order to give it a name we need to write it like:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">namespace</span><span class="p">.</span><span class="nx">Name</span> <span class="o">=</span> <span class="kd">function</span> <span class="nx">namespace_Name</span><span class="p">(){</span> <span class="p">}</span>
</code></pre></div></div>
<p>This can be done as a post processing step in your grunt or gulp with logic similar to the following:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="s2">"namespace.FunctionName = function() {};"</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span>
<span class="sr">/namespace.</span><span class="se">([^</span><span class="sr"> </span><span class="se">]</span><span class="sr">+</span><span class="se">)</span><span class="sr"> *</span><span class="se">\=</span><span class="sr"> *function *</span><span class="se">\(</span><span class="sr">/</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">str</span><span class="p">,</span> <span class="nx">gr</span><span class="p">){</span>
<span class="k">return</span> <span class="s2">"namespace."</span><span class="o">+</span><span class="nx">gr</span><span class="o">+</span><span class="s2">" = fucntion namespace_"</span><span class="o">+</span><span class="nx">gr</span><span class="o">+</span><span class="s2">"("</span><span class="p">;</span>
<span class="p">});</span>
</code></pre></div></div>
<h2 id="using-pure-prototype-inheritance">Using pure prototype inheritance</h2>
<p>If you are using a library that does the right thing when it comes to “this”, then you can add methods to the prototype instead of “this” as a captured variable named “self”.</p>
webforms and confusionhttp://assertfail.gewalli.se/2015/10/30/webforms_and_confusion.html
Fri, 30 Oct 2015 11:41:16 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/10/30/webforms_and_confusion<h2 id="webforms-and-3000-lines-of-codebehind">webforms and 3000 lines of codebehind</h2>
<p>I’ve noticed that the common failures while using asp.net webforms is related to people getting confused about the asp.net page and control life cycle. Since there are so many different events to keep in mind, it’s easy to place code in the wrong place and get something that sort of works (but does not work in all cases). If you are stressed, you might add a small if statement to fix this problem in the special case, increasing complexity in the code behind file. This then turns into 1000-3000 lines of hard to read c#. I’ve found that building small user controls that are built according to how you should build user controls, can help you avoid this mess (the technical lead at Macom when I worked there pushed for this). This requires you to learn how to write user controls though.</p>
<p>I get the feeling that it’s not unusual for developers have a hard time understanding how to interact with different components written in different files. Maybe this is why junior developers using this type of code can create a hard to change architecture: large files with a lot of interconnected logic inside each file.</p>
<h2 id="mvc-and-javascript">mvc and javascript</h2>
<p>Writing asp.net mvc is conceptually easier (there are fewer things to learn, since the focus is different). However, if you want the same functionality you might have to add some javascript in order to get an app (as you get in asp.net). I have found that most developers get confused when reading and writing javascript (unless they have enough experience using it). This confusion can be mitigated by using a subset of javascript or a transpiler (problem is that you need someone in the team that knows javascript in order to be able to make informed decisions about it). In some cases you might write more javascript in order to reduce the overall complexity.</p>
<h2 id="javascript-maturity">javascript maturity</h2>
<p>I find that the difference between c# and java is relatively minor right now. The main feature I missed in java has been lambdas (or lambda like syntax). Ruby, python and php all are similar in the sense that they have sort a class concept and that you can inherit from other classes. There is something like “this”, so that you can access the object. In javascript however, “this” does not mean the current object (it can be, but it’s not always the case). However, since most serverside developers are forced to learn javascript in order to complete most assignemnts, I would imagine that many developers know javascript and one of the other languages that are more similar.</p>
<p>We see many concepts that have been promoted serverside entering clientside applications as well. When working with a larger javascript codebase then the problems that you face will be familiar to working with a large serverside codebase.</p>
<h2 id="conclusion">conclusion</h2>
<p>What could the conclusion be from this? If we see es6 with classes and modules and the adoption of frameworks that work with objects that use this their functions to access the object itself, then programming javascript compared to server side will feel less different. Some of the javascript frameworks out there require you to learn many things (and are then compared to webforms). My feeling is that it’s probably better to avoid larger frameworks like angular and extjs (unless you and your team is prepared to learn a lot of things). It’s better to use well known small and stable libraries (I’ve heard the same opinion being voiced by others so this is nothing new).</p>
ruby on windowshttp://assertfail.gewalli.se/2015/10/16/ruby-on-windows.html
Fri, 16 Oct 2015 05:57:52 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/10/16/ruby-on-windows<p>I’ve had some trouble installing gems on windows instances using <code class="highlighter-rouge">bundle install</code>. I had this problem first at ~2009. The problem is <a href="https://gist.github.com/luislavena/f064211759ee0f806c88">missing certificates</a>.</p>
<p>While this fix is correct, a quick and dirty approach is to make sure that your gem files have source http instead of https:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># A sample Gemfile</span>
<span class="n">source</span> <span class="s2">"http://rubygems.org"</span>
<span class="n">gem</span> <span class="s1">'albacore'</span>
<span class="n">gem</span> <span class="s1">'nuget_helper'</span>
</code></pre></div></div>
<p>This means that the communication to download gems from rubygems is not private.</p>
Mono and OS X El Capitanhttp://assertfail.gewalli.se/2015/10/16/Mono-and-OS-X-El-Capitan.html
Fri, 16 Oct 2015 05:32:05 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/10/16/Mono-and-OS-X-El-Capitan<p>After installing OS X El Capitan on my computer I noticed that fsharp interactive failed to start because it failed to locate mono:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>/Library/Frameworks/Mono.framework/Versions/4.0.4/bin/fsharpi: line 24: exec: mono: not found
Session termination detected. Press Enter to restart.
</code></pre></div></div>
<p>If we look at the file at that position we find that it assumes that mono is in the path. I checked /etc/paths, and it looked correct (i.e. based on the paths file, mono should have been in the path):</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mathieu$ which mono
/usr/local/bin/mono
mathieu$ ls -la /usr/local/bin/mono
lrwxr-xr-x 1 mathieu admin 48 Sep 12 21:56 /usr/local/bin/mono -&gt; /Library/Frameworks/Mono.framework/Commands/mono
</code></pre></div></div>
<p>I’ve found that there is a <a href="http://stackoverflow.com/questions/32806615/xamarins-f-interactive-pad-cannot-find-mono">stackoverflow answer</a>. I opted for a somewhat different approach and created a file in my ~/bin folder with essentially the same fix (this was before the stackoverflow answer, so it’s not exactly alike). You can find it <a href="https://gist.github.com/wallymathieu/99d20a5090f9691e38e0">here</a>.</p>
<p>After that I changed the xamarin studio f# interactive settings so that the path is ~<del>/Users/mathieu/bin/fsharpi</del>~.</p>
<p>I’m thinking that later on I want to change the settings for fsharpi and fsharp to point to a local nuget repository (containg a paket.dependencies file) with <a href="https://www.nuget.org/packages/FSharp.Compiler.Tools">FSharp.Compiler.Tools</a> installed.</p>
Using owin to implement an apihttp://assertfail.gewalli.se/2015/08/31/Using-owin-to-implement-an-api.html
Mon, 31 Aug 2015 15:52:32 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/08/31/Using-owin-to-implement-an-api<p>I tried implementing the same customer service xml api that I’ve implemented in sinatra, rails, c# webhandler, nancy etc. I was pleasently surprised how easy it is to get it up and running. There is a story for how you write tests: <a href="https://msdn.microsoft.com/en-us/library/microsoft.owin.testing.testserver(v=vs.113).aspx">TestServer</a>, that you install by referencing <a href="https://www.nuget.org/packages/Microsoft.Owin.Testing/">Microsoft.Owin.Testing</a>.</p>
<p>Previous times that I’ve tried using Owin on mono, there has been some problems getting it to run (I think it was something related to a missing dll). Now it works fine. :)</p>
<p>You can find the code here: <a href="https://github.com/wallymathieu/CustomerService/tree/master/owin">CustomerService/Owin</a></p>
path unshift dirname of filehttp://assertfail.gewalli.se/2015/08/31/path-unshift-dirname-of-file.html
Mon, 31 Aug 2015 12:17:46 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/08/31/path-unshift-dirname-of-file<p>Instead of using:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="vg">$:</span><span class="p">.</span><span class="nf">unshift</span> <span class="no">File</span><span class="p">.</span><span class="nf">dirname</span><span class="p">(</span><span class="kp">__FILE__</span><span class="p">)</span>
</code></pre></div></div>
<p>to add a folder to the path, a better way inside your ruby code is to use:</p>
<div class="language-ruby highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">require_relative</span> <span class="s1">'subfolder/file'</span>
</code></pre></div></div>
<p>in order to require files. You can also use a relative path in require (i.e. ‘./subfolder/file’).</p>
BDD style testing in qunithttp://assertfail.gewalli.se/2015/08/31/BDD-style-testing-in-qunit.html
Mon, 31 Aug 2015 08:52:38 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/08/31/BDD-style-testing-in-qunit<p>Before the vacation I was working with <a href="https://twitter.com/HerrAdriansson">Karl Adriansson</a> on a project as the front end programmer. I helped get a front end javascript parts back on track. While doing this, Karl and one of the testers supplied me with specifications from the requirements. Since the specifications where very detailed, It was very easy to transform them into sort of BDD style tests:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">test</span><span class="p">(</span><span class="s2">"PROJ-783"</span><span class="p">,</span> <span class="kd">function</span> <span class="p">(){</span>
<span class="kd">var</span> <span class="nx">ctx</span> <span class="o">=</span> <span class="nx">given_a_customer_previously_bought</span><span class="p">(</span><span class="nx">black_sweater</span><span class="p">());</span>
<span class="nx">and_I_currently_have_X_of_Y_in_stock</span><span class="p">(</span><span class="nx">ctx</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="nx">black_sweater</span><span class="p">());</span>
<span class="nx">when_he_returns_product_X_for_refund</span><span class="p">(</span><span class="nx">ctx</span><span class="p">,</span> <span class="nx">black_sweater</span><span class="p">());</span>
<span class="nx">then_I_should_have_X_of_Y_products_in_stock</span><span class="p">(</span><span class="nx">ctx</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="nx">black_sweater</span><span class="p">());</span>
<span class="p">});</span>
</code></pre></div></div>
<p>Note that I’ve taken the specification from <a href="https://en.wikipedia.org/wiki/Behavior-driven_development">wikipedia</a> in order to have a meaningful sample. We used the convention of writing the jira id as the test name in order to know from where the specification came.</p>
<p>Since we are using ordinary language constructs (methods that take parameters), the level of abstraction here is relatively low. Many of the helper methods can in many cases be reused since you might have many specifications related to the same subdomain. Some of the helper methods will only be used once. In some cases you might want to drop some of the prefixes in order to avoid to much duplication.</p>
Build tools and package managers for .nethttp://assertfail.gewalli.se/2015/08/27/Build-tools-and-package-managers.html
Thu, 27 Aug 2015 10:49:54 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/08/27/Build-tools-and-package-managers<h1 id="what-criteria-do-i-use">What criteria do I use</h1>
<p>I prefer for the build tool to work on both *nix and windows. I do some of the .net coding on os x. The build systems mentioned here are all related to working with .net (and all except psake work in *nix).</p>
<h1 id="if-you-are-coding-net">If you are coding .net</h1>
<h2 id="what-package-manager-to-use">What package manager to use?</h2>
<p>Right now there is NuGet. There is no good reason why you should deviate from using that format. However, you can choose to use NuGet.exe, NuGet in visual studio with packages.config files or use <a href="https://github.com/fsprojects/Paket">paket</a> with ‘paket’ files.</p>
<p>Paket assumes that you want to have the same version of a package in all your projects in a solution. There is also a bootstrapper so that you don’t need to install NuGet.exe on you build environment or add it to the repository (the paket.bootstrapper is only 27.5KB). Paket and <a href="http://fsharp.github.io/FAKE/">FAKE</a> makes a nice package (an example can be found <a href="https://github.com/wallymathieu/CustomerService/tree/master/suave">here</a>).</p>
<h2 id="what-build-tool-to-use">What build tool to use?</h2>
<p>I would generally unless there is some good reason avoid writing msbuild files. They are better suited to describe projects (csproj).</p>
<h3 id="gulp-its-grunt">Gulp it’s Grunt</h3>
<p>Since there is a lot of tools available for web developers that leverage grunt, many .net developers use grunt. It works, the api is a bit odd (json can be used to configure tasks). If you code js for other reasons, then the callbacks will probably not bother you. Note that there is another js build tool called gulp. Gulp is smaller and more focused on streaming builds (if you have looked at the ideas from reactive extensions you will find it familiar).</p>
<p>I’ve tried to use grunt. Node is quite easy to install on windows.</p>
<h3 id="rake">Rake</h3>
<p>I prefer to use ruby’s make like tool rake for building open source c# apps since I usually have ruby installed wherever I work. Rake has some nice syntax that looks quite clean. It requires you to know some ruby though.</p>
<p>Usually when using ruby you will want to use <a href="http://bundler.io/">bundler</a> to manage dependencies.</p>
<h3 id="faking-it">Faking it?</h3>
<p>Fake is a build tool where you write f# scripts. For f#-project this feels like a nice way to go. Fake is delivered by NuGet (so you won’t need anything extra installed). It requires you to know some f#.</p>
<p>It works well under mono. I’ve not had any troubles with it.</p>
<p>The syntax is a bit unfamiliar, but that can be the case with f# written APIs (using operators like ==&gt; or »=).</p>
<h3 id="psake">PSake</h3>
<p>Writing build scripts in powershell. This makes a lot of sense. Many times when you write build scripts, you are scripting windows servers as well; so you will have some experience using powershell. However, powershell is a bit of an odd language compared to many other common languages.</p>
<p>If you are doing windows only work, then this tool is valid.</p>
<h3 id="the-cake-is-alive">The Cake is alive?</h3>
<p>There are many different c# build tools. The most popular right now looks to be <a href="https://github.com/cake-build/cake">Cake</a>. You don’t have to install cscript in order to <a href="https://github.com/cake-build/cake">Cake</a> or <a href="https://github.com/yevhen/Nake">Nake</a>, but can download a .net exe from NuGet. You can use this exe to execute build script files. <a href="https://github.com/sakeproject/sake">Sake</a> is installed via chocolatey. Cake-files are actually a different language: a superset of c#. This means that visual studio and monodevelop etc wont work as expected. It will let you write build scripts in a c#-y syntax.</p>
FSharpx.Extrashttp://assertfail.gewalli.se/2015/08/23/FSharpxExtras.html
Sun, 23 Aug 2015 18:44:46 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/08/23/FSharpxExtras<p>Turns out that there is a simpler way of dealing with optional values in c#.</p>
<p>Include FSharpx.Extras to your c# project and then you can do the following:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>optionalValue.Match(
ifSome: value =&gt; ProcessValue(value),
ifNone: () =&gt; NoValueToProcess()
);
</code></pre></div></div>
<p>Thanks to extension methods in this library. There are extension methods for other common discriminated unions as well.</p>
f# 2 weeks laterhttp://assertfail.gewalli.se/2015/08/21/fsharp-2-weeks-later.html
Fri, 21 Aug 2015 15:17:39 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/08/21/fsharp-2-weeks-later<p>Since I’ve been without an assingment I’ve had the time to look into f# more.</p>
<h2 id="where-did-i-find-material">Where did I find material?</h2>
<ul>
<li><a href="http://fsharpforfunandprofit.com/">fsharpforfunandprofit</a></li>
<li><a href="http://fpchat.com/">functional programming on slack</a></li>
<li>stackoverflow</li>
</ul>
<h2 id="why-did-i-start-looking-into-f-again">Why did I start looking into f# again?</h2>
<p>I share the office with <a href="https://github.com/wastaz">Fredrik Forssen</a>. I find his love of f# inspiring.</p>
<h2 id="things-ive-found-that-delighted-me">Things I’ve found that delighted me:</h2>
<ul>
<li>Less ceremony to declare classes, records, methods and functions (when you get used to how you write it)</li>
<li>Easier to compose things (for instance if you want to create a chain in order to use many different classes together for an import)</li>
<li>Monad support (and yes, I know that these things can very easily be abused)</li>
<li>Package manager and Build tool that works well together (<a href="https://github.com/fsprojects/Paket">paket</a> and <a href="https://github.com/fsharp/FAKE">fake</a>).</li>
<li>Records defined in f# are like hand coded readonly classes with IEquatable and IComparable implemented</li>
</ul>
<h2 id="ive-previously-found-the-following-sweet-when-looking-at-the-language">I’ve previously found the following sweet when looking at the language:</h2>
<ul>
<li>Immutable by default</li>
<li>Language construct to create a clone of a record but with different values for some fields</li>
<li>Language construct to match more than hard coded strings, enums and integers</li>
</ul>
<h2 id="what-is-kind-of-annoying-about-the-language-and-tools-related-to-it">What is kind of annoying about the language (and tools related to it)</h2>
<ul>
<li>If you forget to add an equals sign to a type or module declaration you get weird compiler errors</li>
<li>Gui tooling is still a bit alpha (the command line version works great)</li>
<li>It’s easy to create a f# project where you need to manually edit the fsproj file in order to get it to work on mono and windows (this was a problem in the early days of NuGet)</li>
<li>Almost all the library methods in .net becomes a tuple parameter in f#, this is a bit confusing since it looks like an ordinary function call in c#</li>
<li>Exposing f# Option on your types makes it harder to interact with your f# code from c#</li>
</ul>
<div class="language-c# highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="k">using</span> <span class="nn">OptionalUrl</span> <span class="p">=</span> <span class="n">Microsoft</span><span class="p">.</span><span class="n">FSharp</span><span class="p">.</span><span class="n">Core</span><span class="p">.</span><span class="n">FSharpOption</span><span class="p">&lt;</span><span class="n">Customers</span><span class="p">.</span><span class="n">Url</span><span class="p">&gt;;</span>
<span class="p">...</span>
<span class="kt">var</span> <span class="n">customer</span> <span class="p">=</span> <span class="k">new</span> <span class="nf">Customer</span><span class="p">(</span>
<span class="p">...</span>
<span class="n">pictureUri</span><span class="p">:</span> <span class="n">OptionalUrl</span><span class="p">.</span><span class="nf">Some</span><span class="p">(</span><span class="k">new</span> <span class="nf">Url</span><span class="p">(</span><span class="s">"http://someurl.com/something?some=asd"</span><span class="p">))</span>
<span class="p">);</span>
</code></pre></div></div>
Working with spreadsheetshttp://assertfail.gewalli.se/2015/06/07/Working-with-spreadsheets.html
Sun, 07 Jun 2015 20:42:15 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/06/07/Working-with-spreadsheets<h2 id="excel-html-table-hack">Excel html table hack</h2>
<p>I’ve used the classic web hack where you send an html file with excel mime type (and file ending) containing a table. I’ve had trouble with excel being more particular about allowing this hack nowadays. Another problematic aspect is if a user sends you such a file without re-saving it. Since we have open xml based formats for spreadsheets, there is no need for this hack.</p>
<h2 id="csv">CSV</h2>
<p>I’ve used diffent csv-like formats. These have the con of being dependant on the language settings (one partial fix is to detect the user language settings and render different formats). If you are using more than ascii you might also need to do a binary comparison of an excel generated csv and what you generate. Since csv looks fairly simple, many write a short regex to parse it. This has a tendency to devolve due to the different ways that you can implement csv. You can get into trouble when you are begin to support character escaping and newlines. I prefer if you can keep this kind of messy logic out of your otherwise relatively clean domain code (for instance by <a href="https://github.com/Lundalogik/go_import/">using a different language</a> ). By using a different deliverable to transform data into predefined format you have an easier time to use many different libraries to parse weird formats.</p>
<h2 id="xml-based-xlsx">Xml based (.xlsx)</h2>
<p>Due to the popularity of javascript we have some libraries that you can use to generate xlsx files on the clientside. I’ve tried <a href="https://github.com/stephenliberty/excel-builder.js">excel-builder</a> and have been able to use it. From a programmer friend I’ve heard that he has used <a href="https://github.com/guyonroche/exceljs">exceljs</a> in order to generate excel files on nodejs. The documentation of excel-builder is lacking, but it was easier to get it to work than <a href="https://github.com/SheetJS/js-xlsx">js-xlsx</a>. In order to work with excel-builder I read the excel-builder source and compared excel-generated .xlsx files with what the program generated. Most of my problems was due to the client specifying how the excel file should be styled.</p>
Lots of deliverableshttp://assertfail.gewalli.se/2015/06/06/Lots-of-deliverables.html
Sat, 06 Jun 2015 19:31:41 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/06/06/Lots-of-deliverables<p>The use of many assemblies has an appeal from an architectural standpoint. In order to separate dependencies you want different parts of your code to be able to load even though a certain version of visual studio sdk is not installed. To have a fixed api implemented by adapter assemblies for many different versions of a hard to install library dependency is a way to allow work on code without having to install every single version of the dependency.</p>
<p>The problem is if you separate your code into many assemblies to early before you know the interdependencies between different subdomains. You can easily get a lot of code and extra assemblies due to subdomains that need to know much about each other. I like the reasoning in <a href="http://martinfowler.com/bliki/MonolithFirst.html">Martin Fowlers post</a>: That you should wait until you know more.</p>
<p>Sometimes, the best thing is to start with a new library or dll. Starting out a bit greenfield when you start develop something new (something of sufficient size and with sufficiently small amount of knowledge about the existing code). It’s like applying the single responsibility principle on a larger scale.</p>
Thoughts on using Angularjshttp://assertfail.gewalli.se/2015/06/06/Thoughts-on-using-Angularjs.html
Sat, 06 Jun 2015 17:06:11 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/06/06/Thoughts-on-using-Angularjs<p>I’ve done some minor work using angularjs. Angular looks like a promising direction for certain type of applications.</p>
<p>There is a lot of drama surrounding ng2. Some of is due to the fear that ng1 applications will become obsolete when ng2 comes around without a good migration path. Jon Skeet recently blogged: <a href="http://codeblog.jonskeet.uk/2015/06/03/backwards-compatibility-is-still-hard/">backwards compability is still hard</a>. It will be interesting to see if the ng team manages to create a nice migration path from ng1 to ng2. Perhaps we will see ng1 having a continued existance due to the proliferation of applications written in ng1. The python community has struggled for years with python3 and the migration from earlier python versions. However, the complexity of most languages far exceeds the complexity of ng framework (but the differences between the versions looks more prominent).</p>
<p>You can be productive working with ng (as with many other frameworks). This type of framework will probably stick around for a few years until someone comes up with a better way of doing client applications in javascript. I’ve heard criticism from Eisenberg regarding ng2, but find that Aurelia looks very <a href="http://eisenbergeffect.bluespire.com/porting-an-angular-2-0-app-to-aurelia/">similar to ng</a>.</p>
<p>What I’ve heard from people that have done more consulting on ng is that for complicated code the ng model of detecting changes can cause performance issues. For many business type of applications you don’t need that much calculations or complicated business logic. Some people have found ng to be <a href="https://news.ycombinator.com/item?id=7522520">hard to grok</a>. I’ve talked to a former coworker who has started working with backbone. Backbone is easier to learn. You can read the entire <a href="http://backbonejs.org/docs/backbone.html">annotated source</a> of backbone. This is only natural since ng has a lot more code. You might notice how ng compares to backbone is similar to the difference between rails and sinatra. Rob Conery <a href="http://herdingcode.com/herding-code-169-tom-dale-and-rob-conery-on-the-emberjs-angularjs-cage-match-at-ndc/">compares ng to rails</a>.</p>
<p>So, should you use ng on your next project? As always, it depends. For some applications a railsy type of frameworks on the serverside is the best fit (big opinionated frameworks that tell you how you should structure you code). For others, a more sinatra like approach (smaller framework focusing on fewer things). Being stuck in a predefined mould can be stifling if your domain does not lend itself to that shape. If it does, you can be fairly productive.</p>
travis supports csharphttp://assertfail.gewalli.se/2015/03/22/travis-supports-csharp.html
Sun, 22 Mar 2015 19:16:19 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/03/22/travis-supports-csharp<p>I’ve used travis to test c# projects for a few years now. It has been a bit of a pain to get it working (read custom ppa or setting language to objective c and downloading and installing package intended for xamarin studio).</p>
<p>I <em>feel</em> that good things happen because people have more confidence in mono.</p>
<p>How do you test your projects on travis? Read the <a href="http://docs.travis-ci.com/user/languages/csharp/">travis documentation</a> or look at how I have done it in <a href="https://github.com/wallymathieu/with/blob/master/.travis.yml">for example with</a>. I’m using ruby to build c# since it’s cross-platform. You <a href="https://github.com/csainty/Veil/blob/master/Build/gruntfile.js">can substitute</a> rake for grunt if you prefer nodejs.</p>
<p>Another way is to use that bash has some nice filename expansion. This means that you can probably write:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mono ./src/packages/NUnit.Runners.*/tools/nunit-console.exe
</code></pre></div></div>
<p>to avoid hard coding the version of the runner.</p>
Kibana vs Elmah like guihttp://assertfail.gewalli.se/2015/03/13/Kibana-vs-Elmah-like-gui.html
Fri, 13 Mar 2015 22:05:13 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/03/13/Kibana-vs-Elmah-like-gui<p>The nice thing about using <a href="https://www.elastic.co/products/kibana">Kibana</a> for your logs is that you get nice custom filtering. Thus it’s very easy for others to only view errors they feel that are relevant to them.</p>
<p>If you have a many systems (gui’s, services, etc) where you pipe a lot of log data into the same log database, then it can be benefitial to to filter out systems that you’re not coding anything in.</p>
<p>The downside of having easy filters is that it’s really easy to ignore errors. A screen with the graph of all errors could perhaps mitigate that.</p>
<p>It would be nice to have <a href="https://code.google.com/p/elmah/">Elmah</a> like formatting of stacktraces. Perhaps a chrome plugin could fix that. Perhaps port the stacktrace parsing from <a href="https://github.com/wallymathieu/ElasticElmah">ElasticElmah</a> to js.</p>
<p>The nice thing about having your logs in elastic is that you don’t need to just use kibana to query your logs. It’s really easy to use <a href="http://nest.azurewebsites.net/">Nest</a> to do queries. Unless you have huge amount of logs you can do groupings in memory.</p>
Event sourcing and in memory databasehttp://assertfail.gewalli.se/2015/03/03/Event-sourcing-and-in-memory-database.html
Tue, 03 Mar 2015 20:38:37 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/03/03/Event-sourcing-and-in-memory-database<p>Trying out <a href="https://github.com/wallymathieu/origodb-studies">OrigoDb</a>, I found it interresting to try out a more raw <a href="https://github.com/wallymathieu/filedb-studies">file store approach</a> and <a href="https://github.com/wallymathieu/nevent-store-studies">NEvent Store</a>. Why the connection Event Sourcing and In memory databse? Mostly because I tried out OrigoDb first. In memory database feels like a nice fit for Event Sourcing (since the log that can restore the database can be persisted in an append only manner).</p>
<p>Many of us have heard or read Martin Fowlers <a href="http://martinfowler.com/eaaDev/EventSourcing.html">Event Sourcing</a>. He mentions in memory databases in the article as well.</p>
<p>OrigoDb is a bit easier to setup compared to NEvent store. NEvent store is more mature. I like that you don’t need to inherit from a base class in NEvent Store. It does mostly what it says it does: Persists events. This means that it if you want to use it for an in memory situation you probably should make the objects readonly. The OrigoDb approach of using inheritance gives you fewer lines of code (since you don’t get command and handler types). NEvent store is more talkative and requires more code to handle events.</p>
<p>Since OrigoDb assumes that you want help with making absolutely sure that your in memory data is not corrupted by a assignment of on an object you need to interact with the it in a slightly different manner (from <a href="https://github.com/wallymathieu/origodb-studies/blob/master/Tests/CustomerDataTests.cs#L28">OrigoDb CustomerDataTests</a> ):</p>
<div class="language-c# highlighter-rouge"><div class="highlight"><pre class="highlight"><code> <span class="p">[</span><span class="n">Test</span><span class="p">]</span>
<span class="k">public</span> <span class="k">void</span> <span class="nf">CanGetCustomerByFirstname</span><span class="p">()</span>
<span class="p">{</span>
<span class="kt">var</span> <span class="n">customers</span> <span class="p">=</span> <span class="n">_engine</span><span class="p">.</span><span class="nf">Execute</span><span class="p">(</span><span class="n">m</span><span class="p">=&gt;</span>
<span class="n">m</span><span class="p">.</span><span class="nf">QueryOverCustomers</span><span class="p">()</span>
<span class="p">.</span><span class="nf">Where</span><span class="p">(</span><span class="n">c</span> <span class="p">=&gt;</span> <span class="n">c</span><span class="p">.</span><span class="n">Firstname</span> <span class="p">==</span> <span class="s">"Steve"</span><span class="p">)</span>
<span class="p">.</span><span class="nf">ToList</span><span class="p">());</span>
<span class="n">Assert</span><span class="p">.</span><span class="nf">AreEqual</span><span class="p">(</span><span class="m">3</span><span class="p">,</span> <span class="n">customers</span><span class="p">.</span><span class="n">Count</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>
<p>Storing your events in an append manner on the filesystem is the easiest approach. Use of readonly objects simplifies things (easier to make sure that the data does not diverge). Perhaps a usecase for <a href="https://github.com/wallymathieu/with/blob/master/src/Tests/With/Clone_an_instance_into_the_same_type.cs">With</a>?</p>
<p>The problem with using the filesystem directly is that it’s not ACID. However, you get ACID <a href="http://dev.origodb.com/docs/transactions/">using OrigoDb</a>.</p>
Goto considered harmfulhttp://assertfail.gewalli.se/2015/02/22/Goto-considered-harmful.html
Sun, 22 Feb 2015 23:30:11 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/02/22/Goto-considered-harmful<p>Dijkstra wrote the <a href="http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html">following</a>. I agree with his reasoning.</p>
<p>However, goto is useful in certain lower level domains.</p>
<p>The difficulty of reading code with goto statements is that it’s hard to follow the program flow.</p>
<p>The reasoning can also be applied to programming where you do not use goto.</p>
<p>Consider the following code:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>someMethod(){
// some state
label 1:
doStuff();
goto end;
label 2:
if (condition){
goto 1;
}else{
doOtherStuff();
goto end;
}
label 3:
doSomeDifferentThings();
goto end;
...
end:
}
</code></pre></div></div>
<p>How do you emulate the above code in a language without goto? You could use a while and a switch.</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>someMethod(){
// some state
going = true;
while(going){
switch (goTo){
case 1: going=false;
doStuff(); break
case 2: going=false;
if (condition){
going=true; goTo=1;
}else{
doOtherStuff();
}
break;
case 3: goin =false;
doSomeDifferentThings();
break;
...
}
}
}
</code></pre></div></div>
<p>How do you emulate the above goto in a language with objects but without switch?</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Object ThatDoesSomeThing{
// some state
public someMethod(){
line_1();
...
}
private line_1(){
doStuff();
}
private line_2(){
if (condition){
line_1();
}else{
doOtherStuff();
}
}
private l_3(){
doSomeDifferentThings();
}
...
}
</code></pre></div></div>
<p>From <a href="http://stackoverflow.com/questions/1487124/translate-goto-statements-to-if-switch-while-break-etc">stackoverflow</a>:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public someMethod(){
int goTo=0;
while(true){
switch(goTo){
case 0:
doSomething();
goTo = 1;
continue;
case 1:
doSomethingElse();
goTo = 2;
continue;
case 2:
doSomethingDifferent();
goTo = 0;
continue;
default:
return;
}
}
}
</code></pre></div></div>
<p>This translates into:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Object ThatDoesSomeThing{
// some state
public someMethod(){
line_0();
}
private line_0(){
doSomething();
line_1();
}
private line_1(){
doSomethingElse();
line_2();
}
private line_2(){
doSomethingDifferent();
line_1();
}
}
</code></pre></div></div>
<p>The main thing is the usage, not the keyword. Goto is an easy target because it’s famous for being bad. This is cargo cult programming. It’s easy to write an unreadable mess in many ways. In the above examples it might be due to the fact that it’s difficult to follow how the state of the context will be for any line.</p>
<p>The important thing to ask yourself is why is some code harder to read? How do you write readable code? How do you write good texts?</p>
Looking at ORM a few years laterhttp://assertfail.gewalli.se/2015/02/22/Looking-at-ORM-a-few-years-later.html
Sun, 22 Feb 2015 11:20:38 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/02/22/Looking-at-ORM-a-few-years-later<p>When I first started using entity framework (one of the earlier versions) it was not ready yet (some serious performance issues). A few years later I hear good things about it from other developers.</p>
<p>In order to try to get a feel for how the state of entity persistance is today I’ve ported an old <a href="http://nhibernate.info/">nhibernate</a> test <a href="https://github.com/wallymathieu/nhibernate-studies">project</a> to a test <a href="https://github.com/wallymathieu/entity-framework-studies">project</a>
for <a href="https://msdn.microsoft.com/en-us/data/ef.aspx">entity framework</a>.</p>
<p>I initially had some trouble due to my choice of sql express to test the mappings. Once I managed to get EF to use sqlite the testing got much easier.</p>
<p>Both ORM’s support automapping of POCO objects to the database enteties. The fluent automapping for NHibernate looks like it can figure out many to many relations.</p>
<p>The setup of NHibernate is a bit easier since you are not dependant on that web or app config factory settings. You get less confusion in the documentation for the NHibernate xml configuration. It looks like the people behind EF is aware of the problem and <a href="https://msdn.microsoft.com/en-us/data/jj680699.aspx">working on it</a>.</p>
<p>Both frameworks can require some getting used to.</p>
<p>Note that both frameworks works well with <a href="https://github.com/schambers/fluentmigrator">fluent migrator</a> to test against a sql-ish database. One way of getting a nice development flow could perhaps be to use sqlite on dev machines for integration testing and letting the CI machine run the tests against what you’re using on production.</p>
Why global installation of packages?http://assertfail.gewalli.se/2015/02/07/Why-global-installation-of-packages.html
Sat, 07 Feb 2015 07:35:37 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/02/07/Why-global-installation-of-packages<p>What do I mean when I say?</p>
<ul>
<li>System level package / Global package: Package installed so that it is available for every program on the system</li>
<li>Local package: Package installed into sub folder of project and only available to that project</li>
</ul>
<p>Timeline</p>
<ul>
<li><a href="http://anonscm.debian.org/gitweb/?p=dpkg/dpkg.git;a=blob;f=scripts/perl-dpkg.pl;h=ba70fc5f570ed2cd3661a505f642aa85d2295ab5;hb=1b80fb16c22db72457d7a456ffbf1f70a8dfc0a5">dpkg 1994</a></li>
<li><a href="http://web.archive.org/web/20000816230719/http://www.cpan.org/modules/01modules.index.html">cpan, uploaded packages from 1995</a></li>
<li><a href="http://en.wikibooks.org/wiki/Java_Programming/History">jar 1996</a></li>
<li><a href="http://dictionary.sensagent.com/advanced+packaging+tool/en-en/">debian release with apt 1999</a></li>
<li><a href="http://cpansearch.perl.org/src/MURRAY/PPM-2.1.9/Changes">perl package manager goes back to 1999</a></li>
<li><a href="https://github.com/rubygems/rubygems/blob/master/History.txt">rubygems 2004</a></li>
<li><a href="https://rubygems.org/gems/bundler/versions">ruby bundler 2010, git history from 2010, ruby gem from 2009</a></li>
<li><a href="https://github.com/npm/npm/releases/tag/v0.0.1">npm 2010</a></li>
<li><a href="http://nuget.codeplex.com/wikipage?version=1">nuget 2010</a></li>
</ul>
<p>This is just a sampling of when different packaging solutions appeared. My impression is that the first solutions where focused on system level package management. RubyGems and similar package managers came out of that context. I don’t know if it’s a coincidence but it looks like local package management tools started to appear first around 2010.</p>
<p>Global installation of packages probably dates back to system level packages. Since disk space is cheaper, there is no longer the same need to share packages among programs and services.</p>
Render xml as htmlhttp://assertfail.gewalli.se/2015/02/07/Render-xml-as-html.html
Sat, 07 Feb 2015 07:20:01 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2015/02/07/Render-xml-as-html<p>Sometimes when working with xml you have more information in the xml file than you know what to do with in your code. It could be new tags or attributes. A way to use the xml you have not anticipated in your code. A simple way to present that information to the user (so that they can inform you when you’re doing wrong) is to apply a <a href="https://gist.github.com/wallymathieu/8dcc3055b36422d3a504">general xml stylesheet</a>.</p>
<p>First part of the trick is to tell xml that you intend to output html:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;xsl:output</span> <span class="err">...</span> <span class="na">method=</span><span class="s">"html"</span> <span class="na">omit-xml-declaration=</span><span class="s">"yes"</span><span class="nt">/&gt;</span>
</code></pre></div></div>
<p>Next step is to create a root html (in order to be able to add style and scripts). In order to apply the rest o our xsl templates we need to apply the other templates:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;xsl:template</span> <span class="na">match=</span><span class="s">"/"</span><span class="nt">&gt;</span>
<span class="nt">&lt;html&gt;</span>
...
<span class="nt">&lt;xsl:apply-templates/&gt;</span>
<span class="nt">&lt;/html&gt;</span>
</code></pre></div></div>
<p>To render all the child-nodes we do the following:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;xsl:template</span> <span class="na">match=</span><span class="s">"node()"</span><span class="nt">&gt;</span>
...
</code></pre></div></div>
<p>Any attributes? By using @* we can pick out the xml attributes. If they show different intent it could be that we want to style them differently.</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;xsl:if</span> <span class="na">test=</span><span class="s">"@*"</span><span class="nt">&gt;</span>
</code></pre></div></div>
<p>Any child nodes?</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;xsl:if</span> <span class="na">test=</span><span class="s">"node()"</span><span class="nt">&gt;</span>
</code></pre></div></div>
<p>One thing you could do is to pass along the nesting as a parameter to the templates. Then you can add a different class to depending on how deep the element is.</p>
<p>If you want to call a template with parameters:</p>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;xsl:call-template</span> <span class="na">name=</span><span class="s">"some-template"</span><span class="nt">&gt;</span>
<span class="nt">&lt;xsl:with-param</span> <span class="na">name=</span><span class="s">"value"</span> <span class="na">select=</span><span class="s">"."</span><span class="nt">/&gt;</span>
<span class="nt">&lt;/xsl:call-template&gt;</span>
</code></pre></div></div>
<div class="language-xml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;xsl:template</span> <span class="na">name=</span><span class="s">"some-template"</span><span class="nt">&gt;</span>
<span class="nt">&lt;xsl:param</span> <span class="na">name=</span><span class="s">"value"</span><span class="nt">/&gt;</span>
...
</code></pre></div></div>
<p>Xml style sheets are a bit weird to work with. Theyshould probably be avoided for many tasks. However, for some problems they can be quite useful.</p>
Short talk about source controlhttp://assertfail.gewalli.se/2014/11/30/Short-talk-about-source-control.html
Sun, 30 Nov 2014 11:30:35 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2014/11/30/Short-talk-about-source-control<p>This is a rewrite of an earlier talk about source control.</p>
<h2 id="what-is-source-control-and-why-use-it">What is source control? And why use it?</h2>
<p>In order to track changes of your code you use source control. In the simplest setup, source control answers what your source code looked like before you accidentally broke but it looked like it was working.</p>
<p>In a similar sense you might want to store data about your customers in order to find it again. Who had a sale with customer A?</p>
<h2 id="why-use-sourcesafe-or-cvs">Why use Sourcesafe (or CVS)?</h2>
<p>If you are a single dev.</p>
<h3 id="why-not">Why not?</h3>
<p>Technical answer:</p>
<ul>
<li>Does the single file based database accessed using file system sound scary when hosted on network share? It is!</li>
<li>Sourcesafe is not <a href="http://blogs.msdn.com/b/ukmsdn/archive/2011/01/04/end-of-support-for-visual-sourcesafe.aspx">supported</a> anymore.</li>
</ul>
<p>Less technical answer:</p>
<ul>
<li>Problem when working more than one person.</li>
</ul>
<h2 id="why-use-svn-or-similar-with-revision-history-only-on-server">Why use SVN (or similar with revision history only on server)?</h2>
<p>The dev team are familiar with SVN and have an effective work flow in that tool.</p>
<h2 id="why-not-use-svn">Why not use SVN?</h2>
<p>When you branch. It’s actually simpler to merge using git svn … but that adds the additional complexity of having to use git svn with svn. This can be ok if someone on the team can be assigned as an integrator that does the merges.</p>
<h2 id="why-use-git-or-mercurial-etc">Why use Git (or mercurial et.c.)?</h2>
<p>Can be an easy sourcesafe like experience if you are a single developer. If you have lots of developer, it’s easier to work together using git.</p>
<p>When mentioning git, you cant avoid mentioning github. Git is version control. Github is hosting for that version control. Github has added some nice features as well.</p>
<h3 id="distributed-source-control">Distributed source control?</h3>
<p>Not connected to the corporate network at the moment? Do you work on a laptop (not connected to internet 100% of the time)? Do you like to continue browse the history and create commits? If yes, then consider using a dcvs.</p>
<h3 id="open-source-and-github">Open source and github</h3>
<p>Many open source projects have migrated over to github since it enables easier collaboration with untrusted developers. The mechanism at work is called Pull request.</p>
<p>In many closed source project you pay for support and eventual bug fixes. In an open source project you pay with developer time. Sometimes you have a mixed model (you pay for fixes and support but it’s open source).</p>
<h3 id="fork">Fork!</h3>
<p>Any public library hosted on github can be forked if you have a github account.</p>
<p>Why is this sweet? Most of the time the devs behind the library does not care that much about fixing stuff relevant for you. If you fork the library and fix the problem you can send a Pull request with the changes. They might be rejected. They might be ignored. If you are lucky the devs will give you hints to improve the code (this improves the code and your skills).</p>
<h2 id="usability-of-git">Usability of git?</h2>
<p>The command line version of git can be a bit complicated. However, when used by a single dev you can use <a href="http://windows.github.com/">Github for windows</a> in order to work in a manner similar to sourcesafe (simple gui).</p>
<p>A more advanced gui is the <a href="http://www.sourcetreeapp.com/">Atlassian SourceTree</a>.</p>
<h2 id="hosting-your-code">Hosting your code</h2>
<p>There are several providers of git hosting. The ones I’ve been using are the following:</p>
<ul>
<li><a href="https://github.com/">Github</a></li>
<li><a href="http://blogs.msdn.com/b/mvpawardprogram/archive/2013/11/13/git-for-tfs-2013.aspx">TFS</a></li>
<li><a href="https://bitbucket.org">BitBucket</a></li>
<li><a href="https://www.codeplex.com/">CodePlex</a></li>
<li>Versioning for development code on <a href="http://stackoverflow.com/questions/1960799/using-git-and-dropbox-together-effectively">Dropbox</a>?</li>
</ul>
<p>But there are several others. You could also self host with <a href="http://gitblit.com/">Gitblit</a> or <a href="https://about.gitlab.com/">GitLab</a> or others.</p>
Installing build serverhttp://assertfail.gewalli.se/2014/11/28/Installing-build-server.html
Fri, 28 Nov 2014 09:11:37 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2014/11/28/Installing-build-server<p>So, for the N-th time I’m helping out by configuring a build server. This time it was a bit different since we where restoring an old build teamcity server and agent from a crashed server.</p>
<p>There where some gothas as usual.</p>
<p>In order to restore teamcity we had to do some digging to find the data directory .</p>
<h2 id="teamcity-data">TeamCity data</h2>
<p>If you look in the “teamcity-server.log” you can find how the server was started last time. From that we could conclude the old TEAMCITY_DATA_PATH.
We took that directory and zip:ed it. Minus the cache, since windows zip freaked out about one the name of one of our coworkers: Michał Łusiak.</p>
<p>We made sure to set the system Environment variable:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>TEAMCITY_DATA_PATH
</code></pre></div></div>
<p>to where we want teamcity to keep the data.</p>
<h2 id="sql-server">SQL server</h2>
<p>From the teamcity configuration we could deduce how it connected to SQL server.</p>
<p>SQL server was installed with only database engine and management studio.</p>
<p>When SQL was installed we only enabled windows authentication. Since teamcity connects through a tcp port, it started complaining about not being able to connect even though we had attached the old databse added the expected user.</p>
<p>If we tried to connect the same was as teamcity through the command line tool “sqlcmd” we could more quickly iterate over the configuration.
The first problem was that sqlcmd could not connect to the expected port.
In SQL Server configuration manager we had to enter the sub section “SQL server network configuration” and enable tcp.
This got us a bit further. Now our problem was that the user could not connect with the user.
We had created a user under main security in SQL server with the correct password. Problem was that the attached database still had a user with the same name. We removed that user and did “associate user with database”. We also needed to make sure that that user had the same permissions set as before.</p>
<p>Ok, so now we could log on to teamcity using our old accounts. Great!</p>
<p>The builds are failing because teamcity could not access the source control!</p>
<p>Easy fix, just need to add the private ssh keys to the correct folder so that teamcity can access private repositories.</p>
<h2 id="msbuild">Msbuild</h2>
<p>So a lot of the builds where failing because msbuild was not installed. How do you install msbuild without visual studio? Turns out stackoverflow knows the answer:
http://stackoverflow.com/questions/2567018/installing-msbuild-4-0-without-visual-studio-2010</p>
<p>You need the SDK.</p>
<p>I noticed that some of the builds where failing due to missing AL.exe (assembly linker). I installed the SDK associated with the version of windows installed Win2008. I forgot to check the error message closer. It was complaining about not finding “v8.0A” if you look at the error message. I had installed an earlier version if you look at the registry settings.</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(2863,5): error MSB3086:
Task could not find "AL.exe" using the SdkToolsPath "" or the registry key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86". Make sure the SdkToolsPath is set and the tool exists in the correct processor specific location under the SdkToolsPath and that the Microsoft Windows SDK is installed
</code></pre></div></div>
<p>So I needed to install another SDK, the one called “Windows 8 SDK”.</p>
<p>The names of the SDK’s are a bit confusing.</p>
<p>Another project tried to build a web site. It was failing due to missing an imported msbuild targets file.</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>WebSite.csproj(190,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets"
was not found. Confirm that the path in the &lt;Import&gt; declaration is correct, and that the file exists on disk.
</code></pre></div></div>
<p>The common solution here is to copy the targets for web applications from a developer machine in order to get these targets. They really should be part of a nuget package or available as a separate download.</p>
<h2 id="next-day">Next day</h2>
<p>Next day we ran into trouble with using port 80 for teamcity. Probably because the machine had slept during the night ;) . Turns out “system” is binding on port 80:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Powershell&gt; netstat -anbo | where {$_.contains("80")}
</code></pre></div></div>
<p>When we searched to find some answer we found <a href="http://stackoverflow.com/questions/12492025/windows-8-nt-kernel-and-system-using-port-80">stackoverflow</a>.
Turns out “World Wide Web Publishing Service” is listening on port 80.
Why? It looks like it installs when adding “.net 3.5.1” as a feature to windows. We removed the web server role.</p>
Thoughts on using knockout for the last yearshttp://assertfail.gewalli.se/2014/11/18/thoughts-on-using-knockout.html
Tue, 18 Nov 2014 20:11:43 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2014/11/18/thoughts-on-using-knockout<p>It feels very much like the next step after jquery+templates. The nice part is that this enables you to choose your own strategy. For instance only using small amounts of code and regular forms. It requires a lot of decisions about structure decided already in a lot of js mvvm frameworks. These frameworks look like rails for client-side coding. Great for certain types of problems, but requires learning how to use it. Like always, if you can accept the limitations you get a boon. The big problem is that it’s hard to know such things in advance. For small apps jquery might be best. For larger single page like applications you should evaluate the larger frameworks.</p>
<p>Having a lot of knockout computed observables requires that you dig down into the Ko code base. This will probably improve with the maturity of Ko. A lot of computed observables can be created implicitly using a function in the view. On the knock me out blog there is some required reading <a href="http://www.knockmeout.net/2014/10/knockout-cleaning-up.html">Cleaning Up After Yourself in Knockout.js</a>.</p>
<p>There might be improvements of IOC in javascript. Dispose and life cycle could be very useful for some single page apps. For knockout this amplified if you need long living objects. Need to evaluate the different IOC containers out there. Problem is that there is no dispose only a delete in plain javascript (how do you clean up from X?).</p>
<p>Having a proper url simplifies a lot of things. You have to do a lot of complicated code when your user interface creates a view that can’t be navigated to in the ordinary sense. Adding things like filter or navigation context can help you avoid hard to answer customer answers why certain things won’t work. Having the routing primarily server side can also simplify testing.</p>
Bundler uses man fileshttp://assertfail.gewalli.se/2014/06/26/Bundler-uses-man-files.html
Thu, 26 Jun 2014 16:13:24 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2014/06/26/Bundler-uses-man-files<p>Turns out bundler does have documentation related to Bundler.with_clean_env. You just have to read the <a href="http://bundler.io/v1.6/man/bundle-exec.1.html">bundler.io man pages</a> or the man pages for bundler exec.</p>
Bundler.with_clean_envhttp://assertfail.gewalli.se/2014/06/25/Bundlerwithcleanenv.html
Wed, 25 Jun 2014 05:36:52 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2014/06/25/Bundlerwithcleanenv<p>Using ruby is kind of easy in the beginning. We started by having a folder of loose scripts. This turned a bit messy after a while. By moving these to separate gems we got some needed structure. Many of the programmers complained about globally installed gems (i.e. our local gems). In order to get a predictable executing environment we started to levarage bundler more and more. Turns out that there is a gotcha: Executing a bundle exec script inside a bundle exec script. The inside script will inherit the environment from the outer script. In order to avoid this you can use:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Bundler.with_clean_env do
...
end
</code></pre></div></div>
<p>This method is not documented, but it really should be (I’ll do it if I find time).</p>
Big news for .nethttp://assertfail.gewalli.se/2014/04/09/Big-news-for-net.html
Wed, 09 Apr 2014 22:39:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2014/04/09/Big-news-for-net<p>Big news. Microsoft releases the next c# and vb.net compiler as <a href="http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx">open source</a>. Miquel de Icaza <a href="http://tirania.org/blog/archive/2014/Apr-09.html">speaks of</a> making it work on mono as well. It’s licensed under Apache license.</p>
Memory management in knockouthttp://assertfail.gewalli.se/2014/02/21/Memory-management-in-knockout.html
Fri, 21 Feb 2014 20:21:50 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2014/02/21/Memory-management-in-knockout<h2 id="explicit-use-of-computed">Explicit use of computed?</h2>
<p>What does a computed expression like this:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">this</span><span class="p">.</span><span class="nx">isBusy</span> <span class="o">=</span> <span class="nx">ko</span><span class="p">.</span><span class="nx">computed</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nb">self</span><span class="p">.</span><span class="nx">_isBusy</span><span class="p">()</span> <span class="o">||</span> <span class="nb">self</span><span class="p">.</span><span class="nx">_queryIsBusy</span><span class="p">();</span>
<span class="p">});</span>
</code></pre></div></div>
<p>have to do with</p>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">data-bind=</span><span class="s">"visible: _isBusy() || _queryIsBusy()"</span> <span class="nt">&gt;&lt;/div&gt;</span>
</code></pre></div></div>
<p>Internally knockout creates a computed out of an expression in a bindinghandler. Ko does not parse the expression in the html above to register the variables _isBusy or _queryIsBusy.</p>
<h2 id="consequenses">Consequenses</h2>
<p>What does this mean for your code?</p>
<p>If you have something below but want to move the logic to your class from the view:</p>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">data-bind=</span><span class="s">"visible: _isBusy() || _queryIsBusy()"</span> <span class="nt">&gt;&lt;/div&gt;</span>
</code></pre></div></div>
<p>You have two main options:</p>
<p>Option 1</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">Object</span><span class="p">.</span><span class="nx">defineProperty</span><span class="p">(</span><span class="nb">self</span><span class="p">,</span> <span class="s1">'isBusy'</span><span class="p">,</span> <span class="p">{</span>
<span class="na">get</span><span class="p">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">_isBusy</span><span class="p">()</span> <span class="o">||</span> <span class="nx">_queryIsBusy</span><span class="p">();</span>
<span class="p">}</span>
<span class="p">});</span>
</code></pre></div></div>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">data-bind=</span><span class="s">"visible:isBusy"</span> <span class="nt">&gt;&lt;/div&gt;</span>
</code></pre></div></div>
<p>Option 2</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">this</span><span class="p">.</span><span class="nx">isBusy</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
<span class="k">return</span> <span class="nx">_isBusy</span><span class="p">()</span> <span class="o">||</span> <span class="nx">_queryIsBusy</span><span class="p">();</span>
<span class="p">};</span>
</code></pre></div></div>
<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">data-bind=</span><span class="s">"visible:isBusy()"</span> <span class="nt">&gt;&lt;/div&gt;</span>
</code></pre></div></div>
<p>Notice ‘()’</p>
<h2 id="life-cycle">Life cycle</h2>
<p>How long does the computed that knockout creates live?</p>
<p>A bit simplified if you read the code for KO you find that knockout makes new computed (internally dependent observable) with option:
<code class="highlighter-rouge">disposeWhenNodeIsRemoved</code>
This means that knockout will remove the list of referenses to observables that the computed depends on when the DOM-node that the computed is associated with have been removed.</p>
<h2 id="when-is-it-safe-to-use-a-computed">When is it safe to use a computed?</h2>
<p>When you know the life span of the computed you have created.</p>
<h2 id="why-is-it-generally-bad-to-use-computed-willy-nilly">Why is it generally bad to use computed willy nilly</h2>
<p>It is generally hard to reason about when they will be disposed. It is easy to access exposed ko.computed from different objects in the system with different life span.</p>
Self and the gchttp://assertfail.gewalli.se/2014/02/06/self-and-the-gc.html
Thu, 06 Feb 2014 17:59:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2014/02/06/self-and-the-gc<p>For many projects I’ve been using the pattern:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ns.CtorFunction = function(){
var self = this;
this.doStuff = function(){
// do stuff and use self in order to get the object variables
}
}
</code></pre></div></div>
<p>Turns out that this pattern is good for small sites with jQuery (that makes use of this in other ways). For larger code bases where you have lots of code this construction sometimes makes it difficult for the garbage collector. If you have a large single page app, then this might be an issue.</p>
<p>What other patterns are available?</p>
<p>For a knockout js site you could use the pattern:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ns.CtorFunction = function(){
this.doStuff = function(){
// do stuff and use this in order to get the object variables
}
}
</code></pre></div></div>
<p>Knockout sends the appropriate context to callbacks from the view (for instance the DOM click handlers). This makes the above construction work mostly fine. This depends of course of the scope of the knockout view (changed by “with”).</p>
<p>This might not be true for every app. My coworker <a href="https://github.com/2hdddg">Peter</a> found that it depends on the amount of objects. It might be that the browser (chrome) have some limits to the amount of graph traversal that is allowed to identify entities to be garbage collected.</p>
Writing rubyish c# or porting ruby code to c#http://assertfail.gewalli.se/2013/10/27/writing-rubyish-c-or-porting-ruby-code.html
Sun, 27 Oct 2013 14:41:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/10/27/writing-rubyish-c-or-porting-ruby-code<p>Since I liked the ruby version for parsing <a href="https://github.com/sstephenson/global_phone">phone numbers</a>, I ported it to c#. In order to avoid having to rewrite to much I did the following:</p>
<ul>
<li>To begin with, the entire project was using ruby name convention. This simplifies things.</li>
<li>Whenever there is a missing method where the behavior of the method is not the same as the c# one, I added an extension method. For instance I implemented a variant of gsub. The behavior of this gsub uses $1 for matching groups (since it’s more natural to remove a bit of code than make a full port).</li>
<li>I tried to translate different ruby constructs into c#. For instance the lazy pattern found in the library <code class="highlighter-rouge">@variable ||= init_variable</code> I had to replace with <code class="highlighter-rouge">_variable ?? (_variable=InitVariable())</code></li>
<li>After all the tests became green and I had checked in the initial version, it was quite simple to change name convention using resharper.</li>
</ul>
<p>The finished version is available on <a href="https://github.com/wallymathieu/GlobalPhone">github</a></p>
Using values in expressionhttp://assertfail.gewalli.se/2013/10/20/using-values-in-expression.html
Sun, 20 Oct 2013 09:47:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/10/20/using-values-in-expression<p>I’ve done some small tests while writing the library to handle <a href="https://www.nuget.org/packages/With/">readonly objects in c#.</a> Turns out that getting the value of a sub expression can be costly (since you have to compile the expression and execute). When just setting one property there can be a performance benefit of using the following syntax:<br />&lt;blockquote class="tr_bq"&gt;</p>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px; word-wrap: normal;">new MyClass(1, "2").With(m =&gt; m.MyProperty, 3)</code></pre>
<p>&lt;/blockquote&gt;
There might be some way of optimizing the code in order to get better performance for the form:<br />&lt;blockquote class="tr_bq"&gt;</p>
<pre style="background-color: #f8f8f8; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: 1px solid rgb(221, 221, 221); color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 13px; line-height: 19px; margin-top: 15px; overflow: auto; padding: 6px 10px;"><code style="background-color: transparent; border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; border-top-left-radius: 3px; border-top-right-radius: 3px; border: none; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; margin: 0px; padding: 0px; word-wrap: normal;">new MyClass(1, "2").With(m =&gt; m.MyProperty == 3)</code></pre>
<p>&lt;/blockquote&gt;
If there are only a few usages then the performance hit is probably negligible.</p>
<div style="clear: both;"></div>
Using readonly objects in c#http://assertfail.gewalli.se/2013/10/18/using-readonly-objects-in-c.html
Fri, 18 Oct 2013 17:39:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/10/18/using-readonly-objects-in-c<p>One thing I like about f# is the ability to use readonly objects in a way that does not require a lot of code. I’ve done a small lib inspired by this ability of f#: <a href="https://github.com/wallymathieu/with">with</a></p>
<p>The syntax is a bit special since I assume that the properties have a private set.</p>
<h2 id="versions-prior-to-5">versions prior to 5</h2>
<div class="language-c# highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">myobject</span><span class="p">.</span><span class="nf">With</span><span class="p">(</span><span class="n">m</span> <span class="p">=&gt;</span> <span class="n">m</span><span class="p">.</span><span class="n">Property1</span> <span class="p">==</span> <span class="m">3</span> <span class="p">&amp;&amp;</span> <span class="n">m</span><span class="p">.</span><span class="n">Property2</span> <span class="p">==</span> <span class="s">"3"</span><span class="p">)</span>
</code></pre></div></div>
<h2 id="with-5">With 5+</h2>
<div class="language-c# highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">using</span> <span class="nn">With</span><span class="p">;</span>
<span class="p">...</span>
<span class="k">public</span> <span class="k">class</span> <span class="nc">SomeClass</span>
<span class="p">{</span>
<span class="k">private</span> <span class="k">static</span> <span class="k">readonly</span> <span class="n">IPreparedCopy</span><span class="p">&lt;</span><span class="n">MyClass</span><span class="p">,</span> <span class="kt">int</span><span class="p">,</span> <span class="kt">string</span><span class="p">&gt;</span> <span class="n">PreparedCopy</span> <span class="p">=</span>
<span class="n">Prepare</span><span class="p">.</span><span class="n">Copy</span><span class="p">&lt;</span><span class="n">MyClass</span><span class="p">,</span> <span class="kt">int</span><span class="p">,</span> <span class="kt">string</span><span class="p">&gt;((</span><span class="n">m</span><span class="p">,</span><span class="n">v1</span><span class="p">,</span><span class="n">v2</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="n">m</span><span class="p">.</span><span class="n">Property1</span> <span class="p">==</span> <span class="n">v1</span> <span class="p">&amp;&amp;</span> <span class="n">m</span><span class="p">.</span><span class="n">Property2</span> <span class="p">==</span> <span class="n">v2</span><span class="p">);</span>
<span class="k">public</span> <span class="k">async</span> <span class="n">Task</span><span class="p">&lt;</span><span class="n">MyClass</span><span class="p">&gt;</span> <span class="nf">Handle</span><span class="p">()</span>
<span class="p">{</span>
<span class="c1">// fetch instance of MyClass, say:</span>
<span class="kt">var</span> <span class="n">myObject</span> <span class="p">=</span> <span class="k">await</span> <span class="n">_storage</span><span class="p">.</span><span class="nf">Load</span><span class="p">(</span><span class="n">someId</span><span class="p">);</span>
<span class="c1">// change the name of that customer:</span>
<span class="kt">var</span> <span class="n">copy</span> <span class="p">=</span> <span class="n">PreparedCopy</span><span class="p">.</span><span class="nf">Copy</span><span class="p">(</span><span class="n">myObject</span><span class="p">,</span> <span class="m">3</span><span class="p">,</span> <span class="s">"3"</span><span class="p">);</span>
<span class="c1">// ...</span>
<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>
<p>The reason for this style of syntax is due to the fact that compiling expressions are potentially expensive, why you’d want to have a similar pattern as compiled regex.</p>
Rake:ish make clone in c#http://assertfail.gewalli.se/2013/10/14/rakeish-make-clone-in-c.html
Mon, 14 Oct 2013 06:02:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/10/14/rakeish-make-clone-in-c<p>If you prefer to write your build tasks in c# then there is a package for you:<br /><a href="https://www.nuget.org/packages/shake">Shake</a></p>
<div style="clear: both;"></div>
Writing build scripts in c#http://assertfail.gewalli.se/2013/10/13/writing-build-scripts-in-c.html
Sun, 13 Oct 2013 06:42:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/10/13/writing-build-scripts-in-c<p>I went to <a href="http://leetspeak.se/">leetspeak</a> yesterday. <a href="https://github.com/jrusbatch">Justin Rusbatch</a> had a talk about scriptcs. In that talk he mentioned that several people wanted to write build scripts in c# and thought that it would be nice to use scriptcs to do that. I started trying out to write build scripts in c#. Turns out that many of the classes that are available in .net are not supposed to be used by users of .net. It’s cleaner and simpler to execute the command line tools from c#. I started writing some code to try it out. I called it <a href="https://github.com/wallymathieu/shake">shake</a>.</p>
<div style="clear: both;"></div>
Problem running NuGet on Ubuntuhttp://assertfail.gewalli.se/2013/10/06/problem-running-nuget-on-ubuntu.html
Sun, 06 Oct 2013 21:19:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/10/06/problem-running-nuget-on-ubuntu<p>I had some trouble running NuGet on ubuntu. I’m running an Ubuntu server. Turns out that you need to install certificates:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>mozroots –import –sync
</code></pre></div></div>
<p>Otherwise NuGet will fail to decode the results when fetching packages over https.</p>
Skånetrafikenhttp://assertfail.gewalli.se/2013/09/21/skanetrafiken.html
Sat, 21 Sep 2013 18:41:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/09/21/skanetrafiken<p>I dusted off some <a href="https://github.com/wallymathieu/skanetrafiken">old code</a> that I’ve written to query the API provided by <a href="http://www.labs.skanetrafiken.se/">Skånetrafiken</a>. I’ve also published it to <a href="https://rubygems.org/gems/skanetrafiken">rubygems</a>. It’s quite nice to work with soap using ruby.</p>
<div style="clear: both;"></div>
Isop infers parametershttp://assertfail.gewalli.se/2013/09/21/isop-infers-parameters.html
Sat, 21 Sep 2013 07:13:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/09/21/isop-infers-parameters<p>Command line tools should do what people expect. It’s a bit chaotic to navigate how to parse command line parameters since there are many conventions.<br /><br />&lt;ul&gt;</p>
<li>A single - to indicate a short parameter, that is: -a</li>
<li>Two -- to indicate a long parameter, that is: --alpha</li>
<li>A single / to indicate a parameter, that is: /alpha</li>
<li>A single - to indicate a parameter, that is: -alpha</li>
<li>A parameter followed by a space and then a value for that parameter: /alpha value</li>
<li>A parameter followed by a = and then a value for that parameter: --alpha=value</li>
<li>The position of the parameter (the ordinal position) to indicate simply a value</li>
<p>&lt;/ul&gt;</p>
<div>
I've added code to try to infer value for a parameter using it's ordinal position when there are no ordinary parameters present before the inferred parameter value.</div>
<div>
<br />
</div>
<div>
This simply means that it should be possible to write:</div>
<blockquote class="tr_bq">
<span style="background-color: black; color: #cccccc;">my.exe --param1=something --param2=someother</span>
</blockquote>
<div>
and also:</div>
<div>
</div>
<p><br />&lt;blockquote class="tr_bq"&gt;
<span style="background-color: black; color: #cccccc;">my.exe something someother</span>
&lt;/blockquote&gt;
Please register any bugs on <a href="https://github.com/wallymathieu/isop/issues?direction=desc&amp;sort=created&amp;state=open">github</a>. The new version is available on <a href="https://www.nuget.org/packages/Isop">nuget</a>.<br />&lt;div&gt;
<br />
&lt;/div&gt;
<br />&lt;div&gt;
&lt;/div&gt;</p>
<div style="clear: both;"></div>
Materialized view in postgreshttp://assertfail.gewalli.se/2013/09/11/materialized-view-in-postgres.html
Wed, 11 Sep 2013 21:39:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/09/11/materialized-view-in-postgres<p>Looks like <a href="http://michael.otacoo.com/postgresql-2/postgres-9-4-feature-highlight-refresh-concurrently-a-materialized-view/">materialized views</a> are coming to postgres :).</p>
<div style="clear: both;"></div>
What's wrong with spreadsheets?http://assertfail.gewalli.se/2013/09/10/whats-wrong-with-excel.html
Tue, 10 Sep 2013 18:23:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/09/10/whats-wrong-with-excel<h2 id="whats-good-about-spreadsheets">Whats good about spreadsheets?</h2>
<p>Spreadsheet applications offers a lot of usability. The concept of using a grid of variables that are easy to reference is a surprisingly powerful concept.</p>
<p>Many applications can be prototyped in spread sheet applications. I use google drive in order to have a powerful and flexible time reporting solution. I quickly realized that in order to have a software that exceeds these benefits, I would have to spend a lot of time writing it.</p>
<h2 id="what-can-be-improved">What can be improved?</h2>
<p>A few days ago I was about to do something that is usually simple in code, but turned out to be hard in excel. The functions available have not evolved very much since the introduction of spreadsheet applications. This is probably due to the fact that the people expected to work with these type of applications are not expected to learn new concepts (Excel looks very different from the early spreadsheet programs). During that time, commonly used programming languages have evolved. Perhaps it’s time to put the lessons learned in programming to use in spreadsheet applications.</p>
<p>There are some difficulties in applying concepts from programming to spreadsheets. There is not a natural way of assignment for functions that return multiple results, structs or objects. This puts a limit on what type of functions can be used. However, I do believe that it’s possible to use functions that return a single string or number variable to increase the usefulness of the concept.</p>
Refactoring in rubyhttp://assertfail.gewalli.se/2013/09/04/refactoring-in-ruby.html
Wed, 04 Sep 2013 20:07:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/09/04/refactoring-in-ruby<p>We have written a lot of ruby code in the project I’m currently working in. There is a lot of code to help manage, build and schedule the program. We started out simple enough. Just one folder with helper scripts. After 2 years we have built up support for a wide variety of tasks.<br />&lt;h3&gt;
Command line tools&lt;/h3&gt;
We have used and abused<br />&lt;blockquote class="tr_bq"&gt;
<span class="vg" style="background-color: white; color: teal; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; line-height: 17.99715805053711px; white-space: pre;">$:</span><span class="o" style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; font-weight: bold; line-height: 17.99715805053711px; white-space: pre;">.</span><span class="n" style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; line-height: 17.99715805053711px; white-space: pre;">unshift</span><span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; line-height: 17.99715805053711px; white-space: pre;"> </span><span class="no" style="background-color: white; color: teal; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; line-height: 17.99715805053711px; white-space: pre;">File</span><span class="o" style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; font-weight: bold; line-height: 17.99715805053711px; white-space: pre;">.</span><span class="n" style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; line-height: 17.99715805053711px; white-space: pre;">dirname</span><span class="p" style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; line-height: 17.99715805053711px; white-space: pre;">(</span><span class="bp" style="background-color: white; color: #999999; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; line-height: 17.99715805053711px; white-space: pre;"><strong>FILE</strong></span><span class="p" style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 11.818181991577148px; line-height: 17.99715805053711px; white-space: pre;">)</span>
&lt;/blockquote&gt;
and similar constructs far to much. This makes it hard to get a good overview of dependencies between files.<br /><br />
In order to get islands of related code we have turned to making local only gems. The gem structure helps to cut down on weird manipulations of the load path. It’s easier to get an overview by having related files and their tests in a separate folder.<br />&lt;h3&gt;
Bundler&lt;/h3&gt;
Bundler turns out to have a lot of nice tasks (a coworker told me about it):<br />&lt;blockquote class="tr_bq"&gt;
<span class="nb" style="background-color: white; color: #0086b3; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">require</span><span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;"> </span><span class="s1" style="background-color: white; color: #dd1144; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">‘bundler/gem_tasks’</span>
&lt;/blockquote&gt;
Looking at the bundler code helps when using the <a href="https://github.com/bundler/bundler/blob/master/lib/bundler/gem_helper.rb">GemHelper</a> class. If we look at gem_tasks.rb we find:<br />&lt;blockquote class="tr_bq"&gt;
<span class="nb" style="background-color: white; color: #0086b3; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">require</span><span style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;"> </span><span class="s1" style="background-color: white; color: #dd1144; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">‘bundler/gem_helper’</span> &lt;/blockquote&gt;</p>
<blockquote class="tr_bq">
<span class="ss" style="background-color: white; color: #990073; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">Bundler</span><span class="p" style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">:</span><span class="ss" style="background-color: white; color: #990073; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">:GemHelper</span><span class="o" style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; font-weight: bold; line-height: 18px; white-space: pre;">.</span><span class="n" style="background-color: white; color: #333333; font-family: Consolas, 'Liberation Mono', Courier, monospace; font-size: 12px; line-height: 18px; white-space: pre;">install_tasks</span>
</blockquote>
<p>The standard format for gemspecs usually make use of git ls-files. We got a lot of error messages from bundler and switched to use Dir.glob.<br />&lt;h3&gt;
Rails app turns into gem&lt;/h3&gt;
I’ve written a rails-app for a specific task. I started out with having most of the code in models, helpers in the rails app folder. This turned a bit sour after a while. In order to alleviate the code smell, I started moving the functionality into the lib folder. It turned out that we wanted to use the code in a different setting than as a web app. I moved the relevant tests and code from the lib folder into a new package/gem and added a dependency on this gem from the rails app.<br /><br />
We have since stopped maintaining the rails app, and it has been removed.</p>
<div style="clear: both;"></div>
National cloudshttp://assertfail.gewalli.se/2013/07/06/national-clouds.html
Sat, 06 Jul 2013 20:15:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/07/06/national-clouds<p>We first heard of the Australian government gettings <a href="http://delimiter.com.au/2012/04/13/us-slams-australias-on-shore-cloud-fixation/">fallout</a> from the US because of voiced concerns about using offshore cloud providers. Some technologists I have talked with thought it obvious that the US government would use <a href="http://www.guardian.co.uk/world/2013/jun/30/nsa-leaks-us-bugging-european-allies">available means</a> to get accurate information given the obsolesce of certain <a href="http://en.wikipedia.org/wiki/ECHELON">infrastructure</a>. This might spell an increased demand for local alternatives for business software. Another way is to start deploying software in a more security conscious manner. For instance encrypting the stored information so that the cost of spionage increases.</p>
<div style="clear: both;"></div>
Command line ansi colours on windowshttp://assertfail.gewalli.se/2013/07/05/command-line-ansi-colours-on-windows.html
Fri, 05 Jul 2013 09:17:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/07/05/command-line-ansi-colours-on-windows<p>There is a tool for that:<br /><a href="https://github.com/adoxa/ansicon">https://github.com/adoxa/ansicon</a></p>
<div style="clear: both;"></div>
Remote debugging of web pageshttp://assertfail.gewalli.se/2013/06/05/remote-debugging-of-web-pages.html
Wed, 05 Jun 2013 09:11:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/06/05/remote-debugging-of-web-pages<p>The apache project <a href="http://people.apache.org/~pmuellr/weinre/docs/latest/">Wienre</a> looks kind of cool.</p>
<div style="clear: both;"></div>
Listening to traffichttp://assertfail.gewalli.se/2013/05/20/listening-to-traffic.html
Mon, 20 May 2013 10:58:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2013/05/20/listening-to-traffic<p>While developing a web app, it’s easy to inspect the traffic in the browser (chrome, IE and firefox have all the ability to show traffic related to the page you are debugging). I recently refactored a lib to remove a library and use a raw webrequest. This was a move to remove dependencies. In my tests I added machine name instead of localhost and got the traffic in Fiddler. An easy way to remove the abstraction and start accessing the real json api.</p>
<div style="clear: both;"></div>
Test your update scriptshttp://assertfail.gewalli.se/2012/12/13/test-your-update-scripts.html
Thu, 13 Dec 2012 15:14:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/12/13/test-your-update-scripts<p>This is a lesson I should have learned. It comes back to bite me and my coworkers ever so often. Running a script to update data without test is always quick and dirty. SSIS is a wonderful tool, but there are fundamental flaws to this tool as it’s really hard to test SSIS packages. The beauty of using ruby or some other language (powershell, python, et.c.) is that you can write tests for the code. So, when you’re doing yourself the favor of using ruby, write tests!</p>
<div style="clear: both;"></div>
Writers and readershttp://assertfail.gewalli.se/2012/12/04/writers-and-readers.html
Tue, 04 Dec 2012 21:51:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/12/04/writers-and-readers<p>Reading source code is hard. One way of dealing with this is rewriting what is not understood. This can help focus on some parts of the code, but can be detrimental since it’s easy to overlook functionality in files that are not touched or files that look too complex (throwing away functionality). One way of doing this is to create a fork to rewrite one, in order to be able to throw away the changes made essentially to read the code. &lt;div&gt;
<br />
&lt;/div&gt;</p>
<div>
It's usually harder to <a href="http://gamedevwithoutacause.com/?p=1329">read code than to write it</a>. Trying to read a 700 line method can be to hard, thus it may need some <a href="https://github.com/kytrinyx/therapeutic-refactoring">therapeutic refactoring</a> in reduce the components to pieces that can be understood.</div>
<div>
<br />
</div>
<div>
Among several programmers, one reason why there is a tug o war between them can be because of non orthogonal and different best practices: They keep rewriting each others code because they have different ideas on what tradeoffs to prefer.</div>
<div style="clear: both;"></div>
Type matching in c#http://assertfail.gewalli.se/2012/11/22/type-matching-in-c.html
Thu, 22 Nov 2012 18:27:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/11/22/type-matching-in-c<p>I was thinking about how nice you have it in some languages where you can do a case statement for types. Thing is, we have a lot of <a href="https://gist.github.com/4132433">compiler goodness in C# already</a>.</p>
<p>By being explicit about the type and using type inference we can have a generic Case statement of a maximum length (depends on how many if else you think are ok to add).</p>
<p>I find it pretty sweet to write code like this:</p>
<div class="language-c# highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="n">TypeMatch</span><span class="p">.</span><span class="nf">Case</span><span class="p">(</span><span class="n">exception</span><span class="p">,</span>
<span class="err"> </span> <span class="p">(</span><span class="n">GnarlyType</span> <span class="n">e</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span> <span class="nf">HandleGnarly</span><span class="p">(</span><span class="n">e</span><span class="p">);</span> <span class="p">},</span>
<span class="err"> </span> <span class="p">(</span><span class="n">FuncyType</span> <span class="n">e1</span><span class="p">)</span> <span class="p">=&gt;</span> <span class="p">{</span> <span class="nf">HandleFunky</span><span class="p">(</span><span class="n">e1</span><span class="p">);</span> <span class="p">},</span>
<span class="err"> </span> <span class="p">()</span> <span class="p">=&gt;</span> <span class="p">{</span> <span class="nf">Explode</span><span class="p">();</span> <span class="p">});</span>
</code></pre></div></div>
<p>Instead of:</p>
<div class="language-c# highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">var</span> <span class="n">e</span> <span class="p">=</span> <span class="n">exception</span> <span class="k">as</span> <span class="n">GnarlyType</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">e</span><span class="p">!=</span><span class="k">null</span><span class="p">){</span> <span class="nf">HandleGnarly</span><span class="p">(</span><span class="n">e</span><span class="p">);</span> <span class="p">}</span>
<span class="k">else</span> <span class="p">{</span>
<span class="err"> </span> <span class="kt">var</span> <span class="n">e1</span> <span class="p">=</span> <span class="n">exception</span> <span class="k">as</span> <span class="n">FunkyType</span><span class="p">;</span>
<span class="err"> </span> <span class="k">if</span> <span class="p">(</span><span class="n">e1</span><span class="p">!=</span><span class="k">null</span><span class="p">){</span>
<span class="err"> </span> <span class="err"> </span> <span class="nf">HandleFunky</span><span class="p">(</span><span class="n">e1</span><span class="p">);</span>
<span class="err"> </span> <span class="p">}</span><span class="k">else</span><span class="p">{</span>
<span class="err"> </span> <span class="err"> </span> <span class="nf">Explode</span><span class="p">();</span>
<span class="err"> </span> <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>
<h3 id="small-note">Small note</h3>
<p>This type of feature is now part of c# proper as:</p>
<div class="language-c# highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">switch</span> <span class="p">(</span><span class="n">exception</span><span class="p">)</span>
<span class="p">{</span>
<span class="k">case</span> <span class="n">GnarlyType</span> <span class="n">e</span><span class="p">:</span> <span class="nf">HandleGnarly</span><span class="p">(</span><span class="n">e</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
<span class="k">case</span> <span class="n">FunkyType</span> <span class="n">e1</span><span class="p">:</span> <span class="nf">HandleFunky</span><span class="p">(</span><span class="n">e1</span><span class="p">);</span> <span class="k">break</span><span class="p">;</span>
<span class="k">default</span><span class="p">:</span> <span class="nf">Explode</span><span class="p">();</span> <span class="k">break</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>
Debugging fuzzy codinghttp://assertfail.gewalli.se/2012/11/10/debugging-fuzzy-coding.html
Sat, 10 Nov 2012 17:11:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/11/10/debugging-fuzzy-coding<p>As a programmer it is easy to adopt a view of the world in light of our experience. The workings of the world starts to look as something out of the matrix. This has some funny consequences:<br />
While listening to a person reasoning about the complicated events today from the point of view of famous thinkers; You can get the feeling of hearing a formalized thought pattern executed by a very complex machine. This sort of meta thinking naturally can be attributed to the formalization of execution that you work with, i.e. it is a view of programmable minds from the view of a mind programmed by thinking about programming.<br /><br />
This kind of thinking is useless unless it can be applied.<br /><br />
In the terms of a programmer: We are looking into how to debug the domain. The most important aspect of getting to know a domain is learning the language of that domain. The meaning of words inside that discussion context.<br /><br />
How do we reduce the task to something manageable? Simply learning all the language and statements associated with a given domain a huge undertaking. What is it that we want to learn? One of the interesting aspect of the domain is the grammar and the macro expansion of that domain. If we apply this to the world of programming, what kind of form of statements and what kind macros are we thinking in?<br /><br />
Most programmers work with the following concepts (I’m trying to simplify it):<br />
methods, classes (and instances of the classes), variables<br />
The most important execution constructs are:<br />
if, for<br /><br />
Naming methods, classes and variables turns the execution into a meaningful flow. Mostly we are working with details surrounding execution of our concepts. A programmer is working a lot with detail management (much like a weaver of a tapestry have to manage the the threads in order to get a working picture). A very serious problem is that it’s hard to find the right level of detail and abstraction to work with. The concepts above can be used to create detail at arbitrary levels. Kind of like lego versus duplo.<br /><br />
For the most part, many tend to prefer immutable constructs: Specified classes that do not change their behavior after initialization. This greatly simplifies reasoning.<br /><br />
Since programmers are working so much with abstractions, we tend to overdo abstraction.<br /><br />
What kind of conclusion can I draw from this? I’m not sure. It reads like the exact opposite of statistics. Mostly we program in predictable ways that get unpredictable due to the complexity rather than randomness of the input. Do we expect people to behave in this manner? Well, they sometimes behave similarly at a cursory glance. The big question would be what kind of programming we would write for people?</p>
<div style="clear: both;"></div>
The code I wrote is a messhttp://assertfail.gewalli.se/2012/11/06/the-code-i-wrote-is-mess.html
Tue, 06 Nov 2012 23:14:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/11/06/the-code-i-wrote-is-mess<p>Many times when you return to code that you have written you will swear and be annoyed with your lack of foresight.<br /><br />
We have been using a library since a while back. There is a definite strength to having a simple way of exposing actions from a console application. The code for the library and runner <a href="https://github.com/wallymathieu/isop">Isop</a> is a mess. A mess designed to avoid having to code a messy console application in order to do quick interactions with your code (.net code to be specific). The focus of the lib has always been to cater to the needs of business applications. I’ve not spent time cleaning up the code since it satisfies the criteria: If it works, why fix it?<br /><br />
It annoys me that I don’t have the time and energy to write beautiful code. This instinct is both healthy and dangerous. It helps you create maintainable applications, but it can also get you mired down into polishing. Ultimately it goes down to the fact that different structure caters to different intent and intent often changes (thus the unpleasant hindsight). Sometimes it’s that you had something simple to begin with, but as you fill in the gaps it becomes complicated.<br /><br />
What I’m trying to say is that it’s really hard to avoid the problem of complicated code or code that does not fit your intent. What you need is to refactor. This is the skill to use.</p>
<div style="clear: both;"></div>
Why should you make your new developers use ruby?http://assertfail.gewalli.se/2012/10/08/why-should-you-make-your-new-developers.html
Mon, 08 Oct 2012 22:42:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/10/08/why-should-you-make-your-new-developers<p>The impression I’ve gotten from working with ruby is that it’s generally fun to work with. One of my coworkers who has about a year of experience told me:<br /></p>
<ul>
<li>You become happy from working with ruby.<br />
Also, for many tasks it can provide a easier experience than some of the alternatives. Consider the tasks:<br /></li>
<li>Manage builds or server<br /></li>
<li>Simple web app<br />
Tools like rake and sinatra are simple enough to help green developers complete the task without drowning in the complexity.<br /><br />
It’s the same reasoning behind webmatrix. In webmatrix there is a lot <a href="http://stackoverflow.com/questions/5953394/is-there-a-unit-testing-capability-with-webmatrix">less focus on unit testing</a>. It’s a slightly different perspective, but still centered around <a href="http://blog.wekeroad.com/microsoft/someone-hit-their-head">simple fun stuff</a>.</li>
</ul>
<div style="clear: both;"></div>
Dark-room developmenthttp://assertfail.gewalli.se/2012/10/03/dark-room-development.html
Wed, 03 Oct 2012 06:24:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/10/03/dark-room-development<p>One of the fears is that <a href="http://www.codinghorror.com/blog/2012/10/the-pc-is-over.html">the days of PC is considered over</a>. That we there will be a massive shift towards a reduction of the interface. Some have pointed out that the start screen on <a href="http://www.youtube.com/watch?v=X0fsyb-ttcw">Windows 8: It’s Almost Not Terrible</a>. Gartner sums it up <a href="http://www.theregister.co.uk/2012/07/23/gartner_windows_8_review/">in a word: Bad</a> for desktops (however he also says that it’s very fine on touch device).<br /><br />
This all sounds very odd. However, the negativity mostly centered around how to use the start screen on a desktop might not be such a big deal. <a href="http://www.hanselman.com/blog/Windows8ProductivityWhoMovedMyCheeseOhThereItIs.aspx">Hanselman</a> among others assures that you just have to learn the new keyboard shortcuts and that it’s just a matter of getting used to. Our IT-boss (a small company so he does a lot of the IT-operations) tells me that a power user will hardly use the start screen.<br /><br />
As long as the two separate entities desktop and xbox/tablet interface live side by side there might not be cause for alarm for programmers using multiple windows side by side (editor, library documentation, tests, powershell, command prompt et.c.). Other programmers may in fact welcome the one window approach. Some have already used visual studio as the one program to do all things. Also for writers of text there are a few programs for <a href="http://they.misled.us/dark-room">windows</a> and <a href="http://www.hogbaysoftware.com/products/writeroom">mac</a> that focus on full-screen to avoid distractions and get things done. It’s exciting to see where Windows 8 goes.</p>
<div style="clear: both;"></div>
Typescripthttp://assertfail.gewalli.se/2012/10/02/typescript.html
Tue, 02 Oct 2012 19:38:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/10/02/typescript<p>Coffeescript has been heralded as a way to avoid some of the nastiness of javascript. Now <a href="http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript">Anders Hejlsberg introduces</a> a new addition to the story: Typescript. I read this from <a href="https://plus.google.com/102595450120395672452/posts">a pal</a> that <a href="http://tirania.org/blog/archive/2012/Oct-01.html">linked to a blog post</a>. The geist of the post is a slight positive note, but the author notes that <a href="http://en.wikipedia.org/wiki/IntelliSense">intellisense</a> is missing for editors other than visual studio. If the license is good (it’s <a href="http://typescript.codeplex.com/license">in Apache license</a>), the language additions are relevant, there might be people that get some of it to work in <a href="http://blogs.msdn.com/b/interoperability/archive/2012/10/01/sublime-text-vi-emacs-typescript-enabled.aspx">another editor</a>.</p>
<div style="clear: both;"></div>
Funky xml loghttp://assertfail.gewalli.se/2012/09/25/funky-xml-log.html
Tue, 25 Sep 2012 06:13:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/09/25/funky-xml-log<p>I had some trouble where a simple parser would take a bit of time. Turns out that there were many ways of improving this performance. I rewrote it to use the xml reader instead to be able to do <a href="http://www.hanselman.com/blog/XmlAndTheNametable.aspx">these improvements</a>. Some funky bugs got squished. The reader is a bit low level compared to niceties such as <a href="http://nokogiri.org/">Nokogiri</a> (in hindsight, maybe I should have been using). By using this class I could avoid some funkyness of XmlDocument having to cope with wierd xml at the expense of having less appealing code: <a href="https://github.com/wallymathieu/log4net-logviewer/blob/master/Core/LogEntryParser.cs">LogEntryParser</a>.</p>
<div style="clear: both;"></div>
Whats right with windows 8?http://assertfail.gewalli.se/2012/09/24/whats-right-with-windows-8.html
Mon, 24 Sep 2012 17:42:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/09/24/whats-right-with-windows-8<p><b id="internal-source-marker_0.444514345144853" style="font-weight: normal;"><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Imagine the user experience of a gaming console. It’s very focused on a selected few tasks: starting games, playing movies… An ipad is conceptually a similar device. You can surf, run certain applications, watch movies, listen to music. The user interface is simple. Most users have no need for the fuss.</span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">To imagine an operating system where you focus on what normal users want to do, you start looking in the windows 8 direction. The start screen reminds of the Xbox.</span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">I got skeptical and confused when I tried windows 8, looked at videos about it. The reason why it felt wrong: Windows 8 is not intended for me. I’m not part of the 95% that abhors complexity. Ordinary user dislike the “to much information” syndrome present for most desktop operating systems.</span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;"></span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">I have a suspicion that it’s not there yet. Maybe when windows 8.3 or windows 9 is released, my mom can use it without getting frustrated. There are just a few things she wants to do:</span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Surf the web, pay the bills, read her email, manage spreadsheets, write documents, manage her photos and keep the gigabytes of photos backed up.</span></b></p>
<div style="clear: both;"></div>
Always attaching debugger when starting a program in windowshttp://assertfail.gewalli.se/2012/09/24/always-attaching-debugger-when-starting.html
Mon, 24 Sep 2012 09:20:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/09/24/always-attaching-debugger-when-starting<p>So, Im using <a href="http://technet.microsoft.com/en-us/sysinternals/bb896645">Process Monitor</a> to hunt down some permission or anti virus problems in windows. I notice a query to a registry key “Image File Execution Options”. I get curious. Turns out that you can <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ff190925(v=vs.85).aspx">turn on a debugger</a> when starting a program. Someone used it to <a href="http://blogs.technet.com/b/marcelofartura/archive/2006/10/24/a-virus-infection-contolling-the-outbreak-tip.aspx">control a virus outbreak</a>, but it could be handy for other things as well.</p>
<div style="clear: both;"></div>
Visual studio 2012 all capshttp://assertfail.gewalli.se/2012/08/16/visual-studio-2012-all-caps.html
Thu, 16 Aug 2012 15:43:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/08/16/visual-studio-2012-all-caps<p>We are waiting for VS2012. What will impact work experience most will probably be the user interface changes as described in: <a href="http://blogs.msdn.com/b/visualstudio/archive/2012/05/08/visual-studio-11-user-interface-updates-coming-in-rc.aspx">Visual Studio 11 User Interface Updates Coming in RC</a><br /><br />
One thing I don’t understand is the preference for all caps. The interface is riddles with them. However Richard Banks describes <a href="http://www.richard-banks.org/2012/06/how-to-prevent-visual-studio-2012-all.html">howto prevent VS2012 ALL CAPS menus</a>, so there might be hope yet.</p>
<div style="clear: both;"></div>
Spending hours on trying to figure out why it does not checkhttp://assertfail.gewalli.se/2012/07/31/spending-hours-on-trying-to-figure-out.html
Tue, 31 Jul 2012 07:36:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/07/31/spending-hours-on-trying-to-figure-out<p>Yesterday I spent hours trying to figure out why a checkbox did not get checked (visually). When debugging the knockout code, it was clear that the DOM elements got checked. They did not update visually until another checkbox got checked. I tried other methods of checking the checkbox (both setAttribute and jquery) to no affect. What was even weirder is that it works the same in both chrome and IE.<br /><br />
To reproduce, click on the first checkbox and then the second in <a href="http://jsfiddle.net/ozzymcduff/xpk3Y/">this fiddle</a>.<br /><br />
I got the question if I had a click event handler from <a href="http://www.stealmycode.se/">steal my code</a>.<br /><br />
Turns out that the reason for this behavior is that I had a click event handler on a parent DOM element. By having the click handler return true the problem <a href="http://jsfiddle.net/ozzymcduff/xpk3Y/1/">was resolved</a>.<br /><br />
I still don’t understand why it works like this.</p>
<div style="clear: both;"></div>
Is philosophy relevant for programmers?http://assertfail.gewalli.se/2012/07/24/is-philosophy-relevant-for-programmers.html
Tue, 24 Jul 2012 18:30:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/07/24/is-philosophy-relevant-for-programmers<p><br />
Many programmers and engineers I’ve met say when asked about philosophy:<br />&lt;blockquote class="tr_bq"&gt;</p>
<ul>
<li>I don’t really care for it. It’s obsolete because of science.&lt;/blockquote&gt;
Could it be that it’s the engineering point of view? The view that some scientist (tool maker) cooks up the tools that the engineers use? Thus: truth and reality is simply handed down from a more trustworthy source.<br />&lt;h4&gt;
Science picks up the tab&lt;/h4&gt;
Science ( trademark of modern civilization ) has thus replaced philosophy ( funny thoughts by bearded old men ). However, the philosophy taught in schools is mostly focused on aggregating history into manageable chunks. It’s simplified history about thoughts spanning circa 2500 years.<br /><br />
I like the below explanation of philosophy:<br /><br />&lt;blockquote class="tr_bq"&gt;
Anthony Quinton, in T. Honderich (ed.), The Oxford Companion to Philosophy (Oxford University Press, 1995), p. 666: “Philosophy is rationally critical thinking, of a more or less <a href="http://en.wikipedia.org/wiki/Systematic">systematic</a> kind about the general nature of the world (metaphysics or theory of existence), the justification of belief (epistemology or theory of knowledge), and the conduct of life (ethics or theory of value). Each of the three elements in this list has a non-philosophical counterpart, from which it is distinguished by its explicitly rational and critical way of proceeding and by its systematic nature. Everyone has some general conception of the nature of the world in which they live and of their place in it. Metaphysics replaces the unargued assumptions embodied in such a conception with a rational and organized body of beliefs about the world as a whole. Everyone has occasion to doubt and question beliefs, their own or those of others, with more or less success and without any theory of what they are doing. Epistemology seeks by argument to make explicit the rules of correct belief formation. Everyone governs their conduct by directing it to desired or valued ends. Ethics, or moral philosophy, in its most inclusive sense, seeks to articulate, in rationally systematic form, the rules or principles involved.”&lt;/blockquote&gt;
From the <a href="http://en.wikipedia.org/wiki/Philosophy#cite_note-2">wikipedia article about philosophy</a><br /><br />&lt;h4&gt;
Do you really need it?&lt;/h4&gt;
Thing is, you still need to think on your own. You still need to determine what you want to do with your life. What reality or world view you want to have. As programmers we use language and abstractions as tools. <span style="background-color: white;">In order to use these in a </span><a href="https://patchwork.kernel.org/patch/705751/" style="background-color: white;">constructive way</a><span style="background-color: white;"> </span><span style="background-color: white;">(not jiggle things randomly </span><span style="background-color: white;">until they work), </span><span style="background-color: white;">you need to think and learn. </span><br />&lt;h4&gt;
<span style="background-color: white;">Evaluating software</span></li>
</ul>
<p>&lt;/h4&gt;
In many cases you need to evaluate things on your own. You will encounter different entities that try to get you to use different tools and different libraries. Or will you blindly let companies shove their solutions down your throat?
<br /><br />
What kind of shift of reality do you experience when you change environment? For instance change:<br /></p>
<ul>
<li>Programming language<br /></li>
<li>Web framework<br /></li>
<li>Between desktop and web programming<br /></li>
<li>Between server and client programming<br />
When shifting between these environments, it’s also a shift in how you solve problems. Different programmers value different writing experiences. Compare the static typing of java to write client applications in Google Web Toolkit to scripting using javascript. It’s a reflection of how you think about programming.<br /><br />
How do you evaluate a library? If it’s commercial, you try to guess how long it will be maintained by the company making it. If it’s open source, you try to ascertain how well maintained it is. If it is currently maintained et.c.. You try to guess the quality of the library. Also there is such aspects as cost and licence. Can you afford to use the library? Does the library have a licence so that you can use it together with your proprietary code base?<br />&lt;h4&gt;
<span style="background-color: white;">You are not a simple consumer of tools</span></li>
</ul>
<p>&lt;/h4&gt;
As a programmer, you should be willing to write your own library if that’s what you need. You should be able to evaluate what tools to use when doing your work. Programming is the act of creating text that can be used as tools. You are a toolmaker and a tool consumer. Builder and toolmaker. You are an author and a reader. It helps to think.</p>
<div style="clear: both;"></div>
Process within a companyhttp://assertfail.gewalli.se/2012/07/15/process-within-company.html
Sun, 15 Jul 2012 21:11:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/07/15/process-within-company<p>So is a <a href="http://en.wikipedia.org/wiki/Business_process">process</a> something like an algorithm or program but executed by people?</p>
<div style="clear: both;"></div>
Is agile a developer-centric scam?http://assertfail.gewalli.se/2012/07/15/is-agile-developer-centric-scam.html
Sun, 15 Jul 2012 14:25:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/07/15/is-agile-developer-centric-scam<p><a href="http://adtmag.com/articles/2012/07/13/report-says-agile-a-scam.aspx">This article</a> tells of a report where they suspect agile of being developer-centric scam in order for developers to avoid unwanted tasks:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>In spite of the specialization of resources which limits the scope of the work of developers, the Agile movement might inspire and encourage developers to push back on processes, tools, documentation, and following plans,
</code></pre></div></div>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Be aware that the Agile movement might very well just be either a developer rebellion against unwanted tasks and schedules or just an opportunity to sell Agile services including certification and training.
</code></pre></div></div>
<h3 id="unwanted-tasks-like-documentation">Unwanted tasks like documentation</h3>
<p>One assumption mentioned is that in order for a system to be maintainable you need documentation. This assumption is to broad to be of value. It depends on how easy it is to read the code. That is, the readability of the programming language determines if you need large amounts of documentation or not. The usual case is that even for complex systems, it can be detrimental. Adding documentation adds non executable text that needs to be in sync with other source code, that is executable text. Since the time spent developing software and debugging software is related to the amount of text in the associated source files, the time can increase without any benefit. For code that is hard to read: large regexp, assembly language, et.c. There is a benefit of good documentation.</p>
<p>Maybe it’s an excuse to get more work done?</p>
<h3 id="software-engineering">Software engineering?</h3>
<p>The other question is why do they make the contrast “developer-centric” with “software engineering”? <a href="http://www.cs.usfca.edu/~parrt/doc/software-not-engineering.html">If there is such a thing as software engineering</a>, then it <em>does not mean</em> to be <em>oblivious</em> of the core tools (programming languages) used to create software. The usefulness of a processes, such as documentation needs to be reevaluated with new capabilities of the tools.</p>
<h3 id="processes-and-planning">Processes and planning?</h3>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>the Agile movement might inspire and encourage developers to push back on processes, tools, documentation, and following plans
</code></pre></div></div>
<p>I have personally been part of development where the processes and the planning made sure that very little could accomplished if you compare to a small focused development team without the overhead. Development time equals money. That kind of practice is not applicable for every software project.
Again, the conclusion could be that the people involved are just trying to be more effective and productive.</p>
<h3 id="conclusion">Conclusion</h3>
<p>Agile is a scam to lessen unwanted tasks that stifle productivity. Thus, it’s a call to improve software development and help developers breathe more easily. For more information about agile read the <a href="http://agilemanifesto.org/">agile manifesto</a>.</p>
Web versus native app loginhttp://assertfail.gewalli.se/2012/07/13/web-versus-native-app-login.html
Fri, 13 Jul 2012 14:53:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/07/13/web-versus-native-app-login<p>What are the most important differences between native applications and web applications (for mail, rss et.c.) when it comes to login?<br /><br />
Native applications usually store login information. For web applications this is dependant on the browser in order to store login form. Depending on application, there can be days between resubmition of credentials.<br /><br />
For unix applications there are alternatives like ssh shared keys. It enables connection from one machine (login) to another. It would be interesting if this approach could be reused for browser to web server communication. That is: generating a shared key for a single browser/machine. If you could generate a one time use string from the phone company in order to anonymize the identity? The identity of the user would still be transparent to ISP and other infrastructure providers. The setup to use a site from a new machine/login would be a hassle. For single use scenario: Maybe one session tokens sent to the phone when you are at an internet cafe?<br /><br />
Currently the alternatives are reduced to form fillers and password managers. Some browsers implement these features.</p>
<div style="clear: both;"></div>
Refusing to work with a technology or a toolhttp://assertfail.gewalli.se/2012/06/10/refusing-to-work-with-technology-or.html
Sun, 10 Jun 2012 12:21:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/06/10/refusing-to-work-with-technology-or<h2>
<b id="internal-source-marker_0.35410438221879303" style="font-size: medium; font-weight: normal;"><h2 dir="ltr">
<span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap;">Refusing?</span>
</h2>
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">As a developer, assume that you are given technology or tool X and told that you need to create Y using it. Sometime it's just getting down to business and getting it done. Sometimes you realize that using said technology is a mistake. It could be that the technology isn't appropriate for the task. It could be that there are simpler cheaper solutions (things that take less of your time). It could also be that you feel that it's outside of your job: Like asking an accountant to do the floors.</span><br /><h3 dir="ltr">
<span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap;">What do you do?</span>
</h3>
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">What you feel as professional, refusal to waste money and resources, could be interpreted as unprofessional. Your refusal could be interpreted by your manager as </span><a href="http://programmers.stackexchange.com/questions/84332/how-to-deal-with-the-developers-refusing-to-use-certain-technologies-or-tools"><span style="color: #1155cc; font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">behaving as a child</span></a><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">:</span><br /><span style="font-family: Arial; font-size: 15px; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">"Developers who act like children (refusing to use a tool mandated by a customer!) are not good developers no matter what their coding skills. ..."</span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">The above answers sounds a bit childish: Since my parents refuse to let me eat candy, they are not good parents.</span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Another answers deals with the role of a developer (slightly rewritten): </span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">"</span><span style="font-family: Arial; font-size: 15px; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">you hired developers and you are trying to get them to do something else</span><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">"</span><br /><h4 dir="ltr">
<span style="font-family: Arial; font-size: 16px; vertical-align: baseline; white-space: pre-wrap;">If it's not your job</span>
</h4>
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">A more experienced coworker told me that the best action is to endure. If you get to do more interesting things later on, then it could be worth hanging in there. If your manager starts to give you more of the same work, since you have done so well before, then it might be time to look for a new job. It could be that your skills as a developer are less valued than work with technology or tool X at that company. </span><br /><h4 dir="ltr">
<span style="font-family: Arial; font-size: 16px; vertical-align: baseline; white-space: pre-wrap;">Creating shoddy solutions?</span>
</h4>
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">Developers are usually driven to do a good job. I've done things I'm not proud of. I've helped create solutions that are shoddy because the underlying technology is wrong for the customer. But I've done it since the customer wanted it. I've tried to do the best job I can. I've informed my superiors about the problems. It could be that the shoddy solution is good enough for the customer. It could be that you realize that technology or tool X is really good when used specifically to do the things it's designed for. You can then help customers use X when it's </span><span style="font-family: Arial; font-size: 15px; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap;">appropriate</span><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">.</span><br /><h4 dir="ltr">
<span style="font-family: Arial; font-size: 16px; vertical-align: baseline; white-space: pre-wrap;">Try to offer alternatives</span><span style="color: #666666; font-family: Arial; font-size: 15px; font-weight: normal; vertical-align: baseline; white-space: pre-wrap;"></span>
</h4>
<span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">It could be that the request to work with technology or tool X is simply the request to get work Y done. If that’s the case, then you can reason with your manager about not involving technical terms when talking about what needs to be done.</span><br /><span style="font-family: Arial; font-size: 15px; vertical-align: baseline; white-space: pre-wrap;">It could be that a change of requirements can make the technology or tool a better fit. In that case, you should try to get your manager to steer the customer in the right direction.</span><br /><h3 dir="ltr">
<span style="font-family: Arial; vertical-align: baseline; white-space: pre-wrap;">What should you avoid?</span>
</h3>
<ul style="margin-bottom: 0pt; margin-top: 0pt;">
<li style="font-family: Arial; font-size: 15px; list-style-type: disc; vertical-align: baseline;"><span style="vertical-align: baseline; white-space: pre-wrap;">Making it personal or emotional. This will only make it harder in the future to work together.</span></li>
<li style="font-family: Arial; font-size: 15px; list-style-type: disc; vertical-align: baseline;"><span style="vertical-align: baseline; white-space: pre-wrap;">Refusing in front of others. This might require your manager to save face. </span></li>
<li style="font-family: Arial; font-size: 15px; list-style-type: disc; vertical-align: baseline;"><span style="vertical-align: baseline; white-space: pre-wrap;">Talking about the technical reason to a non technical manager or customer. This will sound like an excuse to a non technical person. You should give an easy to understand summary. </span></li>
<li style="font-family: Arial; font-size: 15px; list-style-type: disc; vertical-align: baseline;"><span style="vertical-align: baseline; white-space: pre-wrap;">Fooling yourself into believing that technology Y, that you have not tried yet, is better. It might be better in some aspects. It might also be that it’s got different problems.</span></li>
<li style="font-family: Arial; font-size: 15px; list-style-type: disc; vertical-align: baseline;"><span style="vertical-align: baseline; white-space: pre-wrap;">Fooling yourself into believing that technology Z, that you usually use, is better. If you don’t know technology X, then an outright dismissal of it is without grounds. That said, you should be sceptical of any technology that you hear fearful rumours about. </span></li>
<li style="font-family: Arial; font-size: 15px; list-style-type: disc; vertical-align: baseline;"><span style="vertical-align: baseline; white-space: pre-wrap;">Fooling yourself into believing that you can roll your own framework that does it better.</span></li>
<li style="font-family: Arial; font-size: 15px; list-style-type: disc; vertical-align: baseline;"><span style="vertical-align: baseline; white-space: pre-wrap;">Fooling yourself into believing that you need a framework when all you need is a bit of code.</span></li>
</ul></b>
</h2>
<div style="clear: both;"></div>
Technology and musichttp://assertfail.gewalli.se/2012/06/03/technology-and-music.html
Sun, 03 Jun 2012 19:08:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/06/03/technology-and-music<h4>
We dont event know how old instruments are </h4>
<p>The earliest type of instrument is thought to be flutes. According to wikipedia this technology could be as old as 43,400 and 67,000 years. Simple devices for making rhythm where probably made: drums, rattles. But since they are usually composed of organic matter, they would decompose leaving little trace. Without knowing much I would guess that humans developed stringed instruments relatively early. My unscientific guess is that these kinds of instruments developed alongside bow and arrow. Making them perhaps 18,000 years old. Maybe even older. Or perhaps the use of instruments as a musical tool is more recent (maybe 9,000 years old). I’m very much colored by my perception of human artistic expression.&lt;h4&gt;
Metal working&lt;/h4&gt;</p>
<div>
<div>
As technology advanced, so would the potential for musical instruments advance. With metal working cymbals, sistrum, bells as well as gongs can be made. Trumpets could be made in metal to produce new sounds.</div>
<div>
<h4>
Hydraulic and pneumatic</h4>
<div>
The use of a mechanical power source enabled the hydraulic organ. The church organs must have been expensive technological marvel. It is a huge and impressive instrument. Probably one of the must awesome noisemakers before the invention of electric instruments.</div>
<h4>
Ca 18th century</h4>
<div>
The invention of the piano is around the late 17th and the beginning of 18th century. It's an amazing technological advancement: A key operated string instrument.</div>
<h4>
The 19th century</h4>
<div>
One specific piece of technology are behind some of the brass instruments: Valves. A recent tech, developed in the 19th century. An older technique was to use keys to open holes in a wind instrument.</div>
<h4>
Early 20th century</h4>
<div>
In the 20th century electric instruments where developed. An excellent example of this is the electric guitar. The solid body electric guitar embodies the advent of modern industry. Produced with a wooden solid body and a bolt on neck together with magnetic pickup. It's industrial design! A continuation of the old stringed instruments into the modern era.</div>
</div>
<div>
<br />
</div>
<div>
An exciting development is the theremin. An instrument totally unlike older instruments. Two metal antenna to sense the position of the hands to control frequency and amplitude. </div>
<div>
<br />
</div>
<div>
We have the telharmonium from just before the 20th century. It's a musical instrument made with <a href="http://en.wikipedia.org/wiki/Tonewheel">tone wheels</a>. It is an instrument that was made to generate musical sound from an electric signal. The instrument never caught on since it required immense amounts of power and weighed almost 200 tons. It was an impressive technological achievement since it could reproduce the sound of common woodwind instruments. Hammond created an affordable instrument, using tone wheels, called the Hammond organ.</div>
</div>
<h4>
Later instruments</h4>
<div>
With digitally generated sound, there are huge possibilities. There are enormous possibilities for advancing the usability of tone/sound generation. Another important factor is the price of instruments. A simple flute is very cheap. More complex instruments like an electric guitar or a keyboard are very affordable instruments. A keyboard has excellent usability: The keys maps to the chromatic scale. </div>
<div style="clear: both;"></div>
Github for windowshttp://assertfail.gewalli.se/2012/05/25/github-for-windows.html
Fri, 25 May 2012 12:22:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/05/25/github-for-windows<p>We had a small problem with one of the open source components that we use. One of my coworkers had to make a small alteration to that component (he isn’t using git at work). The <a href="http://windows.github.com/help.html">github for windows</a> program makes interacting with github very easy on windows. All he had to do was to install the program (easy installation) and clone his fork. Really useful for this kind of work.</p>
<div style="clear: both;"></div>
Regarding javascript namespaceshttp://assertfail.gewalli.se/2012/04/07/regarding-javascript-namespaces.html
Sat, 07 Apr 2012 07:22:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/04/07/regarding-javascript-namespaces<p>There seems that the there is a shift from the Crockford style global variables to lower case namespaces or mixed case.
Older libraries use the Crockford style all caps.</p>
<ul>
<li><a href="http://yuilibrary.com/yui/docs/event/basic-example.html">YUI</a></li>
<li><a href="https://github.com/douglascrockford/JSON-js/blob/master/json2.js">JSON</a></li>
</ul>
<p>Probably this is influenced by Crockford’s <a href="http://javascript.crockford.com/code.html">thoughts about global variables</a></p>
<p>Newer libraries use a less screamy namespace name:
jQuery, Prototype, Ext, dojo, ko</p>
Domain analysis of an application databasehttp://assertfail.gewalli.se/2012/03/18/domain-analysis-of-application-database.html
Sun, 18 Mar 2012 12:32:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/03/18/domain-analysis-of-application-database<p>A relational database is not only a source of content. It can also be used as a mine for domain information related to domain of an application that uses that database. The schema, if it is well maintained, will give you an overview of the problem domain. If the schema is not well maintained, you can factor out the conventions used in that particular database for relations and create a patched schema with the real relations. As you generate a graph of the database you can start filtering out some of the details (important for business logic) but not for the big picture. Some of the things you can get from the graph will be trivial. It might also give you a better understanding of the big picture. By plotting this graph, you can get a overview helpful for identifying subdomains.<br /><br />
Maybe if we have a sufficiently large body of text describing the domain we can use a statistical approach to identify words relevant to the domain. The identification of these words will probably be easier if we have some larger body of text to use as for comparison of the frequencies of sentence construction words in that language (that is to filter out words like: ‘the’, ‘for’, ‘he’, ‘she’ et.c. in english).<br /><br />
By combining the above simple domain mining techniques and talking to people fluent in the domain you can get a shallow technical understanding of the domain. This can be helpful for understanding the details of the domain.</p>
<div style="clear: both;"></div>
Project Roslynhttp://assertfail.gewalli.se/2012/03/17/project-roslyn.html
Sat, 17 Mar 2012 10:57:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/03/17/project-roslyn<p>In some settings you might need to access more of the language than available through reflection and System.Linq.Expressions. You might want to look into <a href="http://msdn.microsoft.com/en-us/hh543916">project Roslyn</a> or <a href="https://github.com/icsharpcode/NRefactory/">NRefactory</a>. These will let you access the c# parser. This can be useful in many settings. For instance, to refactor c#. To render the code to another language.</p>
<div style="clear: both;"></div>
Languagehttp://assertfail.gewalli.se/2012/03/08/language.html
Thu, 08 Mar 2012 07:31:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/03/08/language<p>Make sure that the environment variable <span style="background-color: white; font-family: Verdana, Geneva, Helvetica, Arial, sans-serif; font-size: 13px;">LANG is set to “us_EN.UTF-8”. Otherwise you might get the translated versions…</span></p>
<div style="clear: both;"></div>
Chocolateyhttp://assertfail.gewalli.se/2012/02/28/chocolatey.html
Tue, 28 Feb 2012 18:56:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/02/28/chocolatey<p>Thanks to <a href="http://geekswithblogs.net/robz/Default.aspx">Fervent Coder</a> we have <a href="http://chocolatey.org/">Chocolatey</a>. It can be used to setup a development machine with new software. Installing java, notepad++ becomes as easy as:<br /><a href="http://chocolatey.org/packages/javaruntime">cinst javaruntime</a><br />
…</p>
<div style="clear: both;"></div>
File uploadhttp://assertfail.gewalli.se/2012/02/22/file-upload.html
Wed, 22 Feb 2012 20:00:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/02/22/file-upload<p>The alternatives right now (2012-02-22):<br /><br />&lt;ol&gt;</p>
<li>Standard html: File select together in a form that is submitted to a page. (firefox, chrome, IE)</li>
<li>Iframe hack: File select together with hidden iframe used to upload file. (firefox, chrome, IE)</li>
<li>Flash (all flash enabled browsers)
</li>
<li>FileReader
(firefox, chrome)</li>
<ol>
<li>Drag and drop together with FileReader and ajax post. </li>
<li>File select together with FileReader and ajax post.</li>
</ol>
<p>&lt;/ol&gt;</p>
<div>
When building ordinary web applications then the first alternative is definitely the best. It's simple and works well. If you are building a more javascript intense application you are in a different mess. If you are supporting IE 7-9 then alternative 2 and 3 is what you are looking for. To enable the best experience you could sniff if the browser handles FileReader (since IE10 might support it) and enable a better experience in that case.</div>
<div>
<br />
</div>
<div>
Note: I've only considered firefox, chrome and IE. </div>
<div style="clear: both;"></div>
asp.net mvc 4http://assertfail.gewalli.se/2012/02/20/aspnet-mvc-4.html
Mon, 20 Feb 2012 20:40:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/02/20/aspnet-mvc-4<p>asp.net mvc 4 has been <a href="http://weblogs.asp.net/scottgu/archive/2012/02/19/asp-net-mvc-4-beta.aspx">released to beta</a>. The exciting news here is websockets. Migrations for entity framework could help people realize the usefulness the technique.</p>
<div style="clear: both;"></div>
Continuous code coveragehttp://assertfail.gewalli.se/2012/02/19/continuous-code-coverage.html
Sun, 19 Feb 2012 16:54:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/02/19/continuous-code-coverage<p>What if we could do a continuous code coverage? That is, while debugging and testing the app, storing the coverage information. A first version would consider lines that are not changed as covered if they have been executed during previous runs. This could be a sort of blunt tool to help isolate code that should be flagged either for removal, for code review, automatic or manual testing.<br /><br />
It should be simple enough to <a href="https://github.com/wallymathieu/js_codecover_reporting">send information</a> about code coverage when running javascript code. The challenge is to map the coverage information with source lines and keeping some sort of data structure that represents the code and coverage information that can be updated with the old coverage information form previous versions of the code.</p>
<div style="clear: both;"></div>
Avoid batch fileshttp://assertfail.gewalli.se/2012/02/17/avoid-batch-files.html
Fri, 17 Feb 2012 19:36:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/02/17/avoid-batch-files<p>When programming on windows, you will sometimes need to execute batch files. It might seem like a good idea to do something simple in a batch file. This is the time you should realize that it it’s a slippery slope. Dont go there.<br /><br />
There are excellent alternatives! Powershell works well for scripting (as long as you accept the signing or set-execution-policy). Ruby is sweet for scripting. There are alternatives that will let simple things be simple.</p>
<div style="clear: both;"></div>
Metro style revolutionhttp://assertfail.gewalli.se/2012/01/29/metro-style-revolution.html
Sun, 29 Jan 2012 13:14:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2012/01/29/metro-style-revolution<p>The more I think about the <a href="http://msdn.microsoft.com/en-us/windows/apps/br229512">metro style</a>, it sounds really revolutionary for microsoft design. I’ve started looking at how the new windows phone style looks. It looks more modern than the other themes for smart phones. Probably because it’s not been used as much.<br /><br />
I feel that <a href="http://en.wikipedia.org/wiki/Windows_Aero">windows aero</a> was to bloated in visual space. It looks sweet on a machine with high enough resolution and screen space, but looks to bulky on other things. The default margins take to much space. The <a href="http://en.wikipedia.org/wiki/Windows_XP_themes#Windows_Classic_theme">classic gray theme</a> has been my preferred theme when working in windows. When working, it’s nice to have a theme that does not require attention.<br /><br />
So the conclusion is that I’m excited about the possible metro theme for windows.</p>
<div style="clear: both;"></div>
Using backbone routes together with knockouthttp://assertfail.gewalli.se/2011/12/13/using-backbone-routes-together-with.html
Tue, 13 Dec 2011 11:00:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/12/13/using-backbone-routes-together-with<p>We have <a href="https://github.com/SteveSanderson/knockout/wiki/Scott%27s-method">Scott’s method</a>. He uses backbone together with knockout. You might want to read the following <a href="http://groups.google.com/group/knockoutjs/browse_thread/thread/9a7ad2b44885cf5a?pli=1">google group posts</a>. I like how you declare your setup on the app object. The problem with using only knockout for creating js app’s is that it only focused on view to modelview binding. Also Derick Bailey has made <a href="http://lostechies.com/derickbailey/2011/11/22/backbone-vs-knockout/">a comment</a> about the curious idea that you choose either knockout or backbone.</p>
<div style="clear: both;"></div>
MVVM Plus Conductor with Knockout jshttp://assertfail.gewalli.se/2011/12/01/mvvm-plus-conductor-with-knockout-js.html
Thu, 01 Dec 2011 16:34:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/12/01/mvvm-plus-conductor-with-knockout-js<p>A better fit in the browser world for knockout than MVC is to have something like a controller. A class responsibe for being an endpoint for routes. This is natuarally coupled with the responsibility of changing between screens. Since controller is such a loaded word, lets simply call it conductor.<br /><br />
That gives you the following components: Model view, view-model and conductor. In order to implement the pattern you can use crossroads js or something similar.<br /><br />
That means that crossroads will route to different conductors that marries view-models and views and sends them off. When the viewmodel changes in such a way that it needs to update the url, it tells the conductor to change the url. Anyone can also ask a conductor to present an object (thus changing the url and updating the screen).</p>
<div style="clear: both;"></div>
using underscore filter in IE 7 & 8http://assertfail.gewalli.se/2011/11/09/using-underscore-filter-in-ie-7-8.html
Wed, 09 Nov 2011 20:00:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/11/09/using-underscore-filter-in-ie-7-8<p>Array.prototype.filter seems to be slightly off in IE7-8. It looks like they have added support for standard array functions. That is, it looks like there is a prototype for this in IE7-8 mode in IE9. The problem is that the filter prototype does not work exactly as expected in underscore.<br /><br />
If we look at the documentation for this method on <a href="http://msdn.microsoft.com/en-us/library/ff679973(v=vs.94).aspx">msdn</a> you find that this is probably a bug.<br /><br />
It is simple to patch the prototype implementation you find using F12 in IE. Otherwise you could use the prototype described in the <a href="http://stackoverflow.com/questions/2790001/fixing-javascript-array-functions-in-internet-explorer-indexof-foreach-etc">stackoverflow</a> post (i.e. Mozilla’s Array filter implementation):<br /><a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter">https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter</a></p>
<div style="clear: both;"></div>
Isop libraryhttp://assertfail.gewalli.se/2011/11/06/isop-library.html
Sun, 06 Nov 2011 20:54:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/11/06/isop-library<p>Implemented isop auto cli. It’s possible to use the isop library without having a reference to isop.</p>
<div style="clear: both;"></div>
Press play on tapehttp://assertfail.gewalli.se/2011/10/17/different-controllers.html
Mon, 17 Oct 2011 08:31:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/10/17/different-controllers<p>Lovely geekery when <a href="http://www.youtube.com/watch?v=hLWw1OpDrpI">press play on tape plays cannon fodder</a> with old game controllers. Why not <a href="http://www.youtube.com/watch?v=mYZXNVHVfhc">monkey island</a> :).</p>
<div style="clear: both;"></div>
dotnet-console is now Isophttp://assertfail.gewalli.se/2011/10/08/dotnet-console-is-now-isop.html
Sat, 08 Oct 2011 21:28:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/10/08/dotnet-console-is-now-isop<p>I’ve renamed the dotnet-console project on github to <a href="https://github.com/wallymathieu/isop">isop</a>. Isop is the swedish name for hyssop. Like any spice it is intended to give flavor to the development of command line apps in .net.</p>
<div style="clear: both;"></div>
Using msysgit in cygwinhttp://assertfail.gewalli.se/2011/10/07/using-msysgit-in-cygwin.html
Fri, 07 Oct 2011 09:21:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/10/07/using-msysgit-in-cygwin<p>There are some pitfalls. One for instance is that it starts the editor wrong when running msysgit in the cygwin shell. Naturally I tried specifying different paths and ended up with the following configuration of gitconfig:<br /><span class="Apple-style-span" style="background-color: black; color: white; font-family: 'Courier New', Courier, monospace;">c:\cygwin\home\wallymathieu.gitconfig</span><br /><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">[core]</span><br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"> editor = “"/c/Program Files (x86)/Vim/vim73/gvim.exe"”</span><br /><br />&lt;div style="clear: both;"&gt;&lt;/div&gt;</p>
Command line option parsinghttp://assertfail.gewalli.se/2011/10/07/command-line-option-parsing.html
Fri, 07 Oct 2011 05:58:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/10/07/command-line-option-parsing<p>I’ve updated the <a href="https://github.com/wallymathieu/isop">dotnet-console</a> to enable help. It’s not finished, but it’s looking better. Still needs a lot of refactoring though. The tests document the more stable fluent interface. The stuff behind the fluent interface is more prone to change.<br />
It’s an interesting experience to code the tests against a higher level api that is relatively stable (as an interface) and have an underlying changing implementation.</p>
<div style="clear: both;"></div>
Having at least 2 monitors?http://assertfail.gewalli.se/2011/10/02/having-at-least-2-monitors.html
Sun, 02 Oct 2011 21:37:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/10/02/having-at-least-2-monitors<p>Why so <a href="http://www.hanselman.com/blog/TheSweetSpotOfMultipleMonitorProductivityThatMagicalThirdMonitor.aspx">many monitors</a>? I used to have the same kind of layout on my home computer while at the university by using X11. You have virtual desktops (not to be confused with the software) or workspaces.<br /><br />
The same concept on mac os x differs significantly from how it works on linux.<br /><br />
Part of the problem might be technological: When I’ve tried out virtual desktops on windows, the programs become extremely unstable.<br /><br />
User friendly: The concept of virtual desktop is probably not very conceptually friendly for a person without a lot of experience with computers. Since power users are assumed to have enough money to buy enough big monitors.</p>
<div style="clear: both;"></div>
Simple noise on the arduinohttp://assertfail.gewalli.se/2011/10/02/simple-noise-on-arduino.html
Sun, 02 Oct 2011 19:04:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/10/02/simple-noise-on-arduino<p>Inspired by the <a href="http://www.motherboard.tv/2011/9/29/minimalism-worship-these-sweet-loops-were-made-with-only-one-line-of-code">minimalists</a> I tried this out on the arduino:<br /><br /><br />
int speakerPin = 11;<br /><br />
void outp(byte value) {<br />
analogWrite(speakerPin, value); delayMicroseconds(200);<br />
}<br /><br />
void setup() {<br />
pinMode(speakerPin, OUTPUT);<br /><br /><br />
// Set up Timer 2 to do pulse width modulation on the speaker<br />
// pin.<br /><br />
// Use internal clock (datasheet p.160)<br />
ASSR &amp;= ~(_BV(EXCLK) | _BV(AS2));<br /><br />
// Set fast PWM mode (p.157)<br />
TCCR2A |= _BV(WGM21) | _BV(WGM20);<br />
TCCR2B &amp;= ~_BV(WGM22);<br /><br />
// Do non-inverting PWM on pin OC2A (p.155)<br />
// On the Arduino this is pin 11.<br />
TCCR2A = (TCCR2A | _BV(COM2A1)) &amp; ~_BV(COM2A0);<br />
TCCR2A &amp;= ~(_BV(COM2B1) | _BV(COM2B0));<br /><br />
// No prescaler (p.158)<br />
TCCR2B = (TCCR2B &amp; ~(_BV(CS12) | _BV(CS11))) | _BV(CS10);<br /><br />
}<br /><br />
void loop() {<br />
int t;<br />
for(t=0;;t++){ outp(t*((t&gt;&gt;12|t&gt;&gt;8)&amp;63&amp;t&gt;&gt;4)); }<br />
}<br /><br />
It does sound somewhat similar. So right now it’s just a hack in order to try it out.<br /><br />
Note:<br />
The code above is corrected with a little help from <a href="http://forskningsavd.se/">Davey at forsken</a>.</p>
<div style="clear: both;"></div>
Implementing Dispose method in .nethttp://assertfail.gewalli.se/2011/09/25/implementing-dispose-method-in-net.html
Sun, 25 Sep 2011 19:30:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/09/25/implementing-dispose-method-in-net<h3 id="dispose">Dispose</h3>
<p>In order to release unmanaged resources you need to use or implement the dispose method.</p>
<h3 id="unmanaged-resource">Unmanaged resource</h3>
<p>So what is an unmanaged resource? It is simply resources that the CLR does not manage for you. For example: File streams, database connections, P/Invoked api:s.</p>
<h3 id="how-to-implement-dispose">How to implement Dispose?</h3>
<p>Msdn gives a rather clear <a href="http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx">answer</a>.</p>
<ul>
<li>You need to implement the IDisposable interface.</li>
<li>If you have implemented a finalizer as well then you need to add a call to <code class="highlighter-rouge">GC.SuppressFinalize</code> inside the dispose method. This is to avoid that the finalize method is called for the object.</li>
</ul>
<h3 id="when-is-it-unsafe-to-call-both-dispose-and-finalize">When is it unsafe to call both dispose and finalize?</h3>
<p>One reason could be that you’re dealing with a P/Invoked api. Telling the unmanaged code to clean up the resources associated with a particular pointer twice can cause unintended consequences. Using closed handles is a security risks since windows recycles handles. Another reason is performance: A finalize is costly to perform.</p>
<h3 id="alternative-to-using-intptr">Alternative to using IntPtr</h3>
<p>In order to simplify the use of operating system handles you can use “Safe Handle”.</p>
Windows 8http://assertfail.gewalli.se/2011/09/19/windows-8.html
Mon, 19 Sep 2011 20:26:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/09/19/windows-8<p>I like the look of windows 8. For touch devices it will be sweet. What confounds me is that the start menu is replaced by the “Metro” application launcher. That sounds exceedingly annoying when on standard hardware. Where is the love for an ordinary PC?<br /><br />
The reason for the weird usability is that it is intended for touch enabled computers:<br />
http://www.youtube.com/watch?v=ntSdfGzF60M&amp;feature=player_embedded#!<br /><br />
I’m confused about the talk about the name Windows 8. Is it supposed to be a general windows?</p>
<div style="clear: both;"></div>
WinRT replaces win32http://assertfail.gewalli.se/2011/09/19/winrt-replaces-win32.html
Mon, 19 Sep 2011 20:21:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/09/19/winrt-replaces-win32<p>Sounds interesting to hear about the new WinRT api:s for windows. Reading up on it WinRT are COM objects in contrast to the Win32 architecture.<br />
One of the exciting things about this is the promise of being able to use xaml in c++.<br /><br />
An overview of WinRT by Marius Bancila:<br /><a href="http://mariusbancila.ro/blog/2011/09/15/windows-runtime/">Windows Runtime</a><br /><br />
It’s quite interesting to read the list on Msdn:<br /><a href="http://msdn.microsoft.com/en-us/library/windows/apps/hh464945(v=VS.85).aspx">Windows Runtime and the Windows API</a><br /><br />
Right now it’s probably to early to get a good idea of how everything will look and exactly what features will be accessible for Metro style apps.<br /><br />
Replacing the Win32 api:s is probably an overstatement. I would guess that for some things you might be forced to use older api:s.</p>
<div style="clear: both;"></div>
Running Rake under cygwinhttp://assertfail.gewalli.se/2011/09/01/running-rake-under-cygwin.html
Thu, 01 Sep 2011 13:14:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/09/01/running-rake-under-cygwin<p>I had some problems with running rake under cygwin. I get the following error while trying to execute rake:<br /><span class="Apple-style-span" style="background-color: black; color: white;">C:\Ruby192\bin\ruby.exe: No such file or directory – /cygdrive/c/Ruby192/bin/rake (LoadError)</span><br /><br />
Could it be that the problem is that the first line in rake:<br /><span class="Apple-style-span" style="background-color: black; color: white;">#!/usr/bin/env ruby </span><br />
Will return C:\Ruby192\bin\ruby.exe<br /><br />
By being more explicit about what to run you can avoid the problem:<br /><span class="Apple-style-span" style="background-color: black; color: white;">rake.bat</span></p>
<div style="clear: both;"></div>
Writing code without testshttp://assertfail.gewalli.se/2011/05/11/writing-code-without-tests.html
Wed, 11 May 2011 14:58:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/05/11/writing-code-without-tests<p>Suppose that you write code without tests that compile. Suppose that those parts do not have any user interface or tests. Then what you’re doing is actually pushing development cost over to other parts of the project that make use of the code. This will probably mean that any cost/time estimates concerning dependent code needs to be adjusted in order to be able to pay for the additional cost.</p>
Command line option parsinghttp://assertfail.gewalli.se/2011/04/24/command-line-option-parsing.html
Sun, 24 Apr 2011 18:10:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/04/24/command-line-option-parsing<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-size: large;">NDesk Options</span><br />
I started writing an argument parser without knowing about:<br /><a href="http://www.ndesk.org/Options">NDesk.Options</a><br />
Where you have the following kind of syntax:<br /><span class="Apple-style-span" style="font-family: Verdana, sans-serif; font-size: 13px;"></span><br /><pre style="margin-bottom: 1em; margin-left: 1em; margin-right: 1em; margin-top: 1em;">string data = null;
bool help = false;
int verbose = 0;
</pre>
<pre style="margin-bottom: 1em; margin-left: 1em; margin-right: 1em; margin-top: 1em;">var p = new OptionSet () {
{ "file=", v =&gt; data = v },
{ "v|verbose", v =&gt; { ++verbose } },
{ "h|?|help", v =&gt; help = v != null },
};
List<string> extra = p.Parse (args);</string></pre>
<span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-size: small;"></span></span><br /><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-size: large;">FubuCore</span></span>
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<span class="Apple-style-span" style="font-size: large;">Since this post, there is a new option: <a href="http://lostechies.com/chadmyers/2011/06/06/cool-stuff-in-fubucore-no-6-command-line/">Command line in FubuCore</a>.</span><br /><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-size: small;"></span></span><br /><span class="Apple-style-span" style="font-size: large;"><span class="Apple-style-span" style="font-size: large;">Powershell</span></span><br /><span class="Apple-style-span" style="font-size: large;">If you're using powershell it just might be simpler to load your program as an assembly and invoke the classes directly. Looking at <a href="http://stackoverflow.com/questions/3360867/add-reference-to-dll-in-powershell-2-0">stackoverflow</a> there is a command <a href="http://technet.microsoft.com/en-us/library/dd315241.aspx">Add-Type</a>. Otherwise you could use standard .net assembly load.</span>
</div>
<br /><span class="Apple-style-span" style="font-size: large;">Isop</span><br />
All of the solutions above are not really what I'm after. Thus I've written another argument parser loosely based on <a href="http://simpleconsole.rubyforge.org/">SimpleConsole</a> :<br /><a href="https://github.com/wallymathieu/isop">Isop</a><br />
I didn't really think views in an console app was that useful. Instead I've tried to do some of the plumbing in order for you to write console applications more like this: <br /><pre style="margin-bottom: 1em; margin-left: 1em; margin-right: 1em; margin-top: 1em;">static void Main(string[] args)
{
new Build()
.Parameter("server",arg=&gt;server=arg)
.Recognize(typeof(CustomerController))
.Parse(args)
.Invoke(Console.Out);</pre>
<pre style="margin-bottom: 1em; margin-left: 1em; margin-right: 1em; margin-top: 1em;">}</pre>
<br />
There is some simple syntax to extend this. To Set culture, TypeConverter et.c. <br /><br />
So you would invoke the method "Add" on the class "CustomerController" with the arguments id and name:<br /><br />
CustomerConsoleApp.exe Customer Add --id 1234 --name Arne</div>
<div style="clear: both;"></div>
Testing SQL databasehttp://assertfail.gewalli.se/2011/04/17/testing-sql-database.html
Sun, 17 Apr 2011 13:40:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/04/17/testing-sql-database<div dir="ltr" style="text-align: left;" trbidi="on">
What strategies do I know of on how to test your code depending on a database?<br /><br /><ol style="text-align: left;">
<li>Using <a href="http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx">TransactionScope</a> so that you can roll back any changes done by tests.</li>
<li>Setting up a fresh database with the same schema.</li>
<ol>
<li>Using NHibernate SchemaExport(cfg).Execute to export an existing schema onto the new database.</li>
<li>Run your migrations to set the database in the correct state.</li>
<li>Use Code First, auto migrations or whatchamacallit call it. That is, let the ORM generate the tables and columns based upon your data objects. For instance Entity Framework Code First or Subsonic Auto Migrations. </li>
</ol>
</ol>
<div>
What are the pros and cons of these approaches? </div>
<div>
<ol style="text-align: left;">
<li>TransactionScope:</li>
<ol>
<li>
<b>Pros</b>: Very easy to setup. If you have a local version of the database, it's very easy to get started.</li>
<li>
<b>Cons</b>: Running everything under a transaction can be very costly. You need to tweak the configuration of the transaction coordinator. If you forget to use TransactionScope, there is a danger that you get rubbish data in your test database making your tests brittle.</li>
</ol>
<li>Fresh database with the same schema:</li>
<ol>
<li>
<b>Pros</b>: By having migrations that are well tested, it can be considerably easier to create new installations. </li>
<li>
<b>Cons</b>: Using a slightly different schema for your tests (for instance if you have sql scripts to do changes to the database and turn on Code First in your tests) can lead to unexpected behavior. If your logic depends on database specific functionality you might want to use migrations in order to have a fully working schema. It can also be a bit harder to setup. If you use a different database (for instance SQLite), database specific behavior may be an issue. Same vendor but different collation might also give you a headache.</li>
</ol>
</ol>
</div>
</div>
<div style="clear: both;"></div>
Build/test timehttp://assertfail.gewalli.se/2011/04/16/buildtest-time.html
Sat, 16 Apr 2011 21:17:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/04/16/buildtest-time<div dir="ltr" style="text-align: left;" trbidi="on">
<b>Keep solutions simple and think about your deliverables</b><br />
Chad Myers at Los Techies tries to get a discussion about why it's bad to have to many projects:<br /><a href="http://lostechies.com/chadmyers/2008/07/16/project-anti-pattern-many-projects-in-a-visual-studio-solution-file/">Project anti-pattern: Many projects in a Visual Studio Solution File</a><br />
Some of the consideration is about build performance. He is referencing microsoft blog posts... I know the lure of getting to drink coffee while waiting for builds, but you're not getting paid for coffee ;)<br />
There is an article on O'Reilly about the cost of long development cycles:<br /><a href="http://www.oreillynet.com/onjava/blog/2006/03/dead_time_code_compile_wait_wa.html">Dead Time (...code, compile, wait, wait, wait, test, repeat)</a><br /><br />
This is also reflected in the documentation on team development:<br /><a href="http://msdn.microsoft.com/en-us/library/bb668953.aspx">Msdn: Team Development with Visual Studio Team Foundation Server: Chapter 3 – Structuring Projects and Solutions in Source Control</a><br />
They recommend you to keep it simple:<br /><br /><div style="font-size: 13px;">
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Keep the following considerations in mind when designing a project and solution structure:</span>
</div>
<ul style="font-size: 13px;">
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Each project generates an assembly at build time. <u>Start by determining what assemblies you want to create and then use this to decide what projects you need.</u> Use this to determine how to factor your codebase into projects.</span></li>
<li><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;"><u>Start with the simplest single solution structure</u>. Only add complexity to your structure when it is really necessary.</span></li>
</ul>
<div style="font-size: 13px;">
<span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">...</span>
</div>
From Brad Adams msdn blog:<br /><a href="http://blogs.msdn.com/b/brada/archive/2004/05/05/126934.aspx">Perf trade off: lots of small assemblies or fewer bigger assemblies??</a><br />
Puts it like this:<br /><span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">fewer bigger assemblies are better</span><br /><br />
But he is talking about the performance of your applications. He mentions that they optimize for bigger assemblies. This is probably why visual studio is optimized this way as well.<br /><b><br /></b><br /><b>Why writing unit tests and not only integration tests?</b><br />
Integration tests are immensely useful. However, the amount of time you spend on running tests is part of the above mentioned coffee time. If you are writing unit tests when testing your c# code this means less time spent being bored waiting.<br /><br /><b>About why build time is important</b><br /><br /><div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
Note that they are even factoring in the time it takes you to run the tests. Imagine the Dead Time if you need to test manually. Not to rant, but the Dead Time ratio would be even higher. It's simple economics that by writing tests as part of your development cycle will make you more productive. </div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<br />
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
How often do you execute a build per day? Lets say that you do it every 30 minutes ca. If your build time is 1 minute. That gives you a 31 minute cycle. Divide 8 hours by this cycle and you get: 15.5. If the build time is 5 minutes that gives you: 13.7. That means you will be 12% less effective per day.</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<br />
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
The above mentioned number is actually misleading. An experienced developer working with well known tools may be able to work in longer cycles thus avoiding a lot of the Dead Time. However, when working in areas you are relatively inexperienced in (only worked with for a few years) you will benefit from the possibility to do explorative coding if your build/test cycle is short. Michael Feathers touches on this issue in his post about <a href="http://michaelfeathers.typepad.com/michael_feathers_blog/2011/04/the-urge-to-repl-the-urge-to-test.html">the Urge to REPL, the Urge to test</a>. REPL is simply read-eval-print-loop. It's why you can be very productive when you use scripting languages. You can do explorative coding and get instant feedback without waiting for builds.</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
<br />
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">
The numbers also suggests that monitoring your build time, test time can lead to greater productivity. Maybe not running all of the integration tests but letting a continuous integration server let you know if any of them fails.<br /><br />
Another important factor is: Instant gratification. The joy of seeing the result of your action in a short amount of time.<br /><br /><b>Also you might read</b><br /><a href="http://www.simple-talk.com/dotnet/.net-framework/partitioning-your-code-base-through-.net-assemblies-and-visual-studio-projects/">Partitioning Your Code Base Through .NET Assemblies and Visual Studio Projects</a><br /><br /><a href="http://mikehadlow.blogspot.com/2011/06/i-dont-have-time-for-unit-tests.html">I Don’t Have Time for Unit Tests</a>
</div>
</div>
<div style="clear: both;"></div>
When to use mocks?http://assertfail.gewalli.se/2011/04/16/when-to-use-mocks.html
Sat, 16 Apr 2011 07:27:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/04/16/when-to-use-mocks<div dir="ltr" style="text-align: left;" trbidi="on">
You use mocks when you want to test <a href="http://martinfowler.com/articles/mocksArentStubs.html#CouplingTestsToImplementations">how the code interacts with the mocked objekts</a>. <br /><br />
If you care mostly about the end result, the final state, then it's easier and less brittle to use fakes.</div>
<div style="clear: both;"></div>
Migrationshttp://assertfail.gewalli.se/2011/04/15/migrations.html
Fri, 15 Apr 2011 19:49:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/04/15/migrations<div dir="ltr" style="text-align: left;" trbidi="on">
Listening to <a href="http://herdingcode.com/?p=233">herding code on fluent migrator</a> is quite interesting.<br /><br />
You could read <a href="http://lostechies.com/seanchambers/2011/04/02/fluentmigrator-getting-started/">Getting started with fluent migrator</a>. If you feel the need to contribute there is <a href="https://github.com/schambers/fluentmigrator">fluent migrator on github</a>.</div>
<div style="clear: both;"></div>
Simple databasehttp://assertfail.gewalli.se/2011/04/07/simple-database.html
Thu, 07 Apr 2011 05:00:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/04/07/simple-database<div dir="ltr" style="text-align: left;" trbidi="on">
Looks awesome for simple things:<br /><a href="https://github.com/markrendle/Simple.Data">Simple.Data</a><br /><br />
It's Rob Conery!<br /><a href="https://github.com/robconery/massive">massive</a><br />
The blog post <a href="http://blog.wekeroad.com/helpy-stuff/and-i-shall-call-it-massive">and I shall call it massive</a>.<br /><br />
Might be used by stack overflow:<br /><a href="http://code.google.com/p/dapper-dot-net/">dapper</a><br />
As described here:<br /><a href="http://samsaffron.com/archive/2011/03/30/How+I+learned+to+stop+worrying+and+write+my+own+ORM">How I learned to stop worrying and write my own ORM </a>
</div>
<div style="clear: both;"></div>
HOWTO write something FAST that works!http://assertfail.gewalli.se/2011/04/03/howto-write-something-fast-that-works.html
Sun, 03 Apr 2011 13:18:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/04/03/howto-write-something-fast-that-works<h2 id="focus">Focus</h2>
<ol>
<li>
<p>Make sure that you’re always doing the right thing (Erik Arnwald). Try to understand as much as possible of the domain you’re working on.</p>
</li>
<li>
<p>Trim furiously in the specifications and in the code. Make sure to identify the key benefit for the customer and focus solely on implementing this part. Additional wishes and demands tends to change rapidly and might not be necesary at all. The most common reason to break of deadlines and malfunctions is too complex specifications which are changed after the project has been started. (Carsten Hersom)</p>
</li>
</ol>
<h2 id="avoid-coding">Avoid coding</h2>
<ol>
<li>
<p>Sometimes you do not need to any custom code but can use standard components coupled with some education of the customer. For instance a standard CMS module. (Carsten Hersom)</p>
</li>
<li>
<p>Make sure to use stable and well tested third party tools and libraries for your core effort. For instance. The guys maintaining Nhibernate have extensive test coverage of the library. Avoid any tool that is not either really stable and old (and is used by many) or has a good test coverage.</p>
</li>
<li>
<p>The same criteria as for other tools apply to javascript frameworks and libraries.</p>
</li>
</ol>
<h2 id="avoid-breaking-your-own-things">Avoid breaking your own things</h2>
<ol>
<li>
<p>Make sure that everybody uses database versioning tool. Preferably some form of migrations. It’s trivially easy to get into a inconsistent database state otherwise.</p>
</li>
<li>
<p>Make sure to have test coverage of any part of the code you’re unsure of how it works or any brittle parts. Things that are brittle is for instance the use of SqlCommand against stored procedures (SP). As the SP’s are changed code may stop to work without you knowing it. Make sure to have tests of the connection between c# and the sql database. Make sure that your tests are as terse as possible. Don’t be afraid to throw old tests away that are wrong and not needed. You can read about tests in the post: <a href="/2011/03/31/why-automated-tests.html">why automed tests</a>.</p>
</li>
<li>
<p>Be really careful of hiding exceptions (catch the right exception). If something goes wrong, <a href="http://ferd.ca/the-zen-of-erlang.html">it should explode</a>. It’s really hard to find errors if you have written something like: <code class="highlighter-rouge">try{ ... } catch(Exception){}</code></p>
</li>
<li>
<p>Use static analysis to your benefit. Turn off most of the crap (for instance fxcop style rules). Make sure that fxcop only reports relevant information. If unsure, avoid using this tool. Javascript lint is your annoying Besserwisser friend. Change the rules according to your need. You can download an integrated version for visual studio. Make sure to change what it reports (and that it does not complain about third party js libraries).</p>
</li>
<li>
<p>In order to avoid the time spent running integration tests, you might want setup a <a href="http://en.wikipedia.org/wiki/Continuous_integration">CI</a> environment like <a href="http://www.jetbrains.com/teamcity/">team city</a>. Make sure that you instill the value of tests in the developers you are working with.</p>
</li>
</ol>
<h3 id="on-writing-tests">On writing tests</h3>
<p>You may ask: Why writing tests if time is short? The reason for this is that the time spent manually debugging and testing can be considerable. I’ve read estimates of the time spent in software development is mostly fixing bugs: Thus debugging and manually testing. </p>
<p>Some people can write a working program really fast without tests and structure and with mostly duct tape and spit to keep it together. These people are few. Of the programmers I’ve met only a handful have this skill. For most of us it’s not quick and dirty, it’s just dirty. As one of my former coworkers (Mads) told me: Writing quick and dirty code is like taking a loan. There is always an interest that you need to pay. The longer you wait before refactoring the higher the cost.</p>
<h2 id="feedback">Feedback</h2>
<ol>
<li>
<p>Start by making a small part of your program that can be shown to people for feedback. </p>
</li>
<li>
<p>Release as soon as possible so that others (customers and domain experts) can give you feedback. It’s always better to have complete workflows in the gui (even if some of the functionality is faked). It helps the users and customers to visualize and provide better feedback. (Erik Arnwald)</p>
</li>
<li>
<p>In order to get people to contribute feedback on the current site/app you might want to consider automated deployments. This can help you when you need to deploy quickly for some reason (bugs). It can also help people unfamiliar with all the intricacies of a projects deployment to help with this activity. </p>
</li>
</ol>
<h2 id="mentality">Mentality</h2>
<ol>
<li>
<p>Don’t be afraid. If the functionality is to complex, try to understand the problem the functionality is supposed to solve. It might be that you can solve it with less complexity. If you’re afraid of stuff breaking, write tests.</p>
</li>
<li>
<p>Avoid having people around that stress you or your coworkers. It might be better to have stressed managers or customers interact with only one person from the team. Productivity slows to a crawl if people get to stressed.</p>
</li>
<li>
<p>You need to talk and listen. The first thing that happens to me and others are that you stop listening when you’re stressed.</p>
</li>
<li>
<p>If you are in many projects that stress you out, you burn out or make an ass of yourself (burn yourself in the eyes of others).</p>
</li>
</ol>
Why automated tests?http://assertfail.gewalli.se/2011/03/31/why-automated-tests.html
Thu, 31 Mar 2011 21:14:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/03/31/why-automated-tests<div dir="ltr" style="text-align: left;" trbidi="on">
<ol style="text-align: left;">
<li>Work is more fun when the things you create mostly works.</li>
<li>When fixing bugs, the probability of introducing new bugs is reduced.</li>
<li>Specifications of program behavior expressed as tests are easier to maintain than tutorial code or a word document specification.</li>
<li>In order to be able to write unit tests easier you are forced to simplify your classes. </li>
<li>Switching underlying technology or infrastructure. For example: If you have integration tests on your database repositories or data access layers it is easier to switch the underlying implementation. You have a way of verifying that important behavior is intact. </li>
<li>If you are writing code that:<ul>
<li>Requires the use of the debugger frequently.</li>
<li>After you have written it, you fear to change.</li>
</ul>
<ol></ol>
Do you really consider yourself a professional developer?
</li>
</ol>
<div>
Some of it is in relation to having to work late at night and during weekends. Tests can help you with your definition of done, thus alleviating the need for late night coding sessions.<br /><br />
Effective coding means to use the tools available when they are appropriate.<br /><br />
Sometimes it's about doing something simple:<br /><ol style="text-align: left;">
<li>Is the bug to complex to find using tests? The flow of the application is wrong...</li>
</ol>
<ul>
<li>Maybe you could find it easier if you use a logger to trace the behavior?</li>
</ul>
<li>You have written a test that recreates the problem, but you cant figure out why it doesn't work.</li>
<ul>
<li>Maybe putting breakpoints and debugging your test will help you find what's wrong.</li>
</ul>
<div>
If you're a beginner. How do you start writing tests?</div>
<div>
<ol style="text-align: left;">
<li>If you're writing c# then you want to read <a href="http://www.amazon.com/Art-Unit-Testing-Examples-Net/dp/1933988274">"the art of Unit Testing"</a> by Roy Osherove. </li>
<li>If you're unsure about how to write tests. Try using <a href="http://www.typemock.com/test-lint">test lint</a>.</li>
<li>Search posts done by <a href="http://martinfowler.com/">Martin Fowler</a>, <a href="http://www.threeriversinstitute.org/blog/">Kent Beck</a>, <a href="http://cleancoder.posterous.com/">Robert C. Martin (Uncle Bob)</a>, <a href="http://michaelfeathers.typepad.com/michael_feathers_blog/">Michael Feathers</a> .</li>
<li>How do you do when you test your code manually?</li>
<ol>
<li>You set up the state of the program relevant before the method/procedure to test. In Nunit it's called SetUp. You use this attribute to mark the method that sets up the state.</li>
<li>You fill in a form and click on a button, browse to a page with the right parameters in the url, et.c. When testing this is the actual test. You mark a method that does this by the Test attribute.</li>
<li>You look at the result from the action. In Nunit you use the static helper class Assert that contains methods to help you write the expected values.</li>
<li>After you're finished testing, you may need to clean up. In Nunit this is accomplished by marking the a method with the attribute CleanUp.</li>
</ol>
If you are structured in your testing of your app you may know some of the domain of automatic testing. You can read about this in the above book by Roy Osherove.</ol>
<div>
Also, writing tests is not a reason not to test what you've written manually. It is a way to make sure that you don't have to do as much manually testing as before. </div>
</div>
</div>
</div>
<div style="clear: both;"></div>
Role Playing gameshttp://assertfail.gewalli.se/2011/03/31/role-playing-games.html
Thu, 31 Mar 2011 19:47:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/03/31/role-playing-games<div dir="ltr" style="text-align: left;" trbidi="on">
In real life you choose what parts to level, what to learn.<br /><br />
As a developer do you choose to level up or are you stuck fighting the same kind of problems without gaining XP?<br /><br />
As a developer do you choose to spend your experience:<br /><br /><ul style="text-align: left;">
<li>Learning to talk to customers</li>
<li>Learning to work with others</li>
<li>Learn patterns, how to write prose</li>
<li>Learn new technologies</li>
<li>Learn how to write tests</li>
<li>Learn how to automate tasks (build, installation, et.c.)</li>
</ul>
<div>
This is just a short list. What I mean is that you have a possibility to choose certain skills. Probably you will ignore some of them. You will be mistaken if you think that the rest of the skills does not matter. Knowing what customers talk about matter! Being able to write correct software matter (that is, being able to write tests)! If you have chosen not to learn one of the skills, know that you will need other persons to lean on. You need to treat these people with respect. They are not dumb just because they are focused on parts you have not chosen to focus on.</div>
</div>
<div style="clear: both;"></div>
Number of testshttp://assertfail.gewalli.se/2011/03/27/number-of-tests.html
Sun, 27 Mar 2011 21:20:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/03/27/number-of-tests<div dir="ltr" style="text-align: left;" trbidi="on">
The number of test needed for a given functionality in a program is proportional to the probability of unique errors weighted by the business value of correctness for that given functionality. </div>
<div style="clear: both;"></div>
log4nethttp://assertfail.gewalli.se/2011/03/23/log4net.html
Wed, 23 Mar 2011 21:08:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/03/23/log4net<div dir="ltr" style="text-align: left;" trbidi="on">
For parsing log4j files there are some alternatives:<br /><ol style="text-align: left;">
<li>
<a href="http://logging.apache.org/chainsaw/index.html">Chainsaw</a> (java gui). If the links dead, note that it should be part of log4j.</li>
<li>Similar to chainsaw but in .net: <a href="http://github.com/wallymathieu/log4net-logviewer">logviewer</a>.</li>
<li>
<a href="http://log2console.codeplex.com/">Log2Console</a> looks pretty sweet. It has some positive comments.</li>
</ol>
On the logviewer page you find a sample configuration for using "log4net.Layout.XmlLayoutSchemaLog4j". Note that the log4net xmllayout should be parse:able by logviewer as well.<br /><br />
Both <a href="http://nlog-project.org/">NLog</a> and <a href="http://logging.apache.org/log4net/">Log4Net</a> can log to the log4j layout.</div>
<div style="clear: both;"></div>
Logging for Commerce Server 2009http://assertfail.gewalli.se/2011/02/08/logging-for-commerce-server-2009.html
Tue, 08 Feb 2011 20:23:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/02/08/logging-for-commerce-server-2009<div dir="ltr" style="text-align: left;" trbidi="on">
<div dir="ltr" style="text-align: left;" trbidi="on">
You might want to start off by reading the <a href="http://msdn.microsoft.com/en-us/library/dd451660(v=cs.90).aspx">documentation from Microsoft</a>. The short version of this text is that in the new CS2009 there is tracing and it is done through system.diagnostics. I don't know the entire story, but it looks like the exception handling is piped through the trace.<br /><br />
So in order to configure the logging for commerce server you will need to read up on the system.diagnostics tracing.You will need to add a source "Microsoft.Commerce.Exceptions". There you can choose your <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.tracelistener.aspx">TraceListener</a> and specify the information you need by reading up on <a href="http://msdn.microsoft.com/en-us/library/a10k7w6c.aspx">TraceOptions</a>.<br /><br />
The default trace configuration can be found in SystemDiagnostics.xml in the Extensibility kit. You should be aware of that the default configuration logs to the Event handler. This is not always appreciated by your customers since they may want to have Medium Trust for the site.<br /><br />
Note that this means that you can also write your own log-handler for these tracing events by inheriting from <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.tracelistener.aspx">TraceListener</a>.</div>
</div>
<div style="clear: both;"></div>
Whats wrong with Commerce Server 2009http://assertfail.gewalli.se/2011/01/26/whats-wrong-with-commerce-server-2009.html
Wed, 26 Jan 2011 18:00:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2011/01/26/whats-wrong-with-commerce-server-2009<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-size: x-large;">Whats wrong with Commerce Server 2009 </span><br /><span class="Apple-style-span" style="font-size: large;">from a developer perspective?</span><br /><ol style="text-align: left;">
<li>Configuration: There is no single source of object mapping configuration.
Multiple places to insert properties.</li>
<li>FaultException does not include the original exception.</li>
<li>The CS2009 api's look very dynamic... It promises a lot more than it can deliver since it is based upon CS2007 API and thus quite limited.</li>
<li>No transactions for some of the entities. For instance profiles and catalog. </li>
<li>Integration with SharePoint by putting the configuration in SharePoint web.config. That's not the way to go.</li>
<li>Granular permissions for all the web services, for all the databases. There is a lot of work just setting up CS. </li>
<li>Pipelines.... </li>
</ol>
<ul style="text-align: left;"></ul>
<div>
<br />
</div>
<div>
<span class="Apple-style-span" style="font-size: x-large;">How do you improve the experience?</span><br /><ol style="text-align: left;">
<li>Configuration: Just try to write integration tests to catch any errors due to configuration.</li>
<li>Problem with FaultException is fixed in <a href="http://social.msdn.microsoft.com/Forums/en/commserver2009/thread/e33de899-3768-4fea-a914-641485291ef7">CS2009 r2 CTP</a> ... Until an actual release, you might need to write your own logging for operation sequences (theres an extension point for this, just look at <a href="http://msdn.microsoft.com/en-us/library/dd451660(v=cs.90).aspx">Microsoft.Commerce.Common.TextLoggingExceptionHandler</a> and the configuration). I've not tried this, so I have had to look in the console output or Event log. </li>
<li>You could, if you had the time, write a different implementation of the operation sequence that does the queries for the basket or any other CS entity. I don't know what level of the API the pipelines depend on. Probably easier to just ignore this issue and write some code that searches the CS database.</li>
<li>This is a serious issue. This means that you will need to clean up manually after any integration test. Just keep your integration tests small and write fake implementations of the CS entities repositories so that you can write unit tests.</li>
<li>If you're not using default configuration and don't need any serious modification of the web parts distributed with CS2009 then try to as early as possible, put CS within it's own web site and implement your web service wrapper around the methods using CS. Could be a bit tricky, but might save you a lot of work. It's simple math, one big product configuration inside another big product with a lot of configuration equals a lot of work if you're unlucky. I've heard rumors that Microsoft is implementing a service oriented version of CS (but until then, you'll have to implement it yourself).</li>
<li>Permissions: <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=8344d2bc-142a-4609-abab-db7f9a1e0f65&amp;displaylang=en">RTFM</a>! To install CS you need to make sure that everything is setup correct.</li>
<li>Pipelines: If possible try to avoid using them.</li>
</ol>
</div>
</div>
<div style="clear: both;"></div>
Refactoring multiplicity, synchronous versus asynchonoushttp://assertfail.gewalli.se/2010/12/18/refactoring-multiplicity-synchronous.html
Sat, 18 Dec 2010 12:00:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2010/12/18/refactoring-multiplicity-synchronous<p>Sometimes change hurts. <br /><br />
You know what I’m talking about if you need to change the multiplicity of a relationship (let’s assume you talk about an ordinary sql database). For instance: From <br /><i>1 to 1</i><br />
To<br /><i>1 to many</i><br />
For instance, say it’s an adress. The assumptions made when there is only one adress permeates throughout the applications. For instance a person must have bills sent to a different adress (his/her accountant or something <a href="http://sv.wikipedia.org/wiki/God_man">similar</a>). However, when contacted, any mail needs to be sent to the home address. The code changes alone could be many. If there are a lot of reports based on the data (accessing the information without any layer) then these could be based on assumptions out of sync with reality. If you’re unlucky that might mean that you need to manually go through all the reports in the system and look for discrepancies. If you’re lucky the report will simply fail. If unlucky, it will show a random adress.<br /><br />
Synchronous versus asynchronous execution and parallel execution<br />
jQuery has popularized asynchronous programming. Reactive extensions will perhaps simplify your tasks. Parallel LINQ (<a href="http://msdn.microsoft.com/en-us/library/dd460688.aspx">PLINQ</a>) and the Task Parallel Library (<a href="http://msdn.microsoft.com/en-us/library/dd460717.aspx">TPL</a>) might even make the tasks even simpler. But what if your program assumes execution in a consecutive maner? That the parts that you need to make parallel or asynchronous are buried deep within layers of layers … It might be that your program design needs to be restructured.</p>
<div style="clear: both;"></div>
Why git or mercurial?http://assertfail.gewalli.se/2010/12/10/why-git-or-mercurial.html
Fri, 10 Dec 2010 22:21:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2010/12/10/why-git-or-mercurial<p>I’ve played around with branching and merging in git. It looks like a useful tool. <br /><br />
In the current project we are maintaining two different branches right now. I can see that it would be useful to be able to use the functionality in git/mercurial to help me merge and cherry pick.<br /><br /><a href="http://herdingcode.com/?p=288">HERDING CODE 96: ERIC SINK ON VERACITY AND DVCS</a><br /><br /><a href="http://www.hanselman.com/blog/HanselminutesPodcast231EricSinkOnDistributedVersionControlSystems.aspx">Hanselminutes Podcast 231 - Eric Sink on Distributed Version Control Systems</a></p>
<div style="clear: both;"></div>
What's wrong with SharePointhttp://assertfail.gewalli.se/2010/11/26/whats-wrong-with-sharepoint.html
Fri, 26 Nov 2010 23:17:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2010/11/26/whats-wrong-with-sharepoint<div dir="ltr" style="text-align: left;" trbidi="on">
<span class="Apple-style-span" style="font-size: x-large;">Whats wrong with SharePoint</span><br /><span class="Apple-style-span" style="font-size: large;">from a developer point of view?</span><br /><ol>
<li>Packages<br /><ul>
<li>It's somewhat unreliable in it's deployment of files.</li>
<li>Takes a lot of time to install/uninstall a package.</li>
<li>Not a modern approach to package management. Its basically a cab file with files and xml describing it.</li>
</ul>
</li>
<li>Configuration<br /><ul>
<li>How do you test the deployment of configuration?</li>
<li>How does it work exactly? You have to observe the result ... It only works when you use it the right way and you dont get much in error messages.</li>
<li>Deploying the right way is frikkin hard. But, if you expect the tools for sp to work without crashing your site, you better do it the right way.</li>
</ul>
</li>
<li>From line of code to result. Could this be described as lead time of changing a line of code to viewing the results of it in the interface?</li>
</ol>
<ul>
<li>10 min or more if youre unlucky. This means that the roundtrip is not comparable to a clean site in asp.net.</li>
</ul>
<li>Not even a mediocre web platform. Its written for intranet. This shows. <br />
</li>
<li>Running code in SharePoint context can be up to 10 times slower for the same dll.<br />
</li>
<li>Security. Some of the problems with SharePoint are related to security. It adds to the complexity.</li>
<ul>
<li>You need to mark your controls as SafeControls. </li>
<li>Can get you thinking that GAC deployment is a good idea. Also you need to be aware of asp.net security configuration and what you may do. If you put things in GAC without very good reason do not complain if visual studio crashes, your projects use obsolete versions of your code, your build crashes.</li>
<li>Identity Impersonate... </li>
</ul>
<li>Huge. There looks like there at least 3 ways of doing things, and they are all for slightly different scenarios. This is an issue. You have to learn a lot of SharePoint concept in order to get the job done. You have to do extra work to introduce for istance an asmx.<br />
This is not helped by asp.net being a leaky abstraction for producing web sites/apps. It can work well if you accept the behaviour and limitations of of asp.net. Problem is that it's not often that people are satisfied with this. Thus it may help to move to asp.net mvc for a simpler more web centric view.</li>
<li>If you're supposed to develop web, it's not a good experience.</li>
<br />
Compare this to a regular asp.net web app/ site.<br /><br /><span class="Apple-style-span" style="font-size: x-large;">How do you improve the experience?</span><br /><br /><span class="Apple-style-span" style="font-size: large;">Conventional wisdom apply:</span><br /><ol>
<li>Testing your logic using automatic tests is valuable. Even more so since any changes take a lot of time to enter into SharePoint.</li>
<li>If you can simplify by faking SharePoint functionality</li>
</ol>
<ul>
<li>Writing web in regular web and move it using merge or generation</li>
<li>Write simpler versions of SharePoint classes.</li>
</ul>
<li>Fewer dlls. Use ilmerge or consider fewer projects in your solution. Good idea anyway since its good practice to have few projects in visual studio. In .net its best practice to have few dll:s. In visual studio it's <a href="http://stackoverflow.com/questions/1828309/does-having-more-projects-in-your-visual-studio-increase-compile-time">better</a> to have few projects in your solution. You can solve this by having good build scripts and small sub solutions (may not be a good idea if you do not have a lot of code).</li>
<li>If possible avoid putting things in the GAC. It can be useful, but not for everything. You can put dll:s in the <a href="http://stackoverflow.com/questions/1754006/is-sharepoint-local-bin-deployment-possible">bin folder of SharePoint</a>.</li>
<li>Automate as much as possible. </li>
<ul>
<li>Write build scripts. </li>
<li>There is a <a href="http://stackoverflow.com/questions/1000104/visual-studio-configure-debug-to-attach-to-process">sample macro</a> for attaching to a process.</li>
</ul>
<li>If there are no logs or anything to help you with what's going wrong: You might need to use advanced tools like <span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; border-collapse: collapse; color: #333333; font-family: 'trebuchet ms', verdana, arial, sans-serif; font-size: 13px; line-height: 18px;"><a href="http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx" style="color: #3366cc; font-weight: bold;">Process Monitor</a>.</span>
</li>
<div>
<span class="Apple-style-span" style="font-size: large;">Some other helpful tips may be:</span>
</div>
<ol>
<li>
<a href="http://wspbuilder.codeplex.com/">Wspbuilder</a> can be a good starting point. It can help you by automatically registring safe controls. Ms commerce extendability project can show you how to do it without the tool. Some of the uses for this tool might become obsolete with the introduction of Visual Studio 2010 and SharePoint 2010 (might not save your bacon though). I've not tried this, only read it on blogs. It might help you to understand what the tools generate.</li>
<li>Be pragmatic when it comes to configuration. Dont hesitate to use a merge program when your configuration feature fails. Unless of course your client will use the wsp on a SharePoint farm. </li>
<li>Put your code behind wcf services so that the configuration and context is outside of SharePoint. Less configuration helps. Also the separation of your code and the executing context in SharePoint help you configure security easier.</li>
<li>Don't be stressed if it takes time. Read up on the things your working with (try to ignore the rest).</li>
</ol>
</div>
<div style="clear: both;"></div>
XML build files are obsoletehttp://assertfail.gewalli.se/2010/11/20/xml-build-files-obsolete-are-obsolete.html
Sat, 20 Nov 2010 16:59:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2010/11/20/xml-build-files-obsolete-are-obsolete<p>Why using a build system like Ruby rake or some other next generation tool (<a href="https://github.com/JamesKovacs/psake">psake</a> looks promising) to build your .net application or library? <br /><br />
A) Builds are not data. <br />
Xml is for data. It may be that the files or configurations are stored as xml, but does your build program need to be in xlm?<br />
B) Custom tasks are easy to write. Take a look at <a href="http://albacorebuild.net/">albacore</a> for instance. <br />
C) It is easy to manage nontrivial tasks.<br />
D) It’s readable.<br />
Write your build in rake or something similar. Write it in msbuild. You will see that as usual there is a cost to writing it in xml: It adds cruft and that angle-bracket tax.<br /><br />
Or you might like the xml files for some reason: <br /><a href="http://www.jprl.com/Blog/archive/development/2010/Apr-26.html">Jonathan Pryor: Defending XML-based Build Systems</a><br />
He is arguing for the use of xml-basked build files. One reason is that xml is easily parsed and can be used in custom tools.<br /><br />
Personally I feel that coding should be done mostly by writing code. Sure, there might be nifty code generation tools that can be used to simplify some tasks, but at the end of the day you still need to get your hands dirty and make sure that it does what it’s supposed to do.</p>
<div style="clear: both;"></div>
Unit testing using Moq and Unity Containerhttp://assertfail.gewalli.se/2010/09/29/unit-testing-using-moq-and-unity.html
Wed, 29 Sep 2010 18:07:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2010/09/29/unit-testing-using-moq-and-unity<p>I have had troubles writing unit tests for classes with a lot of dependencies. The reason for this is that the initialization of the state for my test code would look like:<br />
[Setup]<br />
public void Setup()<br />
{<br />
stub1 = new Mock<isomething1>();</isomething1><br />
…<br />
stub20 = new Mock<isomething20>();</isomething20><br />
mock = new Mock<imockable>();</imockable><br />
…// Setup mock and stub behavior<br />
classToTest = new TypeOfClass( /<em>a lot of code</em>/);<br />
}<br /><br />
This isn’t very maintainable. How do we make this easier to maintain? I’ve introduced a helper class that initializes most of the interfaces to stubs of the form Mock<itype>. Then these stubs can be added to <a href="http://unity.codeplex.com/">Unity</a>. Thus the setup will be reduced to:</itype><br /><br />&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;[Setup]&lt;/div&gt;</p>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">public void Setup()</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">{</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> container = new UnityContainerTestHelper();</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> container.RegisterStubs();//Registers a lot of interfaces using <a href="http://code.google.com/p/moq/">Moq </a>
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> container.RegisterMock<imockable>();</imockable>
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">...// Setup mock and stub behavior</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> container.RegisterType<typeofclass>();</typeofclass>
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"> classToTest = container.Resolve<typeofclass>();</typeofclass>
</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">}</div>
<div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;">The main thing here is that I'm the dependency injection container do the work. People have told me that dependency injection would help when testing. It does, but I've not seen examples of the use of a dependency injection container. If you have better ideas how this should be done, please post comments.</div>
<div style="clear: both;"></div>
Simple object oriented javascripthttp://assertfail.gewalli.se/2010/07/30/simple-object-oriented-javascript.html
Fri, 30 Jul 2010 07:48:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2010/07/30/simple-object-oriented-javascript<p>The jQuery approach is to avoid object orientation. This is an excellent way of avoiding bloat for small javascript hacks. If you’re starting to build javascript heavy applications then you might need to start organizing your code. The first thing you should learn is how to write jQuery plugins. Later on you will need to learn some simple object orientation. Here’s how:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">TigerType</span><span class="p">(</span><span class="nx">name</span><span class="p">){</span>
<span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span> <span class="k">this</span><span class="p">.</span><span class="nx">name</span> <span class="o">=</span> <span class="nx">name</span><span class="p">;</span> <span class="k">this</span><span class="p">.</span><span class="nx">sound</span> <span class="o">=</span> <span class="s2">"growl!"</span><span class="p">;</span>
<span class="k">this</span><span class="p">.</span><span class="nx">roar</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span> <span class="k">return</span> <span class="nx">that</span><span class="p">.</span><span class="nx">sound</span><span class="p">;</span> <span class="p">};</span>
<span class="p">}</span>
<span class="kd">var</span> <span class="nx">tigerInstance</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">TigerType</span><span class="p">();</span>
<span class="nx">alert</span><span class="p">(</span><span class="nx">tigerInstance</span><span class="p">.</span><span class="nx">roar</span><span class="p">());</span>
</code></pre></div></div>
<p>Note that I’m declaring a variable “that”. If you work with jQuery you know that this will be set to something else. By using a scoped variable you will avoid this problem.
So what about inheritance? The simple solution is to use call or apply.</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nx">TigerWithTeethType</span><span class="p">(</span><span class="nx">name</span><span class="p">){</span>
<span class="kd">var</span> <span class="nx">that</span> <span class="o">=</span> <span class="k">this</span><span class="p">;</span>
<span class="nx">TigerType</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span><span class="nx">name</span><span class="p">);</span>
<span class="k">this</span><span class="p">.</span><span class="nx">bite</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(){</span> <span class="cm">/*some code to bite the programmer ;)*/</span> <span class="p">};</span>
<span class="p">}</span>
</code></pre></div></div>
<p>Since TigerType is a function, call and apply can be used to execute it with the “this” of TigerWithTeethType. This way has the advantage of being simple and jQuery safe.
You might also want to look into:</p>
<ul>
<li><a href="http://ejohn.org/blog/simple-javascript-inheritance/">http://ejohn.org/blog/simple-javascript-inheritance/</a></li>
<li><a href="http://www.crockford.com/javascript/inheritance.html">http://www.crockford.com/javascript/inheritance.html</a></li>
<li><a href="http://bolinfest.com/javascript/inheritance.php">http://bolinfest.com/javascript/inheritance.php</a></li>
</ul>
<p>Try to avoid object orientation when writing javascript. If you’re doing small things then there is no need for the added complexity of object orientation (in javascript).</p>
Different breed of programmershttp://assertfail.gewalli.se/2010/07/19/different-breed-of-programmers.html
Mon, 19 Jul 2010 19:46:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2010/07/19/different-breed-of-programmers<p>After talking to a few of my colleges I’m thinking of the different kind of programmers needed for different projects, for different aspects of projects. <br /><br />
Duct tape programmer:<br /><a href="http://www.joelonsoftware.com/items/2009/09/23.html">http://www.joelonsoftware.com/items/2009/09/23.html</a><br />
Writing code that ships. Does not necessarily need to look clean. Will probably not write any unit-tests. No fancy abstractions, no patterns or anything.<br /><br />
Maintenance programmer:<br /><a href="http://www.codinghorror.com/blog/2006/06/the-noble-art-of-maintenance-programming.html%20">http://www.codinghorror.com/blog/2006/06/the-noble-art-of-maintenance-programming.html </a><br />
Have had every sort of wrench imaginable thrown right in the face. This guy will be very skeptic of dirty code. It’s about pragmatic programming and excelling at making sure that old stuff works.<br /><br />
The thing is: Different type of programmers are good for different things in a project. A maintenance programmer (or a programmer in that mode) will not necessarily be any good at writing new applications FAST (like really, really fast). Maybe the sales force needs something done within a week or a few days. Then you’re looking for a duct tape programmer. But don’t kid yourself. Finding people good at this kind of skills is hard. Problem is, you might loose time by pressuring the other programmers into writing code fast. People might think that they are duct tape programmers. But seriously, few of us are.<br /><br />
Duct tape programming, the term that comes to mind is Quick &amp; Dirty <br />
As a coworker said:<br /></p>
<ul>
<li>When you do it quick and dirty you have actually taken a loan. If you take additional loans to do small fixes, sooner or later any change will take horrendous <b>time</b>.<br /><br />
Where do I stand in this mix? Maybe I’m a mix of a few of these. Frankly I’m not very good at duct tape programming. I try to mix maintenance and duct taping. Doing integration testing and unit testing in order to make sure that the server bits are done until the time that I start coding the GUI. Making sure that the GUI interacts with a decent API instead of doing the logic directly will make it easier if you have a lot of complicated server logic. The pro of this approach is that you do not need to be a pro at the tool you’re using. As the requirements change, you will still have something that works.</li>
</ul>
<div style="clear: both;"></div>
Dojo RTE editor (dijit Editor)http://assertfail.gewalli.se/2010/05/02/dojo-rte-editor-dijit-editor.html
Sun, 02 May 2010 09:43:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2010/05/02/dojo-rte-editor-dijit-editor<p>Finished upgrading an old site to use dojo and codeignite. In order to simplify things I added the RTE editor in order to simplify the code. There is no need to add logic related to the content on the page so html-content is preferable.</p>
<p>excerpt from the content/editor.js:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">dojo</span><span class="p">.</span><span class="nx">require</span><span class="p">(</span><span class="s2">"dijit.Editor"</span><span class="p">);</span>
<span class="nx">dojo</span><span class="p">.</span><span class="nx">require</span><span class="p">(</span><span class="s2">"dijit.form.TextBox"</span><span class="p">);</span>
<span class="nx">dojo</span><span class="p">.</span><span class="nx">require</span><span class="p">(</span><span class="s2">"dijit._editor.plugins.FontChoice"</span><span class="p">);</span>
<span class="nx">dojo</span><span class="p">.</span><span class="nx">require</span><span class="p">(</span><span class="s2">"dijit._editor.plugins.LinkDialog"</span><span class="p">);</span>
<span class="nx">dojo</span><span class="p">.</span><span class="nx">addOnLoad</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span>
<span class="nx">dijit</span><span class="p">.</span><span class="nx">byId</span><span class="p">(</span><span class="s1">'bodyeditor'</span><span class="p">).</span><span class="nx">setValue</span><span class="p">(</span><span class="nx">dojo</span><span class="p">.</span><span class="nx">byId</span><span class="p">(</span><span class="s1">'body'</span><span class="p">).</span><span class="nx">value</span><span class="p">);</span>
<span class="nx">dojo</span><span class="p">.</span><span class="nx">query</span><span class="p">(</span><span class="s1">'[name="submit"]'</span><span class="p">).</span><span class="nx">onclick</span><span class="p">(</span> <span class="kd">function</span><span class="p">(</span><span class="nx">evt</span><span class="p">)</span> <span class="p">{</span>
<span class="nx">dojo</span><span class="p">.</span><span class="nx">byId</span><span class="p">(</span><span class="s1">'body'</span><span class="p">).</span><span class="nx">value</span> <span class="o">=</span> <span class="nx">dijit</span><span class="p">.</span><span class="nx">byId</span><span class="p">(</span><span class="s1">'bodyeditor'</span><span class="p">).</span><span class="nx">getValue</span><span class="p">();</span>
<span class="p">});</span>
<span class="p">});</span>
</code></pre></div></div>
<p>and from the view editor.php:</p>
<fieldset><legend>$actiontitle</legend>
<p><label for="title">Titel:</label>
<input type="text" id="title" dojotype="dijit.form.TextBox" name="title" required="true" value="&lt;? echo set_value('title',$title) ?&gt;" /></p>
<p><label for="body">Body:</label>
<textarea type="text" id="body" name="body"><? echo set_value('body',$body) ?></textarea>
<div dojotype="dijit.Editor" extraplugins="[{name:'dijit._editor.plugins.FontChoice', command:'fontName', generic:true},{name:'dijit._editor.plugins.LinkDialog',command:'createLink'}]" id="bodyeditor" required="true"> </div>
</p>
<p><div class="buttons"><button type="submit" class="positive" name="submit">Ok</button></div></p>
</fieldset>
<p>Note the dojoType attribute of the editor div:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>dojoType="dijit.Editor"
extraPlugins="[
{
name:'dijit._editor.plugins.FontChoice',
command:'fontName',
generic:true
},{
name:'dijit._editor.plugins.LinkDialog',
command:'createLink'
}]"
id="bodyeditor" required="true"
</code></pre></div></div>
<p>As you can see, I opted for the more declarative way.</p>
<p>There were some pitfalls. I could not use the editor directly for instance. I had to define a hidden element for the content and post that element. Also, the declarative statement looks kind of ugly since we have to add the full name of the editor plugins.</p>
<p>The first thing you notice of dojo is that the api isn’t as slick as jquery. That is expected since dojo spans more functionality. dojo shines however in one position: dojo.require. Like the import statement in java and python or the using statement in c#.</p>
Playing around with mongo db in .nethttp://assertfail.gewalli.se/2010/04/05/playing-around-with-mongo-db-in-net.html
Mon, 05 Apr 2010 13:51:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2010/04/05/playing-around-with-mongo-db-in-net<p>Ever since I heard of the NoRM driver for MongoDB I had to try my hands on it. You can find it here:<br /><a href="http://github.com/atheken/NoRM">NoRM</a> , <a href="http://www.mongodb.org/">mongodb</a><br /><br />
The first thing is setting up the server. I dropped the binaries into <br />
C:\MongoDb&lt;br&gt;<br />
Next thing I created two batch files. <br />
To start the db: start.bat<br />
C:\MongoDb\bin\mongod.exe –dbpath C:\MongoDb\data –port 27000 –logpath C:\MongoDb\log\mongodb.log –logappend<br /><br />
The other to access the mongo shell: shell.bat<br />
C:\MongoDb\bin\mongo.exe –port 27000 <br /><br />
Next thing is creating a simple asp.net MVC app that uses MongoDB for storage.<br /><br />
My object of choice is Product:<br /><i>public partial class Product</i><br /><i>{</i><br /><i>public Product()</i><br /><i>{</i><br /><i>Id = ObjectId.NewObjectId();</i><br /><i>}</i><br /><i>[Column(IsPrimaryKey = true)]</i><br /><i>public virtual ObjectId Id</i><br /><i>{</i><br /><i>get {return _id;}</i><br /><i>set {_id = value;}</i><br /><i>}</i><br /><i>…</i><br /><i>}</i><br />
The attribute is for the editor template. Next thing is the controller. Here is the helper for connecting to the database:<br /><i> public class ServerHelper<br />
{<br />
public static Mongo GetServer()<br />
{<br />
return Mongo.Create(“mongodb://localhost:27000/MongoMvc”);<br />
}<br /><br />
public static MongoCollection<product> Collection()<br />
{<br />
return GetServer().GetCollection<product>("products");<br />
}<br />
}</product></product></i><br /><br />
Note that you don’t need to do a create database or collection.<br /><br />
Insert is straightforward. In order to list all “products” I used an empty Find on the collection. To update I did the following:<br />
<i>[HttpPost,ActionName(“Edit”)]<br />
public ActionResult EditPost(ObjectId id)<br />
{<br />
var collection = ServerHelper.Collection();<br />
var product = collection.FindOne(new{ _id = id });<br />
UpdateModel(product);<br />
collection.UpdateOne(new { _id = id }, product);<br />
return RedirectToAction(“Index”);<br />
}</i><br /><br /><br />
Looks interesting. I’ve not delved into any deeper parts than this yet. I could probably have done this without the additional configuration.</p>
<div style="clear: both;"></div>
Debugging javascript in IE8http://assertfail.gewalli.se/2009/07/18/debugging-javascript-in-ie8.html
Sat, 18 Jul 2009 19:55:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2009/07/18/debugging-javascript-in-ie8<p>How do you debug javascript in IE? Before IE 8 you could use fiddler and the visual studio debugger.<br /><br />There was a plugin for IE so that you could get a developer toolbar with some extended script debugging. As of IE8 a toolbar is built in and can be reached by pressing F12.</p>
<div style="clear: both;"></div>
Debugging javascript in Firefoxhttp://assertfail.gewalli.se/2009/07/18/debugging-javascript-in-firefox.html
Sat, 18 Jul 2009 18:17:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2009/07/18/debugging-javascript-in-firefox<p>How do you debug code in Firefox? The answer is that you use one of two eminent plugins:<br />&lt;ul&gt;</p>
<li>
<a href="http://betterexplained.com/articles/how-to-debug-web-applications-with-firefox/%20">Firebug</a><br />
</li>
<li>
<a href="https://addons.mozilla.org/en-US/firefox/addon/216">Venkman</a><br />
</li>
<p>&lt;/ul&gt;</p>
<div style="clear: both;"></div>
web api'shttp://assertfail.gewalli.se/2009/07/18/web-apis.html
Sat, 18 Jul 2009 18:00:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2009/07/18/web-apis<h3 id="local-procedure-calls">Local procedure calls</h3>
<p>Given the scripting nature of the web non-obfuscated javascript code presents itself to the technical user almost as a public API. You can try it out yourself by writing:</p>
<div class="language-javascript highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">for</span> <span class="p">(</span><span class="nx">x</span> <span class="k">in</span> <span class="nb">document</span><span class="p">){</span><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">x</span><span class="p">);}</span>
</code></pre></div></div>
<p>in your browser javascript console. For more persistent changes to a sites behavior tools like Greasemonkey can be used. Last.fm and Spotify have done some integration by releasing a <a href="https://www.spotify.com/blog/archives/2008/12/18/spotify-scrobbles/">Greasemonkey script for last.fm</a>.</p>
<h3 id="remote-procedure-calls">Remote procedure calls</h3>
<p>By using <a href="http://www.fiddler2.com/fiddler2/">fiddler</a> or Firefox Firebug you can watch the client/server interaction (ajax calls made by a modern web app). The stateless nature of the web and ajax calls promotes a simple design of this “API”. This means that programming/scripting against your site can be easily done by, hopefully authorized, users.</p>
<h3 id="conclusion">Conclusion</h3>
<p>Modern web applications have a natural interface for that might yield a plugin-like api unintended by the applications developers. If you’re developing/maintaining a web app, try searching for it on <a href="http://userscripts.org/">userscripts</a>. If your app is used by a wide group of people, then you might be surprised with what you find.</p>
Programming javascripthttp://assertfail.gewalli.se/2009/07/18/programming-javascript.html
Sat, 18 Jul 2009 16:40:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2009/07/18/programming-javascript<p>In the first course in computer science we (students) received the following words of wisdom from the lecturer:
Above anything avoid javascript.</p>
<h3 id="pure-javascript">Pure javascript</h3>
<p>A few years later I started working as a programmer (late 2005) the need to do certain small things arose; impossible without the use of javascript. One of my coworkers showed me how to add some bits of extra functionality that the users needed (easier user interface). Later on there was a need for drag and drop in the browser. I implemented this by using code from another coworker. I updated an editor for presenting study programs. I feel that that experience is a failure. It took me at least 2-3 weeks to get something that wasn’t decent enough. I tried to write good code, but failed. Both the server-side and client-side code is a mess. Fortunately this code is rendered obsolete by the fact that the system I worked on contains more information and therefore can generate such presentations without any manual editing. What I am trying to say: That coding experience sucked.</p>
<h3 id="javascript-library-jquery">Javascript library: jQuery</h3>
<p>Fast forward to 2009. I’ve started working in a team developing what can best be described as an advanced editor (specialized for one purpose) on the web. Enter jQuery: Rich text editing, ajax, items that can be saved without the whole form being submitted, et.c.. The weirdness of developing javascript almost gone:</p>
<ul>
<li>Doing manipulations on the HTML using jQuery yields more predictable results.</li>
<li>Navigating the DOM via jQuery works the same way across different browsers.</li>
<li>Events encapsulated by jQuery work the same in different browsers.</li>
<li>The terse syntax of jQuery reduces the amount of code.</li>
</ul>
<p>Because of the above the quality of the code increases.</p>
<h3 id="lint">Lint</h3>
<p>Since there is no compilation of javascript there is a need to use some form of lint on the code to catch syntax errors, legal javascript but bad syntax et.c.. There are two javascript lint implementations that I know of: <a href="http://javascriptlint.com/">javascript lint</a> and <a href="http://www.jslint.com/">jslint</a>. I use both. Jslint is a bit harder to set up in visual studio, but is stricter and finds more errors (out of the box). I might not have read enough of the documentation for javascript lint in order to use it efficiently. With the use of lint hard to find bugs and errors can be found in a matter of minutes instead of days, makes these tools invaluable.</p>
IE8 Developer toolshttp://assertfail.gewalli.se/2009/06/18/ie8-developer-tools.html
Thu, 18 Jun 2009 07:50:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2009/06/18/ie8-developer-tools<p>As noted in twitter and on <a href="http://blogs.msdn.com/ie/archive/2008/03/07/improved-productivity-through-internet-explorer-8-developer-tools.aspx">IE blog</a> IE8 has a new “developer tools” that is accessible by the key F12. Also they have included:</p>
<ul>
<li>console.log</li>
<li>console.info</li>
<li>console.warn</li>
<li>console.error</li>
<li>console.assert</li>
</ul>
<p>as can be seen on <a href="http://msdn.microsoft.com/en-us/library/dd565625%28VS.85%29.aspx">msdn</a>.</p>
<p>When you’re debugging javascript this is really sweet. If you have seen these methods before, then it might be because you’re developing in <a href="http://getfirebug.com/console.html">firebug</a>.</p>
<p>IE8 is looking hot. The inclusion of Developer tools in this release of IE, developing modern javascript is easier. Before this, developing javascript without firebug was a hassle. I’m going to try to set breakpoints and such (a thing that was notoriously problematic in visual studio when you’re debugging javascript). So conclusion: IE8 a great step forward for IE.</p>
jqueryhttp://assertfail.gewalli.se/2009/04/08/jquery.html
Wed, 08 Apr 2009 22:17:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2009/04/08/jquery<p>I’ve come to admire the simplicity and style of jquery. There are some cons to it’s approach of using context (as can be seen as this in the for instance “each”):</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>jQuery("#table tr").each(function(){
jQuery(this).DoStuffPlugin();
});
</code></pre></div></div>
<p>This wreaks havoc with some object oriented programming techniques:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>var classSmurf = function(){
this.name = "smurfette";
this.SmurfAround = function(){ alert("Smurf: "+this.name); }
};
</code></pre></div></div>
<p>This is a simplified example that is broken by jquery’s use of context. There is a simple work around for this:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>var classSmurf = function(){
this.name = "smurfette";
var that = this;
this.SmurfAround = function(){ alert("Smurf: "+that.name); }
};
</code></pre></div></div>
<p>But don’t take me wrong. I love jquery. It’s really easy to use. A designer (with some css and html knowledge) can learn how to use it. That shows how easy it is to work with.</p>
Mocking smurf datalayerhttp://assertfail.gewalli.se/2009/03/15/mocking-smurf-datalayer.html
Sun, 15 Mar 2009 08:16:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2009/03/15/mocking-smurf-datalayer<p>Mocking is <span class="variant">quite a new concept for me since I’ve mostly written unit-tests tha</span>t can be labelled “automatic test”. But it looks pretty sweet to write real unit-tests where those apply. I’m more than a bit impressed by the ease of testing code written in asp.net mvc.<br /><br />I had some trouble with method interception in Rhino and NUnit mock. Somehow the mocking failed for those frameworks. It was not a total dud since the mocking of properties worked. I spent a lot time yesterday trying to get it to work. Since a standard example from the web failed on my machine, I’ve assumed that there isn’t much to do. Since Rhino looks so sweet, I will try to find out why it fails some other day.<br /><br />What did work however was <a href="http://code.google.com/p/moq/">moq</a>:<br /><br /><span style="font-size:85%;">var Svc = new Mock<ismurfservice>();<br />Assert.IsNotNull(Svc);<br />controller.Svc = Svc.Object;<br /><br />Smurf smurf1 = SmurfTestHelper.GetSmurf();<br />Svc.Expect(e =&gt; e.GetSmurf(It.IsAny<guid>())).Returns(smurf1);</guid></ismurfservice></span><br /><br />As you can se from the example code I’m doing things that are a bit nasty: Exposing the datalayer SmurfService in controller in order to be able to use it in the binding.</p>
<div style="clear: both;"></div>
Modelbinding a complex entity framework/Linq to Sql model to asp.net mvchttp://assertfail.gewalli.se/2009/03/14/modelbinding-complex-entity-framework.html
Sat, 14 Mar 2009 05:41:00 +0000webmaster@gewalli.se (Oskar Gewalli)http://assertfail.gewalli.se/2009/03/14/modelbinding-complex-entity-framework<p>For a couple of days now I’ve been trying to “ModelBind” a more complex model (based on the Entity framework) to a controller action. The problems I’ve been having are mostly related to the amount of code for this task. I’m therefore thinking of ways to reduce the complexity. The main problem is that it’s not directly possible to bind to ordinary EF/LS-graphs.</p>
<ul>
<li>
<p><em>Separate object graph.</em> One solution could be to have a separate object graph for use in with the view. That seems more than wastefull since we want to edit everything on this page and thus end up having to maintain extra objects when we have the EF/LS ones.</p>
</li>
<li>
<p><em>A revised binding to the EF/LS objects.</em> If my modelbinder treated the EF/LS objects in the correct maner then my problems would be solved. Problem is though that I need connected objects in the binding. That implies a UpdateModel pattern with the object context visible from the controller. Not a beautiful solution though.</p>
</li>
</ul>
<p>I’ve written a small asp.net mvc application with a simple (complex model). I’ve a main entity Smurf. The Smurf entity has several SmurfChild records related to it:</p>
<p><img src="/img/2009-03-14-modelbinding-complex-entity-framework_model.gif" alt="smurf model" height="320px" width="278px" /></p>
<p>The model binding I’m trying to do is the following:</p>
<div class="highlighter-rouge"><div class="highlight"><pre class="highlight"><code>public ActionResult EditAll_CustomBinder(
[ModelBinder(typeof(SmurfListBinder))]
IList&lt;smurf&gt; smurfs
)
</code></pre></div></div>
<p>I’m editing a list of smurfs and the related smurf children in the view.</p>