Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's your naming convention for helper functions? [closed]

In functional programming, it's often important to optimize any "looping" code to be tail recursive. Tail recursive algorithms are usually split between two functions, however - one which sets up the base case, and another that implements the actual loop. A good (albeit academic) example would be the reverse function.

reverse :: [a] -> [a]
reverse = reverse_helper []

reverse_helper :: [a] -> [a] -> [a]
reverse_helper result [] = result
reverse_helper result (x:xs) = reverse_helper (x:result) xs

"reverse_helper" isn't really a good, descriptive name. However, "reverse_recursive_part" is just awkward.

What naming convention would you use for helper functions like this?

like image 340
Cybis Avatar asked Jan 06 '09 20:01

Cybis


People also ask

What is naming convention and example?

A naming convention can include capitalizing an entire word to denote a constant or static variable (which is commonly done in Flash programming), or it could be a simple character limit in a coding language (such as SQL). Naming conventions have functional as well as organizational qualities.

Are function naming conventions?

Naming Convention for Functions So, similar to variables, the camel case approach is the recommended way to declare function names. In addition to that, you should use descriptive nouns and verbs as prefixes. For example, if we declare a function to retrieve a name, the function name should be getName.

What is the naming convention for variables and functions?

Function and Class Naming conventions An important aspect of naming is to ensure your classes, functions, and variables can be distinguished from each other. For example, one could use Camelcase and Pascalcase for functions and classes respectively, while reserving Snakecase or Hungarian notation for variable names.


1 Answers

I always use do_, like "do_compute" with "compute". I find it quite descriptive as it is effectively the part of the function that performs the action, whereas the "compute" that gets called needs to have a simple descriptive name for the outside world.

like image 195
small_duck Avatar answered Oct 07 '22 21:10

small_duck