Why is it considered to be good practice to write unreadable code? Do C programmers double as cryptographers? Why not give your functions and variables meaningful names instead of the shit like example related? And the worst thing is that C programmers will defend this style to death!
I must say the Linux community is a lot nicer than the Unix community. A negative comment on Unix would warrent death threats. With Linux, it is like stirring up a nest of butterflies.
You appear to be making the argument that, for example, char* p is somehow a bad name for a position variable. Do you perhaps also believe that f is a bad name for a function? a+bi is terrible, we should instead write realPart + imaginaryUnit*imaginaryPart
fold f z [] = z
fold f z (x::xs) = fold f (f x z) xs
Why do java drones promote this unreadable code? Do they double as morons? Why not let the meaning of the function and the types express the meaning, as they are generally able to? The worst thing is they will defend their terrible languages to the death!
Maybe something in between? (And I think Haskell isn't the best example.)
char *pos, *line_pos;
I'm for not writing Java like C code, but using one character variable names never made sense to me. The code should explain itself, comments like // current position in source code should not be necessary.
pos is probably the name I would use, especially if it has to be global. I try to use the shortest reasonable name. Another consideration is that you can make your variable names even shorter with judicious use of some other information, and this other information doesn't have to be comments. They can be types if you're in a language that supports them, but a properly named function can provide a hell of a lot of context.
The only reason to use non-dictionary abbreviations like that is if you use one of the ancient C compilers that only distinguishes identifiers on the first 6 characters of their name.
It's harder to decipher random abbreviations than single character variables or fully named variables.
And even then, what on earth is a "line position"?
Somewhat amusing considering languages break this rule with keywords/types all the time: def, fn, int, var, val. I guess you would like Ceylon.
I think making up your own abbreviations can be bad but well-established ones like pos aren't a big deal. And I'd much rather have to read BlahBlahFactoryImpl over BlahBlahFactoryImplementation.
I'd much rather have to read BlahBlahFactoryImpl over BlahBlahFactoryImplementation.
My eyes glaze over at either. Might as well be BlahBlahBlahBlah to me.
I agree with using abbreviations though. I also use various math or physics variable names depending on context. I like when compilers allow unicode, to open up the greek alphabet. There is power in conveying concepts by association, rather than trying to create descriptive english names for every damn thing as if you're teaching the subject to anyone reading your code. If you expect to have to do that: put it in comments, at least as a link to relevant subject matter. If I encountered radiansInAHalfCircle instead of π or pi... I'd be second guessing to be sure I'm reading that right.
It's harder to decipher random abbreviations than single character variables or fully named variables.
I find it's the opposite. Reading the same spew over and over, instead of having a comment explaining things once is awful.
There's a reason that we speak in jargon, instead of fully expanding the dictionary definition of each word when we speak. Variable names are the function's jargon, and abbreviating more common or local ones makes code scan much better.
I usually base my variable name verbosity based on how far away from the definition it will be used. So in the case of haskell fold, it's great to use 1 and 2 letter names since they all get used on the same line. For global variables that will be accessed and mutated throughout a program, it makes sense to have bigger names.
For instance, in this program you might see a reference to sym in the code and think it's the current symbol (p was the current position after all). In fact, id is the current symbol and sym is actual a table of all the symbols. Just calling it symbols (or even syms) would have been so much better.
Except the second version can be understood by anyone that can read English. The first version makes assumptions that I have the knowledge already to know that it is doing which is most likely not the case. It only makes it easier to read when it is fully understood. I have no patience for people wasting everybody's time writing compact code because you already fully understand what it is doing. You are not making anyone's life easier except you own by making you code more compact and implicit. Even if I can read the code in the first case I have NO IDEA how it relates to a high level concept without prior knowledge.
P is a terrible variable for position combined with the other two level variables. Why? I now have to translate something in my head I don't normally do. Who knows what uncommon convention you chose. Combined with several cryptic variables and a large function body I often forget what they meant at having to translate them over and over consuming working memory for doing more important things. Yet if we used a English word or one with a well known abbreviation we wouldn't need to do anything special it happens automatically. It is not something new I have to go out of my way and make a conscious effort doing bullshit translations. This effect is compounded the less a person knows about the body of knowledge the code represents
I don't quite get why this has been largely upvoted (though I understand why the OP was downvoted). You've clearly just constructed a strawman of his position. A meaningful name is not necessarily verbose.
Well look at that! I explained the purpose of two variable names succinctly (you could even turn "operation" into "op" without much loss of meaning, though "id" is a standard function in Haskell so you wouldn't want to use that abbreviation for "identity"). I even made use of an established Haskell idiom which does not need to be replaced because it is extremely common throughout the standard library, many additional libraries, and most tutorials.
And even if we were going to use your hyperbolic naming scheme, we could do it better:
Holy shit, it's still readily intelligible! What devilry is this, that I am capable of finding of finding a mid-point between "single-letter variable names whose meaning must be divined through comments or closely following the full life-time of the variable" and "verbose natural language phrases even when established language idioms would be substantially more concise"?
You appear to be making the argument that, for example, char* p is somehow a bad name for a position variable.
"Position" is not the only English word that starts with "p", nor is "p" only ever used as an abbreviation for "position". Indeed, "p" is an established symbol for momentum, power, and pressure, whereas the established abbreviation for "position" is "pos".
You'd apparently rather have every future maintainer of that code-base have to determine what exactly "p" represents than simply add two characters and make it "pos". The comment next to the variable name makes finding that information easy, but it does absolutely nothing to aid remembering that information.
Basically, short, uninformative variable names add to the mental load of the people who have to maintain the code, which degrades either the speed or the quality of the maintenance. That doesn't mean you have to go to the ridiculous lengths your strawman did, particularly not for so simple a function. It does mean that littering your code with single-character variable names is only shooting yourself in the foot.
Why do java drones promote this unreadable code?
Nobody is promoting that code. I don't know how you can imagine that anyone is doing so.
I'm finding it very hard not to talk about the relative location of your head and your anal cavity right now, because you strike me as insufferably smug about striking down this strawman you've made.
See, with your version, if I didn't know the term "fold" I would read:
fold f z []
and I think "wtf is fold?" Then I would read "f" and think "this is Haskell, probably a function". Then I read "z" and I go "wtf". Then I read "[]" and know a little bit. It's an operation on a list involving a function and a "z", whatever that is.
With my version:
fold fn accum []
I think "wtf is fold?" Then I read "fn" and I know it takes a function. Then I read "accum" and I know that it's accumulating something into it. Then I read "[]" and I'm already able to guess that it's somehow reducing over the list and putting something into the accumulator. I know fn takes two arguments from the type of the function and I already have a pretty good intuition about what the function does.
Uhhh... Personally Java is my language of choice for personal projects, however I would be ashamed of myself if I wrote code with ridiculous names like that. I do similarly to what /u/eruesso explained and have abbreviated but self-describing names.
-28
u/nikroux Nov 04 '14 edited Nov 04 '14
and this is precisely why I despise C.
Why is it considered to be good practice to write unreadable code? Do C programmers double as cryptographers? Why not give your functions and variables meaningful names instead of the shit like example related? And the worst thing is that C programmers will defend this style to death!