Would you choose an engine based on it's coding style rather than it's capabilities?

Started by
36 comments, last by Alessio1989 9 years, 1 month ago

I read people's githubs often.

Shogun.

What I'm puzzled about here is: how is knowing the type actually useful? If you see something like CountOfItems += 1, how is it more useful to see nCountOfItems += 1? Or likewise with PlayerName = "Captain Meteor" versus lpszPlayerName = "Captain Meteor"?

Isn't it obvious? Is the += operator only limited to integers? Are C strings the only type of string available? I can live without it, but I still like it. Plus I don't see what all the fuss is all about... still.

Shogun.

Advertisement

I read people's githubs often.

Shogun.

What I'm puzzled about here is: how is knowing the type actually useful? If you see something like CountOfItems += 1, how is it more useful to see nCountOfItems += 1? Or likewise with PlayerName = "Captain Meteor" versus lpszPlayerName = "Captain Meteor"?

1. Is the += operator only limited to integers?

2. Are C strings the only type of string available?

1. No, but I have yet to encounter a case where a "count" of something is anything other than an integer type of some sort. Redundant information is not useful.

2. No, but paying attention to how the PlayerName variable is actually used aside from this will clue you in to the fact that it's a C-string. Eg. is PlayerName passed into a C standard library string manipulation function like strtok or strlen? Is c_str() ever called on it? How about +=? It just isn't necessary.

I can live without it, but I still like it. Plus I don't see what all the fuss is all about... still.

The fuss is about the fact that it makes your code look like line noise, which is not commonly something programmers prefer. If you can live without it, then you don't need it and it annoys other programmers.


1. No, but I have yet to encounter a case where a "count" of something is anything other than an integer type of some sort. Redundant information is not useful

1. You haven't, that's just it. It could be a DWORD, long, even an [un]signed integer larger or smaller than 32-bits. Or it could even be a float or double. In that case, what if I just assume it's a standard 32-bit integer and try to do a bitwise operation on it?

2. The word "count" doesn't tell you much right off the bat, except what it's used for.


2. No, but paying attention to how the PlayerName variable is actually used aside from this will clue you in to the fact that it's a C-string. Eg. is PlayerName passed into a C standard library string manipulation function like strtok or strlen? Is c_str() ever called on it? How about +=? It just isn't necessary.

Not really. Strings are kinda obvious yeah (not if you're cout-ing it though), but consider this: what if we have what is assumed to be an array or pointer? How can you tell whether it is a regular array vs a vector, or a naked pointer vs a smart pointer? There's so much you can tell about a variable by how it's named.


The fuss is about the fact that it makes your code look like line noise, which is not commonly something programmers prefer. If you can live without it, then you don't need it and it annoys other programmers.

How does it make it look like "noise"? Is writing informative code a crime?

Also, I could live without many things code-wise, that doesn't automatically mean that I don't need it or shouldn't use it. That is nothing short of asinine. It's a few extra letters in the form of a prefix, how *bad* can that possibly be?

Lastly, virtually everything I code, do, believe, own, etc. annoys programmers and everyone else in general, so I could care less. I'm sorry, but nothing you are saying is convincing me that Hungarian notation is bad, and should be avoided.

Shogun.

Unless you are writing your code in Notepad, Hungarian notation is not really needed.

I would definitely choose an engine based on it's coding style :)

Well, considering that I have options to choose from, I would pick the one with a good layout, a clean syntax and tight code.

Because I know that I will be reading the code a lot more than writing it, so picking an engine/framework that matches my own preferences is absolutely an issue.

Too many projects; too much time



1. No, but I have yet to encounter a case where a "count" of something is anything other than an integer type of some sort. Redundant information is not useful

1. You haven't, that's just it. It could be a DWORD, long, even an [un]signed integer larger or smaller than 32-bits. Or it could even be a float or double. In that case, what if I just assume it's a standard 32-bit integer and try to do a bitwise operation on it?

2. The word "count" doesn't tell you much right off the bat, except what it's used for.

1. Why are you doing bitwise operations on a counter variable? A counter is something that counts. If you're going to do further operations on a counter then it has effectively ceased to be a counter and has become something else, in which case you should just create another variable or rename the old one with a name that better reflects what you're actually doing.

2. Which I am arguing is the most important thing about the variable in the first place. If I know what something is used for, most of the time what type it should be is self-evident.

I have found that it is far more informative to encode what a variable means as opposed to what it is.

Not really. Strings are kinda obvious yeah (not if you're cout-ing it though), but consider this: what if we have what is assumed to be an array or pointer? How can you tell whether it is a regular array vs a vector, or a naked pointer vs a smart pointer? There's so much you can tell about a variable by how it's named.

If I'm cout-ing, then I don't actually care what the type is, because cout handles that for me.

If it's an array, then the name will be in a plural form or otherwise indicate a collection ("apples", "appleCollection"). If it's a raw pointer I might put "Ptr" on the end, but only to distinguish it from other things in the same area of the code that are not pointers.

Most of the time I don't need to know if something is an array or a vector, they're both contiguous collections. And most coding styles I've worked recently with forbid raw arrays in favor of std::array or a similar collection.

Why do I need to know the difference between a naked pointer or a smart pointer when I'm just reading the code? When I read code, I'm usually trying to get a sense for what the code is trying to accomplish. If I need more than that, ctrl-F is very useful, and if I'm working on a particular section of code a lot I'll just remember what the variable types are because I'm spending so much time there. If I really, really need to encode the ownership semantics of a particular pointer variable in its name, then I'll probably choose to make it a bigger component of that name than a simple prefix at the beginning (which my brain could and probably would easily filter out, which I don't want).

Yes, there's a lot that you can tell about a variable by how it's named. Nobody is disputing that, in fact that seems to be the entire purpose of this tangent.

How does it make it look like "noise"? Is writing informative code a crime?

I have found that it's only informative if you've already learned Hungarian well enough not to have to think about it when you read it and are working with code that is so convoluted that following variable declarations is difficult. If you're writing code that others will read, then by using Hungarian of any sort you're forcing said others to give up room in their mental space for remembering what the prefixes mean and expend mental energy to parse them that could have gone toward actually understanding the code and solving its problems. If readers of your code don't do this, then it looks like noise (as in a random jumble of letters bolted to actually useful information) until they do. I'm not saying that writing informative code is a crime - far from it, I'm saying that Hungarian is not informative in a useful way and that there are better options, ones which impose less of a reading burden on programmers.

Also, I could live without many things code-wise, that doesn't automatically mean that I don't need it or shouldn't use it.

Paraphrasing a quote: "Programs (and other things) should be as simple and straightforward as they can be, but no more so." Hungarian notation, with its random-looking jumbles of letters, does not make programs more straightforward to anyone who isn't used to a style like that already. I have yet to hear a convincing argument as to why someone who hasn't already bought into systems Hungarian should start. If Hungarian works for you, fine, but for most of us, I doubt it would be worth picking up.

That is nothing short of asinine. It's a few extra letters in the form of a prefix, how *bad* can that possibly be?

Prefixes (and suffixes) themselves are fine. I use a number of them myself. I'm arguing that the way they're used in systems Hungarian is bad. A naming convention should be obvious to anyone who looks at the code, even if they are unfamiliar with the codebase, maybe even they're unfamiliar with the programming language itself. That means avoiding non-obvious acronyms and abbreviations (like "cs" for "critical section", "sz" for "null terminated string", and other Hungarian-isms) in favour of obvious ones (like "ptr" and "m_") and preferring to use full words where practical.

Plus reducing redundant information. Take the Hungarian "lpsz" as an example. This generally translates to a "const char *" in Win32 code. I would read that as "long pointer to a string with a zero on the end." Maybe that's useful, but "sz" already means the same thing, and is shorter. Given the syntactic rules, this is redundant, because a c-string is already a pointer (effectively). So a literal reading of this would actually lead me to believe that "lpszClassName" is a const char **, not a const char*! So Hungarian is contradicting itself here (or it's just a bad use of Hungarian, it's hard to tell really). Not only that, but "long pointer" itself is the same as "pointer" in anything more modern than Win16, so this is even worse - it's using a completely outdated naming convention that doesn't add any value. This among others is why I can't recommend the use of systems Hungarian in particular.

Lastly, virtually everything I code, do, believe, own, etc. annoys programmers and everyone else in general, so I could care less. I'm sorry, but nothing you are saying is convincing me that Hungarian notation is bad, and should be avoided.

To be fair, just about anything a programmer does will annoy some other programmer. smile.png

(also, pet hate: it's could NOT care less)


1. You haven't, that's just it. It could be a DWORD, long, even an [un]signed integer larger or smaller than 32-bits. Or it could even be a float or double. In that case, what if I just assume it's a standard 32-bit integer and try to do a bitwise operation on it?

You're not doing a bitwise operation on it because you said this was useful for understanding code in GitHub. So you brought up GitHub as counter argument then stomped on it.

2. The word "count" doesn't tell you much right off the bat, except what it's used for.

Which is what you want when you're understanding code. When you're coding on the other hand, you have an IDE to fill the blanks.

I find pretty much all practices rooted in C/C#/C++ awful. PascalCase, m_ for members, "I" preffixes for interfaces, any kind of field/class preffixes actually, underscores for everything, systems hungarian, etc.

Will I choose a lib or not for it? Well, I'm pretty utilitarian in that respect. The lib is there, I'm not going to reimplement it because I find their conventions bad, I'd waste too much time. If I can find a more appealing alternative great, otherwise I'll prolly use it anyway.

Then again, if the thing is sufficiently small that I could implement it myself, then I might do it. I'm not going to implement my own physics engine because I dislike Bullet's conventions, but I did implement my own math lib because I despise the one you can find in libGDX.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

"I" prefixes for interfaces


What's your preference for interface naming? The "I" prefix in C# is one of those things that all C# code I've ever seen adheres to. What do other languages use?

"I" prefixes for interfaces


What's your preference for interface naming? The "I" prefix in C# is one of those things that all C# code I've ever seen adheres to. What do other languages use?

I think the idea is that since C# actually has a interface keyword the prefix is redundant.

in a language like C++ where there are no real interfaces that prefix for interface classes makes more sense.

[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!



What's your preference for interface naming? The "I" prefix in C# is one of those things that all C# code I've ever seen adheres to. What do other languages use?
No idea what other languages use. I've seen it used in Java a sometimes, but my point is to use no prefixes at all. Name it like you'd name any class (although I'm a fan of the adjective naming Observable, Renderable, etc, but not to the point of forcing all interfaces to use that scheme, that would be silly).

Creeping the "I" in the interface name it just says "HEY! This is an interface!" which helps... nobody? Most of the time you'll be using objects that implement them, prefixing them makes them stand out, when the idea behind interfaces is that you forget what exactly they are, you just use them as regular objects, you just care about the methods they provide.

If you cant use an interface reference as a regular object and you have to know its specific class or if its an interface or not for some reason, then you pretty much failed at making that interface and should rethink it.

So, if knowing if something is an interface or not should hopefully make no difference when you use it, then prefixing them makes no sense to me. It doesn't adds anything very valuable and it literally "taints" every singe time you'll ever use that interface.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

The coding style of an engine has no impact whatsoever on my choice. The only decision when choosing an engine is does it get the job I need it to do done.

Even if they use camelCase, Hungarian, or Pascal notification a third party lib is never going to match your coming style exactly.

This topic is closed to new replies.

Advertisement