The last time we talked about naming conventions, we had only seen a few kinds of things that needed naming. A lot has happened since then – the kids are grown, congress has been replaced with sentient carrots, and we’ve learned about all kinds of new nodes that we get to name.
First things first. Let’s pretend you’ve created a script that successfully performs one job in your bot. You look at the script’s tab to see “Untitled Script”. Let’s title it. A script should perform a job to completion. As such, a script should should be an action verb in title case that describes the job taking place. For example, “Create Account” is a better name than “account creator”. “Email Stan Lee” is a better script name than “Emailer for the comic book guy”.
Next up: Commands are similar to scripts in that they accomplish some sequence of actions. When you define a command, use a descriptive action verb or verb phrase, this time in all lower case. Commands are not complete jobs in the way that scripts are, but rather they are individual tasks. Examples might include fill out login form, and click the red button.
Functions, like commands, should be all lowercase. But instead of a verb phrase, they should be noun phrases. $square root is an obvious example. Maybe you have a function that gets the weather called $weather. You get the idea.
Put all these thing together, and you get a uBot. What should we name our uBots? In short, uBots should have a name that makes them easy to identify at a glance. For instance, maybe a bot helps you manage your business’s facebook page. Such a bot might be called “Facebook Page Keeper”. Maybe your bot is more ambitious, and attempts to manage all of the social media for your business. That bot could be called “Social Media Manager”. Ultimately, a bot name should be a short but descriptive noun phrase that makes it easy for people to know what it is and what it does.
Of course, some uBots aren’t intended to be actual bots at all. Sometimes you’ll want to create a uBot so that you can include it in another bot. In this case, the name should describe the functionality that it adds to the uBot you include it into, followed by the word “library”. For instance, maybe you have some common functions for dealing with lists. You might save those to a uBot called “List Library”.
Now that you know all the rules, understand that there will be times to break them. Think about writing code the way you would think about writing a novel – or better yet, a letter to an employee that explains how to do something. Your goal is readability. When you read over your scripts, is it immediately clear what you were trying to do when you wrote it? Code is read more than it is written, so write your code to be read.
Previous LessonNext Lesson