Which one characteristic is most important for a good routine?

Procedures, procedures, methods - everything that you call them, they are important building blocks for us developers. What common characteristic would you rate as the most important?

(Providing one attribute for one answer, you can vote for them individually. That is, the purpose of this question is not to solve one characteristic, but to highlight all the important ones.)

+3
source share
20 answers

I think the most important criteria are that he has one goal.

After that, he satisfies this goal (and only this goal) correctly.

+16
source

Self comment names.

Examples: GetStoreFromAddress GetCarsByMake

+8
source

It should be easily tested.

+4
source

The name of the subroutine maps one to one functionality with it.

It is amazing how often the function X has X, as well as Y or most of X, but not all X.

+4
source

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

Among the criteria:

  • conceptual integrity: he does what can be described in a simple short form, one sentence or paragraph;
  • Loose communication: its behavior is not sensitive to what is happening in the code around it;
  • reasonable size: long procedures are more difficult to read and understand, and less likely to have good conceptual integrity;
  • Parny’s criterion: they “hide” one thing that can change, so changes in requirements are limited to affect the rest of the system.
+4
source

designed to be easily read and understood by people - without it in place it is much more difficult to change it in order to have all the other wonderful attributes that will be listed here.

+3
source

The number of attempts to make.

If this is not exactly 1, then you probably have a problem.

+3
source

It should not have unexpected side effects.

+3
source

good error handling (reliability)

+2
source

Brevity

(This should have been a semi-fun answer, but SO did not allow one word to be published!)

+2
source

It must be atomic

+1
source

Lines of code.

+1
source

You must keep track of the number of corrections required after the procedure has been put in place. A “good” procedure is a procedure with a small number of necessary changes. A “bad” routine definitely proves this to be the case when many fixes are required.

This can easily be done using the comment header for each method call that is updated after each edit.

+1
source

He does one thing or delegates several things to other functions.

+1
source

Clarity - Easy to understand

+1
source

I think this is easier to answer if you are considering procedures as part of the API. There are not many routines that stand alone, at least not in a really useful system. Honestly, I think the most important things to consider when writing routines are:

  • Intuitiveness How intuitive is my set of instructions - will people understand the goal without missing a lot of documentation?

  • Orthogonality How orthogonal are my routines? Does everyone perform one specific task, or are there several (but several different) ways to do the same? If so, this is bad, and the API probably needs to be redesigned.

  • Compactness . How much API is required for simple tasks? Do I need to learn a lot to do something, or is it enough for me to just a couple of procedures that do something intuitive and powerful? You need to weigh the trade-offs of this with orthogonality in order to achieve a good balance for your specific domain.

+1
source

From the name of the subroutine, you can say what the procedure does (and when you check the code, you understand that you are right ;-)

+1
source

This procedure uses a consistent level of abstraction.

+1
source

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

+1
source

Single point of return

0
source

All Articles