Live data from Hacker News

A way to torture an interviewer (C++, FizzBuzz)

news.ycombinator.com

11–20 of 84 posts

Re: A way to torture an interviewer (C++, FizzBuzz)

#12
post #2

If a candidate were suggesting this as their serious FizzBuzz implementation fit for production, I'd have a hard talk with them about readability.

What implementation of FizzBuzz do you use in your production environment?

Enterprise FizzBuzz, obviously

https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpris...

Re: A way to torture an interviewer (C++, FizzBuzz)

#13
post #2

If a candidate were suggesting this as their serious FizzBuzz implementation fit for production, I'd have a hard talk with them about readability.

If an interviewer had a "hard talk" about anything during an interview, i'd have an immediate hard walk.

If I couldn't convince you to walk back and finish the interview, I'd say that was a hard balk.

Re: A way to torture an interviewer (C++, FizzBuzz)

#14

As someone who avoids C++ these days ... Is this a compile time FizzBuzz? `(char*)&1[""]` is the empty string here returning its data segment address as the offset? Not sure about the purpose of `1`. Is the iteration achieved by the constructor basically re-invoking itself?

&1[""] is the same as &(""[1])

Re: A way to torture an interviewer (C++, FizzBuzz)

#15
post #2

If a candidate were suggesting this as their serious FizzBuzz implementation fit for production, I'd have a hard talk with them about readability.

What implementation of FizzBuzz do you use in your production environment?

A bug-free one (nonexistent). :)

In seriousness, the interview is supposed to give a taste of how the candidate thinks and codes in general. If they start using every obscure language feature under the sun, I am not too sure they got the idea.

Re: A way to torture an interviewer (C++, FizzBuzz)

#16
post #14

As someone who avoids C++ these days ... Is this a compile time FizzBuzz? `(char*)&1[""]` is the empty string here returning its data segment address as the offset? Not sure about the purpose of `1`. Is the iteration achieved by the constructor basically re-invoking itself?

&1[""] is the same as &(""[1])

Ah, so it's the nil address?

Re: A way to torture an interviewer (C++, FizzBuzz)

#19
post #3

Yay, let's talk about FizzBuzz! This is the fastest PHP version I could come up with so far: I'm sure there still are ways to make it faster. But I fail to think of them. Except for unrolling multiple loops into one. But that is so ugly. Any ideas of elegant ways to make it faster? Testing the performance like this: php fizzbuzz.php | pv > /dev/null 215MiB/s on my slowish laptop. The "yes" command gives me about 10x…

https://tech.marksblogg.com/fastest-fizz-buzz.html

Not sure I'd call writing Assembly "elegant" but hey!

Re: A way to torture an interviewer (C++, FizzBuzz)

#20
post #10

As someone who avoids C++ these days ... Is this a compile time FizzBuzz? `(char*)&1[""]` is the empty string here returning its data segment address as the offset? Not sure about the purpose of `1`. Is the iteration achieved by the constructor basically re-invoking itself?

It's a static initialization time FizzBuzz. In this case, I think it's executed before main() is called, and not at compile time. Unless, of course, you have a very clever compiler that determines memory allocation is not actually allocating anything and that the output is a static string, and there are no side effects. Such a clever compiler could optimize it all into just one "puts" call.

Neither GCC nor Clang bake the final string into the data segment. If I had to guess, printf is the one preventing the more fancy optimizations to take place.
Post reply on HN