3 ms·
I found that terse naming has several advantages: * Most obvious one: it's easier to type. Especially in Erlang - the language I write most code in these days,
by hassy 18y ago
I found that terse naming has several advantages:
* Most obvious one: it's easier to type. Especially in Erlang - the language I write most code in these days, where variables must start with a capital letter. The fewer times I have to reach for the shift key to make a capital (if I used CamelCase) or to make an underscore, the better.
* Short names help you fit code in 80 columns.
* Terse variable names force you to pay close attention and make no assumptions about what's inside that variable. Also, I found that a short name + an inline comment to explain what's there works better than an overly descriptive name.
I do the same for function names too, with the exception of public functions -- those get proper names. So I'd call the public function `integer_to_string` but if I were to use it only privately, it'd be `itostr`.
- ericb 18y agoitostr takes time to mentally process (or pronounce), if I had to read your code. integer_to_string takes no effort and can't be confused. To make the point: itostr - itoaster? itostr - int to stream? itostr - internationalize OString? itostr - The string representation for indium tin oxide?
- msluyter 18y agoNo, it's Iguana to Stretchpants.
- hassy 18y ago> itostr takes time to mentally process (or pronounce), if I had to read your code. integer_to_string takes no effort and can't be confused. The idea is that the first time you saw `itostr` you'd do something like this: * Jump to the definition of `itostr` (a couple of keypresses in Emacs). * Read the Edoc comment for the function ("Convert integer to string"). * Jump back to where you were (one key combo). Sure, if the function was named `integer_to_string` you wouldn't have to do the above. But this was a trivial example. Many functions would take more than three words to describe what they are doing precisely, especially when your functions are granular and do exactly one thing. This can quickly lead to long lines, which I find hard to read and ugly. At the end of the day, it's all down to personal preferences and style. I like things this way, and you like them the other. It's just the way it is, and there are arguments for both approaches. For me, the benefits of terse naming outweigh its disadvantages, and the advantages of long descriptive names.
- ericb 18y agoI guess, to me, if those lookup keystrokes resulted from saving a few keystrokes in a function name, and developers might look it up many times, it doesn't seem like you come out ahead. But, as you say, to each their own.
- jamongkad 18y agoPersonally I would rather have descriptive variable names such as "this_goes_to_db" or something to that effect. But then the question is how long is too long? and by me practising that I find my code it readable but at the same time uneccesarily verbose.