STUPID vs SOLID

 SOLID Principles were first collected by Robert C. Martin (also known as "uncle Bob"). It is the acronym for:

  • Single Responsibility
  • Open/Close
  • Liskov Substitution
  • Interface Segregation
  • Dependency Inversion

  • I will be talking about each of them in a series of Posts in this blog. But, let's talk first about the STUPID principles (believe it or not, this is also an acronym), opposite to this set of good practices, that we should avoid:

  • Singleton
  • A Singleton is a software design pattern  that restricts the instantiation of a class to one single object. This is useful when exactly one object is necessary to coordinate actions across the system. That is what theory says, but it's difficult to think of many situations which would require you to model an object with a singleton. It is, in fact, referred to as an anti-pattern. The main reason for this to be avoided is that it involves a high level of coupling, when we are in fact looking for the oppositte: low coupling and high cohesion.
  • Tight Coupling
  • As it's been explained, a tight coupling is a poor strategy as it will make it difficult for you to extend the features in your app. 
  • Untestability
  • Most of the times due to a tight coupling or to poor strategies such as calling static methods instead of using constructors.
  • Premature Optimization
  • The tittle speaks for itself, right? I know thinking big is a huge temptation when you first start developing your own app, but adding innecessary complexity won't benefit you. Small steps and clean properly written code is better than getting entangled in complex relationships between entities that you might or might not need in the future. Scalable code is the key to success!
  • Indescriptive Naming
  • I cannot insist enough in how important it is to use semantic names. You think you are good at choosing them? It doesn't matter. Before writing even the first line of code, sit down with a paper and pen and write down a brief glossary to name your entities and variables or you might find yourself refactoring a whole feature because the names you chose are duplicated, you don't even rememember what they mean or the don't represent the reality you are trying to model.
  • Duplication
  • It's such a great pleasure when you are able to reduce your 300 lines code to a readable "story" that perfectly fits in your screen and that you (as well as your granny) and other developers will be able to understand in 10 years time without comments. First learn how to make your code work, then, make it look beautiful!

    I hope this helps anyone following the hard but satisfactory path of self-learning!
    Happy coding and happy weekend 

    Comments

    Popular posts from this blog

    SOLID: The Single-Responsibility Principle (SRP)

    Symfony HTTP client

    Inheritance: Abstract classes and interfaces