7 ms·
No unique ptr, auto, or for each loop? No thanks
by google234123 5y ago
No unique ptr, auto, or for each loop? No thanks
- uwagar 5y agoi write/maintain solo this software for 15 years and just dont want to start doing autos in for loops. then i have to go and change all the loops otherwise it would bother me. i dont want to go back and start messing with code that is pretty solid all these years.
- ncmncm 5y agoThe answer is simple: just don't. Write new code the new way, and leave old code that works alone. There will never be a case where you wonder why old code looks like old code. Continuing to write new C++03 is just masochism. You might find reasons to switch some old stuff to use move semantics, eliminating reference counts, which is a small job. Leaving alone stuff that doesn't need to change needs only discipline, not time. Discipline builds with use. I recommend it.
- uwagar 5y ago> Continuing to write new C++03 is just masochism disagree. this keeps things simple, readable and maintainable. beyond STL i havent found need for any new data structures or algorithms. i roll my own for domain specific (audio/graphics). > Discipline builds with use. I recommend it sure daddy. perhaps if the c++ committee had discipline they wouldnt have added these crazy things to the language too and made it a mess that it is today. however we masochists are pleased with the concession offered by stroustrup's one-liner: 'if u dont use it, u dont pay for it'
- maccard 5y ago> disagree. this keeps things simple, readable and maintainable Unique pointers pre C++11 are fundamentally broken, and smart pointers are the poster child for modern C++. Other features like nullptr, enum class, range based loops, and constexpr provide huge gains in readability too. > i havent found need for any new data structures or algorithms That's great - however the unordered contains are for many people a drop in replacement with a performance boost that came in C++11 .
- simplestats 5y agoHow hard is it to read a "for" loop? Even when programming in python, half the time I find myself switching to a simple loop over an index because I realize I need the index. Often it's for debugging, because that index has a real meaning I can interpret when I see it. Along those lines, I think the real disconnect in the argument here is in terms of what kind of problem people are programming for. For many applications, advanced C++ is solving problems they don't have. The above poster mentioned audio. The data there is in single (or perhaps few) big buffers with a very simple and regular structure determined by international standards. They only need a few simple pointers. Or maybe just std::vector. Similarly just a few types also with real-world meanings. Debugging may require them to check the processing in ways that abstraction, type-checking, etc. will only get in the way of. And new features may not work within whatever abstractions had been put into place for previous features anyway, because the features relate to the underlying data.
- dragonwriter 5y ago> Even when programming in python, half the time I find myself switching to a simple loop over an index because I realize I need the index. If you need to iterate over an iterable xs and discover you need the index as well, in Python you shouldn't switch to a loop over the index, you should switch from: for x in xs: ... to: for idx, x in enumerate(xs): ...
- maccard 5y ago> How hard is it to read a "for" loop? for (std::unordered_map<std::string, int>::const_iterator it = some_map.cbegin();it != some_map.end(); ++it) is pretty damn unreadable (and for bonus points it doesn't compile) compared to for (const auto& keypair : some_map) Which doesn't have the possibility of the issue in the previous snippet (cbegin != end rather than cbegin != cend) > For many applications, advanced C++ is solving problems they don't have. No-one here is talking about advanced c++, we're talking modern c++. > The above poster mentioned audio. ... They only need a few simple pointers... And we all know that audio is immune from massive security vulnerabilities, right? [0] "New" features like nullptr (instead of NULL), unique_ptr, move semantics as examples can just flat out avoid classes of bugs that come up in low level programming, and features like constexpr and static assert can make runtime checks compile time checks instead. All these features can be escape hatched if you really really need to just cast to a void pointer to fill a buffer at the end, but the surface area for nasty bugs is significantly reduced if you do so. [0] https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-41331 https://msrc.microsoft.com/update-guide/vulnerability/CVE-20...
- ncmncm 5y agoC++03 is Turing-complete, implying nothing in any newer Standard is "necessary". Yet, many things were added, for reasons. That you have failed to learn to understand those reasons is not a fault in the Standard. Blaming your own failure to to learn on the committee does not fool anybody.
- uwagar 5y ago> C++03 is Turing-complete thank god for that. and also thank god that it is not a proprietary language/platform. eg., Apple otherwise we would be mandated to write in the latest C++. >That you have failed to learn to understand those reasons is not a fault in the >Standard. Blaming your own failure to to learn on the committee does not fool >anybody what you call as my failure to learn is not remotely unique to me. many others more eminent and eloquent than me (and you too) have said more unkind things about C++, least being the phrase 'cognitive load'. the 'trouble' with software is it its impossible to leave it alone. an 'update or perish' sword hangs above it. and C++ has swallowed the bait totally. it has competed with the joneses all the time: oh Java has garbage collection, why cant C++ have that too?..oh well cant cos...our users write imperative, sequence critical software that we cant have unpredictable, behind the back GC...so hah smartpointer, nullpointer kludges. oh LISP has lovely lambdas, why C++ has no lambdas?....well we give u lambdas but please close ur eyes to that horror-syntax; hey we can give static const variables values in the struct/class declaration, why not other variables?...sure that isnt a big problem! and the horror of all...C++ so proud of be a type-safe language yet modern programming is all about type-free so hah lets give u auto! what if i used auto as a var name in my code. tough luck. gotta change it dumbo. u are a bad programmer to make a variable name with just 4 letters. C++ is so thorny, every symbol impregnated with meaning. walking on egg-shells, no wonder they call it 'cognitive load'.
- kazinator 5y agoMore like, Wirth's Pascal from 1970 has broken, downward-funarg only local functions? So does GNU C. Why can't C++ have some similarly lame local functions? And then make them anonymous like lambda? Only we can't introduce a lambda keyword. I called static's agent, but evidently static is tied up playing five roles already. I know, let's use the array brackets: they have not had a good diddling.