Naming Bash Functions

Picking meaningful, ease-to-read names is one of the most important design skills you can foster. Bash is unique in that it allows a lot of things other POSIX shells do not. This gives Bash one big advantage when it comes to naming functions. We can use kebab-case.

is-valid-username () {
  ...
}

Don’t Sweat the Length

Long command and function names are not a problem. They are easy to understand. Obviously a shorter command name is always better but if the name is relatively unique at the beginning it will be easy to use through command-line tab completion. When the full name is required in scripts the readability will provide clarity that you — and those after you — will be thankful for later.

Yes It’s Okay to Use Dashes

Ever used the ssh-keygen or its family of commands? Yep. They all use kebab-case and have been for more than three decades.

Snake_Case is Slime

The snake_case popularized by Python turns out to be an absolutely horrible convention on modern terminals and web pages. The underscore is easily lost when combined with other contextual underlining.

💢 Having once naively embraced snake_case, I have come to absolutely loathe it now because of the many problems with readability on modern terminals and unnecessary shift it requires to type. This doesn’t seem like a big deal at first, but when you have to type that evil little _ as much as a 10x terminal master does you understand why it is so horrible. Such types are already used to typing the dash - a lot because of all the options to different commands UNIX / Linux requires. Yes. The evil _ is one of worst things things Python, PHP, and Perl have done to the mass of developers out there who actually think they are good things.