Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> In fact, aside from the profusion of variables with unhelpful names, the C translation of Lovelace’s program doesn’t look that alien at all.

Clearly the author never met my coworkers.



I'm reminded of a high school programming class where a project partner named variables with the most crude and lewd words he could imagine. Not that I was prudish, but he unsurprisingly never remembered what "butts" was for and somehow never figured out why he kept getting confused by his own code.


For school once I had to write a program called "Poetry Writer". Basically it would take input text, build a linked list(taking in account proceeding and following words) with for each word and output a randomized version of the poem.

I HAD to of course name all of my variables as poets and poems.

So you have "Edgar_Allen gets new The_Road_Not_Taken", all was fine during my tests but for some reason it did not interface well with the code provided by the teacher to do the actual input so I had to take it to the TA for help.

I then learnt why descriptive names, not just comments are helpful. Although, the TA was impressed by my selections XD


Butts ARE distracting sometimes.


...or worked with any mathematicians/physicists/engineers who program. As soon as I saw that, I thought "typical quant".

Like my dad (A chemical engineer) learned to program in FORTRAN, which used to insist variable names were 1 letter and up to 2 digits. He later learned Basic, but his code was still spiritually FORTRAN so the one-letter-two digits thing stuck. I thought that was just him but then much later I went to work on Wall St and had to work with quants who were copying code out of "Numerical Recipes" and it was exactly the same just now in C.


I helped port a physicist's assembly code long ago; variables were named alphabetically in the order encountered in the code, e.g. A, B, ...A1, ..., AA1, etc. up to ZZ23.

Still amazed that the nearly-incomprehensible code (and the port) worked


When I was a kid I used to think that having variables A... without any gaps in the letters meant that I did a good job of thinking out the program in advance.


Not sure which Fortran this refers to. I never used Fortran I, but as I understand it, names were up to 6 characters long, first character alphabetic; names with initial letter A-H and O-Z were REAL, I-M INTEGER (Fortran II added declarations to override the defaults). Dartmouth Basic restricted names to a single letter and an optional digit.

Incidentally, the various Autocode languages of the 1950s in Britain had 1-character variable names.


That’s super interesting. It would have been some mainframe fortran from the 1970s because I remember him bringing me and my brother as children into a university computer lab where he had weaseled some time on a mainframe so he could punch cards. He told me the variable naming thing (and was prone to exaggeration) so it might not even be true - I can’t ask him now as he’s writing pseudo fortran implementations of Newton-Raphson with short variable names in the great computer lab in the sky at the moment.


Thus giving rise to the old joke: "GOD IS REAL, unless declared integer"


I guess because mathematical formulas usually use single letters for symbols. It is so common that you end using several different alphabets, lower/upper case and even calligraphic variations. Of course it doesn't scale when you need thousands of symbols and your variables doesn't have well established meanings like "magnetic field" or "pressure". However they are used to it and it's hard to break some mental models after several years of using them everyday. For good or bad some scientific computer languages (like Julia) encourage you to use the Unicode alphabet to align your code with your paper/book.


That naming convention makes perfect sense to the mathematician, so why not? It's why we use `for(int i = i; i < n; i++)` in for loops; its the mathematical sigma sum of values with the same naming convention


A loop counter doesn't carry much semantic weight so it gets a short name. Doing that for important things that deserve a descriptive name is the problem. Maybe passable with literate programming, but even Knuth's code is pretty inscrutable due to transclusions everywhere.


The question to me always was, does it makes sense in the way of, it is intuitivly understandable, or does it only make sense, if it was drilled into you long enough?

(I suspect the latter)


Harder maths are often so inscrutable that single letter variables are also the least of your problems.


Certainly. But on top of the hard problem, I don't like to be distracted by unreadable code ..


Which is why Haskell likes single letter variables too


Oh yeah. And if you're like my dad you call them "do loops" not "for loops"


While the Americans have encountered first the "DO loops" of FORTRAN (1954), the "for loops" of ALGOL are derived from the earlier use in Europe of "for loops" in programming (actually "für loops", Heinz Rutishauser, 1951), which in turn had been preceded by the use in mathematics of the "for-all" quantifier (Gerhard Gentzen, 1935), which includes an implicit loop (and in many more recent programming languages, starting with Alphard in 1974, it is preferred for the most frequent loops to use a syntax essentially identical to the mathematical notation from 1935, i.e. like "forall X in A do ...").




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: