Zit Seng's Blog

A Singaporean's technology and lifestyle blog

PM Lee Has Confused C With C++

PM Lee's Sudoku programI think our Singapore Prime Minister, Lee Hsien Loong, must have recently gotten a new social media team. Quite notably, of late, his social media posts have been clever, witty, and popular. His recent sharing of his Sudoku program source code, for example, has caught on with international media, even including the techie ones like Arstechnica.

Although PM Lee described his program as written in C++, and the source file having the requisite “cpp” extension, the contents are really in plain C. There were no C++ features used in the program. The program does, in fact, compile with the standard “gcc” command. I suppose the busy man must have gotten a little mixed up with the language he had used.

This program compiles not just without errors, but also without any compile warnings. I know of many programmers who couldn’t care to write programs that compile perfectly, without warnings whatsoever.

PM Lee’s Sudoku solver program is fairly straightforward. The entire program source is just 223 lines long. The PM isn’t very generous with his source code comments. Like me, perhaps. I often joke that my code is the documentation. That way, my documentation is always correct, and up-to-date.

Screen Shot 2015-05-06 at 1.12.25 pm

I’ve tested PM Lee’s program with a sample Sudoku puzzle, and I’m pleased to see that the output is legit. The program doesn’t do any error checking though, the onus is on the user to ensure that input is valid. That’s alright, it’s a simple program.

Now, if only our PM can channel his energies to address the concerns and worries of Singaporeans.

Future job applicants to the Singapore civil service, be warned that you may be asked to spit out a Sudoku solver program in Haskell during your interview. Sudoku shall become the benchmark “Hello world” program for testing programmers.

8 thoughts on “PM Lee Has Confused C With C++

  1. I feel that you are nitpicking here. Had he said I wrote an “object oriented” code, then I would agree that he is mistaken. But C++ encompasses C and more (Stroustrup pretty much started off by extending C to include all the other awesome features). So you can say C++ features do include C features. Moreover, C++ predecessor was named “C with classes”. And come on man, if you compile the code with a c++ compiler (e.g. g++), it is not going to spit out some nonsensical warning like “this is not C, please use C++”…it will instead just compile it with no problem whatsoever.

    REF: http://en.wikipedia.org/wiki/C%2B%2B

    1. I meant for my post to be lighthearted. If you could consider this to be nitpicking, I’m afraid you’re equally doing so. Stroustrup also said that C isn’t a subset of C++ in the strict mathematical sense. You can write code valid in C that’s not valid in C++, or which have different meanings in C and C++. Yes, I know, of course, that g++ will compile PM Lee’s code just fine. But com’on, just show this source code to any decent programmer, is he/she going to say this is C or C++?

      1. Well it can be considered C or C++. stdio.h is a header recognized by a C++ compiler too. My point is that it does not matter whether you call it C or C++, but it definitely is not OOP. Yeah, maybe I am nitpicking too;)

    1. I laugh when you wrote that. If you know c, I don’t understand why you want to lower yourself.

  2. Big men do big things. Small men do small things. So you want the PM to say “Hey Zitseng! You are right!” then you feel happy?

Leave a Reply

Your email address will not be published. Required fields are marked *

View Comment Policy