background preloader

Refactoring

Facebook Twitter

The SOLID Design Principles Deconstructed by Kevlin Henney - YOW! 2013. The Open/Closed Principle Dojo. The SOLID Principles in Real Life - DaedTech. DRY is about Knowledge. Code duplication is not the issue.

DRY is about Knowledge

Published on 02 August 2014 by @mathiasverraes Have a look at these two classes: <? Php // example 1 final class Basket{ private $products; public function addProduct($product) { if (3 == count($this->products)) { throw new Exception("Max 3 products allowed"); } $this->products[] = $product; }} final class Shipment{ private $products; public function addProduct($product) { if (3 == count($this->products)) { throw new Exception("Max 3 products allowed"); } $this->products[] = $product; }} Would you say this is duplicate code? If it is, then the solution to get rid of it, could be something like this: <? The code is identical, but why? In another scenario, the similarity of the code might also be simple coincidence. Reasons to Change Whatever the case, it doesn’t matter. You might be tempted to solve the problem by abstracting the limit: <?

This works to certain extent, but the rules might change in unexpected ways. Knowledge Read more Follow up posts: IEEE Software Blog: Why Should Software Architects Write Code? In the software engineering community there is a divide on who needs architects, what responsibilities should architects have, and whether architects should code.

IEEE Software Blog: Why Should Software Architects Write Code?

We all have heard these questions in one form or another, all motivated by a wide range of pragmatic opinions. Some practitioners argue that architects responsibility is for the integrity of the entire system, and satisfying business goals while mitigating the risks; Therefore, architects can postpone other lower-level decisions, including the coding decisions, to developers that typically have more limited responsibilities. On the other side of this spectrum, a group of practitioners argue architects should code. Some critics even take the criticism of “architects not practicing coding” further and argue that: “powerpoint architects'' are ineffective while expensive to afford. These architects join the project kickoff meetings, draw all sort of diagrams and leave before implementation starts. IEEE Software Blog: Why Should Software Architects Write Code? Joebew42/study-path: A study path about Clean Code, TDD, Legacy Code, Refactoring and IDD.

Refactoring extract override. Refactoring parametrize constructor. Que faire lorsqu'une méthode privée veut être testée ? - Nadia Humbert-Labeaumaz. The SOLID Design Principles Deconstructed by Kevlin Henney - YOW! 2013. Game Programming Patterns. Game Programming Design Patterns. Programming is one truly interesting skill.

Game Programming Design Patterns

Many choose to study it for years in University, while others can pick it up in their spare time simply by reading and completing tutorials online. Learning to build things quickly can be both lucrative and life-improving. However, knowing more of the theory behind programming will help you write great code and comparing your style of programming to others can be a terrific eye-opener. As multiple developers work on a codebase over time, the software will typically suffer from some common problems: tightly coupled code and spaghetti code are recurring topics amongst developers – and create messes most will want to avoid. For the past ten years I’ve been coding professionally, I’ve neglected to spend more time learning the underlying theories behind programming. The Double Buffer Pattern What is a Buffer?

The Command Pattern “Commands are an object-oriented replacement for callbacks.” The Observer Pattern Wrapping Up What are you waiting for? Design Patterns & Refactoring. Tamas Puski sur Twitter : "#cleancode cheat sheet @ #itakeunconf ....sitting in the second line & waiting for the opening #worklifebalance ..;) Refactoring with Loops and Collection Pipelines. The loop is the classic way of processing collections, but with the greater adoption of first-class functions in programming languages the collection pipeline is an appealing alternative.

Refactoring with Loops and Collection Pipelines

In this article I look at refactoring loops to collection pipelines with a series of small examples. A common task in programming is processing a list of objects. Most programmers naturally do this with a loop, as it's one of the basic control structures we learn with our very first programs. But loops aren't the only way to represent list processing, and in recent years more people are making use of another approach, which I call the collection pipeline.

This style is often considered to be part of functional programming, but I used it heavily in Smalltalk. Refactoring a simple loop into a pipeline I'll start with a simple example of a loop and show the basic way I refactor one into a collection pipeline. Let's imagine we have a list of authors, each of which has the following data structure. Java Ruby.