Showing posts from May, 2013

Named functions in Javascript

I am at Progessive.Net at the moment in the Helen Emerson talk. She mentioned a benefit of naming functions, you can then use them to recurse. Normally I would assign a function like
var boo = function() { //something }; But if you name the function as well, you can then use it to recurse. I didn't realise you could do this so I am quite pleased. She also mentioned that it can also help when debugging and when you are catching exceptions.

Anyway, here's an example!

Update: Her examples and presentation is available on her github account I really like the console library that she is using. Quite a cool little thing.

Messing about with Javascript Jasmine Tests

I first started messing about with Jasmine tests over a year ago at a Progressive.Net conference (A friend had mentioned them before that too I think), but I never got round to implementing them properly. I am having a bit of an evening of tinkering with our core software platform at work and thought it would be cool if  these were integrated into the admin site perhaps.

Anyway, I need to get back up to speed so I have begun giving them a whirl. I can't remember the exact syntax before but this time looking at ig I am really impressed. The test runner prints the tests out in a real cucmberish way that allows you to essentially keep a nice living specification of the javascript on your site.

Take a look at the site and some more examples here

Fibonacci algorithm performance testing in .NET languages.

I was doing a little tidy up of the some of the books under my desk and I started to flick through Foundations of F# by Robert Pickering. It's a great book and I started to flick through it. I spotted the Fibonacci sequence and it got me thinking. How could I waste some of my afternoon?

I did the algorithm in F# and then begun to wonder if something in C# would be faster. That got me thinking about how to accurately measure performance. In the end I went down a bit of a rabbit hole but I found some interesting results.

 The results above correspond to the names of the tests below. It's very difficult to create a true scientific test on your own computer but the tests were run an i5 Sandy Bridge with 8gb of ram. No other programs except Visual Studio and Windows 7 were running. I ran the test 5 times, each time it ran the tests 100,000 times and then it grouped on the test name and took the average and saved it to sheet 2 above. I then used a pivot table and aggregated / avera…

Anonymous types and functions in Visual Basic.Net

A lot of people poo poo VB.NET and yet I think almost none of them know anything about it. It has essentially all the same functionality as C#. With the latest versions of VB.NET you can use anonymous functions really nicely. I think the syntax is very clear and it makes it more obvious to a beginner programmer what is happening ie, the lambda you are passing into the where is a function. I think that's a real commendable thing to do and the syntax is very true to the language.

I think you would find an awful lot of C# developers using expressions such as

results.Where(x => x.Success);

but many of them (certainly a lot of the devs I have met in the past) would not really understand what is happening here. It's arguably not important but that's not fair. Using lambdas just in Linq wastes so much potential of the language.

Anyway, there's an example below in VB.NET. This syntax is in some ways more similar to the way F# does lambdas! ie

let test = fun x x < 2

Now if…

Android Development - No default tying up of controls

After having a quick peek at Android Studio, I was hoping in the latest version of Android would automatically tie up or help you automate the leg work involved in getting a handle on controls on the view.You still have to find the view by Id and then cast it to the correct view. To me this just seems so stinky. I think something like the below is nicer as it just keeps your code more readable....I quite like Ropbojuice too, this automatically squishes the things you need in and is worth looking into.

Android Studio won't load up - Solution :-)

I installed Android studio on several machines but could not get it to load up. It didn't even complain with an error. A very upsetting experience considering my extreme excitement about it.

After a little moan about it on Twitter, my friend Adrian pointed me in the right direction. Even though during the installation the installer confirms the location of the JDK, it still can't find it.

So you just need to:

Find where you installed Android StudioOpen Studio.batAdd this line -> set JDK_HOME=C:\Program Files\Java\jdk1.7.0_03 (two lines below @ECHO OFF)Run Android Studio.  That should be it! Hope that helps someone out there.

Mulitple Assertions in one test

This might be a bit of an anti-pattern to some but I have found it's sometimes useful to test more than one assertion in a test. Some would say, one assertion per test and yes this is normally the case. But sometimes you want to just check that all the values on a form have been bound to a model or all the values have been saved to an object correctly. In this case, one assertion per test is just a gigantic bit of ceremony. All you really want to express is that the model is bound so you can call the method TheModelIsBoundCorrectly() and not TheDateIsSet(), ThePostcodeIsSet(), TheNameIsSet(). Ugh that would be a pain.

The problem with putting all the assertions in the same method is that when one fails, it raises an exception. It's a real pain to have to fix the test, run it and then the next field fails too and so on. The above would run all the tests first and only throw …

My Blog is Back!

I have finally sorted out my blog! It has resulted in me returning to my original blog on After leaving Posterous, I attempted to just host my blog on my Raspberry Pi but unfortunately barely a day went by when the Pi wasn't unplugged for some reason so I decided to move it again. There was a degree of foolery involved, I had to export my blog to a wordpress site then convert it to a blogger site then import it. Anyway! Hopefully blogging shall now commence!