I've been a member of Stack Overflow for a couple of weeks now and have answered questions and read others answers, mostly in C/C++. True, I have learned about some things. For example, undefined behavior
which in the past, knowing what's going on from inside the CPU to compiler code generation, all those "seemed" defined and worked as I expected them to. I understand now how conforming to rules such as not evoking undefined behavior are good for you, even though you know in your PC, in your compiler it works without a flaw.
However, at times I got negative points for answers involving using macros or certain codes that makes me wonder why among people here, there are such very strict rules. For example, almost any time you talk about macros, people say "use functions instead". I understand that functions are better in many ways, but there are many places macros are more fit. Are macros so frowned upon here? Another example is, if for any reason you write a simple for
loop to find a character, you get a lot of comments telling you to "use prewritten functions instead" or you get negative points for suggesting the loops. I understand the functions in standard library have all kinds of error checking in them and probably are most efficient in general, but is it such a crime to write a simple loop for your own specific case?
What I'm asking is more general than these mere examples. It seems to me that among the users of Stack Overflow, there is "defined" (if not written) standard of coding in C/C++ and that's the only way they accept it. I'm not saying it's bad. I'm not saying that at all. I learned a lot myself about things that made my code not portable. However, almost all of those things turned out to be too much restriction. Things such as "if you do like this, your code won't work in computers that don't encode characters in ASCII". Do you think people will always want their code to run on all possible computers? Isn't that a bit too much? A simpler, faster method that you know works on computers you know your program would run on, seems to me a better solution than a completely portable one.
There are great codes out there that seems to me if they were judged here, they would get the worst results. Codes such as the Linux Kernel, implementation of STL that comes with g++, Mesa3D's implementation of OpenGL and so on. Look at these codes and your eyes are flooded with macros and bitwise operations. Do you condemn the programmers of the Linux Kernel too? Would you rather have your OpenGL library drop framerates by 10% but possibly run on a 16bit microprocessor too?
So, is what occurred to me true? Are people in Stack Overflow so strict on judging others' codes? Or have I just been unlucky enough to stumble upon a minor few?
Edit: I'm a master's student in robotics, my bachelors was in software engineering. My master's project was library/kernel module for a project funded by european union and through that I got offered PhD (in a subject that has to do with writing some software). I also code for fun. It's been 15 years that I'm familiar with C/C++ and 8 years that I actively code. (What I mean is, I didn't start programming just yesterday)
Update: After doing some research I found out there are a lot of C programmers, if not most, who hate C++ and a lot of C++ programmers, if not most, who hate C. As someone who finds beauty in both languages and maintains a coding style of a mixture of the two, I find those hatreds absurd. However, as it seems the majority of the programmers in either language have this hatred at least to some extent, I no longer see a reason for continuing this argument.
I came to the conclusion that I would write the answers they way I see fit, and just ignore everyone when they start throwing a fit because I didn't use a vector
or something (Seth Carnegie, the 7th comment). However, I would put a note on the bottom saying: This code is not meant for copy-paste. There may be lacking error checking. This is just to demonstrate how blabla works, and not necessarily the easiest way to do it. and other legal stuff. You know, like what you see in a EULA.
vector
or something. – Seth Carnegie Sep 12 '11 at 10:51