**Comments + Markdown = 🖤
**One of the most important tasks in coding is to make it understandable for other developers and your future self. And for this, there are 3 main tricks:
Write simpler constructs. If / else, instead of ternary operators, for loop instead of filter + map + reduce (namely, when you have to use all 3 in combination), pre-calculate predicates, assign them to a union type, and make a switch, instead of multiple nested if / else.
Extract code into functions. This is, by the way, one of the bonuses of the declarative style, when thanks to the function name, input and output typing, you can understand "what" is happening, rather than reading the code that describes "how" it happens.
Add comments to the code.
**And about the last point, it's rare to find useful information, so I've developed a few cool principles for myself:
Comment Driven Development – I very often first write comments in a function about what it should do, and only then write the code. This allows me to see and solve logical collisions in advance.
Use Markdown.
**Example without Markdown:
// First comment const foo = await bar()
if (foo) { // Second comment await helloWorld() }
// Third comment const ping = await ping()
Now, can you say: are First comment and Third comment related or not? That is, is it the next step in the code or part of the previous one?
The answer can only be guessed.
But if you use Markdown:
// # First comment const foo = await bar()
if (foo) { // ## Second comment await helloWorld() }
// # Third comment const ping = await ping()
As you can see, I denote through Markdown "chapters" of the code, as if it were regular text. Thanks to this, you can clearly understand that Third comment is a new "chapter" (the next step).
With this simple movement of the hand, your comments acquire much more context and clarity for other developers.
What tricks do you use to write comments?