Variable Naming Conventions
Learn best practices for naming variables to keep code maintainable and readable.
We'll cover the following...
Before moving on to building full models, we’ll take this chapter to focus on best practices for coding data science projects in R. It’s important to remember that in data science, our code is not only written for the computer to execute, but also for other human beings to read and understand. All code needs to be easily understood; if not, our projects will fail. Remember, the best code reads like a book: it’s self-explanatory and self-connecting. We need others to understand our code so they can:
- Understand our analyses and where our conclusions came from
- Check for logical errors
- Debug syntactical issues
- Help us to improve our algorithms overall
These tasks are much more manageable when code is well-structured and follows a consistent style guide. Consistent styling makes it much easier to pass a script to a colleague and have them quickly understand the underlying logic and functionality, even if they haven’t worked on that particular problem. As such, the most critical style guide is that of our own data science organization. Our organization’s style guide should always precede any other best practices.
Naming styles
That being said, we should follow a few core rules for coding data science projects in R. In this lesson, we’ll focus on naming conventions. For those who’re familiar with other programming languages, the idea that good naming conventions are the foundation of understandable code will come as no surprise.
Let’s take a look at an example of good ...