Everybody is playing Worldle these days…

And I love TDD.

So, let’s get moving…

TL;DR: With just a few steps we can build a robust Worldle.

Defining a word

The minimum information amount in Wordle is a word.

We can argue that *letter* is smaller, but we think all needed letter protocol is…

Incomplete objects cause lots of issues.

Photo by Brett Jordan in Pexels

Problems

  • Mutability
  • Incomplete objects
  • Concurrency inconsistencies between creation and essence setting.
  • Setters

Solutions

  • Pass the object’s essence on creation

Examples

  • Some persistence frameworks in static typed languages require an empty constructor.

Exceptions

  • Stateless objects. Always better solution than static class methods.

Sample Code

Wrong

Right

Photo by Stacey Vandergriff on Unsplash

Protocol is empty (with setters/getters).

If we ask a domain expert to describe an entity he/she would hardly tell it is ‘a bunch of attributes’.

Problems

Solutions

1) Find Responsibilities.

2) Protect your attributes.

3) Hide implementations.

4) Delegate

Examples

  • DTOs

Sample Code

Wrong

Right

TL;DR: Don’t name your variables as Data.

Problems

  • Readability
  • Bad Naming

Solutions

1. Use role suggesting names.

2. Find names in the Bijection.

Context

We use ‘data’ a lot in our variables.

We are used to doing it.

Using this kind of name favors the anemic treatment of objects.

We should think about…

Image by Tumisu from Pixabay

TL;DR: Name all your magic numbers

Problems Addressed

  • Readability
  • Complexity
  • Code Reuse

Related Code Smells

Steps

1. Move the constant code fragment to a constant declaration

2. Replace the values with a reference to the constant.

Sample Code

Before

double energy(double mass) {
return mass * 300.000 ^ 2;
}

After

//1. Move the constant code fragment to a constant…

Photo by Dan Nelson on Unsplash

TL;DR: Don’t test your private methods.

Problems

  • Breaking Encapsulation
  • Code Duplication

Solutions

1. If your method is simple, you don’t need to test it.

2. If your method is complicated, you need to convert it into a Method Object.

3. Do not make your methods public for testing.

4. Do not use…

Maximiliano Contieri

I’m senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store