

Cppquiz – Figure what a given C++ program does - alok-g
http://cppquiz.org/

======
S_A_P
I don't write C or C++, but I do write a lot of C# and some occasional obj-C.
Maybe I will get down voted for this, and I completely see merit in learning
all you can about a language and features as it makes developers more valuable
to their employers.

<now for the but> In my over 10 years as a developer, I rarely if EVER come
across these sorts of problems. I've been in many problem domains and modeled
many sorts of problems. I have come across these sorts of issues maybe 1 or 2
times. When I did come across this sort of problem a few hours of thought
allowed me to come up with a rational solution that didn't require stretching
the bounds a of a language. </but>

So while Im all for academic curiosity and figuring out the way things work, I
dont know that these sort of things are applicable as to whether someone can
write code to do a job that is robust, scalable and reliable.

So please excuse me while I go read my C++ books because I feel stupid...

~~~
FreezerburnV
That's a pretty valid <but>...</but> tag. However, I would argue (based on
what I know of software development and the stories that I've seen posted on
occasion on HN) that knowing some of these oddities and details can come in a
lot of handy someday. Even careful developers can accidentally run into some
strange scenario which turns into one of these rarely-seen specifications,
causing some bug. If you don't know these kinds of things, you'll have no clue
where the bug could be coming from. And this is especially true in a language
that can be as thorny as C++.

As an example, in a program I'm working on which is still some ridiculously
simple 100-line program, I shadowed a variable name inside a loop. (C++) I
figured it would be ok because I was declaring the new variable after I was
done using the previous one. But apparently, declaring a variable at all in a
scope causes the new variable to be the one used inside that scope, even from
the beginning. And considering the two variables were of a different type, it
was causing a problem. Not hard to find in a small program, but might be
harder to find in a large one.

On the flipside, a lot of these issues might be relatively easy to find with a
little intelligent Googling or asking Stack Overflow. But that time might have
been better spent continuing development on the current project. And that time
can add up.

------
malkia
WTF C++11 - WTF -

[http://cppquiz.org/quiz/question/38](http://cppquiz.org/quiz/question/38)

The answer is in the C++ name.

~~~
thwest
Seriously declreftype would have been a much clearer way to signal intent here
rather than making parenthesis significant.

~~~
pbsd
Yeah, this special case always weirded me out, it's hard to see a justifiable
use case. In regular usage you'd use auto& instead to achieve the same effect.

C++14's decltype(auto) confuses things even further: [http://coliru.stacked-
crooked.com/a/f7d8195efc4708f3](http://coliru.stacked-
crooked.com/a/f7d8195efc4708f3)

------
jimmaswell
It'd be nice if there were an option to just give the answer for if you
honestly had no clue.

------
taspeotis
This [1] is my candidate for why I'm not cut out to be a master C++
programmer. There's far too many arcane rules. I want to use a language I can
enjoy.

[1] [http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-
the...](http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-
important-const/)

~~~
bcoates
In fairness to C++, that rule mostly has effects where it silently does the
right thing even if you don't know the rule rather than breaking things. It's
just kind of surprising when it fixes code that looks broken.

------
faizdev
I would kill to answer questions on the corner cases of modern web languages,
such as JS, Ruby, Python or Dart. Pretty cool idea.

~~~
PhearTheCeal
Here is a JS one for you

    
    
        Array(10).join("hn" - 1) + " Batman!"

~~~
Groxx
Or most JS bits in
[https://www.destroyallsoftware.com/talks/wat](https://www.destroyallsoftware.com/talks/wat)

------
bcoates
Static destruction order is way more deterministic than I thought, and I have
no idea how function template specialization rules work.

------
nfoz
C++11 trivia.

~~~
ajross
Pretty much. I tried three questions:

Understanding the first rested on the fact that a friend function declaration
requires that the relevant function declaration be present above it in the
translation unit (e.g. friend int A::foo();" requires that "class A" be
defined, even though the prototype is otherwise correct). Meaningless trivia,
and something every compiler will remind you about instantly and clearly.

The second one was pretty straightforward and basically about understanding
that a superclass constructor is invoked before the subclass constructor.
That's certainly important to understand, but in my experience rarely
misunderstood except by true OO newbies (basically the same behavior has to
hold for any static type system with inheritance).

The third called a public virtual function through a superclass pointer and
expected you to recognize that declaring the derived function private in the
subclass that the object belongs to didn't matter. Again, trivia that doesn't
correspond to any meaningful real-world code pattern.

I gave up after that. Yawn.

~~~
eridius
You gave up too early. How about the question that tests your knowledge of
std::async behavior, in a way that has very real practical results? (very real
in that if you don't understand the behavior, you're almost certainly using
std::async incorrectly and with no benefit to your code).

Or the one that makes sure you understand that, if a function isn't declared
virtual, then you get static dispatch instead.

Or, heck, the one that ensures you know that floating-point literals default
to double, and that this fact affects function overload resolution.

