background preloader

Construction

Facebook Twitter

Curly's Law: Do One Thing. In Outliving the Great Variable Shortage, Tim Ottinger invokes Curly's Law: A variable should mean one thing, and one thing only. It should not mean one thing in one circumstance, and carry a different value from a different domain some other time. It should not mean two things at once. It must not be both a floor polish and a dessert topping. It should mean One Thing, and should mean it all of the time. The late, great Jack Palance played grizzled cowboy Curly Washburn in the 1991 comedy City Slickers. Curly: Do you know what the secret of life is? Curly's Law, Do One Thing, is reflected in several core principles of modern software development: Don't Repeat Yourself If you have more than one way to express the same thing, at some point the two or three different representations will most likely fall out of step with each other.

The Single Responsibility Principle says that a class should have one, and only one, reason to change. Code Kata. Start.sbastn.com/programmer-personality. Java - How does this code break the Law of Demeter. The Clean Code Talks - Don't Look For Things! Law of Demeter. The Law of Demeter (LoD) is a simple style rule for designing object-oriented systems. "Only talk to your friends" is the motto. The style rule was first proposed at Northeastern University in the fall of 1987 by Ian Holland and popularized in books by Booch, Budd, Coleman, Larman, Page-Jones, Rumbaugh and others. A 2000 book that describes it well is The Pragmatic Programmer by Andrew Hunt and David Thomas. The name "Law of Demeter" was chosen because the style rule was discovered while working on the The Demeter Project which ever since was strongly influenced by the Law of Demeter.

The Demeter Project develops tools that make it easier to follow the Law of Demeter. (Demeter = Greek Goddess of Agriculture; grow software in small steps.) For example, DemeterF is an exciting Java tool to follow the Law of Demeter in Java. In 2003/2004 the Law of Demeter was revisited for Karl Lieberherr's ICSE 2004 keynote paper and presentation. This paragraph is added in September 2011. S.O.L.I.D. Software Development, One Step at a Time. Most professional software developers understand the academic definitions of coupling, cohesion, and encapsulation. However, many developers do not understand how to achieve the benefits of low coupling, high cohesion and strong encapsulation, as outlined in this article. Fortunately, others have created stepping stones that lead to these goals, resulting in software that is easier to read, easier to understand and easier to change.

In this article series, I will define three of the primary object-oriented principles and show how to reach them through the five S.O.L.I.D. design principles. Have you ever played Jenga? It’s that game of wooden blocks that are stacked on top of each other in rows of three. In Jenga you try to push or pull a block out of the stack and place it on top of the stack without knocking the stack over. Have you ever thought you were playing a game of Jenga when you were writing or debugging software? Software development does not have to be like a game of Jenga. Eliminate Most Mocks from Unit Tests « Arlo Being Bloody Stupid. Easily Eliminate Most Mocks July 15, 2012 by Arlo In previous discussions about mock-free unit testing, I’ve shown techniques that I use to eliminate the hard-to-eliminate test doubles.

I’ve skipped the simple techniques that I apply all the time. Time to fix that. One technique eliminated about 90% of the test doubles in my code. It’s simple. Extract Method . Let’s start by looking at a common example that is used to motivate unit testing with mocks. How would you test this? Easy: it’s all set up for dependency injection. But why coddle the poor design? The fact that we have to test it with a mock is telling us something. Or look at it another way: is the name of the function correct? It has multiple responsibilities. Let’s fix that. And how do I test this? This simple refactoring changes a side effecting function with complex logic into a tiny function composition, a side-effecting logic that is write-only, and a pure, side-effect free function. Tags: design , example , no mocks , tdd. Blog: Lets-Play TDD. Refactoring By Example. In-situ Coding: Programming in the Concrete Kent Beck, Three Rivers InstituteSeptember 2007 This paper describes in-situ coding, an extension of test-driven development, and it’s implementation in Eclipse.

From a test Eclipse helps you create stub methods. Filling in the real code can sometimes best be done in the presence of real data. Change the method body template to throw an UnsupportedOperationException and set a breakpoint on all UnsupportedOperationExceptions. Test-driven development (TDD) reverses the traditional flow of programming work. One of the advantages of the TDD cycle is that filling in the implementation is easier once you have figured out the tests. Even with TDD, writing code requires considerable mental effort. Early dynamic programming environments like LISP and Smalltalk supported programming in the debugger. In implementing in-situ coding, one goal is to reduce the number of information-less keystrokes.