Bad advice and bad functions

Well since i joined this forum i have come to know about bad programming practices like using eof() or goto or system(), etc.
Suprisingly all these methods were told to me by people who are supposed to be experts of c++.
What i dont understand is that why these unfriendly functions still exist?
Shouldn't they be removed from newer versions of compilers?
Otherwise they will continue to be recommended to beginners.
> What i dont understand is that why these unfriendly functions still exist?

Because the wide experience of the C++ community has been that:
a. they certainly are not "evil" (no matter what people on forums tell you).
b. each one of them is a useful facility, which can be used safely and correctly, given the right context
c. there are programming situations where no clearly better alternative is available.

The C++ standardisation process has been quite aggressive in first deprecating and then removing features where unequivocally better alternatives are available.

For example, std::auto_ptr, std::unary_function, std::binary_function, std::random_shuffle, std::ptr_fun, std::mem_fun, std::mem_fun_ref, std::bind1st, std::bind2nd have all been removed in C++17.
There are billions upon billions of lines of code out there that use these. You can't just break all that code by removing things. Its backwards compatibility.

That said, bad and good are binary, there are grey areas. Goto is still the only way to get out of nested loops in C, and c++ allows C statements. eof is bad in a loop when used incorrectly, but it DOES tell you if you are on the end of file marker and does have valid uses. It is incorrect usage that is bad, not the function. System is a complex story about security flaws, but every replacement for it can suffer the same issue if the program called externally has been compromised.

Besides the good things said above, C++ often has ways to do things multiple ways and some ways are better (safer, more maintainable, more efficient) than others, but those others are still necessary in some specific cases. Much of the C++ Core Guidelines project https://github.com/isocpp/CppCoreGuidelines is about placing those bad (unsafe, error-prone, etc) features behind safe interfaces, such as hiding arrays behind spans and ranges, hiding new/delete behind unique_ptr, etc, so that the programs can enjoy all the good things modern C++ has to offer without giving up on any of its darkest powers.
Last edited on
> There are billions upon billions of lines of code out there that use these.
> You can't just break all that code by removing things. Its backwards compatibility.

That is not a stumbling block to eventually removing something that is clearly inferior or undesirable. That is the raison d'etre for the concept of deprecation.
https://en.wikipedia.org/wiki/Deprecation#Software_deprecation
Last edited on
Forgive me, because your name is Indian, and the description of your experiences, (and the times of your activity), leads me to think you are probably sitting somewhere in India right now. Correct me if I am wrong.

The state of computing is growing fast in India, but the global resources for the computing still can't compete with places like the USA, Western Europe, Australia, etc. So people on the forum here might often sound like we're sitting in a glass tower when we say things about modern C++.

It is an unfortunate fact that a lot of IT industry and, worse yet, University-level education in India is ten or more years behind the state of the art. What this means is that this forum is often plastered with students asking for help with code designed for things like Turbo C++ and the like. (Though, thankfully, lately that seems to be happening less and less. Maybe most Indian Universities have finally told their professors to stop requiring their students to use ancient technology and get themselves a free modern compiler to use.)

We even get the occasional person bragging about how he's part of some big IT firm in India and then suggests an answer which is absolutely wrong.

In any case, the best way to move forward -- not just for yourself but for India -- is to educate yourself to good practices as best you can, by visiting online forums like this one and stackoverflow and the like, and using good practices even when you are required to use crufty old stuff, and, importantly, push back a little when asked to do things the wrong way. If everyone does that then India's IT industry will catch up faster and compete better.

You can bet people in Dubai IT aren't using Turbo C++.

Anyway, end rant. I hope you are enjoying the learning process.

*There are a lot of really bad programmers in the USA, etc too, so don't anyone get too offended over something I didn't say.
and then there are old folks in the USA that are trying to relearn because everything we knew in 2000 is obsolete :O
@jonnin +1

My father worked in the industry back in the '60s. He has said to me on more than one occasion something to the effect that

"I used to know everything about computers. These days, the field is so large that I don't know anything any more."
@Duthomhas Yes i am from India.I am not in university but in school.
:)
And yes school teachers here are not very literate themselves.
"Well since i joined this forum i have come to know about bad programming practices like using eof() or goto or system(), etc."

eof() and goto aren't bad programming practices.
They can be used in the wrong way.

Using your logic: "hunting rifles are weapons of murder!!!11! and should be banned!!111!"
@ondrej008
OP didn’t use logic resembling anything even close to what you are accusing him of.

Welcome to the forum. Please keep it civil, and try to avoid posts that are nothing more than the equivalent of “U SUCK!!!”
Topic archived. No new replies allowed.