Tag: <span>F#</span>

OK, so the title is really misleading, as you can’t really compare two such different languages, but it’s interesting to try to anyway.

Anyway, being a rank beginner, I had to start with everyone’s favourite recursive function, the factorial. This is a good one, as it’s so simple, but quickly generates numbers so big that it’s pretty useless unless you do something more than the basic coding. The results were surprising.

A while back I blogged about a situation where thinking out of the box helped me write some code more quickly. In a nutshell, I needed to extract an exchange rate from an XML feed, and found that by using F# to do it, then translating the code back to C#, it was much easier than trying to write the code in C# in the first place.

I thought it might be interesting to revisit this in both languages, and compare the two experiences. I found this to be a significantly better sales pitch for F# than anything else I’ve seen.

Having finally given up with dasBlog, and decided to join the rest of the world using WordPress, I was left with the painful job of transferring all my old blog posts across. One advantage this gave was the opportunity to re-read some of my old posts, and see how much (or not) my opinions have changed.

One of my older posts was written when I first started learning F#, and was hugely frustrated at the blatant lies told by a lot of the community in an attempt to convince C# developers to use F#. Whilst I was enjoying F#, and felt it had something fresh to offer, I was (and still am) really annoyed at some of the rubbish being written.

Well, it’s now over two years later, and not much has changed.

A hopefully enlightening story.

I had the need to get the latitude and longitude for UK postcodes. Knowing that another developer had recently done a lot of work doing similar things using the Google Maps API, I had a look at the code she had written. Following the Google guidelines, she had ended up adding wads of C# classes, defining the various data types that the API returns, as well as a lot of helper methods to parse the data. I had that horrible sinking feeling you get when you can see a small design requirement blow up out of all proportion.

Whilst contemplating the problem, I had an epiphany, and realised that I could solve the problem in a much simpler way, albeit with some initial effort. I thought the technique might be useful to others, but more significantly, thought that the idea of thinking outside of the box may be of interest.

As my regular reader will doubtless remember, I recently blogged about the important lesson I learnt while solving problem 8. I prophetically commented there…

“So, am I going to contemplate my problem domain before diving in and coding next time? Probably not, but at least if I don’t, I might have some idea where to look when the bug reports come in!”

Hmm, I thought I was joking! Well, sadly I wasn’t.

As my regular reader will know, I love anything shiny and new, and so was intrigued when I came across F#. When I was an undergraduate (some 25 years ago, ulp!), I played around with Prolog, and enjoyed the different approach to programming it offered.

However, as my time in front of the computer is at a premium, my F# learning started off with reading books and blog posts late away from the computer, usually last thing at night, and not actually doing any coding. Like most C# developers who come across F#, my initial reaction (other than “Hey, that’s shiny and new, I want to learn it!”) was “Why?” If you search around for terms like “why f#” and “c# vs f#” you’ll find that this is a very common question.

The problem is that the answers aren’t very good. Well, let’s be blunt, there are a lot of lies out there.