Code Quality
I consider Code Quality
to be everything related to code that helps us deliever better, well tested products.
- Readability of code, such as format, commenting and naming conventions.
- Maintainability - Logs and Configuration.
- Performance - Efficient code.
- Devops - testing, deployment, E2E tests, A/B testing.
- Class/Entity design - construct code based on proper entity design, Functional/OOP/Entity/Data/etc…
- Architecture - 3rd Products used, DBs, Pipelines, Mqs, etc…
Time to live (TTL)
Everything has an expiration date, even code.
In this post I want to talk about how to take into account the lifetime of code in the design process.
High level code
- Easier to read
- Easier to maintain
- Easier to replace
High level code abstracts core concepts for programming.
It’s easier to replace whole concepts like switching From TCP
to UDP
.
The more “high level” code is , the easier it to be replaced and changed.
Usage
The usage of code may consist of few things:
- Direct run from a user call - batch, py or tools.
- Other scripts/code that are depended on our code.
- Higher level applications: servers, apps, web sites, etc…
- Core libraries that are dependecies for other software.
- “Battle tested” code:
The deeper we go the higher amout of usage - the higher quality of code we should assume.
The level of code quality is correlated directly to the amount it will be used and vice versa.
Scripts
When we write a simple batch or a script we make all the mistakes that we ourselves would dismiss in a code review:
1 | import os |
This is a simple script that was written to delete some files,
What are these files, what created them, what id 0 means - these are all the question that the code won’t tell us.
Because it was probably was written for few usages and that’s it.
Scripts tend to live a short amount of time therefore we don’t invest time in them.
Tooling
Tools are higher level scripts.
The difference is, tools tend to provide easier and configurable API for the user or other scripts.
The tendency is to cut corners in the code base of the tool - for sake of fast development and faster changes for the requierments of the tool.
The counterpart for this assumption is the amount of time the tool is needed to be used or changed.
If it’s expected to be used and extended in the future, design time should be invested.
Else it’s not necessary since the the tool will be discarded any time soon.
High level applications
Applications tend to last longer therefore a proper design is needed.
To accomodate the needs of the clients/buisness there’s a higher magnitude of design needed to plan and construct the software.
This is derived from 2 planning steps:
- Gathering behavior requierments - buisness/client
- Defining important software charactaristics - high level techincal requierments.
Core libraries
Libraries, especially core/standard/infrastructure libraries tend to live long.
Applications are constructed on top of the core libraries.
These apps earn money, core libraries are dependent on the revenue to be maintained and constructed.
This is why it should be important to design it carefully.
When the core libraries are written in low level code, such as C
it will live longer since lower level code costs more to maintain and build.
Quality, Life and purpose
There’s a direct proprtion between Code Quality and code TTL.
Higher expected TTL means we need to invest more time in code quality.
Higher code quality means we expect the code to live longer.
It’s not necesserily means that if we want the code to live longer we need to invest more in its quality.
Code needs to serve a purpose - if we want the code to server its purpose longer, we need to make sure its quality is great.
Categorization of lifetime
- Usage - When is the code used.
- Role - is this an assignment? A learning project? Full scale product to be sold?
- Purpose - Does the code makes specific tasks or is it generalized to perform many abstract tasks?
- Audience - What entity consumes the code?
- Technology - What kind of technologies are used?
- Expertise - What kind of expertise is needed to maintain the code?
Each category affects the lifetime of the code and vice versa.
Usage:
When code is no longer used it served its purpose, a WebAPI that is no longer needed may be discarded.Role:
The lifetime of an assignment ends when the student recieves grade on their assignment.Purpose:
A generalized version of the code may eliminate the need for specific code implementations.Audience:
If an open source is no longer used by people - although it may be a great product with high quality code - it will be discarded.Technology:
If too many Technologies are integrated into a solution, a smaller customer may not want a “big” solution.Expertise:
If code requires crazy amount of expertise - it will be considered to just throw away everything at some point.
So how does the lifetime of code affects your code?
Thanks for reading!