Lorem ipsum dolor sit amet, consectetur adipiscing elit lobortis arcu enim urna adipiscing praesent velit viverra sit semper lorem eu cursus vel hendrerit elementum morbi curabitur etiam nibh justo, lorem aliquet donec sed sit mi dignissim at ante massa mattis.
Vitae congue eu consequat ac felis placerat vestibulum lectus mauris ultrices cursus sit amet dictum sit amet justo donec enim diam porttitor lacus luctus accumsan tortor posuere praesent tristique magna sit amet purus gravida quis blandit turpis.
At risus viverra adipiscing at in tellus integer feugiat nisl pretium fusce id velit ut tortor sagittis orci a scelerisque purus semper eget at lectus urna duis convallis. Porta nibh venenatis cras sed felis eget neque laoreet suspendisse interdum consectetur libero id faucibus nisl donec pretium vulputate sapien nec sagittis aliquam nunc lobortis mattis aliquam faucibus purus in.
Nisi quis eleifend quam adipiscing vitae aliquet bibendum enim facilisis gravida neque. Velit euismod in pellentesque massa placerat volutpat lacus laoreet non curabitur gravida odio aenean sed adipiscing diam donec adipiscing tristique risus. amet est placerat in egestas erat imperdiet sed euismod nisi.
“Nisi quis eleifend quam adipiscing vitae aliquet bibendum enim facilisis gravida neque velit euismod in pellentesque massa placerat”
Eget lorem dolor sed viverra ipsum nunc aliquet bibendum felis donec et odio pellentesque diam volutpat commodo sed egestas aliquam sem fringilla ut morbi tincidunt augue interdum velit euismod eu tincidunt tortor aliquam nulla facilisi aenean sed adipiscing diam donec adipiscing ut lectus arcu bibendum at varius vel pharetra nibh venenatis cras sed felis eget.
Developers are often bombarded with various principles and concepts that you have to remember when writing code.
YAGNI. Open/Closed. SOLID. Law of Demeter. SoC.
There are far too many so it's often tough to remember all of them, especially if you're writing code in functional or object-orientated specific languages.
In this issue, we outline the 4 most universal and important principles to remember that will help you write better and cleaner code by default. From there, you can explore some of the more specific principles mentioned above.
Let's dive in.
A fun acronym with a super important principal behind it.
Writing code that is simple, easy to read and even easier to amend is the name of the game. KISS speaks to keeping your codebase as simple as possible so that you, or anybody else, can easily hop in and make some changes.
Building a codebase that is overly complex only adds to frustrations and time wasted trying to understand the code before any improvements or changes can be made.
Don't show off. Focus on simplicity.
Writing simple code is more impressive than complex, massive repositories.
DRY aims to mitigate code duplication. Logic, functions or pieces of data should only exist in a single space in your codebase to then be referenced where needed.
Having 2 methods that achieve the same thing creates lengthier code bases, adds unnecessary complexity and will often make debugging far more difficult.
The opposite of DRY is WET (write everything twice). Avoid this at all costs. Nobody wants to be called out for being a WET developer.
This isn't a principal that is unique to software development, but it's definitely one that needs to be thought of more frequently.
Before you start working on a feature or begin writing some code, plan out your work. Think about what you're needing to achieve, what files you're needing to add or adjust and how you're going to go about building the feature.
Planning out your work will help you gain foresight on any potential issues that you'd only otherwise discover midway through writing the code. Which leads to time-wasting and a messy scenario of having to undo or refactor your code before it's even merged into your main branch.
Optimization is great when you're looking to speed up some performance or make your code easier to reuse down the line. However, this principle speaks to not performing optimization too early in the development process.
The reason for this is two fold:
Choose to rather optimize out of necessity or when you know that changes to that specific piece of code are never going to happen. So optimizing it now won't have an impact on a potential refactor.
There are so many more principles to think about when writing code, but if we were take the 4 most important, in my opinion, it would be the list above.
These principles also transcend functional or objected-orientated, JavaScript or Python, frontend or backend. Use them in every bit of code that you write.
See you again next week.