Live data from Hacker News

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

scottmeyers.blogspot.com

91–100 of 181 posts

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

#91
post #49

Earlier quoted context omitted.

> Then, one day, decades and several versions hence, you may find yourself now dealing with all of the warts that language has accrued over time. What languages are getting even close to being as bad as C++ in this respect though? Java, Python and JavaScript have been around for a while now for example and they seem more opinionated in a way that stops too many warts from appearing. C++ has undefined and compiler dep…

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

Undefined behavior is not specified, by definition! It is the absence of requirements, including the requirements to diagnose.

C++ has something called "unspecified behavior" also, which is stronger than undefined, because it gives requirements. It denotes some circumstances when an implementation can behave in one of a finite possible ways (none of which fail) and must choose one of them without documenting which choice is made. For instance the expression f(a(), b(), c()) can call the functions a, b and c in any of the six possible permutations of the order: no particular order is specified. (This arises due to the order of evaluation of function arguments being unspecified, together with the sequenced evaluation of function calls.)

The specifications of C and C++ contain large number of places in which they carefully state that no requirements apply to some situation. This is not a good thing; it's basically a myriad holes punched in the requirement spec, any one of which could be a pitfall.

Few languages are so chock full of holes in their requirements.

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

#92
post #11
post #4

Earlier quoted context omitted.

Like "Wargames", the best way to win is not to play. Between moving from MS to POSIX environments in the 90s, and the "death" of Borland, this left me with few options other than another Faustian deal with Java-land, alas. I'm actually liking Javascript nowadays, though. Especially as more of an FP-capable language than an OOP-mandatory language.

I'm loving the fact fact that languages seem to be moving towards some of the better parts of FP and away from some of the worse parts of OOP. I'm not particularly fond of fully FP languages but they have some really nice ideas that I've been enjoying using.

I agree. And for myself at least, I could also say:

I'm not particularly fond of fully OOP languages, but they have some nice ideas that I've been enjoying using.

If a thing I want to make is a stateless process, modeling it as a function seems nicest. If that function can be truly a function (i.e. pure), that's best. If it can be semi-pure, in the sense that its only access to mutation is via its arguments (e.g. it takes in a DB handle explicitly), that's alright. If it has other access to global state, perhaps reconsider.

If a thing I want to make is a container for state, and its state transitions have some structure to them, then I hear there's this thing called an ADT, and OO seems pretty nice.

Neither of those statements is an architectural manifesto, and OO design and functional design both seem like bad ideas to me. That is, requiring modules to be instances of language-syntax-level functions or language-syntax-level objects seems like a bad idea to me. I guess if you go read the plain-English descriptions of Smalltalk objects, that matches my idea of how modules should work, except when they should be functions in a plain-English sense.

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

#93
post #79

Earlier quoted context omitted.

Java is over two decades old and one of the most widely used languages in the world. It has absolutely stood the test of time. While it does has its pain points its nowhere near as terrible as C++ and (in my opinion) is improving with new versions, and honestly, I think its a joy to program in though that might not be a "cool" thing to say. Whereas C++ is a chore to program in. That's my opinion, maybe I'm just too u…

Well, there's not a lot of room for problems to crop up when all one can do is define classes :) Still, here's a few for you: the design of Cloneable is considered to be a mistake, as are exception specifications. These have real negative consequences. File IO was laughably bad and completely unintuitive needing several classes for the simplest of tasks (perhaps this was fixed more recently, but funny you should ment…

File IO got a rework with java.nio.

"Several classes" Are you taking about input/output streams, not file I/O?

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

#94
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.

Undefined behavior is not specified, by definition! It is the absence of requirements, including the requirements to diagnose. C++ has something called "unspecified behavior" also, which is stronger than undefined, because it gives requirements. It denotes some circumstances when an implementation can behave in one of a finite possible ways (none of which fail) and must choose one of them without documenting which ch…

> Undefined behavior is not specified

> unspecified is stronger than undefined because it gives requirements.

I do not understand what you are saying.

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

#95
post #39

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…

There is nothing to "figure out". You are putting up a false narrative that this is at all a big problem in C++. You'll have to do more work than that if you want anyone to seriously believe such an outlandish claim. The only reason such syntax bugs become popular is because because C++ has a sizable chunk of the complexity-loving developer populace who are attracted to such things. The vast majority of C++ developer…

> nobody really sits and thinks how weird it is that 1 == '1' is true in JS

I beg to differ https://www.google.com/webhp?sourceid=chrome-instant&ion=1&e...

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

#96
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.

Is this a typo for Pascal? When I did the ICPC, Prolog was not a permitted language in my region, and IIRC not at worlds either. But Pascal was (which I always found quaint, but perhaps that was my provincialism).

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

#97

Earlier quoted context omitted.

Haskell, at least in my case.

Haskell has syntax that is as problematic as this one, and a huge number of extension combinations that nobody can be sure not to be problematic. I'm running into it as much as I can too, but it does look like a language we should replace with something simpler once we get an specification that works.

> Haskell has syntax that is as problematic as this one...

Examples, please.

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

#98
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).

That comparison is unfair.

For starters, there's not the syntactic ambiguity (or at least human uncertainty) found so often in C++.

There may be language complexity, e.g. how visibility interoperates can be difficult in weird cases. But I can at least parse it.

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

#99
post #80
post #75

Earlier quoted context omitted.

This is how it works in Ruby. In the CRuby/MRI interpretter when a segfault happens it calls the #to_s method on the current execution context, to get the some memory address and technical details. Ruby happens to be flexible enough that you can override that method. Then you can call whatever you want and you have effectly "recovered" from a segfault. The parser is totally in an inconsistent state and could crash at…

Interesting post. Small comment: the C++11 standard has about 1300 pages, not 5500, thank goodness.

I misremembered...

So I just went and look this up the C++14 standard, or at least the nNvember draft is 1368 pages and the Ruby ISO standard is 313. I was off by a fair amount.

But this made my point more extreme. C++ has mauch smaller feature list than Ruby and the spec is more 4x the size C++ is much more specific and precise. Ruby and many other languages will use the behavior of some de-facto implementation as their standard.

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

#100
post #39

Earlier quoted context omitted.

There is nothing to "figure out". You are putting up a false narrative that this is at all a big problem in C++. You'll have to do more work than that if you want anyone to seriously believe such an outlandish claim. The only reason such syntax bugs become popular is because because C++ has a sizable chunk of the complexity-loving developer populace who are attracted to such things. The vast majority of C++ developer…

> nobody really sits and thinks how weird it is that 1 == '1' is true in JS I beg to differ https://www.google.com/webhp?sourceid=chrome-instant&ion=1&e...

Sorry, I don't quite understand what your point is. You will have to be more clearer than posting a link as a reply to an obvious use of a rhetorical device. But if that was the extent of the reply then you will have to excuse me from any pedantic argument.
Post reply on HN