C# variable naming

One of the worst things you can do designing an API, a programming language, a library, probably just any system in general, is provide multiple ways to do the same thing.

This makes things messy and lead to holy wars for no reason. It doesn’t even fucking matter so much if it’s one way or another but people will debate on and on, someone will come up with “a 3rd, best of two worlds” way to do the thing, then 4th, 5th and it’ll only get worse and worse.

It’s good to listen to the community but it’s also important to set strict rules without ambiguity that you yourself follow and make others follow them as well.

UPD: My opinion on the original topic
Maybe call it m_v3fWorldTransformPosition? Or PositionOfTheObjectInSpace? Any nowadays language and IDE supports in-code function/property documentation, seeing an expression like ply.Pos, if it’s super unclear to you what it is because you fell from Moon yesterday you can hover your cursor over ply and the IDE will tell you that it’s an instance of type Player, you can hover over Pos and see something like Vector Pos - Entity position.

Some people prefer typing out whole words, some don’t, but I don’t agree it’s super necessary if it’s still super understandable, and it sure is for Pos, Dir, Rot, ply and so on in the context of game programming.

If you write tons of code you’ll find it annoying using such long variable names and the code will occupy too much horizontal space, requiring wrapping and spacing it across multiple lines when you could’ve avoided it if it was 10 symbols shorter. It’s also sometimes surprisingly harder to visually parse code with long names (even though intuitively you think the opposite) than with reasonably shorter names, so here’s that.

6 Likes

So, my final questions are:

  1. Why some variable names are shortened when others don’t? (Pos, Rot, direction)
  2. Why someone needs to shorten names of 8 letters when we all have autocomplete?

Maybe call it m_v3fWorldTransformPosition? Or PositionOfTheObjectInSpace? Any nowadays language and IDE supports in-code function/property documentation, seeing an expression like ply.Pos , if it’s super unclear to you what it is because you fell from Moon yesterday you can hover your cursor over ply and the IDE will tell you that it’s an instance of type Player, you can hover over Pos and see something like Vector Pos - Entity position .

How am I suppose to choose names for variables in code where every developer follows their own rules? It’s not about finding the best name, it’s about following one set of rules of code writing, your jokes are not funny. I’m not new to game programming as you might think, I also have experience beyond it and I find such naming decisions problematic.

If you write tons of code you’ll find it annoying using such long variable names and the code will occupy too much horizontal space, requiring wrapping and spacing it across multiple lines when you could’ve avoided it if it was 10 symbols shorter. It’s also sometimes surprisingly harder to visually parse code with long names (even though intuitively you think the opposite) than with reasonably shorter names, so here’s that.

What’s so bad about breaking code into multiple lines? I don’t get it, this is a standard practice in most code formats along with maximum line length limit. There are many reasons why you might find the code harder to read and I’m sure this is not the case with full words.

1 Like

I do agree that it’d be much nicer if there was a convension used for all names in the project, that’s for sure.

I’m just saying it’s not always bad to shorten names as some people here state.

This wansn’t addressed directly to you. I wish these were just jokes but I know people who write code like this today. I was trying to show that variable naming can sure look too verbose, but deciding if a particular case is or isn’t is a very personal thing and there are arguments for both sides.

I didn’t say it’s something bad, you should always do that, I said sometimes with long names that’s an additional step to making code readable which happens more often with long names than short names.

1 Like

I think you can apply the same questions to most spoken/written languages, like English, French, Spanish, Portuguese etc.

No language will be 100% exact on how you speak or write, at least not the ones I mentioned. Sentences and even words can have multiple forms, especially when you include informal language. In programming, ‘position’ is, sometimes, written as ‘pos’, just like in english ‘you’ can be written as ‘u’ or ‘please’ as ‘pls’.

So yeah, it would be easier if programmers could name variables/classes/functions all the same way, but you shouldn’t expect that, we are talking about individuals and while you might think ‘pos’(as ‘position’) can be problematic, many others won’t see a problem and that’s probably enough reason for them to name stuff as they want.

2 Likes