DEV Community

Cover image for Which is better for teaching? C# or F#
Jakob Christensen
Jakob Christensen

Posted on • Updated on • Originally published at leruplund.dk

Which is better for teaching? C# or F#

This article originally appeared on my personal blog.

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 (and have almost no resemblance to the picture above). 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");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

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#?

Oldest comments (14)

Collapse
 
bgadrian profile image
Adrian B.G.

Mathematicians == functional programming, there is no question.

But if they are not into programming, and you want them to enter just as a hobby do not include work matters, do not call upon the HUGE languages like .net where you get lost on stack overflow. Make funny projects with them, games are always good for the morale

start slow - Khan academy - JS canvas library
CodeCombat.com or codingame.com or other competitive ones, where you can battle each other, a tournament is always good for spirit
Unity3D - has Mono, but you can achieve a lot of things w/o scripting. Do weekend game jams.

Collapse
 
t4rzsan profile image
Jakob Christensen

I never thought about using non-.NET languages. JavaScript may be a good place to start. I will think about it.

Anyways, most of them are not completely new to programming. They have done some SQL and VBA and the intention is to level up. But you are right - none of them are really into to programming so your suggestions may show them the joys of it.

Thanks for your advice.

Collapse
 
bgadrian profile image
Adrian B.G.

Np, as a professor is hard to find something they might like. For kids Scratch works great for example.

You can try other fields too like: make a pathfinding route for the Roman empire or learn how to query one of the biggest public DB hosted at GCloud, like GDELT, make scripts to fetch those data or you download them, and make cool contests to find the weirdest popular news like how many ppl were killed by a parrot :).
The point is that languages are just tools, you will learn a tool when you have a project for it and understand it's utility, and want too.

Collapse
 
matthras profile image
Matthew Mack

Definitely F#, but highly suggest you be prepared to adjust your teaching approach on the fly depending on your colleagues. There'll be, in my experience, two ways of approaching a new topic:

  1. Learn the theory, then apply it to building stuff.
  2. Build stuff/scripts first, and then teach the theory afterwards. As a mathematician this is my approach with coding, because what I find fun is figuring out the abstraction, and then confirming/normalising that with the theory.

Definitely think about the learning curve. With your C# example it was far too steep to begin with, partially because your example had a lot of additional details that for you, it's easy to not worry about. For beginners, they have no idea what to focus on, so their attention goes everywhere and as a mathematician myself I'm obsessed with the details, so my head would also be springing with questions like "What's namespace, static, void? etc.".

Start with scripting and doing things, and if there's such thing as a symbolic maths package/library for F# you can have a bit of fun with that. I know nothing about F#, so I don't have any other specific suggestions.

Collapse
 
t4rzsan profile image
Jakob Christensen

Thank you for your comment.

I think you are right that there are too many details in C#.

Starting with scripting is a good idea and F# is really good at that. All you really need is a text editor.

Collapse
 
saint4eva profile image
saint4eva

I bet to differ. There are also many details in F# hello example, it was the writer who decided to leave them out for brevity. C# also has a scripting capability both in Visual Studio, VS Code, and Xamarin WorkBook.

You can just do WriteLine("Hello World"); in C# example. I would suggest the teacher do some researchers to find out what is needful and meaningful for the team based on the tasks they will be rendering the company.

Anyways, F# is a great language, and C# is a great language - all taking advantage of a powerful platform - .NET.

Collapse
 
danieljsummers profile image
Daniel J. Summers

I'm a big F# fan, so I'd be remiss if I didn't mention that your "boiled down" F# example missed the module and [<EntryPoint>] declarations (unless you're running in an fsx file). :)

I'd agree that F# will fit the mathematician's mind better than C# will. Of course, a lot of the .NET Framework examples assume C#, so being passingly familiar with C#'s syntax will be a benefit to your protegΓ©s. So, as BG Adrian said - don't lead with the .NET Framework, lead with "automated mathematics," and bring in the framework when they need to do something the language doesn't handle "natively".

Collapse
 
t4rzsan profile image
Jakob Christensen

Thank you for your suggestions. I will start with real world assignments and bring in whatever is needed from the framework or from Nuget as we go.

I admit that I did cheat a bit with the F# example to state my point. But one of my points is that F# can be easily used for scripting (.fsx) so it is still valid :-)

Collapse
 
saint4eva profile image
saint4eva

C# can easily be used for scripting also - (.csx)

You can use Xamarin Workbook or VS Code to start teaching your colleagues.

You can just use WriteLine("Hello World"); After you have declared the using statement, which you did not do in your F# example - whence biases.

Anyways, teaching one programming depends on many factors and there must be biases and preferences. People will always resist new ways of doing things until you break that barrier by motivating and influencing them.

Without mincing words, C# is a powerful and wonderful language with many great features - check out C# 6, 7, 7.1 and upcoming version 8. And F# also is a great language. All of them running on a great and powerful platform - .NET or .NET Core.

So if you feel F# will be better for what they will be doing for the company, teach them F#. But is C# will be useful and better for what they will be doing, teach them C#. After all, I do not think is hello world they will be developing for the company.

Consider the prospect of the language, industry support, platforms they run on; how many different types of application you can develop using them. etc.

Collapse
 
yonifra profile image
Jonathan Fraimorice

I think that C# has maybe a bit bigger learning curve at first, but afterwards you gain important knowledge in one of the most popular languages in the worlds, and knowing C# will help later on in moving to other similar languages such as Java.
I've never seen a job post with F# requirements, but maybe it's just me.

Collapse
 
t4rzsan profile image
Jakob Christensen

It seems that FP is gaining in popularity (especially Elm) but you are right about the popularity of C# and the missing job postings for F#.

Thanks.

Collapse
 
yawaramin profile image
Yawar Amin

I highly recommend this course: coursera.org/learn/programming-lan...

It's a free online MOOC with short lecture videos, about 10 mins each. The professor has a knack for explaining functional programming concepts simply and succinctly. He teaches statically typed functional programming, and I think covers the concepts that will really open your mind to the specific way of thinking with types and functions.

About a year ago, I actually started a lunchtime study group with some of my colleagues to tackle this course, with the expectation that it would take about four to six weeks to finish. The course itself is taught in Standard ML, but I prepared some supplementary notes to convert the syntax and some techniques to F# (the two languages are very similar). I can send you the notes privately if you want.

In our case unfortunately we didn't have the time or discipline to keep up the course, but if you have some support and engaged learners it should be possible.

Collapse
 
t4rzsan profile image
Jakob Christensen

Thank you for your comment.

I will definitely take a look at your link.

Collapse
 
voronoipotato profile image
Alan Ball

F# is easier to teach someone to get started imho.