// GOOD
let fullname = 'John Smith'
// BAD
let f = 'John Smith'
// GOOD
let fullname = 'John Smith'
// BAD
let f = 'John Smith'
People get in a lot of trouble when they try to write descriptive names for everything.
It was one of the most interesting things in the Lenat/Guha book on Cyc that people get fooled by labels that look like natural language. If you really have a database of unique concepts and try to attach meaningful labels you are going to have an increasingly hard time when n goes past 1,000,000. Wikipedia does about as well as can be done. There's something to say about lowering your cognitive load and using names like "that", for instance
return this.add(that)If this is a variable in a 20LOC func, f is completely sufficient, easier to type, easier to read.
In the other extreme, names can also be too meaningful: ´ThingMessageRelayAdministratorMiddlewareComposer` or `storage_access_administrator_storageshelf_listview` are jacked full of meaning, and about as useful as a hammer without a handle.
Not sure how "easier to type" is relevant - aside from Notepad pretty much every editor offers some completion feature. I'm definitely a fan of longer identifiers, though abbreviated where it makes sense and using short words where possible.
In a 20 LOC function, that takes me about a second, if that long.
> aside from Notepad pretty much every editor offers some completion feature
It's still easier to type `f` than `fi` + leadkey + N or whatever the editor uses. Bonus points if the first prediction is wrong, or ambivalent.
And the more important reason is "easier to read", especially in long expressions;
for e := getFirst(); e != nil; e.Next()
is much easier to read than for currentElement := getFirst(); currentElement != nil; currentElement.Next()
Finally, not only the name itself, but also it's length should convey meaning. If I see a variable like `currentElement` in my code, I immediately know that it probably lives beyond the scope it is defined in. If I see a variable named `c` I know that it is a short lived throwaway.but I was asking if there's anything to keep in mind when building large complex code.
- how long or short are your functions?
- what do you comment?
- can you actually use only pure functions?
- how large are your files?
- how do you manage 3rd party dependences or do you don't use any?
- how do you mange bundle size and enforces code quality?
- when to break a function or break a file into smaller parts?
- do you create functions that call only other functions or each function should have some procedural code?
giving code examples of a well written code snippet would be so helpful!