Hacker News new | ask | show | jobs
by thisiswrongggg 1459 days ago
You wouldn't torture him. You would just zero the probability of getting an offer. There's no SW house or colleague in his right mind that would want a developer that writes obfuscated and needlessly complex to understand code.
7 comments

I would not want developer to write this kind of code in production applications but I would very much hire a person who is capable of coming up with the code like this.
..except they probably wouldn't come up with janky code like this - especially not during the interview

This is something you memorize to try to show off

>"person who is capable of" - is not equal to actually doing it on an interview unless it was their own original code
This whole point of Fizzbuzz is to see how one structures their code. Or at least ascertain that one _can_ write code in the first place.
I could not care less about the purpose of FizzBuzz. In my other life I've interviewed many programmers and I did not get disappointed. But I would never ask them to do live coding in a first place.
How much structure can a fizzbuzz have exactly?
shudder

Sometimes I wonder why some dev teams take 10x longer to develop some functionality than what I would consider reasonable.

Then I see code like this.

  > How much structure would you like?

  top = 100

  data = { 
      3: "fizz",
      5: "buzz"
  } 


  for i in range(1, top+1):
      output_num = True
      for j in data:
          if i%j == 0:
              print(data[j], end="")
              output_num = False

      if output_num:
          print(i)
      else:
          print("")
This is enough structure to anticipate the inevitable customer changing the requirements. No magic numbers in the real code.

Of course, I just banged this out in a web browser text editor. In PyCharm that better be wrapped in a function at minimum, or a module.

You can make it easily extendable for division by 7.
Is consider this entertaining rather than torturous.

A playful response to the mind numbing idiocy of fizzbuzz.

If someone wrote that in an interview I'd be keen to get them to explain to me exactly how it works... my C++ being a bit rusty (I mean old).
Explanation:

1. There are no data members inside X, in this case the size of the structure is 1 byte.

2. main() does nothing.

3. *x = new X[100]() - this requests a new array of 100 elements of type X, at a stage before main() is called.

4. The new[] operator is overloaded in the class, this operator must return the address for the requested array. It returns the address of the empty string object plus 1.

5. For each of the 100 elements, the X() constructor is called, the "this" address for those elements will be the value returned by new[] plus an index from 0 to 99. The X() constructor converts this to a number from 1 to 100 by subtracting the address of the empty string. This is the only UB here, but it works in all major modern compilers since they combine the same strings into one instance.

> This is the only UB here.

That's debateable.

1. new[] doesn't return a pointer that is suitable for storage for the objects. Yes the objects are empty (only contain padding), but that doesn't absolve from UB.

2. "" is used at two places, assuming that they refer to the same const char array. This is optimization is allowed, commonly implemented, but not guaranteed.

3. An empty struct having 1 byte size is also implementation defined, although common ABIs specify this. It also wouldn't make sense to implement it differently.

Since new[] does not actually return an array (returns a pointer to 1-past-the last element in "" string/array) and later "this" pointer is calculated using an arithmetic operation that goes out of bounds (for elements that > 0), that would also be UB. ""+2 would be UB for example.

But maybe it is not UB because it is not calculated explicitly by the program, hard to tell

Unless they had, and i know this is hard to imagine in a c++ dev, a sense of humour
I mean the code also includes a bunch of undefined behaviors, we do not joke about that
QA engineer for a C++ compiler?
This program is undefined, so no, except maybe if you can make the compiler itself to crash.
That's a good thing to test.

Btw, here's a C++ sample that crashes icc: https://pastebin.com/PiRtZi1t. I haven't reported it because it's funnier this way.

What if the SW house is competing in the ioccc?
Fizzbuzz is a pass to the next questions. It's a way to weed out random people who have no idea about programming but for some reason came to the interview.

While this code wouldn't be an instant offer, it would be a great solution in my eyes and it would follow hardest questions to qualify a candidate for senior position.

That's my opinion at least. I'm making a hiring decisions in my company.

It's a great way to tell jokes, loosen up the interviewee, and get the jitters out.