8 ms·
There are two schools of thought on this: it is and it isn't. For people who believe code isn't literature descriptive names are wasted characters. The bigge
by austincheney 10y ago
There are two schools of thought on this: it is and it isn't.
For people who believe code isn't literature descriptive names are wasted characters. The biggest difference between code and literature is that code is structured where literature isn't (literature makes up for this with a flow like a plot). Explicit structures are things like subtypes and nested scopes, qualities that exist directly and not through inference or reference resolution. There are things that can be inferred directly from structures like context and scope. For these developers code can be less explicit and less wordy because they aren't reading code line by line and guessing at how the pieces come together.
The code is literature camp represents an educated formalism. In the absence of explicit structures you need to understand what the code is doing by simply reading the code.
The problem with the code is literature approach is that it is for humans only. The computer absolutely doesn't care, and so therefore it can be wrong or deceptive.
- mtrn 10y ago> For people who believe code isn't literature descriptive names are wasted characters. Data point: I do read code like books and I can't stand longAndMeaningful variable names. Rather, cut to the chase.
- TuringTest 10y agoWhat do you do if you find a section of code that solves a problem that you have never seen before? How do you decide what it's supposed to do, and whether it is doing it right or it has a bug?
- TheOtherHobbes 10y agoThe chase being what? It takes no time at all to read a longAndMeaningful variable name, and no time at all to work out what it's doing. Assuming you don't name variables a1 to z256, calling a variable something like "items" makes it context dependent, which is a little too much like building state into the syntax. Long names provide an extra informal level of type safety. You should be able to see what a variable is doing by looking at it, and you should also be able to see that it provides a clean level of abstraction/composition instead of just being an arbitrary container with a label.
- Vinnl 10y agoI think it's somewhat of a middle ground. What I think hampers your ability to understand code, next to not knowing what variable names are supposed to mean, is not being able to easily discern variables from eachother, making you do double-takes while reading and thus making it more difficult to understand. If your code is littered with variables like longAndMeaningful and longAndWithMeaning and lengthyAndMeaningful etc, that becomes really annoying to read. And of course, there's a difference between longAndMeaninful and reallyVeryLongWindedAndExplicitButOhSoMeaninful. And let's not start about the FactoryFactoryBuilderEtc thingies.
- kornakiewicz 10y agoI'm now reading one book, in which author is using names for variable like "iep" (of type IfExpressionParser), or so. If the code is longer than ten or twenty lines I need to go back to the variable definition to make sure what it really is. Not convenient reading at all.
- TuringTest 10y agoThere is one single thing that the structure and choice of commands in code cannot communicate: intent. For most parts of the program this doesn't matter much, because many programs are conventional and do pretty much the same things; so the programmer can reasonably guess why the code is doing what it does if you have already seen similar programs. But if your name and variables don't explicitly explain what each code section tries to achieve, there's no way to figure it out what it's supposed to do and why it's coded the way it is, if you don't already know that. From the code itself you can only learn what the code does, not what the developer intended to achieve; if you don't know the latest, there's no way to tell if there's a bug in it and it's working in a wrong way. This is specially important for the parts of the program you don't understand, which are the ones where you would benefit the most from proper comments/explanations, i.e. literature.