Tuesday, May 08, 2018

[yytxjjsk] No word separators in identifiers

When an identifier in computer code is composed of two or more words, consider mashing them together with no separator or camelCase.  The reason is because English (as well as many other languages) has compound words, and, in light of that, "no separator" is easier for the programmer to remember: Is it doghouse or dog-house/dog_house/dogHouse?  In English, something might etymologically start out as 2-word noun phrase, dog house, then gradually morph through dog-house into doghouse.  It's easy for the programmer to remember the two words (as concepts), but harder to remember where in that spectrum the words lie, dictating whether it gets a separator.

One could do a less stringent policy where words of very different grammatical purpose can have separators/camelCase: doghouse_is_darkgreen.  Also, add a separator when there would be confusing ambiguity: experts-exchange.

It might look like German with its long compounds (which has worked fine with no hyphens or camelCase!).  It might be a bit harder to read (a tradeoff in making the code easier to write), but tools can help with reading: maybe a comment where the identifier was declared and hover text (hover-text? hovertext?) over the identifier in use, displaying that comment.

No comments :