4 ms·
I use probably 70% Java in a given week, there was a time when I was 100% .NET, and there have been long stretches where the majority was overwhelmingly C, Node
by manyxcxi 10y ago
I use probably 70% Java in a given week, there was a time when I was 100% .NET, and there have been long stretches where the majority was overwhelmingly C, Node, Python, PHP. This is a long way of saying I've spent a lot of time floating around some very stylistically different languages so I don't really adhere to one dogma over another and I've grown to write code that mostly kind of/sort of feels the same between languages. Naming convention-wise at least.
Java/.NET naming verbosity is great when I'm trying to figure out what the heck I'm receiving without tracking down the class definition. The thing is, you're only willing to be that verbose because you've got autocomplete in an IDE so peeking into that long object/class/parameter name is only a click away.
The naming conventions like OncePerRequestHttpWebHandlerSecurityContextAwareInterceptorFactoryImpl are obsurd, but there's no reason you can't come to a more concise descriptive name. Frankly, if you're implementing the interface you can call it whatever you want.
On the other hand I've seen some C and JS code that I could SWEAR was run through an obfuscator before I got to it, but no, the devs refused to use more than about three letters max. This is not helpful.
Names like strlen, idx, propCnt are concise AND descriptive. I generally like to put units on things if they're some kind of measurement so I typically do stuff like intvlMS, distKM.
There's nothing wrong with being descriptive, but you can really do a disservice to those (including yourself) coming after you when it becomes very hard to fit the mental model.
- milansm 10y agoEnglish is not my native language, and it took some time for me to actually parse those short variable names you provided as examples. Though, I still don't know what propCnt is supposed to mean. But even if I did, it takes some cognitive effort to parse shortened names. I think that's the case with native speakers as well, but it's more noticeable at non-natives because the time interval is longer. IMO those little parsing efforts add up and are tiresome if you have to do it all day long. Imagine if the books are written that way.
- kosievdmerwe 10y agoYou're not taking something into account with the shortened names: they are common and have consistent meaning. So after a few exposures it becomes trivial to read.
- greenhatman 10y agoI find it frustrating. Why not make it trivial to read the first time? I didn't get that intvl was interval until I read the reply. Why not just write interval or propertyCount? It doesn't make it much longer, and it's much easier to read. Long names only becomes a problem when you're concatenating more than three words for one variable. And that's really the problem, the number of words in a variable, not its character lenght.
- jstimpfle 10y agoYou can answer it yourself, but here goes: Because the trivial investment you have to make to learn these ubiquitous abbreviations might (no general judgement made) be outweighed by the benefit of better readability once you made that investment. "propertyCount" is 6 characters longer than "propCnt". In arithmetic expressions this can easily amount to 12 or 18 characters saved. I suggest you point out a specific example and show how you would do it in a better way.
- andreareina 10y agoI suspect it's supposed to be popCnt (no "r"), which is short for "population count", which is the number of set bits in a byte/short/int/long/what-have-you.
- userbinator 10y ago"prop" is a common abbreviation for "property".
- janekm 10y agoKind of a perfect example of the ambiguity in over-shortened names ;) I also read it as propertyCount (which in my style shouldn't even be a variable...)
- masklinn 10y agoThat one specifically strikes me as a counter-example if anything, you don't lose anything by adding two more characters and calling it popCount, and it's significantly easier to read and understand.
- Noumenon72 10y agoI'm going to second that "intvlMS" is terrible. I didn't confuse it with "intval", but it's like making people play Wheel of Fortune with your variable names. It takes so long to read. Even if you called it "intervalMS", that is not how you pluralize things (which would be "Ms") or how you abbreviate meters ("m"). It could be "intervalMicroSeconds". Just call it "intervalMeters" and save everyone from parsing your "concise" hand-minified code.
- manyxcxi 10y agoThat was probably a bad off the cuff example, my point was that there's a happy medium between concise and verbose, and I think we're better off erring on the side of verbose.