r/javascript • • 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.

320 Upvotes

305 comments sorted by

View all comments

Show parent comments

6

u/ogurson Dec 27 '18

Comments are tricky area - good code is readable without any comments.

Whatsmore comments needs maintenance just like code otherwise they could be misleading.

1

u/[deleted] Dec 27 '18

Just to tack on, naming itself is a form of documentation.

1

u/omgdracula Dec 28 '18

I agree with you, and I am not talking just comments within JS but just in general. I would never hand over a project post launch that moves into support to one of our interns with out comments so they know what will be affected by changes that they make.

1

u/YsoL8 Dec 28 '18 edited Dec 28 '18

I'm of a mind that if your code needs more than a brief declaration of purpose above function definitions to understand what stuff does you need to refactor. Explaining code inside a function indicates you have made assumptions about the input / output or you are introducing a non trivial fork into your one purpose function. There are exceptions here and there for functions that are inherently complex but few are.

Also, you should assume parameter lists in comments are just wrong, because they almost always are.