DEV Community

loading...

Discussion on: 4 practices for better code

Collapse
tux0r profile image
tux0r

getWET, getKISS. Ha!

One important thing missing here: Write good comments!

Collapse
effingkay profile image
Klaudia Author

Good point! I wholeheartedly agree 👍
But comments deserve their own article, there's so much to tell about commenting :)

Collapse
joshichinmay profile image
Chinmay Joshi

How about writing self-explanatory code instead?

Collapse
hellsinglord22 profile image
H (إتش ) • Edited

i disagree, comments usually lie .
See code get updated all the time but there is no restriction on comments so it can mislead you .
i think you better put all the effort in writing readable code and only use comments with

  1. license
  2. explaining an algorithm
  3. Generate documentation using JSdocs or whatever tool your are using .
Collapse
tux0r profile image
tux0r

explaining an algorithm

Precisely.

Thread Thread
spikespaz profile image
Jacob Birkett

I think he's saying don't add comments on every single line.

/// Gets the last item index used in the current state.
size_t getLastIndex() {
    [...]
    // Returns the last index.
    return lastIndex;
}

The doc comment at the top of the function already says what the last line if the function body is, yet I see things like this all the time.