How You should not write code | JavaScript | TypeScript
This is an article from mini-series of How you should not write code. The next part of this section is How You Should Not Write Code — JavaScript, Part-2
There are many articles on the web on how to write better and clean code. I had emphasized the words clean and better
. I think by the time all of us had adopted those concepts in day to day coding life. However, sometimes I feel that we do over-engineering and copy-paste things. It is to save time.
In this article, I will highlight some of the coding practices or code smells that we should either drop or don't follow it.
Table of content
- Dependency Injection
- Use of special char for private variable
- Explicitly assigning null as a value
- Use of traditional for loop
- Try-Catch Hell
- Long path imports
1. Dependency Injection
I have seen many libraries that use dependency injection. DI(Dependency Injection) makes code more readable and maintainable. However, This is not a valid case for JavaScript. JavaScript is a dynamic language. You can modify the context of the object or constructor
on runtime.