-2

Often in math a vector or matrix will be denoted by a single capital letter. Would it be bad to have some variables such as this? Vector3 A = ... int Bx = ... int By = ... int Bz = ..

I would normally never do his but it seems weird when doing some vector math, especially when using ints and capitalizing the component instead of the vector name.

closed as primarily opinion-based by gnat, dagnelies, David Arno, amon, Tulains Córdova Oct 10 '16 at 19:02

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    People with think it's the class A and it'll be no end of confusion. A better question is why are you choosing between A and a when both are terrible names (rather that forceVector for example) – Richard Tingle Oct 10 '16 at 13:16
  • @Richard Tingle Sometimes it is not so easy to name vectors depending on what they do and is easier to document when their purpose is. Take for example this archive.gamedev.net/archive/reference/articles/article676.html – user3441843 Oct 10 '16 at 13:57
2

In general, it's better to respect the conventions of a language or framework as it lowers the cognitive dissonance for anyone reading the code (including you in years to come).

However, it is perfectly reasonable to have exceptions where it helps with the understanding of the code. For example, where you are coding up an algorithm, say, that is based on an academic paper. In that situation it may help with understanding if you follow the paper's conventions to some extent (assuming you link to the paper in your comments or similar).

In your comment to @Richard Tingle, you link to an article that has a more mathematical convention. If you are coding up a portion of that paper, and you are linking to it in your comments, then it may well be sensible to use their conventions.

  • 1
    @notifications don't work in answers. – Robert Harvey Oct 10 '16 at 16:37
2

This type of naming scheme reminds me of a physics class or a math class. I really recommend you refrain from using naming conventions from other fields as most fields focus far more on truncation than readability.

I would suggest sticking to normal conventions unless you are absolutely certain that people reading it will be able to understand the intention. For instance, in the case of generic programming, people will often use a single capital letter. In your case however, I do not believe people reading it would be able to determine your intention.

Think of it this way. I don't know what the intention of those vectors are as an outsider, and that's a problem. I should be able to immediately know the purpose of those variables, or have a good idea by simply reading the names.

If you think for a bit I'm sure you can come up with a more suitable name like textureCoordinates (if this is indeed what you are trying to implement). Otherwise you're going to have to leave comments giving a short description of what your variable is used for, which can be quite annoying for those who may have to keep going back to it.

  • 1
    Variable names don't always represent the programming domain; they often represent the domain for which you're writing the program. – Robert Harvey Oct 10 '16 at 16:35
  • 1
    Yes, the names themselves will be, but the convention will not. You won't use the same naming conventions in mathematics as you would in a program that is doing something mathematical. For example, if you are implementing rotation using quaternions, you wouldn't name every variable with a single letter, you'd give them descriptive names based on what they are being used for in the context of the program. – imnota4 Oct 10 '16 at 16:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.