Would using underline in C# be good practice?

Asked

Viewed 355 times

5

The question refers to development pattern and good practices.

I come from a Javascript and PHP world, work for 12 years with development, and I’m very used to using underlines _ variables, such as for example nome_completo.

But I am starting to develop in C# and it is not customary to do this in high-level languages, in college when I saw Java already noticed this, it is customary to write nomeCompleto.

If I keep using underscore in C#development, would it be good practice? Does anyone use this pattern as well? Or will I have to give in and change this behavior?

2 answers

9


It’s neither good nor bad practice, it’s style.

Not to mention that good practice is usually a rule without explanation, so one takes it as a good thing without even knowing why and ends up becoming bad practice because it uses something potentially good in the wrong way and becomes bad. If people let go of this idea of good practice they would program better.

It can be used normally, the language accepted, so it’s not bad, if it were, it would prohibit.

The standard that was agreed to adopt in C# is not to use _ nor in the beginning, nor in the middle of the identifiers of all kinds. Some people violate it, but it gets weird for people who are used to codes in this language.

Today the underline has specific semantics in the language (value discard) using alone (no other characters), so it can make it a little difficult to read some codes, nothing serious, but creates some visual confusion.

This has nothing to do with the language being of high level, depends on culture created, that’s all.

Just remembering that JS doesn’t adopt this style either (Google, Douglas Crockford), some people adopt. In PHP it is inconsistent. So I probably wasn’t following that "good practice".

If you do so in C# your code will look alien to other people.

  • Thank you for the opinion, it would really seem alien, I agree with you. In all the companies I worked there is the fight "whether use or not use underline", it is similar to the fight "key in the same line or key below" (I am the key team below hehehe)

  • It’s not an opinion, it’s a fact, we don’t give opinions here.

  • Okay, thanks for the suit

  • @Maniero, but JS uses underline yes.

  • @Miriancherbo I quoted two references you can quote from.

  • @Maniero, you said yes, but they’re not official language links or her breeding grounds. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Values,_variables,_and_literals#Vari%C3%A1veis

  • @Miriancherbo But they are guides who people follow. What you mentioned is not a guide, and even if it were, it would not be official because there is no official. Being able to use doesn’t mean you should use.

Show 2 more comments

2

What I recommend to you is to use the name convention of the team or project in which you are inserted. This is more important than "debating which naming convention is best used".

By doing this you ensure that all programmers use the same nomenclature and understand each other. In the end the project will be at least consistent in terms of names, which ends up being worth much more than it seems. And it also limits the margin for fighting since everyone uses the same naming convention.

Now if you are going to start a new project, either alone or with a team in which you decide the nomenclature, you can opt for any one. It may even be that all programmers are more accustomed to Snake case (the underscores) and that they are more productive that way.

It is worth noting that Microsoft has defined the nomenclature patterns that they recommend, as @Maniero has already mentioned, and are the ones you should follow if you don’t have a strong opinion to choose one of them.

If you follow the nomenclature standards defined by Microsoft, your code comes out with the nomenclature most used in the C# world and so your code will be more natural to other C# programmers and vice versa.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.