Geeks With Blogs
Buhay Programmer Dont byte more than you can chew

I don't remember exactly where, but some years ago I've come across a book that said something like -- A "complete" programmer must know the 3 main programming styles, 1. C-based (C#, Java C++ etc) 2. Scripting (Perl etc) and 3. Functional (Haskell, OCaml etc).  Each style requires a different mind- set when writing code.    I started out as a Perl programmer (i know it's weird that my first language was Perl... ), moved on to C++ and now I'm doing .NET (C# and BizTalk mainly).  So, I've covered the first 2 "styles" and that leaves just functional programming. 

I've always been interested with functional programming but I somehow I've always found an excuse not to try it.  Add to that the facts that

  1. Going from OO to functional programming is hard. By that I mean the learning curve is very steep!!!
  2. I didn't want to throw away my existing knowledge on C#
  3. I didn't want to throw away the libraries I've compiled and written over the years.
  4. There are no F# jobs!! (at least there's none in Singapore)

 

A few weeks back Microsoft announced that it is productizing F#.  It is now going to be a supported .NET language. That is really great because now my excuses #2 and #3 are no longer valid!  Excuses #1 and #4 though it still has some weight, it is not enough anymore to keep me from learning functional programming with F#.  Yes, there will always be a learning curve.  And, the jobs...well, hopefully the bio-tech companies will soon adapt F# given that because of its functional nature, Microsoft is marketing it as a language for scientific reasearch and development.

F# is not a pure functional language like Haskell i.e. it allows side-effects.  This is perfectly fine (I'm not a purist) because this is actually allows interoperability with other .NET libraries.  Which means coding in F# will in no way greatly reduce my productivity.

For 2 weeks now, I've been reading up on F# while travelling to and from the office. Below is my first F# code.  Check out how System.Windows.Forms controls are available from the code.

#light
open System
open System.Drawing
open System.Windows.Forms
open System.Windows.Forms.Design

let label =
  let temp = new Label()
  do temp.Name <- "label1"
  do temp.Size <- new System.Drawing.Size(35, 13);
  do temp.Text <- "Hello F#"
  do temp.AutoSize <- true
  do temp.Location <- new Drawing.Point(26,27)
  temp

let form =
  let temp = new Form()
  do temp.Name <- "ErikForm"
  do temp.Text <- "EriKForm"
  do temp.ClientSize <- new System.Drawing.Size(292, 266);
  do temp.Controls.Add(label)
  temp

let ticker =
  let temp = new Timer()
  temp.Enabled <- true
  temp.Interval <- 1000
  temp.Tick.Add(fun _ -> label.Text <- DateTime.Now.ToLongTimeString())

do Application.Run(form)

Posted on Monday, November 5, 2007 6:14 PM | Back to top


Comments on this post: Hello F#!

# re: Hello F#!
Requesting Gravatar...
You may also be interested in http://feeds.feedburner.com/planet_fsharp
Left by code17 on Nov 12, 2007 5:26 PM

# re: Hello F#!
Requesting Gravatar...
In year 1999, I searched a job in C# . Icouldn't find one. We will see, what will happen
in 3 years.
You quote :programmer must know the 3 main programming styles

You left out logical languagelike Prolog
Left by Some one on Dec 14, 2007 7:32 PM

# re: Hello F#!
Requesting Gravatar...
Your comments are good to motivate the persons towards learing F#. It encourages the persons to learn easily.

Thanks
Left by Gopal on Dec 17, 2007 1:33 PM

# re: Hello F#!
Requesting Gravatar...
I am experienced but upto windows programming (VB6). I am begineer of Asp.Net and know a little about all. Please how can it be helpfull to me if I learn F#?
Left by Jaques on Jan 04, 2008 1:19 PM

# re: Hello F#!
Requesting Gravatar...
Hi Jacques,

For the moment there is no immediate financial benefit from learning F# mainly because its new and there are not much jobs apart from those within Microsoft. At best we could hope that the companies using OCaml will migrate to F# to be able to take advantage of the .NET Framework libraries.
Judging though by the trend among popular (or at least those that generate a lot of buzz) languages like Python, Ruby and D, these "imperative" languages are increasingly supporting functional constructs which people are having fun using. Even C# is already supporting functional constructs with LINQ. The way I see it, the programming world is slowly waking up to the functional way of doing things. Learning F# (or any functional language for that matter) we'll be able to easily ride these changes.
Another important reason for learning F# is "CONCURRENCY". The future belongs to multi-core machines. This means that programs must be easily parallelizable. And because functional languages can be coded to have no side effects, they are easily parallelized.

F# is a long term investment.


- Erik
Left by Erik on Jan 10, 2008 11:12 PM

Your comment:
 (will show your gravatar)


Copyright © Erik Araojo | Powered by: GeeksWithBlogs.net