News for hackers. Stuff that matters.
Re:Ill-Advised C++ Rant, Part 2 (2016) by banachtarski on Wednesday October 25, 2017 @03:41PM (#15553406)
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.

Re:Ill-Advised C++ Rant, Part 2 (2016) by pcwalton on Wednesday October 25, 2017 @03:56PM (#15553554)
> 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.

Re:Ill-Advised C++ Rant, Part 2 (2016) by to3m on Wednesday October 25, 2017 @05:22PM (#15554403)
C# 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.
Re:Ill-Advised C++ Rant, Part 2 (2016) by fwsgonzo on Wednesday October 25, 2017 @04:37PM (#15554002)
Yep, 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
Re:Ill-Advised C++ Rant, Part 2 (2016) by metalliqaz on Wednesday October 25, 2017 @04:03PM (#15553623)
I 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.
Re:Ill-Advised C++ Rant, Part 2 (2016) by stabbles on Wednesday October 25, 2017 @03:44PM (#15553436)
Some good points. But "See reflection TS", really? That lands only in C++20. This article is from 2016.
Re:Ill-Advised C++ Rant, Part 2 (2016) by wrsh07 on Wednesday October 25, 2017 @04:33PM (#15553951)
Yeah, 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.

Re:Ill-Advised C++ Rant, Part 2 (2016) by DonbunEf7 on Wednesday October 25, 2017 @05:03PM (#15554246)
Languages 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.

Re:Ill-Advised C++ Rant, Part 2 (2016) by metalliqaz on Wednesday October 25, 2017 @03:59PM (#15553579)
This comment is hilarious. C++ is more than 30 years old now, and you're expecting users to have mastered proposed future enhancements?
Re:Ill-Advised C++ Rant, Part 2 (2016) by wrsh07 on Wednesday October 25, 2017 @04:34PM (#15553964)
If 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...
Re:Ill-Advised C++ Rant, Part 2 (2016) by PopsiclePete on Wednesday October 25, 2017 @06:26PM (#15554850)
Dude, for code I'm writing today, your future solutions are worth nothing.
Re:Ill-Advised C++ Rant, Part 2 (2016) by banachtarski on Wednesday October 25, 2017 @07:29PM (#15555184)
Most 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...
Re:Ill-Advised C++ Rant, Part 2 (2016) by dpc_pw on Wednesday October 25, 2017 @08:12PM (#15555384)
> 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

Re:Ill-Advised C++ Rant, Part 2 (2016) by ender341341 on Wednesday October 25, 2017 @04:56PM (#15554183)
> 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;`

Re:Ill-Advised C++ Rant, Part 2 (2016) by Koshkin on Wednesday October 25, 2017 @05:30PM (#15554458)
> 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.

Re:Ill-Advised C++ Rant, Part 2 (2016) by tempodox on Thursday October 26, 2017 @01:01AM (#15556479)
Just 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.
Re:Ill-Advised C++ Rant, Part 2 (2016) by drngdds on Wednesday October 25, 2017 @03:56PM (#15553549)
What's Reflection TS?
Re:Ill-Advised C++ Rant, Part 2 (2016) by Posibyte on Wednesday October 25, 2017 @04:53PM (#15554169)
It 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

EDIT: Here it is :D

https://www.meetingcpp.com/blog/items/reflections-on-the-ref...

Re:Ill-Advised C++ Rant, Part 2 (2016) by metalliqaz on Wednesday October 25, 2017 @04:00PM (#15553596)
It's a proposal for inclusion into the C++ standard.