Tuesday, 17 July 2012

A Calculated Moan

Numerical methods in C/C++ feels like a strange world of programming.  The numerical methodists have these mysterious algorithms with exotic names, and to me it feels like they enjoy a bit of obfuscation.  Clarity and readability are sacrificed for use of mathematical terms and often compactness of a method.  I understand that in the heat of the moment, for example when I was doing some data structures stuff,  I felt very proud of myself after getting some specialist vocab into a program and some variables that only a fellow data structures studier would follow.  But how will that pan out in a week, a month, a few years?  The smugness will probably turn to hours of frustration and trying to reunderstand some code that just seemed so obvious at the time.

So when I work through these numerical methods books, I'm aware I see it as a beginner, and some of the conventions are new and will take getting used to.  Also, the book "Numerical Recipes" is a reference, not a tutorial, and the explanations are detailed and informative.

A cook-book for the hardcore
To me, as a programmer, mathematical definitions are obscure and not enough for me.  Like given in the data structures discussions, I believe some pseudo-code goes a long way for explaining more complex methods.   Breaking down things into the fundamentals and why they work.  Many of all the variable names in numerical methods code, in my opinion, are cryptic and unhelpful.  As a result the code reads like a numerical method rather than english.  For example, why use a load of one letter variables? In one code example of "Introducation to Numerical Methods" there's 'a', 'b', 'i', 'n', 't', 'k' and 'aki' all being used in a small function.  I understand the use of things like 'i' and 'j' for loop iterations is concise and also widely recognised, and can definitely result in more readable code.  However, especially in some complicated algorithm, I need all the help I can get, and helpful variable names can make a huge difference.  Finally, I'm a bit fed up of reading things like a variable 'i' and another called 'ii' in the same function.  It seems to be a numerical methods quirk, and possibly the pinnacle of unhelpful variable names.  Of course, this is just my opinion!

There's an air of hypocrisy about it all, so I'll try putting up some numerical stuff that I've been doing, and some resources that I make along the way.  Even so, I'm sure I use variable names that personally, I'm comfortable and familiar with, but someone else will find more difficult to interpret.  I guess when you have complex methods, this becomes magnified, even with thorough commenting and good structure.  Sometimes, when trying to decide on a variable name, I feel like I'm becoming pedantic over small and inconsequential details, like whether I should say "val" or "value", so it would be interesting to see an objective study to see what's important when picking the best variable names (but not descending into underscores vs camel case flame war).

Finally, the above post is not meant to be disrespectful to the authors of "Numerical Recipes", or "An Introduction to Numerical Methods", all of which are much more experienced in terms of programming, and actually an authority on their subjects.  Their books, together, are really helping me understand and get into numerical methods, and are full of expert knowledge.  Also, I understand that in books space is definitely a limited resource, so they really have to compact vertically and horizontally, and can't afford lengthy explanations and pseudo-code.  This is really my motivation for building up my own resources which can go into way more depth for my own problem areas!

No comments:

Post a Comment