r/javascript • u/FunPieceOfPaper • Dec 27 '18
help What differences do you see in novice javascript code vs professional javascript code?
I can code things using Javascript, but the more I learn about the language, the more I feel I'm not using it properly. This was especially made apparent after I watched Douglas Crockford's lecture "Javascript: The good parts." I want to take my abilities to the next level, but I'm not really sure where to start, so I was hoping people could list things they constantly see programmers improperly do in JS and what they should be doing instead.. or things that they always see people get wrong in interviews. Most of the info I've learned came from w3schools, which gives a decent intro to the language, but doesn't really get into the details about the various traps the language has. If you have any good book recommendations, that would be appreciated as well.
24
u/djhalon Dec 27 '18
I like what I call "the rule of three". On the third time writing the same (or very similar) code, time to DRY it up. It's just a recommended rule of thumb that helps define that line for myself and the team to prevent early optimization and also help make sure you really understand what the code is doing and how it is being used before trying to abstract it.
There are definitely times where I know I will be reusing code on the first draft, so I just write it that way. The flip side is the dreaded "it almost looks the same" and when you try to DRY it up and it either becomes a configuration nightmare passing in all kinds of options or the code is branching/switch hell. Sometimes duplicated code really isn't that bad.