Upgrade to Pro — share decks privately, control downloads, hide ads and more …

My Favourite Design Principles

My Favourite Design Principles

Mark Taylor

May 20, 2020
Tweet

More Decks by Mark Taylor

Other Decks in Technology

Transcript

  1. The Software Peter Principle • Describes a dying project that

    has become too complex to be understood. • Often these days we just call this “legacy”. • It’s known as the silent killer of projects. • Based on the theory of incompetence in organisations due to promotion. • Can be avoided using good coding practices and avoiding unnecessarily complex code. • You can read much about it in Dilbert comics.
  2. Causes of the Software Peter Principle • Rushed code due

    to: – unrealistic or poor planning – Deadlines – Feature creep • Inexperienced developers / poor mentoring. • Lack of effective code reviews. • Overly complex code.
  3. The evolution of a (PHP) developer • Hey look at

    me, I can make this HTML page show things in a database, cool! • I’ll just use these variables from the query string to connect. Let’s mix it all up for speed. • Yay, MVC! Views are for winners. Separate all the things. • What is this Symfony framework thing people keep talking about? Composer is life. • Hey I’m getting pretty good at this OOP thing, let’s abstract all the things. Re-usability! • Input escaping is cool, look ma, no SQL Injections. XSS is so yesterday. • I am a code ninja. I don’t even see the code any more. I just see blonde, brunette, redhead. • Who wrote that awful unreadable code. What does it even do? Oh wait that was me a month ago. • Why god, why??? • OK, let’s just keep it simple, stupid. Simplicity is sanity.
  4. So, let’s write readable code • Write code with others

    in mind, don’t just write code for a machine to read. • Write code like future developers are armed, and know where you live. • Name your variables clearly, along with method and class names. • Make good use of in-line comments and doc blocks, though no pointless comments. • Use, but don’t abuse the Single Responsibility Principle. You can go too far! • Have consistent coding standards – e.g. PSR2. It really doesn’t matter which. • Try to have a nice low cyclomatic complexity score. • Generally, just avoid unnecessary features and complexity.
  5. KISS is a design principle that says that most systems

    perform best when they have simple designs rather than complex ones. The simplest solution is often the best. In Philosophy it is called “Occam’s Razor”.
  6. "You aren't gonna need it" (YAGNI) is a programming design

    principle that states a programmer should not add functionality until deemed necessary. No more “oh but someone might need this in future, it’ll only take a minute”. ++$maintenance ++$tests ++$bugs YAGNI