This term I teach the course "Introduction into Programming with C++" for the first-year students of Engineering Sciences.
The course was requested by the University and targets the students with no prior knowledge of programming. The choice of C++ as the language of the course was not mine, this is the default language to teach OOP at our university (Hamburg University of Technology), for the professor in charge is doing his research primarily using C++. So, the decision to use C++ as the first language was more or less imposed on me by the dean office.
During the very first session I provided students with several motivating examples. One of those was the classical task about the chessboard and the wheat beads, where one Vizir truly enchanted by the wonderful game of chess asks the inventor for a decent reward and the latter asks him to put one wheat bead on the first field, two beads on the second fields etc. until every field is covered. This seemingly trivial task results in a very high number which is not so easy to compute directly using a brute force approach (without deriving the summation formula for this geometric row).
So, we implemented this task in several languages. Here is the one-line implementation in F# (MS version of oCaml for .Net):
let rice =
[0 .. 63] |> List.map (fun x -> 2I ** x) |> List.sum |> Dump
The equivalent C# (and with small changes C++) code is much longer and requires much more things to keep an eye on:
void Main()
{
ulong sum = 0;
for(int i = 0;i < 64; i++)
{
sum+= power2(i);
sum.Dump();
}
sum.Dump();
}
// Define other methods and classes here
ulong power2(int power)
{
ulong answer = 1;
for(int i=0; i < power; i++) answer=answer * 2L;
return answer;
}
This is why I do agree with the widely spread opinion that Computer Science and especially the algorithms should be first taught using a non-imperative language, like Haskell, oCaml, Erlang, Scala or F#.