Paul Hsieh said:
This is like void main - only a truly incompetent programmer could foul it
up.
Right, but I need to know whether the candidate deals with string at
the average level of people who post here in c.l.c. or whether they
are a candidate worthy of real consideration. Some people don't get
the fact that you cannot return a string that you declared as an array
in the inside of your function, or that use of statics inhibit multi-
threading. Enough people that its worth testing that.
Much laughing. So a Fortran program is good enough, provided you're using
a compiler that accepts Fortran? I Don't Think So.
Which of the options listed (that you have deleted from the thread, of
course) do you think a Fortran compiler will accept?
Portability has its benefits, whether you realise it or not.
*Cough* straw man *cough*.
If you insist on disagreeing with the candidate, then yes, of course,
thank him for his time and let him go - there's no point hiring a bright
guy if you're not going to listen to him.
"Bright guys" besides being a subjective turn, can do all sort of
intolerably wrong things (there is even a movie about this based on
the book: "The Smartest Guys in the Room" that is worth watching).
Productivity, and understanding the real world of coding (not this
strange fantasy world that CLC seems to operate in) kind of matters.
Code may and likely will migrate to C++, that's just a general
principle that people should be aware of, that's far more important
that someone's bad argument for avoiding a useful cast.
So you think of "getting it right for good reason" as being an ideology,
and presumably an ideology with which you disagree? Well, so be it.
Whatever, I only have evidence and measurable data on my side. (I
have never written a line of C code in my professional code that
didn't eventually get handed to a compiler that could do, or *did* do C
++.)
Two wasted tests. x and y are unsigned types.
You have to be kidding me. There is a *GARGANTUAN* amount of waste in
my routine, even ignoring the recursion, and you managed to isolate
the most irrelevant? (And if you look again, it does appear to be
*three* wasted tests, as fb cannot spontaneously become NULL as it
gets passed recursively.) In graphics, you tend to ignore these
things when bandwidth to pixel data is a factor.
Look, like many of the other problems with my solution, the originally
proposed *INTERFACE* limits my ability to do this right. In this
case, you went and made the coordinates unsigned for some bizarre
reason. Anyone who knows basic graphics or has been in the graphics
industry for even a short time knows that you never do this -- it will
muck up all of your standard clip algorithms. My natural tendency is
to do things as they are really meant to be done and ignore errors in
design; in this case the prototype.
If that was supposed to be "a trick question" kind of thing, it seems
like a fairly shallow and also valueless trick (its not like array
reversal, where the trick of making sure your index only goes half way
through is fundamental to getting it right.)
[...] But you will be pleased to hear
that the code does actually do its job, albeit rather slowly.
A candidate who wasted his spare time staring into space instead of
finding those redundant tests would not be doing himself any favours.
As opposed to the time I spent agonizing over this interface and how
it forces me to read back each pixel at least twice? You have a
bizarre sense of priority.
[...] but we'd expect the
basics. Almost certainly the candidate will go for the naive recursive
implementation, on the grounds that anything else is likely to take him
more than five minutes!)
Follow-up (and this is the important one): look at the code you've just
written - what would you say is wrong with it?
Its fully recursive.
Right.
By changing the interface, its possible to
remove the redundant pixel reads and redundant coordinate bounds
checking.
You don't need to change the interface to at least make a start on that.
(I won't explain further, because you explained it yourself - "direct
fills" - further on in your article.)
No what I meant was that the interface should include the color from,
use *signed* integer coordinates, and guarantee that the incoming
coordinates are in bounds. Look closely. My solution reads each
pixel twice (once to decide whether it should recursively flood fill
there, and once to figure out which color its trying to match) and it
checks for being in-bounds twice (once upon input, and once for each
of the four recursions.)