I see four programming styles, basically determined by two binary ideas. The first bit is fast programming, which favors productivity, versus careful programming that more favors engineering. The other bit is described by the perspectives that whatever gets software working and doesn't damage the machine is permissible versus the idea that if undefined behavior (as per the ISO standard) is used, that's a bad thing.
I've seen a ton of discussion on all four combinations of these perspectives, and for the most part it seems that which is used depends on who is doing the selecting and what it is being used for -- though each programmer seems to have their favorite approach that they think is the "only" or "right" way.
This is confusing for a budding coder because people don't often rationally support their ideas. Instead, they simply state what they think is best, insult anybody who questions it, proclaim their unquestionable authority, and go about their merry way. That accomplishes nothing at all except to troll somebody trying to learn.
The part of the article that I quote changes that for me in regard to one of those four philosophies. Rather than declare that hackish tricks that are undefined under the standard are "bad" and leave it at that, the author gives us an actual reason for the idea. Namely, that an implementation may change thus leading to the failure of a program that once compiled under an older version of it.
From what I see, as I try to continue to evolve my grasp on what kind of coders are out there (and consequently, what kinds of coding), this doesn't immediately negate the idea of using ISO standard undefined behavior to accomplish something. On this very page, somebody advises that one simply avoid upgrading their compiler.
Personally, as I see that each of the four styles under these two binaries is widespread, fiercely defended, and constantly attacked, I still think that none is universally "better" than any other. Instead, it still appears to me that each is appropriate under its best circumstances, but I understand better why one of those four is not so often lauded as the other three.
Can you give an example of undefined behavior that someone has tried to exploit for productivity? I honestly can't think of anything. Usually undefined behavior is very, very hard to statically verify in source code, so it's neither practical or worth the effort to go over every line of code trying to get rid of it, but I can't think of any reason one would substitute well defined behavior for undefined behavior and claim that there is some kind of improvement in the code, regardless of practical vs. ideological considerations.
We should keep in mind there is a world of difference between undefined behavior, which I think should universally be regarded as incorrect and something to avoid, versus unspecified behavior, where the standard basically leaves the behavior up to the compiler, but the compiler is required to produce well defined behavior.
There are also these cases where something is technically illegal, but in reality is required to work and works (because platform makes it like that).
Like casting of void pointer to pointer to function. If i read std correctly this isnt allowed anywhere, so should just not compile. In reality this is required to work as both Windows api (GetProcAddress) and unices (dlsym) expose functionality of dynamic symbol (whatever it is) loading by returning void*.
4
u/[deleted] Jan 21 '13
I see four programming styles, basically determined by two binary ideas. The first bit is fast programming, which favors productivity, versus careful programming that more favors engineering. The other bit is described by the perspectives that whatever gets software working and doesn't damage the machine is permissible versus the idea that if undefined behavior (as per the ISO standard) is used, that's a bad thing.
I've seen a ton of discussion on all four combinations of these perspectives, and for the most part it seems that which is used depends on who is doing the selecting and what it is being used for -- though each programmer seems to have their favorite approach that they think is the "only" or "right" way.
This is confusing for a budding coder because people don't often rationally support their ideas. Instead, they simply state what they think is best, insult anybody who questions it, proclaim their unquestionable authority, and go about their merry way. That accomplishes nothing at all except to troll somebody trying to learn.
The part of the article that I quote changes that for me in regard to one of those four philosophies. Rather than declare that hackish tricks that are undefined under the standard are "bad" and leave it at that, the author gives us an actual reason for the idea. Namely, that an implementation may change thus leading to the failure of a program that once compiled under an older version of it.
From what I see, as I try to continue to evolve my grasp on what kind of coders are out there (and consequently, what kinds of coding), this doesn't immediately negate the idea of using ISO standard undefined behavior to accomplish something. On this very page, somebody advises that one simply avoid upgrading their compiler.
Personally, as I see that each of the four styles under these two binaries is widespread, fiercely defended, and constantly attacked, I still think that none is universally "better" than any other. Instead, it still appears to me that each is appropriate under its best circumstances, but I understand better why one of those four is not so often lauded as the other three.