Haiku. Silverpoint drawing. Strict counterpoint. You wouldn't want to not have any other way to express yourself, but what a learning exercise!
Andrew Binstock relates a certain set of constraints within which to practice OO programming.
One of them I like a huge amount:
Wrap all primitives and strings. [...] So zip codes are an object not an integer, for example. This makes for far clearer and more testable code.It certainly does, which was the topic of the session which Ivan and I ran at Spa this year.
Another is this:
Don’t use setters, getters, or properties. [...] “tell, don’t ask.”Indeed. What we now know as jMock was invented to support this style of programming. It works a treat.
This one, though, I'm a bit equivocal about:
Don’t use the ‘else’ keyword. Test for a condition with an if-statement and exit the routine if it’s not met.See, depends on what's meant. It could be that a trick is being missed. On the one hand, I'm a huge fan of code that returns early (
if(roundHole.depthOf(squarePeg).sufficient()) return;), and also of very aggressive guard clauses (
if(i.cantLetYouDoThat(dave)) throw new DeadAstronaut();) On the other, I believe that the constraint that does most to force you to "get" OO is this:
Don't use any explicit conditionals. Never mindCan you see how that would work? I learned this so long ago that I can't remember where from (by some route from "Big" Dave Thomas, perhaps?)
else, use no
Oh yes, and for bonus points, Andrew mentions this: "Don’t use any classes with more than two instance variables". I suggest that you try not using any classes that have any instance variables, and see how far you get. You might find that to make progress you need a better language.