• Create Account

## Ugh! Your shorthand is too short!

46 replies to this topic

### #1Tutorial Doctor  Members

Posted 15 January 2014 - 09:16 PM

One of the most annoying things I keep seeing is people who write shorthand code with variables like:

i = true


Where "i" means "initialize" or some miscellaneous other word that starts with an "i."

How will you go back later and debug when the code has reached 1,000,000 lines and you forgot what "i" does?

Better yet, even 1,000 lines would throw me for a loop (pun intended).

I mean, C++ code is already cryptic enough, why the extra brevity?

Sometimes I truly think people initially write the full names in the code, and then go back and make things cryptic on purpose just to scare away code thieves. In that case I understand, but is the stereotype really true that programmers are just lazy?

There is a way to be brief yet descriptive without feeling like you are monologuing in your code. I understand that we can sacrifice a little human readability (according to human language standards) for the sake of "getting it done" but really....

Something like:

init = true


would be better, but even then....

Anyone else know what I'm talking about (I am a beginner)?

Edited by Tutorial Doctor, 15 January 2014 - 09:18 PM.

They call me the Tutorial Doctor.

### #2Nypyren  Members

Posted 15 January 2014 - 09:31 PM

POPULAR

One of these days I should write an entire C# program using nothing but the following variable names: eax, ecx, edx, ebx, ebp, esi and edi.

And an internal static Stack<object> somewhere for when 7 variables aren't enough.

Edited by Nypyren, 15 January 2014 - 09:36 PM.

### #3Tutorial Doctor  Members

Posted 15 January 2014 - 09:35 PM

haha! While you are at it you can program an OS in Omgrofl.

They call me the Tutorial Doctor.

### #4JTippetts  Moderators

Posted 15 January 2014 - 11:13 PM

POPULAR

Well, if you are having to decipher the usage of i in the context of 1,000,000 lines, or even 1,000 lines, then you ought to refactor that function a bit since that's just a tad too long. Unless you're trying to say that i is a global, in which case then yes, that's wrong.

### #5ultramailman  Prime Members

Posted 15 January 2014 - 11:49 PM

I was trying to learn about b-trees, and so I looked around and found this implementation, full of one letter variable names:

http://attractivechaos.awardspace.com/kbtree.h.html

### #6fastcall22  Moderators

Posted 15 January 2014 - 11:59 PM

full of one letter variable names:
http://attractivechaos.awardspace.com/kbtree.h.html

Having one letter variable names is the least of your worries in this code...

Edited by fastcall22, 15 January 2014 - 11:59 PM.

zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC

### #7Servant of the Lord  Members

Posted 16 January 2014 - 02:05 AM

POPULAR

so I looked around and found this implementation, full of one letter variable names

Yea, that's something that annoyed me when learning easing functions - everyone assumed I knew what (float t, float b, float c, float d) stood for.

The 't' stands for 'time'? No, 'c' stands for 'chrono' - which means time. No, no, 'd' is time and stands for 'delta'... What's 'b'? Baklava?

It's perfectly fine to abbreviate my username to 'Servant' or 'SotL' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames -

### #8samoth  Members

Posted 16 January 2014 - 03:13 AM

The more annoying thing aboug one-letter variables is about highlighting or finding them (pray you do not have to refactor such code), not so much about understanding what they mean (if the programmer is only somewhat sensible, the purpose of one-letter names is usually still obvious).

But once you find out that your editor lets you conveniently highlight all occurrences of greater-than-N substrings (usually N=3) you start shouting at people who use one-letter variables because it doesn't work with the default settings, nor is there a way you could configure it so it works in a usable way without highlighting every frequently occurring letter in every keyword too.

### #9MaxDZ8  Members

Posted 16 January 2014 - 03:23 AM

Since I've switched to DVORAK-DEV I sometimes find myself doing very... sad things.

So, on DVORAK-DEV numbers are really difficult to do. They are... on the row you expect but in a different order, with 0-1 being passable, 2-3 ugh. I still don't remember the position of the others. It turns out 9 is on QWERTY-6.

Ah, and you have to hit SHIFT to do numbers, as default those buttons produce symbols.

So, when I don't have expressive names, I end up doing even worse stuff:

void Some::Function(uint argo, uint argi) { ... }


Because you see, o is a small 0. And i is 1. And 2 is... what about t? Cuz it looks like two isn't it? And 3 is e... uuuuh my head!

Previously "Krohm"

### #10ambershee  Members

Posted 16 January 2014 - 06:54 AM

I was trying to learn about b-trees, and so I looked around and found this implementation, full of one letter variable names:

http://attractivechaos.awardspace.com/kbtree.h.html

THE HORROR.

### #11ApochPiQ  Moderators

Posted 16 January 2014 - 01:23 PM

Nobody tell this guy about codegolf.

Wielder of the Sacred Wands

### #12Nypyren  Members

Posted 16 January 2014 - 03:17 PM

I was trying to learn about b-trees, and so I looked around and found this implementation, full of one letter variable names:

http://attractivechaos.awardspace.com/kbtree.h.html

OK, that page is *truly* worthy of being called a Code Horror.  I'm absolutely certain I can write more readable code in assembly.

### #13slicer4ever  GDNet+

Posted 16 January 2014 - 04:12 PM

I was trying to learn about b-trees, and so I looked around and found this implementation, full of one letter variable names:
http://attractivechaos.awardspace.com/kbtree.h.html

that macro is just...insane.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

### #14ApochPiQ  Moderators

Posted 16 January 2014 - 04:57 PM

Meh... that's just what happens when you try to write type-generic containers in C. I've seen worse.

Wielder of the Sacred Wands

### #15ferrous  Members

Posted 16 January 2014 - 05:51 PM

So, if 'i' is just some loop variable, that's fine with me.  for i = 0; i < SomeMeaningfulNameHere; ++i

If the variable names are used because they are formulas to an equation, that's mostly okay, though I prefer it when at least the signature of the function is meaningful, even if later on in the function, distance is shortened to d, and startPoint is shortened to p0 or whatever.  If a link to the formula is in the code, that's super handy.

I hate it when someone decides to get cute with variable names, there was a guy who had all his packet structures named after anime characters.  Or when every single variable is just a,b,c,d,e,f,g,h and so on, until it wraps around to aa,ab,ac.  (Though that's a sign that the code is probably overcomplicated, when you have more variables than the alphabet.)

### #16Tutorial Doctor  Members

Posted 16 January 2014 - 10:34 PM

I was trying to learn about b-trees, and so I looked around and found this implementation, full of one letter variable names:

http://attractivechaos.awardspace.com/kbtree.h.html

Hahaha. Wow! I've seen code like this before. I can't tell if that was intentional or not, because there is so much that is off about that code.

They call me the Tutorial Doctor.

### #17JTippetts  Moderators

Posted 16 January 2014 - 11:21 PM

It's not really off, nor is it even particularly ugly, once you look past the heavy use of complex macros. It's just code from a different time. Looking at the copyright dates, you can see that original versions of it date back to 1997. 1997 was eons ago, in terms of language development. It was written in C first of all, and even if they'd have used C++, template support in C++ compilers of the day was nowhere near what it is now. Like Apoch said, it was just someone trying to write a generic tree type in the C language. To achieve that type of genericity in C took some arcane contortions, as you can see, but in many cases it was well worth the effort; and in fact, an old-school C programmer would not in any way be all that intimidated by that code, being more accustomed to that style of programming. Remember that in C, macros were not the pariahs they are now; in fact, they were quite integral to advanced usage of the language.

### #18Vortez  Members

Posted 16 January 2014 - 11:48 PM

One letter variables are well suited for loops, or simple math formula, otherwise it's best to give an accurate variable name, even if it's long imo.

Edited by Vortez, 16 January 2014 - 11:49 PM.

Posted 17 January 2014 - 02:31 PM

Use longer names instead of single letter variables. Consider replacing

a with alpha

b with beta

d with delta

etc.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #20Tutorial Doctor  Members

Posted 17 January 2014 - 04:54 PM

I understand single letter variables for constants and loops, but I have seen code like the one posted prior that look like alien language. I just don't get it.

I mean, in math we represent quantities with variables, usually when those quantities are unknown or variable. But in programming we have freedom to give the variable a more descriptive name. I mean, it is useful to use single letter variables for formulas and perhaps this would be a justifiable use of single letter variables also.

m =

x =
xx = x*x

b =
a =
c =

m*xx + b*x + 4*a*c


And if these variables represented numbers that are generated by some arbitrary process, then I can see how code can get real cryptic looking but still be understood easily.

But it seems sometimes, for the sake of brevity, people use single letter variables or even non descriptive  abbreviations all over the place. I'd have a hard time myself if I didn't make it recognizable for later on.

They call me the Tutorial Doctor.