views:

343

answers:

20

Routines, procedures, methods - whatever you call them, they are important building blocks for us developers. What single characteristic would you rate as the most important one?

(By providing one characteristic per answer, it is possible to vote for them individually. I.e. the purpose of this question is not to decide single out one characteristic, but rather, to highlight all of the important ones.)

+1  A: 

It has to be atomic

Chris Lively
+1  A: 

Lines of code.

Whytespot
+8  A: 

Self Commenting Procedure Names.

Examples: GetStoreFromAddress GetCarsByMake

TJMonk15
I agree, but CamelCasing either variable or method names sucks dead bunnies.
innaM
+15  A: 

I think the most important criteria would be that it has a single purpose.

After that, that it satisfies that purpose (and only that purpose) correctly.

Vinko Vrsalovic
That's two criteria ;-) I'd say the single purpose would be the single most important one.
Joachim Sauer
Yes, I agree. I even had it like that at first :-)
Vinko Vrsalovic
+4  A: 

It should be easily unit tested.

Rob Hruska
+3  A: 

designed to be easily read and understood by humans - without that in place it is much harder to modify it to have all of the other wonderful attributes that will be listed here

RedFilter
+4  A: 

Number of things it tries to do.

If this isn't exactly 1 then you probably have a problem.

Joachim Sauer
+4  A: 

The routine's name maps one to one to it's functionality.

It's surprising how often a function X does X and also Y, or most of X but not all of X.

Jon Ericson
+1  A: 

You should track the number of edits required after the routine was put into use. A 'good' routine is one with few edits required. A 'bad' routine definitely proves itself to be so when there are a bunch of fixes required.

This can easily be accomplished with a comment header on each method call that gets updated after each edit.

Darian Miller
+2  A: 

good error handling (reliability)

+1  A: 

It does one thing or delegates multiple things to other functions

jmucchiello
+1  A: 

Clarity - Easy to understand

marcumka
+1  A: 

I think this is more easily answered if you consider routines as part of an API. There aren't many routines that stand alone, at least not in a truly useful system. So honestly, I think the most important things to consider when writing routines are:

  1. Intuitiveness How intuitive is my set of instructions -- will people understand the purpose without having to wade through a lot of documentation?

  2. Orthogonality How orthogonal are my routines? Does each accomplish one particular task, or are there multiple (but slightly different) ways to do the same thing? If there are, this is bad, and the API probably needs to be redesigned.

  3. Compactness How much of the API does it take to get simple tasks done? Do I need to learn a lot of stuff to get something done, or can I suffice with just a couple routines that do something intuitive and powerful? You need to weigh the tradeoffs of this one with orthogonality to strike a good balance for your particular domain.

tgamblin
That's nice. Why not split it into three answers then?
Ola Eldøy
Maybe I shouldn't have answered the question b/c I think it oversimplifies. I'm saying that many times you can't consider a routine by itself in any meaningful sense. These three go together for considering all the routines in a module or API.
tgamblin
Thank you for your input, though. The points you made are very good ones!
Ola Eldøy
I disagree. You certainly can analyze a single routine and say if it's a bad routine or a good routine. You can (and should) also analyze at the API level, but it's just that, a different level.
Vinko Vrsalovic
+1  A: 

From the routine name, you can say what the routine does (and when you check the code, you realize that you were right ;-)

gius
+2  A: 

There is no single criterion that distinguishes a good routine from a bad one.

Among the criteria are:

  • conceptual integrity: it does something that can be described in a simple short form, one sentence or paragraph;
  • loose coupling: its behavior is not sensitive to what goes on in code around it;
  • reasonable size: long routines are harder to read and understand, and are less likely to have good conceptual integrity;
  • Parnas's criterion: they "hide" one thing that can change, so that requirements changes have limited effect on the rest of the system.
Charlie Martin
So then you could write four answers, eh? ;)
Ola Eldøy
That would mean I was agreeing that a single characteristic could characterize a good routine. I do not.
Charlie Martin
I do not see it that way. In my opinion, highlighting one characteristic at a time does not imply that we believe any single one characteristic to be enough. It is merely a method by which we can vote for the ones we think are important.
Ola Eldøy
You fool! You have violated the one characteristic per answer rule!
titaniumdecoy
+1  A: 

The routine uses a consistent level of abstraction throughout.

Jimmy
+3  A: 

It shouldn't have unexpected side-effects.

Cristian Libardo
+1  A: 

I would say well documented (and actually enforced) pre and post conditions.

+2  A: 

brevity

(this was supposed to be a semi-fun answer, but SO wouldn't let be post the single word on its own!)

Alnitak
A: 

A single return point

Rich