I heard the opinion that STL itself is not safe and you should not use it in your projects. I want to hear the opinion of professionals about this opinion. Are there any problems associated with its use?
Closed due to the fact that it is necessary to reformulate the question so that it was possible to give an objectively correct answer by the participants Viktor Tomilov , Vladimir Martyanov , aleksandr barakin , Kromster , D-side Jan 30, 18 at 9:45 .
The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .
- fourI have not heard such an opinion. - arrowd
- 9Have you heard, by the hour, opinions that C ++ is not safe, and using it in your projects is a bad form? In the end, now what is called STL is just part of the standard C ++ library ... - Harry
- 2it is not clear why the minus is that the question is wrong. - Stanislav Petrov
- @StanislavPetrov At least there are no commas - Mishakov Maksim
- 3Advice for the future: do not turn to Stack Overflow for opinions . Opinions do not have answers. - D-side
2 answers
This opinion comes from the times when the templates were new, and each stl developer considered it his duty to add something to his implementation. For example, Scott Myers writes in Effective STL:
... in the area of using STL, there were purely practical problems that were impossible to ignore. Adaptation of any STL program, with the exception of the simplest, was fraught with many problems, which was explained not only by the difference in implementations, but also by the different level of support for templates by compilers. STL textbooks were rare, so achieving the STO programming dao was not an easy task. And as soon as the programmer coped with this difficulty, another one appeared - the search for a fairly complete and accurate reference documentation ...
The book is excellent, by the way, I recommend. But she, for a moment, is 17 years old. You have no problems now with template support by compilers? Or with the search for documentation? Or with textbooks? In IT, everything is changing very quickly (look at javascript though, they have a new framework there every day).
The next time you meet this opinion, find out what year it is from.
- fiveBut this statement does not concern security issues ... - VTT
- one@VTT, To tell the truth, I have never heard of anyone discussing the "security" of STL. Yes, and Myers does not mention this in his book. But about the fact that using STL is a bad form, I hear it not for the first time. And these judgments are from those times about which I wrote in the answer. - yrHeTaTeJlb
STL is really unsafe. And the reason is not in the templates but in the failure of the outdated concept, the disgusting architecture of the library and the ill-conceived interfaces that turn the code using it into a poorly readable code. This alone is enough to consider it unsafe. Well, as if I did not see the leading manufacturers of frameworks use it in their products. What is Microsoft that Borland / Embarcadeo that Qt use their counterparts that are much clearer made and much more convenient to use.
в провальной устаревшей концепции, отвратительной архитектуре библиотеки- please expand your thought in response. Which concept is outdated? What exactly is bad in architecture? - Jan- one
Что Майкрософт что Борланд/Эмбаркадеро ...- Microsoft is not an indicator, they have a policy of crowding out competitors .... что Qt пользуют свои аналоги- Qt is designed for binary compatibility of its already compiled dll and so libraries between versions and computers. The standard library is simply an interface specification, the implementation of which is different even between different versions of the same compiler. Because of this, Qt is essentially forced to implement the entire standard library from scratch. - Jan - 3replace the Qt functions with the STL counterparts, according to the table below. - Qt recommends using stl for algorithms. the second is that in Qt there are many inconsistencies. The most getting is a jumble of sign and unsigned types. Sometimes in the inside of one class. QByteArray.size - Signed ... - KoVadim
- one@KoVadim; I will add about a jumble of types. There is (or was) such a problem that for Qt-shnyh iterators, the
difference_typeisptrdiff_t, and theoperator-()returns anint. As a result, everything works fine with gcc and clang, but somehow msvc somehow gets a type through the fifth point, which actually returnsoperator-(), declares a variable of this type and tries to initialize it with a value of typedifference_type. As a result, there is a warning about narrowing the type, which, along with -Werror, gives a compilation error - yrHeTaTeJlb - one@Croessmah And degrade slowly in the direction of the water. embedded arrays allow a signed type for a completely different reason (because pointers). Further from the above quotation, it is said that this is not the best solution. And in order for this solution to work, they need to redo the entire stl (which is stupid and naive - we don’t know where else it will come out). - KoVadim