I wish zig adopted Pascal_Snake_Case for structs and and functions that return generic structs. So that we can have normal snake_case for variables and regular functions.
I sometimes do stuff that generates code, and itâs much simpler to go from e.g. âsome_thingâ to âget_some_thingâ than âsomeThingâ to âgetSomeThingâ. Especially in macros (in other languages) or comptime stuff.
Thatâs basically the worst of both conventions combined
FWIW I mostly use snake_case in C projects with everything lower-case except PREPROCESSOR_MACROS. Types get the _t postfix instead so that they donât collide with other names.
In TS and Zig I use the camelCase vs PascalCase convention (also perfectly fine).
Although this might be bikeshedding, Iâm still curious why.
Even though this style may not be very efficient to type, if we follow the principle of âcode readers over code writersâ, I think it is quite pleasant to read.
Oh! I always thought that identifiers ending with _t are reserved identifiers in POSIX, so I would deliberately avoid using them.
Too much âtyping complexityâ, you have two characters side by side which require pressing the shift key, which is unusual. Also in the middle of a string both _ and uppercase character combined is redundant for separating âwordsâ, one of those is sufficient.
Also I think it looks ugly (I could probably live with This_is_a_type - no idea what this convention is called though).
Oh! I always thought that identifiers ending with _t are reserved identifiers in POSIX
True, so just donât name your own types like POSIX types, problem solved And if youâre not talking to the POSIX APIs (e.g. the C standard and POSIX are entirely separate things) POSIX conventions are irrelevant anyway.
Ikr, Iâve never seen any popular projects adopt to that case, it helps with niche cases like UTF8String, here you know UTF8 is a sperate thing but think about some other abbreviations youâre not familiar with, with Pascal_Snake_Case it would be UTF8_String, itâs clear String is a seperate thing, UTF8 is another seperate thing and since the words are started with capital word we can infer easily itâs a type.
I was just looking through the binding generators for the sokol-headers, and Odin seems to use this Pascal_Snake_Case convention for types (apparently itâs called Ada_Case).
And I just wish more people would follow the Zig stdâs (and for most of the Zig ecosystemâs) code style when writing Zig so that I donât have to have a mix of conflicting styles in a single project. Looking at you, microzig.
That said, itâs just what weâre going to do in the standard library - individual projects can obviously do their own naming conventions. And sometimes projects doing their own naming conventions can be handy in its own way, the human understands that one area of code has this vibe, another has that one.
Iâll also consider changing the naming conventions of builtin functions. For whatever reason, camelCase in builtin functions just feels wrong. I often mistype @typeInfo and @TypeOf in particular.
Just as a historical note, the venerable ACE C++ libraries used Pascal_Snake_Case, for readability and for ease of moving the cursor over each separate word. Even if it was not my preferred style, I always respected the fact that they had a real, practical argument for their choice.
I likewise came from a C# background, and thought that Pascal/Camel-case were superior, even abandoning my beginner Ruby roots which uses snake case for most function and variable names.
To be honest, I disliked Zigâs naming conventions when I first started using it. At the time, I had some rough outline of an idea that there were too many different case-conventions being mixed together, though if I was being honest with myself, the reason was that I simply didnât like it for aesthetic reasons and being different than what I most often used.
I have since come to really like and appreciate it, and recognize the benefit of having different styles for the common distinctions in the grammar. Maybe it is just my eyes getting older and me getting set in it my ways, but I have also grown to like snake_case for the common identifiers that I must read the most.
Your topic actually sparked some interest and I wondered about it. I figured that there have been many studies done on this over the years. To my complete non-surprise, none of them agree with each other, and they all reach different conclusions, regardless of which methodology or metric is used. There are some obvious agreements what is âbadâ, but as far as snake_case vs camelCase, the jury is still deliberating, and likely still will be long after we are gone.
I did find a helpful article that linked to many different studies as its citations. It will make it easier for us to each pick the study that proves are preferred style is the correct one.
Also vim is better than emacs, and there is One True Brace Style.
I am happy if people just use their own style. as long as it is kinda logical and readable and consistent.
In C# I started using snake case just because it conflicted with the standard conventions: easy to distinguish my own things.
Thatâs just Systems Hungarian which is, in todays age of LSPs and good developer tooling, indeed a quite foolish and, so I think, stupid idea.
But I do like the notion of Apps Hungarian Notation where you encode Semantic meaning about the variable into it. I quite like this post which is a bit longer but gets the point across.
On the topic on style in Zig I would really like everybody to just use the one outlined in the language reference because then you can just easily read âforeignâ code. camelCase vs snake_case vs PascalCase doesnât really matter in the game scheme of things, but having one true consistent style for a language is indeed nice. Just look at all the different ways how people format their C. If I may say so: no your project or code isnât so special that you should disregard the, hopefully soon, standard for Zig.
I used to care. I donât know if a little age has eroded my sense of style or sharpened my ability to read âanythingâ at about the same speed⌠but I just donât care any more, as long as thereâs some consistency within the language, and, for a project, if it adopts its own, as long as itâs relatively self-consistent.
âDo yuo fnid tihs smilpe to raed?â I think thatâs one of the better-known âmissing letter effectâ examples; we can do a lot with a little, if we focus on the meat.