You are a company that has legacy projects, these projects have been coded by developers that have moved on. You asked them to create some documentation and over time it got dated.
This project is one massive 9000+ line PHP file that linearly runs. Any small change effects everything and its one of your main systems.
It is a monster and no developer wants to touch it because they are afraid they will lose their job.
What do you do? Every change makes it incrementally harder to make a new one. Code has been neglected and now there is a lot of tech debt.
How would you fix one or multiple flat files with over 9000 lines of code?
The right answer is to rewrite it or refactor it.
In a future post I'll write steps on how to approach that fixing an existing application, but for now how does one avoid it?
It takes a lot of thought to come up with a structure that leaves room for flexibility, and reduces redundancy.
Over the years there have been many advancements in software architecture paradigms, but one fact remains.
Let's unpack that prior statement.
When you are working on enhancing developer experience you need to ensure that projects remain its own separate entities, and that they speak for themselves.
Changes to the project should not introduce a new way of doing things unless a plan to remove the old is fully removed.
Developers should ask, "Is there a way to do what I want that is already part of the existing code base?" Then if there isn't introduce a new concept, otherwise use the existing way, or make the case to refactor.
“Two of the most important characteristics of good design are discoverability and understanding.” ― Donald A. Norman
Contributors should be able to discover the styles of the project, understand and implement them on their own by just looking at the code.
Sometimes projects are built overtime, new features are added and even though these features are consistent with the style of the code, it still introduced redundancy and a lack of flexibility. This is very normal, and part of the building process, so how do you combat it?
In his book, "How buildings learn, and what happens after they're built" Stewart Brant discusses a term called preventative maintenance, which means to every now and then look at your building and inspect it for things that can be repaired. He states that if you do preventative maintenance, small problems that lead to big problems are caught early and overall ends up costing less money in the long term.
For example you notice a little water on your ceiling, before the pipe bursts you can fix the pipe, strengthen it, and save yourself water damage, and having to rebuild the whole thing.
I'm sure you've heard the acronym before, and wonder why is it so important?
SOLID is a set of principles that will help your code remain flexible, uncoupled, and have lower redundancy over time.
Typically as you build an application it starts off with little abstraction. Overtime it needs to be refactored and abstraction needs to be added.
Abstraction is a fancy way of saying interfaces/classes and design patterns.
Design patterns will be discussed in a future post, but they are a vernacular way of building software. Over plenty of refactors developers have come to consensus on how to build things. For instance the "Cache-Aside" design pattern describes adding an ephemeral key value lookup table and how to maintain it. Many companies have used and proven this concept. It uncouples the code, and adds increased availability.
Now let's get to the SOLID acronym.
It was introduced by Uncle Bob and Robert Martin with the goal of making code easier to maintain, and extend without breaking things.
Single Responsibility:
Open/Closed:
Liskov Substition Principle: To understand LSP, you need to understand the below. Which I will extrapolate what it means after.
"""Let theta(x) be a property provable about objects x of type T. Then theta(y) should be true for objects y of type S where S is a subtype of T."""
-> Derived classes should be able to substitute its parent class without the consumer knowing it.
Interface Segregation Principle:
Dependency Inversion Principle:
Avoid the need to rebuild entire applications, keep track of projects and their states. Build with thought and refactor early. Doing this will reduce costs over the long run.
This has been a letter from a coder.
Best Regards, Tyler Farkas
We know, not another newsletter pitch! - hear us out. Most developer newsletters lack value. Our newsletter will help you build the mental resilience and emotional intelligence you need to succeed in your career. When’s the last time you enjoyed reading a newsletter? Even worse, when’s the last time you actually read one?
We call it Letters, but others call it their favorite newsletter.