7 ms·
A good name is like a good car. Is a race car a better car than a truck? Lot of trade-offs to make. You want names to be short, so you easily write and read th
by js8 7y ago
A good name is like a good car. Is a race car a better car than a truck? Lot of trade-offs to make.
You want names to be short, so you easily write and read them. Especially if you use them a lot, it's useful to use abbreviations, like x, e, i, z.
You also want names to be easy to understood, therefore, longer than few letters. So, "count" instead of "cnt" or "c", in short, no abbreviations.
You want names not to clash. So every name should be a unique 64-character long identifier, as far as distant from anything else as possible. However, they should also be optimized for the tree search when using completion.
You want names to describe similar things with similar names. In particular, my pet peeve, how to name objects that are "essentially the same thing" but only different structure so I could better manipulate them, like converting list of tuples to a dictionary? From purely domain point of view, they should not even have different types! And did you know that every Monad is an Applicative?
Should the name reflect the result only or also the path that was taken to get to it - "customerList" or "customerListFiltered"? Or perhaps just "list", because the function is not specific to customers. It's local context versus global consistency.
There are minor problems as well. Underscore_case looks ugly, dash-case is mostly not supported, camelCase is just weird when you want to have anotherCamel (now strangely upper-cased), and CapitalCase looks ugly with acronyms. And should we put adjectives in front or at the back? And why are the elements of EMarble called RED, GREEN and BLUE?
- mxschumacher 7y ago> You want names to be short, so you easily write and read them. Especially if you use them a lot, it's useful to use abbreviations, like x, e, i, z. when I look through older C codebases (Python, Linux), I often notice the extremely short and cryptic names. I wonder whether this practice is an artefact of a time before auto-completion & automatic refactoring? These days, you can use meaningful names without much typing. From a reading perspective, I believe that longer names (within limits) are easy to parse. Humans see words, not characters. -- E.g. When I first understood that argc means "argument counter" and that argv stands for "argument vector" it was a little revelation to me.
- rocqua 7y agox is a variable name I still use quite a lot. Because it is quite meaningful as 'a meaningless parameter that is just a variable'. Same with y and z, though less often. I'd also say that short names are sooner a product of line-length limitations than refactoring. Having to spread out every single statement over many lines because your reference a 12 character function 3 times in the same line and you are limited to 80 characters sucks.
- elsurudo 7y agoPoint taken that it is ok to use i, x, y, z sometimes (eg. when iterating), but the notion 'a meaningless parameter that is just a variable' doesn't really exist... if it's meaningless, why are you saving it? Only other use case I can think of is doing metaprogramming or some sort of templating where you have a variable, but might no even know what it represents, because it isn't your concern.
- marcosdumay 7y ago> if it's meaningless, why are you saving it? Because you are writing abstract code. Odds are that a lot of your code is better done abstract, and only fully specified in a short context.
- mrgriffin 7y agoWhat about implementing something like map for lists? You know literally nothing about the values and the function except for their types. map :: (a -> b) -> [a] -> [b] map f [] = [] map f (a:as) = f a : map f as Personally I don't see any reason to use longer names than f, a, and as because you can't add any additional information. You might say "well I don't write code like that", and I don't have any answer for you. But I find I write a fair amount of generic code.
- chalst 7y ago> you can't add any additional information Well you could... map transforming_function (element:rest_of_list) = transforming_function element : map transforming_function rest_of_list ...but the cost in terms of loss of brevity would far outweigh a benefit that would only accrue to complete beginners, who would be better served by comments and test cases.
- yreg 7y ago>You want names to be short, so you easily write and read them. Hmm, I don't think short names are easier to write or read than a "medium length" ones, at least not for me. I mean naming something with a 30 character string is another matter, but names composed of a few words are not getting in my way during development/review.
- Fnoord 7y ago> You also want names to be easy to understood, therefore, longer than few letters. So, "count" instead of "cnt" or "c", in short, no abbreviations. Yet in cars, BMW is an abbreviation. IBM is also an abbreviation, Microsoft gets abbreviated to MS, and NS to NextStep. "Nobody" calls BMW and IBM by their full name. Only people in IT know and/or use the abbreviation MS (which is functioning), and only people into NextStep and macOS use the abbreviation NS (also functioning). Would you want people to spell out Bayerische Motoren Werke all the time? With or without AG? Or would you want to use the English version, Bayern Motor Works? People all around the world know the acronym BMW; it does not have to be translated. Would you want the API calls to spell out NextStep? I feel like established abbreviations are perfectly fine, and some people/companies (entities) try to get established.
- Jedd 7y ago> "Nobody" calls BMW and IBM by their full name. In many cases these abbreviations have officially - legally - become the organisation's full name. In Australia, for example, the Colonial Sugar Refinery, known as CSR, officially changed their name to simply CSR (and only CSR) in the 1980's, IIRC. While I love the sound of Bavarian Driving Machines, it's a translation / transliteration (mostly the former), and doesn't add much value beyond nostalgia. Also, in Australia, these vehicles are mostly called Beemers anyway. (I'll note that I'm not a fan of Strine vernacular.) A small nitpick - BMW is not an acronym - it's an abbreviation or initialisation. Acronyms are pronounceable words.
- majewsky 7y ago> Bavarian Driving Machines It's actually "Bavarian Motor Works" which, coincidentally also comes out as BMW in English.
- Jedd 7y agoOh, thank you - I'd seen this listed as driving machine translation several decades ago and hadn't pursued it more, just assumed that was legit. Reviewing on Wikipedia I see that: "Bayerische Motoren Werke [...] This name is grammatically incorrect (in German, compound words must not contain spaces) ..." which is reassuring, given my own general bewilderment with German grammar.
- learnstats2 7y agoI think it's underestimated that you also want names to change. In simple English: "the car" becomes "your car" and "my car", when you have more than one.
- vbezhenar 7y agoI don't understand why would anyone find underscores ugly. Underscores are basically spaces. And we use spaces in our language to separate words. May be text editors should draw underscores with more subtle way? Now-dashes-are-ugly.
- omaranto 7y agoEnglish is a dash-using language, not an underscore_using one. Maybe that's why many of us prefer dashes to underscores?
- Bedon292 7y agoDoes any language use underscores? They seem like a purely technical thing to me. In a sentence you are certainly correct the - is much better. But as for the name of something in code, I would personally prefer _.
- inkeddeveloper 7y agoUnderscores are difficult to distinguish from underlining. That's just one issue. Underscores_make_full_highlighting_easy Dashes-make-single-highlighting-easy It's also a use case thing. Double click on each sentence and note the behavior. It depends on which one you want. We use snake case in our urls because you can copy something from the documentation and easily highlight a portion to change.
- dariusj18 7y agoI have attributes, properties, metas, and values. And somehow each of those things can mean different things.