cover-img

Code Smell 47 - Diagrams

Diagrams are not code. They cannot be a code smell. They are just Diagram Smells.

30 January, 2023

2

2

0

Diagrams are not code. They cannot be a code smell. They are just Diagram Smells.

Problems

  • Maintainability
  • Trash code
  • Code Duplications
  • Diagrams focus only on structure (accidental) and not behavior (essential).

Solutions

  1. Use diagrams only to communicate ideas with other humans.
  1. Program on your favorite IDE.
  1. Thrash all diagrams. Even the ones generated from the source code.
  1. Trust your tests. They are alive and well maintained.
  1. Use Domain Driven Design technique.

Examples

Sample Code

Wrong


Right

<?

final class BookItem {
// No. We will not inherit from concrete class Book since this is another smell

// No. We will not list a bunch of anemic attributes. since yet this is another smell

function numberOfPages() {
//
}

function language(): Language {
//
}

function book(): Book {
// Book can tell us a lot about her/his author, title etc.

}

function edition(): BookEdition {
// ..
}

// Loan and overdues are not book items responsibility

}

final class LoanTracker {
function loan(BookItem $bookCopy, LibraryUser $reader, DatePeriod $loanDates) {
// DatePeriod is better than anemic $fromDate and $toDate
}
}

final class LoanTrackerTests extends TestCase {
// Lots of maintained tests telling us how the system really works
}

Detection

We can remove all code annotations and forbid them by policy.

Conclusion

Designing is a contact sport. We need to prototype and learn from our running models.

Papers and JPGs don't run. They live in the utopic world where everything works smoothly.

CASE was a very hot trend back in the 90s.
No good system was developed with these tools.

Relations

Code Smell 01 - Anemic Models

Code Smell 25 - Pattern Abusers

More Info

Laziness II - Code Wizards

Credits

Photo by Nick Seagrave on Unsplash

The Diagram is Not the Model. The model is not the diagram. It is an abstraction, a set of concepts and relationships between them.

Eric Evans

Software Engineering Great Quotes


This article is part of the CodeSmell Series.

How to Find the Stinky Parts of your Code

2

2

0

Maxi Contieri

Buenos Aires, Argentina

🎓Learn something new every day.📆 💻CS software engineer 👷coding👨🏽‍🏫teaching ✍🏾writing 🎨Software Design 🏢SOLID 🌉TDD 👴Legacy 💩Code Smells

More Articles

Showwcase is a professional tech network with over 0 users from over 150 countries. We assist tech professionals in showcasing their unique skills through dedicated profiles and connect them with top global companies for career opportunities.

© Copyright 2024. Showcase Creators Inc. All rights reserved.