šŸ  Coding conventions /or/ Why you canā€™t be a normal?

Denis Kuzmin
5 min readAug 15, 2019

--

What is your favorite coding style or preferred coding convention? And what specific style are you finally using because of your team, company, projects, and so on? šŸ„

About opening illustration see below.

The original article was published by me at June 2017 for G+. Here, I just want to continue my thoughts with some updates. And finally to check the medium platform.

I am saddened by the fact that the existence of various decorative conventions on the style of coding in various languages increasingly dominates the programming language itself.

Although the automation is available through various tools for your personal preferred style in X project and its related workflow, weā€™ll just try to look at the darkest side of any reference standardization.

Despite the fact that all this has a positive effect on integration involving these processes in future like for any science or technologies at all, ā€¦

Is it possible to push oneā€™s own preferences against corporate standards?

Well, Who knows ā€¦

Java culture

Everyone who knows me better already knows that I love Java style, its culture, and its spirit at all.

Because of ā€¦ I donā€™t know, itā€™s really clear for the meaning by my view, and this is really good on different occasions.

Specially and not, but partially I use this with lot of other languages like C#, C++, JavaScript, TypeScript, PHP, ā€¦ if itā€™s possible of course.

Because usually we also need to follow the rules from existing projects. Therefore, for 90% itā€™s only the new project that you will coordinate and support.

So when you see again some new convention for specific language, your first thoughts

ā€œno, no, noā€¦ I really do not want to do thisā€

And moreover, how about internal coding style for project, team, etc.

It looks like some big guys (who has weight and influence) are just trying to impose their style, their preferences.

The good example: PSRā€™s of php (PSR-4 and so on) ā€” oh my God ! are you really ?

C# and its corners (sharp! corners)

We have even something more like an Capitalization Conventions. And weā€™re talking not about framework or some specific engine as the base for other project. No, weā€™re talking about entire language specification. Meet the Voluntary enforcement recommendation ā€˜as isā€™.

And for example, this is PascalCasing that you need to follow for your legit code in C#

I really donā€™t like the use of basic fields and methods in PascalCasing manner.

Who else?

Add here CA1707 rule when by convention, identifier names (+namespaces) should not contain the underscore ā€˜_ā€™ character.

I could say what I think:

Hey doctor, I have a purchased `r-eg` web domain and I just need an `net.r_egā€¦` namespace use. Should I buy new domain specially for this rule?

So, Whatā€™s wrong with you? When even VS2017 against you by default, and now indicates part of this amazing rules via green underline, for example, for any method names in camelCasing:

I miss you Java. Wait, C, C++, JavaScript, TypeScript, PHP, Python, even Lua, hmm ā€¦

Why it cannot be a common practice at all. Netbeans example

The example below will illustrate how part of this ā€œgreat rulesā€ cannot be a common practice at all. Where for ā€˜common practiceā€™ I mean such as `I` prefix for interfaces and so on, you know.

I remember some rules in Netbeans (~2013 I think) but for most common practices such as nesting level when no more than 3ā€“4 (number of nested braces).

I agree fully that big nested level is not convenient and usually Iā€™m also writing special logic to reduce lot of possible levels. My basic trick is:

But :) Did you see C# ? the following example below is normal case because it contains only minimal units:

Did you say about 3 ? about 4 ? huh ! Netbeans exactly counted levels including method and class by default.

Well, about 20ā€“30 it will be really scary anyway. However, I think You Understood Me.

Update from 2019: modern C# compiler provides `=>` for properties & methods declaration. But this is another story.

Seems itā€™s very elegant, laconic, and reasonable!

Hmm, wait a minute. What about this in C#

The is part from LSender, part of Conari engine ā€” https://github.com/3F/Conari

And seems itā€™s very elegant, laconic, and reasonable ā€” that I think, and ā€¦ Should I also declare my manifest and new convention to use all static methods in PascalCasing, and use camelCasing for other things just because I like this due to laconic and more understandable way.

Because I just want to see this also from other src. Because Iā€™m tired of customizing tools for myself. Right ?

It would be good for me at least. But wait again, we can also consider another justified way, and ā€¦

Inconsistency even among big guys

ā€˜IDE1006 Naming violationā€™ rule (like in my old code here) much more interesting to compare together with internal code from Microsoft.

See:

Everything was fine even for Microsoft! Before some new changes in one sunshine day <_< and ā€¦

But today even some components from Microsoft still generates incorrect code for IDE1006 rule inside VS2017.

Fortunately we can still suppress IDE1006 rule same as CA rules, but ā€¦

Conventions and standardization are not evil!

Yes! some convention is needed for unified style at least for one project, team, and so on. However, every man to his own taste, and ā€¦ <_<

The basic units like: PascalCase for any class names; interface names with `I` prefix (like ITask, IData, ..), uppercased const, etc. The is de-facto for all practice in any places, and I support this 100% because of transparent logic.

But specific standards/force-recommendations like PSRs ā€¦ quiet horror.

So, Dear big guys, please donā€™t make such plugs from your own habits! Be a strong but more flexxxxible.

OP illustration

This is my very old ASM code and its snake_case style.

As I remember, I used snake_case by default also for all C/C++ program in that period.

But, after Java ā€¦ now you know.

Final thoughts

So what are your thoughts? What is your personal way?!

Donā€™t give up. Rules are configurable but only if you really know what are you doing there. Or follow us if you donā€™t know or not sure yet.

Thanks for reading. Went to suppress CA1707 rule for my namespaces!

net.r_eg.MediumPost1

Side Note from 2019

Related thoughts now can be found on:

Related OpenSource projects:

--

--

Denis Kuzmin

怌 Software architect 怍Analyzers/parsers, compilers/VM, math, stats, lot of plugins, libs, tools, opensource, ā€¦ I love šŸ–¼ļøšŸŽ¹šŸŽ»šŸš“ā€ā€¦ github.com/3F