Live data from Hacker News

Help me sort out the meaning of “{}” as a constructor argument

scottmeyers.blogspot.com

61–70 of 181 posts

Re: Help me sort out the meaning of “{}” as a constructor argument

#61

I've been programming professionally for over 20 years, most of it in C++. I really like developing fast code, and C++ used to be my favorite tool for the job. But the language complexity gets more insane with every revision. It's now at the point where Scott Freakin' Meyers can't figure out the interpretation of a short little chunk of code. I'm now actively looking for gigs in which I can develop high-performance c…

Any sense of where the C++ refugees are heading? Rust? Go?

Java/C#, though the complexity is now matching C++, especially with all the new fashionable functional "features" most large code bases are a huge mishmash of styles and complexity that is making me wish for sensible C++ developers again.

Re: Help me sort out the meaning of “{}” as a constructor argument

#62

The answer to the problem can be found in the comments, but not in a single place: X {{}}; will: for T = DefCtor call the initializer_list constructor with a single default constructed element. The outer brakets are for the initalizer list and the inner ones are for the DefCtor constructor. The brackets for T constructor itself are allowed to be elided. for T = NoDefCtor, the previous overload resolution is not valid…

My god c++ is atrocious.

So was this comment. Please take the negativity to r/programming.

Re: Help me sort out the meaning of “{}” as a constructor argument

#63
post #49

Earlier quoted context omitted.

Most languages have Undefined and Implementation specific behavior. Few languages have so carefully specified their undefined behavior as C++ though.

Any examples? My experience is you will frequently be bitten by undefined behaviour in C++ if you don't know the rules well but this is very rare in other languages. It's rare you're going to get a segfault or the whole program crashing in languages like Python, Java and JavaScript.

Those languages all have heavy runtime environments; if a segfault occurs it's an interpreter bug. Whether the mistakes you can make are a result of "undefined behavior" is a different question whether from the consequences of a mistake are an abrupt termination, or an abrupt termination with a helpful error message.

Re: Help me sort out the meaning of “{}” as a constructor argument

#64
post #57
post #51

Earlier quoted context omitted.

It's what prepares you best as a young person to pass interviews at companies of your dreams or win ACM ICPC and similar competitions.

None of the companies of my dreams was using C and "ACM ICPC and similar competitions" was done in Prolog.

:)

Re: Help me sort out the meaning of “{}” as a constructor argument

#65

C++ FAQs are full of massively complex conundrums like this for problems you just don't get in other languages. I used to love learning all these highly specific C++ rules and playing language lawyer when I didn't know any better and thought it was a good use of learning time to become an expert. I've since moved on to languages that weren't full of problems like this that let you just get on with what you're meant t…

> I've since moved on to languages that weren't full of problems like this I think you mean aren't full of those problems yet . :) There's a lot of nasty corners in C++ but almost all of them are because it effectively has 40 years of wild success. (I say 40 because C++ inherits C's baggage and success.) It's totally reasonable to pick a younger language with fewer warts. Become an expert in it! Be productive! Ship l…

Eh, from what I've seen, a lot of what people now consider to be the "warts" of C++ were there when I learned it in the '90s. Not all, obviously — but a lot of them, like the STL and all the relics of C, are quite old.

It seems similar to JavaScript. There were some initial good ideas and a bunch of early bad ideas and we're stuck layering improvements over that very uneven base.

Re: Help me sort out the meaning of “{}” as a constructor argument

#66
post #40
post #29

Earlier quoted context omitted.

Same here, I will look at Scala Native, like Scala, but instead of JVM as the target platform, its using LLVM

You'll go from bad to worse; Scala is to Java what C++ is to C; barely anyone understands all constructs in either language. You either know everything or nothing (i.e. you can't understand somebody else's code unless you enforce rules or know the complete language in detail).

Even if C++ have been the way I've earned money the past +20 years, I've programmed quite allot of Scala in my spare time. If find the language beautiful in its compact, expressive syntax, I also like the standard lib and the vibrant community. Being able to mix OO and functional programming, is also something I enjoy very much.

So being able to use this language as a system language, I very much look forward to.

But your mileage may vary.

Re: Help me sort out the meaning of “{}” as a constructor argument

#67
post #8

Earlier quoted context omitted.

C++ is hard. If one sticks to a strict subset it is a nice language. The problem is the code one didn't write. Even the STL is ugly to use. They are trying to fix the language by adding features but it's like Javascript, the old ugly ones are still part of the spec.

The worst part of the JS "enhancements" is trying to make it more like Java, rather than bringing it back to its Lispy + Smalltalky roots. I guess the assumption nowadays by The Management is that programmers are too stupid to learn anything new delimited by other than curly braces, or learn how to backtrace data flow between functions, rather than debugging by property-setter breakpoint.

Can you give me an example of a "JS enhancement" you are talking about? Its not that I don't believe you I just am curious. I haven't changed the way I, personally, written Javascript since jQuery came out so I'm not up with the new stuff.

Re: Help me sort out the meaning of “{}” as a constructor argument

#68

Earlier quoted context omitted.

My god c++ is atrocious.

Back in the 90's I was working on an operating system kernel that was written in C++. I had read up on the language and had done a lot of compiler work, so I was kind of a local tutor. I'll never forget my boss' reaction when he overheard me tell a coworker "look, if you want to expose your private parts here, you'll need to make a friend."

The old idiom I learn in college a long time ago was "only your friends can see your privates."

Re: Help me sort out the meaning of “{}” as a constructor argument

#69
post #66
post #40

Earlier quoted context omitted.

You'll go from bad to worse; Scala is to Java what C++ is to C; barely anyone understands all constructs in either language. You either know everything or nothing (i.e. you can't understand somebody else's code unless you enforce rules or know the complete language in detail).

Even if C++ have been the way I've earned money the past +20 years, I've programmed quite allot of Scala in my spare time. If find the language beautiful in its compact, expressive syntax, I also like the standard lib and the vibrant community. Being able to mix OO and functional programming, is also something I enjoy very much. So being able to use this language as a system language, I very much look forward to. But…

Sure, I use and like both of them. C++ for 3D graphics, Scala for Big Data. Yet I have seen so many things go wrong in both of them so my perspective is a bit different. Imagine if somebody redefines basic operators to mean something different, starts throwing int as exception in C++ or use templates with template parameters with number parameters and you have to figure out what exactly does this thing do? Or in Scala if somebody feels super clever and redefines half of the language by preparing some half-baked barely functioning DSL unable to compile a slightly different code than expected and you have to use it? It's the price you pay in both C++ and Scala for expressibility.

Re: Help me sort out the meaning of “{}” as a constructor argument

#70

C++ FAQs are full of massively complex conundrums like this for problems you just don't get in other languages. I used to love learning all these highly specific C++ rules and playing language lawyer when I didn't know any better and thought it was a good use of learning time to become an expert. I've since moved on to languages that weren't full of problems like this that let you just get on with what you're meant t…

I can see why he is taking time off C++ -- I have read his Effective Modern C++ and it did not encourage me to want to understand the depth of C++ anymore. Ruined my desire to be an expert -- does not lead to sanity.

    “The object of life is not to be on the side of the
     majority, but to escape finding oneself in the ranks 
     of the insane.” 
          ― Marcus Aurelius, Meditations
Post reply on HN