5 ms·
This person is not a very good C++ programmer. Also for some of the things he mentions, it will be covered by the Reflection TS. 1. Size of a static array: Use
by banachtarski 9y ago
This person is not a very good C++ programmer. Also for some of the things he mentions, it will be covered by the Reflection TS.
1. Size of a static array: Use std::array please
2. Maximum value of an enum: See reflection TS
3. Converting enum to string: ditto
4. Converting string to enum: ditto
5. #pragma once: see modules. They are in fact trying to make something better. There are also some cases where you don't want/need it
6. C99 designated initializers. They are there!
7. Binary file includes. Ugh this is just such a dumb idea I can't even. When do you want the file to load? When the executable does? What if you want to read it in chunks? This idea is not well suited for a systems-oriented language
8. FourCC codes. Again, this is a silly idea not even worth addressing. Just define it yourself. C++ is a programming language. Not your media toolkit
9. do/while(0). What are you using macros for in 2016 (the time of writing)?
10. preprocessor gripes. Stop using it! You have <type_traits> and stuff now
11. Switch/case is stupid. No it's not. You want fall/through cases as well and if you can't see why, don't criticize. This is true in pretty much EVERY language that supports switch/case
12. Still no strong typedefs. There are! Use the explicit keyword on a constructor definition.
13. Types as Primitives. See reflection TS
Basically, this feels like any other "C++ rant." Someone who didn't learn the language properly or respects what the language needs to achieve.
- stabbles 9y agoSome good points. But "See reflection TS", really? That lands only in C++20. This article is from 2016.
- wrsh07 9y agoYeah, but look at when C++ started getting regular releases. These are hard problems, and the things in 11, 14, and 17 are useful. Ultimately, people [on the committee and developing the language] are prioritizing what they need. It's not a closed process; it's just a slow one.
- drngdds 9y agoWhat's Reflection TS?
- metalliqaz 9y agoIt's a proposal for inclusion into the C++ standard.
- Posibyte 9y agoIt took me a minute with a few googles, but the TS in this case means "Technical Specification", which helped out a ton with searching. Unfortunately, I'm still not 100% this is what they're referring to, but I think this is it. https://isocpp.org/files/papers/n3996.pdf https://isocpp.org/files/papers/n3996.pdf EDIT: Here it is :D https://www.meetingcpp.com/blog/items/reflections-on-the-reflection-proposals.html https://www.meetingcpp.com/blog/items/reflections-on-the-ref...
- pcwalton 9y ago> This person is not a very good C++ programmer. Am I a bad C++ programmer for agreeing with some of it? > 5. #pragma once: see modules. They are in fact trying to make something better. There are also some cases where you don't want/need it The fact that modules have taken so long, and still have prominent members of the community saying they need to be sent back to the drawing board, is a legitimate criticism. > 7. Binary file includes. Ugh this is just such a dumb idea I can't even. It's a useful feature, much used in the language I work on, allowing you to distribute a program that needs just one or two static data files as a single executable. It's also good for packaging data as libraries: for instance, Unicode libraries need a lot of random tables and it can be convenient to store these in binary form. Having to embed binary in C/C++ syntax as, say, ICU does just adds parsing overhead at compile time for no reason. > 9. do/while(0). What are you using macros for in 2016 (the time of writing)? There are lots of use cases of macros, too many to list here. Templates don't always suffice. > 11. Switch/case is stupid. No it's not. You want fall/through cases as well and if you can't see why, don't criticize. This is true in pretty much EVERY language that supports switch/case I designed much of the pattern matching system in an industry language without fall through in switch case and I have never missed it. Nor has anyone else in the community I know of.
- metalliqaz 9y agoI think you can regard switch/case as syntax sugar for a series of if/else. So fallthrough may not be needed but more sugar is nice to have available.
- fwsgonzo 9y agoYep, I also think modules are still relatively far away. I also hope that the C++ community can embrace some package management system.. at some point in time. Hopefully before I die
- to3m 9y agoC# lets you do "goto case XXX" to go to another case, and empty cases fall through to the next. This is a bit inconsistent, but it at least retains the useful fall-through case, gets rid of the usually-undesirable case, and still accommodates the occasional exceptions.
- metalliqaz 9y agoThis comment is hilarious. C++ is more than 30 years old now, and you're expecting users to have mastered proposed future enhancements?
- wrsh07 9y agoIf you're going to complain about missing features in the language, you should probably be aware of what plans are being made for the language's future...
- PopsiclePete 9y agoDude, for code I'm writing today, your future solutions are worth nothing.
- banachtarski 9y agoMost of these features are available in the core language already. The ones that aren't are implemented in the form of libraries. Like every other language...
- ender341341 9y ago> 7. Binary file includes. Ugh this is just such a dumb idea I can't even. When do you want the file to load? When the executable does? What if you want to read it in chunks? This idea is not well suited for a systems-oriented language This can be really useful in embedded devices where there is no file system but I don't really see the need for it to be part of the language, every time I've needed it the toolchain came with build tools to handle this. > 11. Switch/case is stupid. No it's not. You want fall/through cases as well and if you can't see why, don't criticize. This is true in pretty much EVERY language that supports switch/case a smarter option may have been to require an explicit break or fallthrough keyword but we're a good 40 years late. >12. Still no strong typedefs. There are! Use the explicit keyword on a constructor definition. Define a new wrapper class (maybe I'm missing something)? It would be a lot nicer if you could do something like `typedef explicit int FooId;`
- Koshkin 9y ago> Define a new wrapper class For simple types, for which this makes most sense but from which you cannot inherit, it is a lot of work.
- tempodox 9y agoJust to play devil's advocate, you could make a template for defining such wrappers. But then, it might just as well be built into the language for elimination of such boilerplate.
- DonbunEf7 9y agoLanguages where switch-statements or switch-expressions don't fallthrough by default include Ada, C#, E, Go, Monte, Perl, Swift, and I think basically every flavor of Pascal. "Pretty much every language," right? C++ is right in there with C, JavaScript, and PHP.
- dpc_pw 9y ago> This person is not a very good C++ programmer. This is the biggest thing that is wrong with C++. Everything is always stupid human's fault. :D