Skip to main content

Posts

Showing posts from October, 2016

POODR Highlights Part 1

Practical Object-Oriented Design in Ruby or POODR is clearly a book about Ruby development, however the odd aspect is much of the concepts apply to other languages. In fact I've taken these ideas and used them both before and after reading the book in other dynamic languages and even static languages such as C#. In summary the book is well worth a read, even if you don't do Ruby development full-time.A few of the highlights for me will be spread out across the following posts.DependenciesThe author takes a firm stance on dependencies. Anything that cannot be controlled by the class itself should be protected from change. In other words a message sent to self/this is preferred than directly interacting with a dependency.I've followed this pattern in the past, but the seeing the justifications for the benefit of this has made me realise the importance of such a practice. In the first example the publish method directly knows about the twitter feed it must interact with. In t…

The New Guy

Everyone is new at some point. No matter your experience level. You're either new to the team or new to the business. Being the new person is both a blessing and a curse.You're NewWhen you're new you come with no baggage. You're full of questions and curiosity.Why do we do it this way?Isn't there a better way of doing this?Have you considered this instead?These are all great questions for new starters to ask, and for teams to hear.You Have a New Team MemberWhen you have a new team member you gain someone with a fresh perspective. They're full of questions and curiosity. Rather than history, they'll be open to new and fresh challenges. A new member can ask you to question current practices. It is very easy to overlook problem areas only until someone with a fresh outlook arrives.How to be NewThere are two roles a new team member must play.LearningChallengingThe learning phase should involve questions, shadowing and pairing. The goal is to learn about the sys…

Constant Object Anti Pattern

Most constants are used to remove magic numbers or variables that lack context. A classic example would be code littered with the number 7. What does this refer to exactly? If this was replaced with DaysInWeek or similar, much clarity is provided. You can determine that code performing offsets would be adding days, rather than a mysterious number seven.Sadly a common pattern which uses constants is the use of a single constant file or object. The beauty of constants is clarity, and the obvious fact such variables are fixed. When a constant container is used, constants are simply lumped together. These can grow in size and often become a dumping ground for all values within the application.A disadvantage of this pattern is the actual value is hidden. While a friendly variable name is great, there will come a time where you will want to know the actual value. This forces you to navigate, if only to peek at the value within the constant object. A solution is to simple perform a refactor …