Mario Cervera Profile picture
I help you become better software engineer. Clean code, TDD, testing, design, algorithms & DS. Software craftsman @lifullconnect. Lecturer @UniversidadVIU. PhD.
Oct 16, 2021 β€’ 9 tweets β€’ 3 min read
πŸ“… One year ago, in October 2020, I published my first blog post.

Since then, I've published 8 posts, in topics such as:

- Clean code
- Software testing
- Test-Driven Development (TDD)
- Design patterns
- Refactoring
- Algorithms

This is a thread with links to the 8 posts πŸ§΅πŸ‘‡ ❓ What is clean code?

I guess most people would agree that code is clean when it's easy to read and maintain.

But this is a bit shallow.

In this post, I dig deeper, discussing the essence of clean code beyond readability and maintainability.

mariocervera.com/the-essence-of…
Sep 29, 2021 β€’ 13 tweets β€’ 4 min read
πŸ“š I've read many technical books during my career as a software engineer.

So, people often ask me for book recommendations.

This is a thread about the most common recommendations that I give (grouped in 5 knowledge areas) πŸ§΅πŸ‘‡ 1⃣ Algorithms and Data Structures.

The canonical reference is the CLRS book:

πŸ“” "Introduction to Algorithms".

This book is thick and it contains a lot of algorithm analysis, so it's quite math-heavy.

But it's the best, in my opinion.
Jun 22, 2021 β€’ 10 tweets β€’ 3 min read
During the last year, I've written threads on various topics, such as:

- Clean code.
- Automated testing.
- Software design.
- Algorithms.

🧡 This is a thread with links to the threads that I find more useful πŸ‘‡ ❓ What is clean code?

Mar 14, 2021 β€’ 8 tweets β€’ 2 min read
🎨 The Single Responsibility Principle (SRP) says:

"A module should have only one responsibility".

❓ But, what does this mean? What is a responsibility? How do we know if a module has more than one?

Let's find out πŸ§΅πŸ‘‡ Example: the Customer class.

πŸ”ΉgenerateInvoice: calculates the amount the customer must pay.

πŸ”Ή calculateDiscount: returns a % discount for the customer.

πŸ”Ή save: stores the customer in the database.

πŸ”Ή toString: returns the customer as a string so it can be added to a report
Nov 14, 2020 β€’ 4 tweets β€’ 1 min read
❓ What is technical debt?

Technical debt is not poorly written code.

The technical debt metaphor only applies when there is a conscious and strategic decision.

A short thread with examples πŸ§΅πŸ‘‡ Example 1⃣

You write code to reflect your *current* understanding of the problem.

You incur debt when this understanding is *partial* and, even then, you deliver the software (to learn more).

But you must pay the debt: you must incorporate the new learnings into the software.
Sep 23, 2020 β€’ 9 tweets β€’ 2 min read
❓ Have you ever wondered what interfaces are for in object-oriented languages?

They are more than a just a class with abstract methods.

They play a key role in many design patterns and principles.

A thread 🧡 about 6 key aspects of interfaces. 1⃣ Interfaces establish knowledge boundaries.

When you call an interface method, you can often ignore what is under the hood.

Example: class 'C' need not know the exact database that stores the data.

πŸ”‘ Interfaces reduce complexity because they allow us to separate concerns. Image
Aug 25, 2020 β€’ 9 tweets β€’ 2 min read
❓ What do you think about functions with many parameters?

Around 4 parameters, I usually start to feel that there's a problem.

But there are a lot of details to consider in this issue.

A thread 🧡 about functions with long lists of parameters πŸ‘‡ Long lists of parameters have 3 main problems:

1βƒ£βš οΈ Readability

You need to engage a lot of brain cells to understand functions with many parameters.

Long parameter lists are hard to read and often inconsistent.

These problems increase exponentially as the list grows.
Aug 20, 2020 β€’ 9 tweets β€’ 2 min read
I have the impression that many developers don't automate tests.

This is just an observation. I may be wrong πŸ™‚

In any case, I want to try to motivate the developers that are not into testing yet.

A thread 🧡 about 8 benefits of automated testing πŸ‘‡ 1⃣ Tests are the code samples of our system.

❓ Have you ever skipped an answer in StackOverflow because it didn't contain a code sample?

Code samples help us understand how things work.

πŸ”‘ A software system is easier to understand if it has automated tests in place.
Aug 18, 2020 β€’ 8 tweets β€’ 2 min read
❓ Do you know what characterization testing is?

The term was introduced by @mfeathers, the author of the well-known book:

πŸ“” "Working Effectively with Legacy Code"

A thread 🧡 about characterization testing. Imagine that you want to refactor a piece of legacy code, but the code:

πŸ”Ή Is too complex to know what it does.
πŸ”Ή Does not have any form of written documentation.
πŸ”Ή Has no tests that allow you to refactor safely.

πŸ’‘ Characterization testing can help you!
Aug 14, 2020 β€’ 8 tweets β€’ 2 min read
❓ What are design patterns?

Design patterns emerged (roughly) 30 years ago.

And yet, many people believe they are as relevant today as they've always been.

A thread 🧡 about design patterns. πŸ‘‡ ❓ First, what is "design"?

This thread is about software design, not UI design.

Everything in the code is design. From details such as variable names to more architectural issues.

πŸ”‘ Design is the shape that the system takes to meet its requirements.
Aug 13, 2020 β€’ 4 tweets β€’ 2 min read
Yesterday, I posted a thread about Bachmann-Landau notation.

O-notation is well-known, but Ξ© and Ο΄ are not so much.

This is a thread 🧡 to explain a famous example of use of the Ω-notation:

➑️ "Any comparison sort algorithm requires Ω(n log n) steps in the worst case".

πŸ‘‡ 1/4 πŸ“” Ξ©-notation is used to establish lower bounds.

If someone proves that the worst case of an algorithm is Ξ©(n), then the algorithm can *never* run faster than linear time in the worst case.

❓ How does this apply to sorting algorithms that are based on comparisons?

πŸ‘‡ 2/4
Aug 12, 2020 β€’ 5 tweets β€’ 1 min read
❓ Did you know that "Big O" is part of a wider family of related notations?

This family is called: the Bachmann-Landau notation.

In this thread 🧡, I try to explain 3 important members of this family in a very *informal* way:

1⃣ O (Big O)
2⃣ Ξ© (Big Omega)
3⃣ Ο΄ (Big Theta) This thread uses Quicksort as an example.

Let's assume a Quicksort implementation that *always* takes O(nΒ²) steps when it receives a worst-case input.

Quicksort is faster on average, but let's focus on worst-case execution, which is O(nΒ²).

"n" is the length of the input array.
Aug 7, 2020 β€’ 6 tweets β€’ 2 min read
There have been a few misunderstandings around this tweet, so I just want to clarify a few things. I hope it comes across better this time πŸ™‚ 🧡 I understand that we, as developers, are often in a very hard position: tight deadlines are imposed on us, and there are always important business reasons for this, so it is unavoidable.

When we must deliver something "yesterday" it is hard (almost impossible) ...
Aug 4, 2020 β€’ 11 tweets β€’ 3 min read
❓ What is Clean Code?

As @unclebobmartin says in the Clean Code book: there are probably as many definitions of Clean Code as there are programmers.

This is a thread 🧡 about what I believe Clean Code is. First, my favorite quote from a well-known author:

"Clean Code reads like well-written prose" (@Grady_Booch).

A short sentence that says it all.

Clean Code should be as enjoyable as reading a good novel. Names are revealing. Flow is simple. Clean Code tells a story.
Jul 23, 2020 β€’ 5 tweets β€’ 2 min read
🎨 A use case for empty interfaces:

Creating an empty interface "I" allows us to make explicit that objects of type "I" must be opaque. You can reference objects of type "I" and pass them around, but you can't invoke behavior.

Example: the Memento design pattern.

🧡 1/5 The intent of the Memento pattern is to support the creation of snapshops of the internal state of objects so that these objects can be restored to this state later.

That is, the Memento pattern helps us implement "undo" operations.

This is the structure of the pattern: 2/5 Image
Jul 6, 2020 β€’ 6 tweets β€’ 2 min read
Several days ago, I published a tweet where I asked which of these two statements was better:

1⃣ dog.expressHappiness();
2⃣ dog.getBody().getTail().wag();

Many things can be said in favor of the first statement.

A thread 🧡 1/6

#SoftwareEngineering #oop #100DaysOfCode The first statement:

πŸ”Ή Increases readability: it expresses the intent of the code clearly.
πŸ”ΉReduces complexity: it contains only one method call.
πŸ”ΉHides implementation details: it expresses "what" the code does, not "how". 2/6
May 28, 2020 β€’ 4 tweets β€’ 1 min read
✏️BDD tip: when you capture behavior as scenarios, focus on *what* the system must allow users to achieve, not *how*.

Your specifications will be more durable and easier to automate.

Example and counter-example πŸ‘‡ Example:

GIVEN: I have entered correct username and password.
WHEN: login action is invoked.
THEN: login is successful.
May 11, 2020 β€’ 4 tweets β€’ 1 min read
❓Design question: if we have an "Address" class, is this concept an *Entity* or a *Value Object*?

Each instance of this class represents the address of a house (street, city, zip code, country, etc).

Correct response in thread πŸ‘‡ #DDDesign The answer is: it depends.

It depends on the use cases of the system. That is, we must consider what the system (and its users) care about.