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

Starting with design

To design is difficult. It’s not like most everyday problems you might face. To learn to design a dummy house for instance, might require knowledge of good placement of windows and doors. Better design is always an evolution. Design is a... Continue →