The BEST Naming Strategy for Any Programming Language

  • Shortest names possible
  • Easy to understand
Readily Logo
Example of Readily Features

Naming Conventions != Naming Strategy

Firstly, while I won’t get into too much detail into case convention, but here are the most recognized ones for completeness.

  • camelCase : all words except the first are capitalized at the first letter (JavaScript)
  • PascalCase : all words capitalized at the first letter (C#)
  • snake_case : all lowercase, words separated by underscores (python)

High-Level Overview

Now, the key concept in this naming strategy is adding prefixes to functions to indicate to declare what will happen when it is called. This allows future developers to quickly identify where in the code any business logic was implemented incorrectly given a set of debug logs.

Prefixes, Why?

Using prefixes encapsulates what occurs in functions using the single responsibility principles, meaning that functions should ever only do one thing, or make one kind of decision.

  • current (integer), indicates the sentence number the user is on
  • highlights (map), indicates which sentences should be highlighed
  • commands (array-like), stores the command history
Prefix Table
[1] The commands object most closely resembles a stack. A command is pushed to the object to be at the top. However, when undoing, the top command is just popped and discarded. The undone commands are kept until a redo is executed or the user applied a new command to overwrite the popped commands. The popped commands could be stored in another stack.

Further Notes on Prefixes

  • doIter
  • user
  • calc & get

Additional Functions

For ReactJS, the following function is also used:

  • componentDidUpdate: compare previous state and new state, then apply do functions

Example Flow

Here is an example of how these functions are used. In it, you can see how the encapsulation makes it clear what would happen in the functions.

/**
* The following chain will increment the this.state.current
* value to indicate that the next sentence should be
* highlighted.
*/
userMoveNextSentence() // Calls the command function to
// record the action
- commandMoveNext() // Calls the execute to apply state change
= executeMove(commandProps) // Causes the re-render
- (state-change re-render)
- componentDidUpdate() // Calls the do functions to
// remove the previous
// highlight and add the next one
- doRemoveHighlight(prevN), doAddHighlight(nextN)

Conclusion

In this article I have discussed the best naming strategy for encapsulating several types of functions. Using this naming strategy, developers can significantly enhance the maintainability and understandability of their code.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Justin San Juan

Justin San Juan

Award-Winning Software Engineer | Business and Web Consultant