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:

    What people don’t realize is that intimacy has its conventions as well as ordinary social intercourse. There are three cardinal rules—don’t take somebody else’s boyfriend unless you’ve been specifically invited to do so, don’t take a drink without being asked, and keep a scrupulous accounting in financial matters.
    —W.H. (Wystan Hugh)

    Art, it seems to me, should simplify. That, indeed, is very nearly the whole of the higher artistic process; finding what conventions of form and what detail one can do without and yet preserve the spirit of the whole—so that all that one has suppressed and cut away is there to the reader’s consciousness as much as if it were in type on the page.
    Willa Cather (1873–1947)