Ugh! Your shorthand is too short!

Started by
42 comments, last by l0calh05t 10 years, 1 month ago

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)?

They call me the Tutorial Doctor.

Advertisement
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.

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

They call me the Tutorial Doctor.

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.

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

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...

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? dry.png

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.

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"

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.

This topic is closed to new replies.

Advertisement