sabato 25 giugno 2011

Professionalism is all about taking responsibility - First : Do Not Harm to Function

I just started reading the new Uncle Bob's Book "The Clean Coder".

From the beginning it seems another great book.

Actually I'm reading the first chapter titled "Professionalism".

I completely agree with Bob when he write "professionalism is all about taking responsibility"


How do we take responsibility?

Uncle Bob says "First, Do Not Harm" :

  • do not harm to Function
  • do not harm Structure
Do not harm to Function, by being responsible for your errors.

because the only way to not harm the function of our SW is not creating bugs therefore to be professional we must not create bugs .

You must apology for every bug QA or even worst users find.
But this is not enough, you have to struggle for decreasing your bug rate towards the asymptote of zero.... we know zero is impossible but this is not an excuse for not trying to be as close as possible to it.  

He tell us that it's unprofessional to send to QA "code you aren't certain about".

YOU MUST KNOW IT WORKS and you have only a way to be sure it works:

You have to Test it, Test it and Test it .

Uncle Bob demand, not only suggest, for 100% test coverage.

Naturally he tell us 100% is an asymptote as for 0 bugs.

He tell us that if code is hard to test the only reason is that "code has been designed to be hard to test" so  "design your code to be easy to test".

Uncle Bob naturally tell us which is the best way to design our code for easy testing, "write your test first".

Here ends the first part of the story, in a future post I will talk about the Uncle Bob advise on how Do Not Harm Structure.

This is only a very short and raw summary of the Do Not Harm to Function topic, the book is full of explanations, examples and great stories... so I can only say buy the Book The Clean Coder Book and start reading it, for me is a must.

A second advice is to visit The Clean Coders Web Site the videos are cheap and great.

giovedì 23 giugno 2011

goto statement - bad or not?

I just started reading some stuff about Go programming Language (http://golang.org/and I discovered it supports the goto statement.


But goto statement is bad..... a good programming language should not have a goto statement or not????


So I started surfing the web trying to understand why smart guys like those at Google could create a  new language with a goto and I found golang-nuts and than the Linus Torvalds opinion on this topic  http://kerneltrap.org/node/553/2131.

I think it's worth reading.

mercoledì 22 giugno 2011

Constant Interface Antipattern

I thought was a good practice to  put static members into an interface and inherit from that interface.

But it's a very bad idea or even more an Antipattern : Constant Interface Antipattern (see Effective Java) .


Why is it so bad?


The use of static member from another class is an implementation details and interfaces are used to abstract from implementation details. 


In other words:
The use of static member causes a leakage of implementation details into many unrelated classes, because any of the defined static constant will be available to all of your classes that implement this interface.


So remember:


Interfaces are for defining contracts, not for constants.


Why do you want to declare static members into an interface?

May be to avoid putting class names in front of constants while accessing them or to group related constants .


Solutions?


Put constants into class and use static import but Very sparingly! 


Use only when you require frequent access to static members from one or two classes.

If you overuse the static import feature, it can make your program unreadable and unmaintainable, you not know which class a static member comes from but used appropriately, static import can make your code more readable, by removing the boilerplate of repetition of class names.

Interesting link :

http://download.oracle.com/javase/1,5.0/docs/guide/language/static-import.html

http://www.jroller.com/ksevindik/entry/some_thoughts_about_constant_interface

http://stackoverflow.com/questions/3547792/grouping-related-constants-shared-between-classes

sabato 18 giugno 2011

Linux - which program is using a device

There has never happened to not be able to unmount a device because of a message tells you some program is using it?
But which program?


The lsof command is what you need. 


For example if I mount a device as /media/disk 
typing lsof /media/disk I obtain the following result:



COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
Thunar  1448 drea   20r   DIR   8,16    32768    1 /
Thunar  1448 drea   21r   DIR   8,16    32768    1 /media/disk


pretty useful information :-)