DEV Community

Discussion on: 4 Things I Learned From Building My First Site Solo

Collapse
glowkeeper profile image
Steve Huckle

I've been a professional coder for twenty-five years, and in that time, I've barely written a single comment. Instead, name functions and variables descriptively, since that'll help comment your code for you (IMHO). Furthermore, keep functions super simple, so when you (or someone else) comes back to them, a year or two later, it ain't that hard to work out WTF they're doing. I reckon that is best supported by the declarative/functional style, espoused these days by es6 and react, as opposed to the imperative style to which your post leans...

Collapse
mbjelac profile image
Marko Bjelac

100% agree on the descriptive names.

Also, tests are a HUGE help. They serve as in-depth documentation for your code, which is continuously up to date.

There are a lot of testing frameworks for JS, currently I use Jest.

I strongly recommend trying out test-driven development (TDD) ... check out a clear & concise video of why it matters. As frontends are not only putting backend model props into templates anymore but have their own behaviour, I think its really important that they are treated the same as backend code (i.e. that they have tests, and preferably that they are test-driven).

Collapse
mloru profile image
Mirko Lorusso • Edited

+1 (even though I think that comments are important too)
I'm nearly a noob (PHP) dev and I'm reading Clean Code by R.C. Martin, and this is one of his tips too.
Some of the things he wrote might sound almost "weird", but it's a mother lode to me, especially as a not-so-experienced developer.
(Sorry for my English, I hope it's understandable).