Whats your go-to naming convention?

Sunny' 🌻@slrpnk.net to Linux@lemmy.ml – 205 points –

As far as I know there are these;

  • Camel case = coolFileName
  • Snake case = cool_file_name
  • Kebab case = cool-file-name
  • Pascal case = CoolFileName
  • Dot notation = cool.file.name
  • Flat case = coolfilename
  • Screaming case = COOLFILENAME

Personally I prefer the kebab/dot conventions simply because they allow for easy "navigation" with (ctrl+arrow keys) between each part. What are your preferences when it comes to this? Did I miss any schemes?

157

It depends a bit on the use case. I try to follow naming conventions within specific environments like Python. When just sorting some documents together, I usually do a mix of Kebab and snake case, where I split semantic parts with underscores and connect words with dashes like 2024-08-30_author_document-name_other-important-info.ext

This is exactly what I do. It lends itself to something like 'prefix_specific-info_version' which is both sortable and easy to read.

Yeahh that's the best IMO ! But I get most of the time stuck with some testOFtest001 files/directory... cause I'm lazy...

But I always ALWAYS regret it afterward... :/

Is something like this defined in a standard somewhere?

Snake case.

  • Starts with a lowercase, good for shell autocompletion
  • No spaces, so no worrying about spaces in shell commands
  • '_' is better than '-' because it shows the spaces between words more clearly

Counterpoint: you have to use Shift a lot

For this reason, I use kebab case for directories. But because I agree underscores show spaces better, I use snake case for files.

I put an unnecessary amount of spaces in all my file names to break anyone who wants to use CLI tools on them

i use windows btw

I put newlines in my filenames to break both CLI tools and Windows filesystems

Underscore to delineate different parts, hypen to delineate words.

Like: my-resume_draft.pdf

And to make it consistent and easier to reuse parts for project names and such, I have a command line utility written for it. It caches the parts and uses a template system (support for generating current datetime in parts)

Available here (is in AUR too):

https://github.com/Atreyagaurav/nameit

Thats what I do as well. It makes it easy to seperate between logical units.

I like Camel Case for code, but mostly because it's ingrained in my brain, coming from Java as my first language.

For folders and files, I like Kebab Case.

Luckily, I was not ingrained by my first programming language like that, or my coworkers would strangle me.

I started with BASIC, which allowed only two letters for variable names...

SCREAMING_SNAKE_CASE just has the best name

YES, I USE THIS TOO TO STAY CONSISTENT WITH SQL QUERIES

I am a fan of Python's or Rust's official conventions.

For package names, tho, I don't get why this-is-used over this_clearly_better_system, as I would expect a double click to select_the_whole_thing, whereas it does-not-happen-here.

While i do agree, snake looks a lot better too. I just wish it was possible to navigate through each parts of the word more easily with ctrl+arrow. That would make it the superiour choice imo.

Camel case, but with a twist -- if the next word is about to start after a capital letter, I'll have it lower case.

topSecretFBIfile.txt for example

Interesting, I'd tend to demote the initialism, ie topSecretFbiFiles.tar.gz

That's probably more commonly accepted. I defer to whatever my team is doing, but for my own files, I wouldn't want things like UsStudentList or USStudentList which both look wrong to me.

USstudentList looks right to me, and if that's wrong, I'm okay with being wrong! Haha

IT'S

COOLFILE.NAM

THERE IS ONLY 8.3 AND THERE IS ONLY UPPERCASE

For files, kebab case. For variables, snake case. For servers, megaman villains.

I like to use my enterprise number and a UUID (all in lower case, for legibility). Here's an example:

.1.3.6.1.4.1.33230.0d456e46-67e6-11ef-9c92-7b175b3ab1f1

Now you might say that the UUID is already globally unique or at least pretty unlikely to turn up anywhere else, so why bother prefixing it with more stuff? To that I say: "I need to be absolutely or at least reasonably sure ... OK nearly sure".

Anyway, you maintain a database of these things and then attach documentation and meaning to them. An editor could abstract and hide that away.

I started this post as a joke. Not sure anymore. Why get your knickers in a twist with naming conventions for variables and constants. Programming is already a whopping layer of abstraction from what the logic gates are up to, another one wont hurt!

How about "cool file name"?

All my systems use modern file systems that are case sensitive and can contain any character except / and \0.

Using commands on that is still more annoying, so no way

not really

You can easily escape spaces with \ and my modern shell (fish) suggests and completes filenames for me anyway, so i don't have to type more than the first word in more than 90% of cases.

Typing \ in those cases instead of _ is super annoying.

In my keyboard layout backspace is behind altgr.

the standard keyboard layouts (qwerty, qwertz, etc.) are mostly trash

are there any good alternative keyboard layouts for your native language (finnish if im not mistaken)?

In Germany there is the Neo Family: Neo{,2}, NeoQwert{y,z}, Bone, Mine, ... as well as offsprings of that, but I guess you need your diacritics: å ä and ö. While Neo layouts have these diacritics available, they are made for german, so only ä ö and ü are easily accessible.

Finnish indeed. I'm not aware of any alternative layouts. å is completely unnecessary for finnish, so maybe the layouts you mentioned could work.

Now do it with a for loop on every file in a dir with thousands of files

for i in path/to/dir/*
  dosomething_with_my_file $i
end

where is the problem? fish shell doesn't split arguments at spaces

$IFS splits files at spaces

IFS is a special shell variable in bash, ksh and POSIX shells that lets you configure how the shell splits words

by default it splits at spaces tabs and newlines

I use fish a shell that is intentionally not POSIX compatible. While it borrows some principles from Bash and POSIX, it simplifies a lot of things and removes most footguns. Words are split at new lines in fish, which admittedly can also cause troubles, but not nearly as often as in bash and other POSIXy shells.

True. Linux, Android, Windows all have no problems

Using dots in a file though...

Snake case. I find it the easiest to read.

I'm starting to warm up to Pokemon case, which would simplify functions like

  • GottaCatchThemAll() to 🍚()

or

  • this to ⚡🐹IchooseU

which I think we can all agree is much easier to read

25% Camel case, 25% Pascal and 50% of the time flatcase. It drives me insane when I try and autocomplete a folder only to realise it was Downloads instead of downloads. I keep telling myself i will go through and make it all flatcase but I put it off because i tell myself i will rebuild my computer next week every week.

Never thought about making the home folders flatcase, thanks, takes all of 2 minutes btw.
If anybody else wants to do it, remember to edit ~/.config/user-dirs.dirs with your new flatcase folders.

I do the flatcase in my machines too, but it stopped being such big a nuisance to me when I moved to ZSH - it can autocomplete case-insensitively.

Is zsh a terminal or a language like bash? I don't get what it is from reading descriptions

Zsh is a shell like bash that supports shell scripting like bash (though with some syntactical differences). It's a bit more like ksh than bash, but anyone familiar with bash will have no problems with zsh.

You can check out oh-my-zsh for an accessible preconfigured version of it (though I'd suggest installing via your package manager rather than the script on their website). I like the jreese theme.

Thanks I'm gonna give it a go

The only correct answer is to be consistent with the code base you're working in or the language's conventions. If neither of these conventions exist, then someone has already failed you.

Given OP mentions kebab-case, this is probably about file-systems. But you are absolutely correct about code.

I’ve never been to a naming convention but I have been to some comic conventions!

For files? An unholy amalgam of snake, kebab and dot, depending on what exactly I'm trying to convey. (I still have much-ported files around with DOS 8.3 filenames, so they're truncated scream case (SCREAMIN.NAM), but I don't actively name files like that anymore.) The important thing is to separate the words/sections while using characters that are valid without escapes in both ext4 and vfat if at all possible.

For variable names, camel or Pascal case (depending on language convention) if I think anyone else is going to read it. Flat case for code I don't think anyone else is ever going to see (don't do this—it has left teethmarks in my ass from time to time and will do the same to you).

Random mix and match. I’m all for diversity!

Kebab. Not my favorite visually speaking but I had RSI issues for a while and I'm still very focused on limiting keystrokes (no shift key needed with kebab).

It really depends.

If I know I will never open the file in the terminal or batch process it in someways, I will name it using Common Case: "Cool Filename.odt".

Anything besides that, snake case. Preferably prefixed with current date: "20240901_cool_filename"

Snake case, but I'm the World's second worst programmer and just name files like this because I was alive when spaces were not allowed.

Depending on environment/language and policies. As long as its consistent throughout the project.

My old projects still have camelCase sprinkled around, you can tell which bits are new and old depending on whether it's camel or kebab

Depends. Java-like languages ofc camel/pascal case.
Bash, Python, etc., snake case, with constants as uppercase.
Filenames: I prefer snake case.

I like snake, but in some interfaces the underscores blend into the text line or are not rendered properly, so it becomes eaaier to discern if the filename has spaces or separators by using kebab.

This question just shows how messed up, and broken much of IT is.

It heavily depends on the context: Filenames? Variables? Functions? Interfaces/Classes? Java? C? Shell?

I usually like to call my functions cool-Filename and my variables moronic_typeClass. Shell executable aliases look like 'if\ then\ else' and C constants are 'IFTHANELSE'

Both snake and camel case. Sometimes I mix it in the same project and I hate myself for it

Snake case, usually. Some perhaps unfounded fear that something will blow up on a dash in a file name kicking around. Or I'll do a weird typo/premature enter and part of the file name will be treated like a -flag of some sort.

Whatever case I get when my finger reaches the shift key.

The guy on shift before you got the Case of the Missing Variable. What will you get when your finger reaches that shift? Who knows... It will remain... A_Mystery!

code: camel or snake, depending on language

files/dirs: snake + kebab + dot mixture (trying to avoid caps and special chars here)

For files, date+Snake: 20240831Letter_to_Rodney.odt For variables, Screaming

I kebab case mine for personal files.

It's mostly because I don't have to use a modifier key and it's doesn't need url encoding and all in the same lowercase. Dot notation looks nice but I feel like dots are for extensions only. Flat case is horrible to read, screaming case even worse, camel/pascal case to many times ends up as coolFileNAme on first time typing.

I've done a couple of different styles because of programming in different languages but now if I have to do anything that's not kebab case I make a small frown.

General purpose: Kebab case

But really, follow the conventions of what you're working on. For example, I'd use pascal case when working on a Java/Kotlin project, and snake case when working on a Python project.

I don't like it but I am used to reading old C codebase (windows: https://learn.microsoft.com/en-us/windows/win32/stg/coding-style-conventions) with Hungarian notation.

pszMyString 😥

That's called camelCase, right? starting off small and then use Upper. Hungarian notation is a form of camelCase, just with the type added in front I think. But that's for coding standards, not filenames. One can think of Hungarian notation as to what file extensions is to files, just added in front. Imagine files named as "txt.MyFile", just for illustration.

Ah yes I dont know what I thought OP was asking about coding standards 😂

Snake case for all kinds of file names and camel case for programming

FileName_IMPORTANTCATEGORIZATION.yyyy.ext

With all bits being optional (not every file needs the date it refers to)

So eg (slight modifications for anonymity):

SunLifeInsureance_SIGNED.2024.Q1.pdf

SpotDoesTrickAndFalls_ORIG.mp4

JSmithPassport_CANADA.2015_2025.pdf (I am a dual citizen)

JSmithCOVIDPass_DOSE1.2021.pdf

Snake case or kebab case I guess. But why is it called kebab case?

Because it looks like the words are on a rod, like kebab meat

Huh thanks,, I guess it's based on a misunderstanding of the word kebab then. Correctly it would have to be called şiş/shish case then, but that certainly has less of a ring to it.

I don't have a consistent style for everything and it depends on the circumstances. snake_case is often used, especially to avoid spaces. Sometimes I just do flatcase instead, and in rare cases also kebab-case or combined_snake-and-kebab-case. The combined_case is often useful to group parts of the name, like a dates and version numbers together and to indicate what part is constant; example-name_2024-08. Sometimes I also do the "Title Case", which is basically PascalCase, but with spaces. Or even even more weird, "Python_Case", which is PascalCase, but with snake_case, when I want to avoid spaces.

I often avoid dots in regular filenames, unless they indicate a file extension or format, such as ".svg" and ".inkscape.svg" to indicate its a specific version of the SVG format. Or ".xiso.iso", as a specific compressed version of the regular ISO file (for use with Xemu emulator). Basically the same logic and tradition as ".tar.gz" (but in reverse order).

I don't like extra dots simply because pattern matching might get weird down the road. Keep dots for extension type and use Pascal to make it easier to read multiple words. Flatcase only if it's short or I'm lazy for a temp file.

I use flat case most of the time, but I also try to stick to single word files so there is no case to get in the way.

I think for documents I might share like a PDF I'd use Pascal case.

In a classroom or teaching setting I will sometimes use Kebab case as I find it is the least confusing and makes it extra clear where the word division is. Similarly I avoid Dot notation since it's confusing for folks coming from a Windows world.

And I would avoid Screaming because that's just too loud anywhere.

I try to make everything Pascal case. It's easy to read in a terminal and pretty easy to type.

Have been defaulting to kebab case for variable and function names in all languages recently because of cargo yelling at me

Pascal case for class names cause c#, snake case for python files because it doesn't like kebab

Screaming case for env files because that's what everybody else does

Snake if writing in python

Camel if writing in PowerShell

I tend to stick with what the language wants me to use.

Depending on the file it’s either dot notation or flat case.

For files? I like title case (like in article headlines). For example, I have a "Shell Tricks.txt". I'm not really consistent though, sometimes it's all lowercase or whatever really.

I took a CS class that was java based, and now my go-to is Pascal for file names. Sometimes I do flat or screaming just 'cause.

Pascal or camel case for code, snake case for files and screaming snake case for globals

Kebab case with Pascal case in the usual places. I'd change to all kebab case but the muscle memory of typing Documents would nearly kill me.

Kebab for most things, camel for source code

If its my own personal code, snake case, if I am sharing with my frontend devs then camel case. If I am writing short scripts, then flat.

I use PascalCase for classes, camelCase for functions and variables, SCREAMINGCASE combined with snake_case for constants and for filenames/folders mostly snake_case with kebab-case if date or timestamp is involved.

camelCase for non-source-code files. I find camelCase faster to "parse" for some reason (probably just because I've spent thousands of hours reading and writing camelCase code). For programming, I usually just use whatever each language's standard library uses, for consistency. I prefer camelCase though.

I use camel case for methods and functions and snake case for variables. And pascal case for constants. Why? I don’t really know, it makes for a nice distinction I guess.

generally i still to camelcase if i have no separators, if i do have separators i stick to - now. _ sucks. I use . notation when dealing with copies of files.bak or something like that.

If i feel really special i throw a space in the name just because

my go_to NamingCovention: ANYTHING but camel-case 🤮

Since Linux is caps sensitive, at least I always use lowercase.

I guess I use kebab case for any file used for IT projects

That's why camelcase starts with a lower letter. If you're using a good terminal+shell setup then it'll be irrelevant most of the time.

Me, a sick fuck, who likes a quick fuck:

/etc/moron-syntax/I\ write\ like\ a\ gay\ fish\ \(\Kanye\)\