I gravitate toward functions that are discrete. I.E. they only read or write information as defined in their prototype. But all day long at work I find functions that read and write global variables, UI items, and the database. We are good about labeling all functions with a short prefix. (IMNSHO, all shops should have a convention of giving names prefixes according to the type of things they name: strSomeString, intSomeInt, CSomeClass.file, objInstanceOfSomeClass, fncSomeFunc, subSomeVoidFunc.) But I think it would be cool if we also had an indication by looking if a function is an ideal function or something more promiscuous.
An ideal function's only interaction with the outside world is via its arguments and its return value. Other functions might choose to interact in their function bodies with global variables, user interface elements, or the database. In my personal prefix convention I'm going to add an indication of that.
prefix | Description |
---|---|
sub | A void function, possibly with parameters, but with no other outside interaction. A waste of computer time. The inside of a black hole's event horizon. The only legit use of this I can think of would be subWaitThisManySeconds(int) or something--even that might technically be considered reading the clock, which is link to the universe, i.e. a sensor. So that would really be subuWaitThisManySeconds(int) as defined below. |
fnc | An ideal function, with a return value, and parameter(s). |
sub[d|m|u] | A void function, possibly with parameters, that reads and/or writes values to/from the database, module level (global) variables, and/or user interface or sensor resources. |
fnc[d|m|u] | A function with a defined return value, possibly with parameters, that reads and/or writes values to/from the database, module level (global) variables, and/or user interface or sensor resources (mnemonic for sensors could be that they interact with outside universe). |