Subroutine - Conventions

Conventions

A wide number of conventions for the coding of subroutines have been developed. Pertaining to their naming, many developers have adopted the approach that the name of a subroutine should be a verb when it does a certain task, an adjective when it makes some inquiry, and a noun when it is used to substitute variables.

Some programmers suggest that a subroutine should perform only one task, and if a subroutine does perform more than one task, it should be split up into more subroutines. They argue that subroutines are key components in code maintenance, and their roles in the program must remain distinct.

Proponents of modular programming (modularizing code) advocate that each subroutine should have minimal dependency on other pieces of code. For example, the use of global variables is generally deemed unwise by advocates for this perspective, because it adds tight coupling between the subroutine and these global variables. If such coupling is not necessary, their advice is to refactor subroutines to accept passed parameters instead. However, increasing the number of parameters passed to subroutines can affect code readability.

Read more about this topic:  Subroutine

Famous quotes containing the word conventions:

    It is not human nature we should accuse but the despicable conventions that pervert it.
    Denis Diderot (1713–1784)

    I find nothing healthful or exalting in the smooth conventions of society. I do not like the close air of saloons. I begin to suspect myself to be a prisoner, though treated with all this courtesy and luxury. I pay a destructive tax in my conformity.
    Ralph Waldo Emerson (1803–1882)

    Languages exist by arbitrary institutions and conventions among peoples; words, as the dialecticians tell us, do not signify naturally, but at our pleasure.
    François Rabelais (1494–1553)