miércoles, 18 de agosto de 2010

Function's Name, Code and Usage Relationship

To show how important the relation between a function's name, code and usage is, let me show you this silly example using Python:

#Look this valid function definition:
def are_different(a,b):
return a==b

#This line looks nice. They are different:

if are_different(1,2):
print "1 & 2 are different!"
else:
print "Houston: we have a problem!"
#Huh? Where is the mistake?

raw_input
("Press [ENTER] key...")

(You can download previous code in this link. Double-click to run it.)

What can you see? It's fun to see how function name says one thing, and its implementation says another.

Conventions are important. It should be clear by reading any part of the code.

In validation functions, there are two possible values. True and False. Although you can choose to return the one you like the most, when you want to say that a validation has_failed or has_passed, it "should" be clear what value to use, shouldn't it? ...

Actions (or processes) should be according with names. Names should be chosen according to actions. "What you say should be backed-up with what you do." "Things you do speak louder than things you name."

Comparing this with Positivism, I like how inspiring messages are written, although they don't promote planning.

#300-private

No hay comentarios:

Publicar un comentario