Writing clean code looks easier than it actually is, but the benefits are worth it. Here are 7 ways you can instantly apply to improve as a developer ππ»
1. Readability > Cleverness
Too many programmers conflate "clean code" with "clever code" as if compacting ten lines into one is somehow cleaner. Sure, it takes up less space on the screen, but is it actually easier to understand? Sometimes, maybe. But most of the time? No.
Too many programmers conflate "clean code" with "clever code" as if compacting ten lines into one is somehow cleaner. Sure, it takes up less space on the screen, but is it actually easier to understand? Sometimes, maybe. But most of the time? No.
2. Keep a consistent coding style
One of the downsides of watching programming tutorials is that newbies end up picking a wide variety of conflicting habits, especially as they pertain to coding style. Not saying one style is better than another.
One of the downsides of watching programming tutorials is that newbies end up picking a wide variety of conflicting habits, especially as they pertain to coding style. Not saying one style is better than another.
If you want braces on their lines, go for it; if you want to precede method calls with spaces, fine. If you prefer tabs to spaces, don't let us convince you otherwise. But whatever you do, stay consistent.
3. Choose the Right Architecture
There are many paradigms and architectures that you can use to create your projects. Note how this tip is about selecting the right one for your needs, not about selecting the best one out there. There is no "best" here.
There are many paradigms and architectures that you can use to create your projects. Note how this tip is about selecting the right one for your needs, not about selecting the best one out there. There is no "best" here.
For example, the Model-View-Controller (MVC) pattern is popular in web development because it helps to keep your code organized and designed in a way that minimizes maintenance efforts.
Similarly, the Entity-Component-System (ECS) pattern is popular in game development because it helps modularize game data and logic in a way that makes upkeep easier, all while producing code that's easier to read.
4. Master the language's idioms
One of the difficulties in mastering a new programming language is learning the nuances that separate it from all other languages. These nuances can be the difference between ugly, convoluted code and beautiful, easy-to-maintain code.
One of the difficulties in mastering a new programming language is learning the nuances that separate it from all other languages. These nuances can be the difference between ugly, convoluted code and beautiful, easy-to-maintain code.
Every language has idioms that encourage a certain way of coding. There are also "anti-patterns", which are essentially suboptimal design patterns that result in inefficient, unreliable, or bad code. Study & unlearn all the common anti-patterns related to your language.
5. Study the code of masters
If you want to write clean code, the best thing you can do is to see what clean code looks like and try to understand why it is the way it isβand there's no better way to do this than by studying the source files of industry masters.
If you want to write clean code, the best thing you can do is to see what clean code looks like and try to understand why it is the way it isβand there's no better way to do this than by studying the source files of industry masters.
6. Write good comments
This is one of the oldest piece of advice in programming. Here's a good rule of thumb: comments exist to explain WHY a piece of code exists rather than WHAT the code actually does.
This is one of the oldest piece of advice in programming. Here's a good rule of thumb: comments exist to explain WHY a piece of code exists rather than WHAT the code actually does.
If the code is written cleanly enough, it should be self-explanatory as to what it doesβthe comment should shed light on the intention behind why it was written.
7. Refactor, refactor, refactor!
Just as editing is part of the writing process, refactoring is part of the coding process. An aversion to refactoring is the quickest way to end up with unmaintainable code, so in many ways, this is actually the most important tip to consider.
Just as editing is part of the writing process, refactoring is part of the coding process. An aversion to refactoring is the quickest way to end up with unmaintainable code, so in many ways, this is actually the most important tip to consider.
That's a wrap!
If you enjoyed this thread:
1. Follow @codedamncom for more of these
2. RT the tweet below to share this thread with your audience
If you enjoyed this thread:
1. Follow @codedamncom for more of these
2. RT the tweet below to share this thread with your audience
Loading suggestions...