270 More Software design [2d]

Updated . Posted . Visible to the public.

Building on Software design basics, this lesson covers more principles and code smells, technical debt, and architecture antipatterns, using real repos to find examples.

Important

Work on this lesson in advisor mode.

Learning goals

  • You can explain what a code smell is and recognize the common ones in Ruby code, e.g. feature envy, objects reaching deep into other objects, classes with several responsibilities.
  • You can apply the design principles you know — single responsibility, Law of Demeter, Tell Don't Ask — to real code and propose a concrete refactoring.
  • You can explain what technical debt and technical drift are, how they arise, and how a team keeps them in check.
  • You can find debt and drift in a real repository and judge whether fixing it is worth the cost.
  • You can recognize code that ignores module boundaries — logic for one concept scattered across models, controllers, views and helpers — and pull it back into one place. This is the most common flaw in agent-generated code.

Resources

Read what's new to you, skim what's familiar, skip what you already master. Stop when you can meet the learning goals.

Your agent can also generate an overview, a tutorial or an explanation for anything here, tailored to what you already know. Just ask.

Code smells and refactoring

Module boundaries

Technical debt

Exercises

Find the debt

Look at the repo for Cards and find two or three examples of technical debt or drift. For each one:

  • What pain does it cause today? Which changes does it make slower, harder or riskier?
  • What would it cost to fix: how much time, and what else would have to change with it?
  • What would we gain? Is it worth fixing?

Find the scattered concept

Take one concept in Cards that is truly scattered — the card search — and list every file that knows about it. Where does logic for that concept live in models, controllers, views and helpers? Sketch where it should live, and what a single module for it would look like.

Second opinion

Your agent has a design review that looks for the problems from this lesson: scattered concepts, mixed responsibilities, coupling, misplaced logic and inconsistency.

  • Before you run it, write down the design problems you see in your MovieDB, each with the principle it breaks.
  • Run /trainee-design-review over your whole MovieDB.
  • Compare its findings with yours. Which did you both find? Which did you miss, and which did it miss? Do you agree with each finding and its direction?
  • Fix one or two findings you agree with. It's fine if problems remain.

Tip

Keep running /trainee-design-review on your changes after this lesson, e.g. before you ask for a review.

Profile picture of Henning Koch
Henning Koch
Last edit
Niklas Hasselmeyer
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra Curriculum (2015-08-03 16:24)