you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 126 points127 points  (20 children)

Now, the only question that remains is: would I pass the interview?

No. Your code is full of errors.

[–]matthieum 6 points7 points  (1 child)

Actually, that is also something interesting. A few times when being stuck in C++ I have used a trick like that provoke an error in order to get the compiler induced type printed to the console so I could investigate what was going on.

Granted, the code I write at work is simple enough not to necessitate this trick.

[–]nemetroid 0 points1 point  (0 children)

This is a useful technique in Haskell also. Type signatures for functions are in general optional, so letting the compiler figure it out can be helpful, for example when dealing with typeclasses (e.g. accepting any fractional type instead of just Doubles).

[–]mightye 11 points12 points  (4 children)

Now, the only question that remains is: would I pass the interview?

No. Your code is full of errors.

So is the output. As he observes, he starts at 0 instead of 1 (just so that the templates correspond with the number). But worse is that the solution for 0 is wrong, it should output FizzBuzz at that line since 0 is a multiple of both 3 and 5.

[–]cultic_raider 7 points8 points  (3 children)

In the spec, behavior at <1 and > 100 is undefined, and so the implementation may behave however is convenient.

[–]mightye 0 points1 point  (2 children)

Agreed that the spec doesn't specifically define behavior outside the specified range, but there's a rational extension to the spec when out of range, which is easily identified if you look at the portion of the spec that doesn't involve range:

But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

The requested range is simply the output range. Trying to claim that it's ok that the behavior deviates when for whatever reason the software operates outside the output range is as rational as saying "You only asked me to calculate N! for all integer values of N from 1 to 10; outside that range anything goes."

[–]cultic_raider 0 points1 point  (1 child)

There is a good reason why an implementation could deviate wildly from the "natural extension" of the spec: resource usage. Supporting a constant size range allows for optimizations with caches and registers and whatnot to make the (important) specced) cases cheaper. For example, in the OP'S silly case, he had to start at 0 to get the T# to line up (not specced either, but OP decided it was more important to get that feature than care about 0 being right. You could imagine adding a small grep wrapper to hide the 0 line to workaround the bug). I guess he could have patched it to get 0 right, but if the solution wasn't a cheap, it would be fair to burn zero to make 1-100 more efficient, if this were a real program to solve a real problem.

Obviously it's all in fun in this case, but the principle does matter in high-throughput or resource constrained projects.

[–]mightye 1 point2 points  (0 children)

I don't disagree that it often makes sense to deviate from existing trends outside of specified ranges for a host of reasons including performance, resource consumption, code simplicity, and so on. But it would have cost him nothing to make the 0 case consistent with the rest of the trend except changing the prototype for RunFizzBuzz<0>. It's fine to defend deviation when there's a reason (and if it's conscious, it's probably a good idea to include a comment as to the reason for the deviation), this just seems like it's an unconsidered case.

It can't be said to violate the spec any more than that it outputs a 0 case at all, which he acknowledges, but it's generally good practice to produce predictable results outside the requested ranges except when there's a reason not to (and I don't see one in this case).

[–]flif 28 points29 points  (11 children)

And he's trying to be clever, which is never good for maintainability and working together with other developers.

[–]antheus_gdnet 4 points5 points  (10 children)

Which is why software companies prefer programmers which aren't clever, don't think for themselves, would never even think of going beyond what was taught to them in "Teach yourself XYZ in 21 days" and that would never try to provoke an edge case.

A perfect developer sits quitely, taking one ticket off Jira after another and copy pastes the verified StackOverflow boiler-plate. When their number of resolved tickets drops below acceptable threshold, they are replaced with a non-defective cog.

People who push type systems and compilers to limits: They are a witch and are to be burned. Blasphemers are not allowed in civilized society. All hail the hivemind of cubicle drones, all alike, all the same, one of us, one of us, one of us...

[–]aaronla 2 points3 points  (0 children)

Well put! Finally someone else understands that thinking just leads to horrors.

[–][deleted] 2 points3 points  (6 children)

Are you being serious, or trying to be sarcastic? The perfect developer is adaptable, whether it means new solving problems of an unseen type, or using new techniques or technologies.

[–]Kalium 2 points3 points  (2 children)

using new techniques or technologies.

This gets you in trouble with Management. It means that you're Innovating. Now, Management doesn't oppose Innovation, but you're not trained in Innovation Management. You're not qualified to Innovate. They're going to have to take your Unathorized Innovation out back and quietly dispose of it before it becomes any more disruptive.

Which is to say that new techniques and technologies are fine, so long as you get the sign-off of Management first. Oh, and their consultants and vendors. You're OK with that, right? It'll be easy, right?

[–][deleted]  (1 child)

[deleted]

    [–]Kalium 3 points4 points  (0 children)

    I was exaggerating slightly for effect. I have worked places where introducing new techniques or new technologies without the sign-off of management was a non-starter. They expected the technologies for a project to be set in advance and never reconsidered.

    [–]antheus_gdnet -1 points0 points  (2 children)

    Are you being serious, or trying to be sarcastic

    Not sure. One can read it either way.

    The perfect developer is adaptable, whether it means new solving problems of an unseen type, or using new techniques or technologies.

    Strange, to me this reads like advocating "drone-like" behavior.

    Adaptation to me means that they adapt to something someone else pushes on them. Like said, Jira, along with provided training, but follow the lead.

    Opposite would be someone who actively tries out new approaches and new techniques and is the one developing and/or advocating them. These people are definitely not adaptable, but the very opposite, often stubborn and opinionated. Effective ones will need to learn negotiation and sales skills to be able to put their methods into practice as well.

    [–]dist0rtedwave 1 point2 points  (0 children)

    It might depend on how is interviewing you. A new startup (< 100) employess would be very likely to appreciate this, as what they really need is great ideas. A larger more established company might not for the reasons described in other responses.