Maths is Neat!

March 12, 2010

Wow, its been over a year since I posted anything here. This blog was meant to be only about C++ but that might change now. Two interesting books where published last year that I did not have time to read. They where Stroustrups new book “Programming: Principles and Practice Using C++” and Stepanovs “Elements of Programming”. The first is aimed at C++ beginners, the second at Mathematicians. Stepanov is the genius that invented STL.

That brings me to the point of this post. I always wanted to learn more maths but somehow never got around to studying it seriously. There was always something else. As a programmer you can make a career without any maths knowledge at all. I would guess 95% of programming jobs don’t require any maths. But then again 95% of programming jobs are quite boring. Its seems to me all the interesting programming is in maths heavy areas. For instance 3D programming is heavy with linear algebra, physics simulation is heavy with calculus. Algorithm and data structure design is also heavy with maths. That all interesting stuff.

So I bought a bunch of math book, put them in my backpack. Quit my job. Bought a one way ticket to South America. And for the  last year I have been living cheaply and studying hard. Who needs schools and teachers when you can teach yourself anything. It might sound crazy but its been great. I started studying pre-calculus, all that stuff I once knew and forgot. I moved on to study lots of linear algebra. I have also been studying a bit of calculus and about the math in games. I have also had time for sum fun and games, im in South America after all. By summer time I’ll be job hunting for a programming job that requires some of this math. I’ll try getting a 3D game programming job. I think that would be very interesting. My plan B is to go back to University and study maths. This stuff is interesting in its own right. I got nothing but respect and admiration for mathematicians and what they can do. Mathematics is the language of the universe after all. And what could be more interesting than that?

Maths is just great, especially in connection with programming. I hope I keep motivated to keep studying this for years to come.



I have been waiting to see if some authority in the c++ community would bite and give a response to Linus Torvalds flame about how bad C++ is compared to C. Steven Dewhurst’s wrote a good response. But first, If you haven’t heard the gossip.. A while back Linus gave sound bites like:

“C++ is a horrible language. It’s made more horrible by the fact that a lot of substandard programmers use it. […] C++ leads to really really bad design choices. You invariably start using […] STL and Boost and other total and utter crap […] and anybody who tells me that STL and especially Boost are stable and portable is just so full of BS that it’s not even funny. [C++ leads to] inefficient abstracted programming models. […]  The only way to do good, efficient, and system-level and portable C++ […] is limiting your project to C [which] means that you get a lot of programmers that do actually understand low-level issues and don’t screw things up with any idiotic ‘object model’ crap.”

You can read the whole thread here if you like.

I find it a bit chocking that a highly respected programmer like Torvalds would write such statements about the most advanced language in common use. He did not give any references to back up his claims about C++’s inefficiency or importability. He gave very little context for his views, so its hard to see where he is coming from. I got the impression reading the thread that C++ is unpopular in the open source developer community.

It’s been a long time since C had any performance advantage over C++. A decade ago The inventor of STL, Alexander Stepanov, wrote a famous article and benchmark where he debunkes the myth of the abstraction penalty of C++ compared to C. You can read the whole paper here.

The current C++ standard has been out for a decade, and today’s main compilers and standard library implementations are very conformant. So I cant imagine portability being much of an issue today. Even assuming Boost has portability problems, the library is just another 3rd part library, so you cant really blame the C++ language for it.

As for bad code and programmers. The fact that C++ has data hiding and abstraction features, and has stronger type safety than C, makes it easier to write good code. Without using data hiding and abstractions, dependencies are stronger and their number greater than necessary. It seems rather anti-intellectual to prefer more detail over more abstraction. After all, math, the purest science of all is all about abstraction. Good code is correct code, first and foremost. And performance, although important, is a secondary concern. With C++ we get the best of both worlds. Powerful abstractions and high performance.

I see no benifit to C, other than it being a simple language to learn. C++ might be complex, but not needlessly so. Every feature (well almost) is there for good reason.

Anyways, finally, here is Steven Dewhurst’s (a well known C++ author) response to Linus comments about C++. I’d love to see Linus response. Maybe he could explain his reasoning better given another chance.