Walking the fine line

If it stinks, change it.

—Grandma Beck, discussing child-rearing philosophy

A way of thinking about writing a good piece of code is to remember that not everything out there is good.

Not all language features will help you write quality code. Some features may in fact be considered harmful (a code smell) and are hence discouraged.

Responsibility

OK, let’s rephrase in a more appropriate context

With great power of language features, comes great responsibility of deciding what not to use.

Let’s consider the case of getters and setters. They are common in most languages.You might say

What’s wrong about getters and setters?

Well everything!

Getters and setters break the very concept of encapsulation and data abstraction. They essentially give access to the internal implementations which should never happen in any good OO design. Only place where you might think of using getters is comparison between same type of objects.

Learn everything but use only what is absolutely required.

That’s it for today. Caio!

Credits for image : [xkcd](xkcd.com)

 
0
Kudos
 
0
Kudos

Now read this

Adding Google maps in rails

Today I hope to clear basic concepts related to integrating google maps in rails app. We will be using Gmaps4Rails gem for it. I will also discuss some common gotchas related to it. First things first # First thing to go about adding... Continue →