Reviewing the Clean Code in JavaScript
A couple of days ago I read about the Clean Code in JavaScript which the author James Padolsey shared about his idea of how a clean code should be in JavaScript.
At this stage, I'm probably more familiar with Java than JavaScript, but I think there are a few principles that are pretty universal when it comes to programming.
I'd like to share a few points that I think are important and will (probably) be applied in my work in the future.
Reliability
The Reliabily includes Correctness, Stability, and Resilience.
Correctness:
Ensure that the study defines technically valid correctness, e.g. a valid e-mail addresses need to be considered when it comes to defining a user's input.
Stability:
Consider different hardwares, screens, operating systems, or transponders, etc. Under most use case scenarios will the application work well, so make sure to arrange for testing in a variety of environments.
Resilience:
Consider the fault tolerance - Graceful degradation. The application can still be used even if not all the ideal conditions are met, for example, when some failures occured like
- HTTP cannot be delivered correctly
- Browser does not support JS version
- Blocked by adware / JS disabled
If (above situations don't happen) { operate the system } else { some of the functions, which are considered some of the most important ones, still work}
Efficiency - Time and Space
- Time: Eliminate unnecessary work as a rule.
- Space: Take capacity into account.
If the above stuff doesn't work well, the negative impact will spill over outside of the code. ex.
- Consume resources
- Hurt emotions of the team
- Reduce user and programmer's productivity
Usability
This principle is a favorite of mine, which the core concept is to avoid taking too much time for people to understand, as I enjoy developing products that are both user-friendly and colleague-friendly. A thoughtful consideration before building something is vital, especially we are in a world where valuable products are often built with brilliant team. Below are some implementations or considerations before we start coding.
Design a User Story
A User-oriented design in my personal opinion is the core when it comes to the program design. Use the following steps to develop a good user story.
As a As a { }
I want to { }
to achieve { }
Intuitive design
Don't deviate from the norm, don't show off.
Accessibility
Make sure the product is accessible to people with disabilities, both programmers and users, so take the concept of accessible web design into account. ex. wcag guidelines.
I think that's all my sharingš
There are still a lot of good rules or principles that might be applied in my work, such as SOLID, LoD (Law of Demeter), etc. but I think I need more practical expereince, so these rules will make more impact on my work.