Recently I have had the pleasure of training a couple of colleagues in the wonders of programming. At work we use C# for most of our applications so naturally I started preparing my material in C#.
I did not get very far before it occurred to me: This is going to be a long haul…
Now, my colleagues are smart, really smart, much smarter than me, but they do not have much experience in programming. They have been using SQL, some VBA, and perhaps a bit of R, but none of them have been doing real application development and they know nothing about OO theory.
Unfortunately, you do not get very far with a language such as C# without knowing just a little bit about OO programming.
Let’s start with the compulsory and useless “Hello, world” example:
using System;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, world");
}
}
}
That’s a lot of code just to print out a stupid message on the screen.
“What are all those things for?” my colleague complains and I answer “We’ll get to namespaces, classes, static, void, arrays, and more stuff later”. He’s not happy and continues “Do I really need to write all those curly braces and semicolons?”. And when I tell him yes, and don’t forget that it’s all case sensitive, he breaks down and says “I miss VBA…”.
Of course curly brackets and case sensitivity has nothing to do with OO but I think we can all agree that OO is really, really hard. Heck, I don’t even master it after years of C++ and C#.
I find that it takes a long time for beginners to grasp OO and when they start to see the light they will abuse inheritance and create everything as singletons. And interfaces seem to be impossible to understand even though I do my best with lousy metafors such as cars and DVD playsers.
Usually, beginners actually tend to completely ignore that C# is object oriented and they take a straight forward approach and create a very long Main
function.
So, perhaps teaching my colleagues C# is not the right approach. Perhaps I should try teaching them a functional language instead such as F#? Now, I am not saying that functional languages are easy but I do think that you can get really far with F# without knowing advanced stuff such as monads. In F# the “Hello, world” example boils down to
printfn "Hello, world"
Very simple. Not much to talk about.
Besides, there are a couple of important points to consider when bringing F# to the table:
- My colleagues are all mathematicians and functional languages are perfect for math stuff.
- F# is a .NET language and will work together with all the C# code in our company.
- F# can work as a scripting language for makeshift assignments.
I am thinking that it would suffice to teach the basics of F# such as record types, functions, pattern matching, the Seq module, type providers, and perhaps partial application.
What do you think? Would F# be easier to grasp or should I go for the usual C#?