Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31245

Re: How would you prepare for javascripting interview?

From Scott Sauyet <scott@sauyet.com>
Newsgroups comp.lang.javascript
Subject Re: How would you prepare for javascripting interview?
Date 2016-09-05 20:37 +0000
Organization A noiseless patient Spider
Message-ID <nqkl2e$6bt$1@dont-email.me> (permalink)
References (4 earlier) <operator-20160721051934@ram.dialup.fu-berlin.de> <1875389.irdbgypaU6@PointedEars.de> <nn044b$e69$1@dont-email.me> <nqf8t7$h37$1@dont-email.me> <nqhg6o$st6$1@dont-email.me>

Show all headers | View raw


Doc O'Leary wrote:
> Scott Sauyet wrote:

>> Remember that the context was the functions `Math.max` and `Math.min`,
>> so a number-centric implementation makes perfect sense.
> 
> No, it doesn’t.  It makes *zero* sense for either function to return a
> number that wasn’t in the input set.  That’s just a bad decision in the
> language’s design.  

I disagree.  The realistic choices are

  (A) Return something of the correct type, even though it's not 
      in the (empty) input list.

  (B) Return some semaphore of a different type that signals that 
      things have gone wrong: `undefined` or `null` are most likely.

  (C) Throw an error.

None of these choices is ideal, but we have to choose between them.  I'd
say that the best ordering is A > C > B.

Of course this is better for numbers than for some other types because 
numbers specifically encompass maximum and minimum values of their type.  
But this is the `Math` API.  Why should it not speak to the number type?


> It also creates an inconsistent behavior if they
> every *do* want to add such functions for other data types.

Since the second choice in my hierarchy is to throw an error, I think it 
would be reasonable to do so if the type does not permit a reasonable 
maximum or minimum value.  For Javascript, only three ordered types come 
to mind: Numbers, Dates, and Strings, although I may be missing some.  
Dates have an underlying fixed bit-sized number, so we could easily do 
the same for Dates.  An imaginary `String.max()` could be satisfied with 
the empty String, but `String.min()` would be much harder; I think it 
would have to throw.  For custom types, since it's already incumbent on 
the creator to make the ordering functions, it's not so hard to ask them 
to either supply such max/min values or to signal that it would throw in 
this case.

It's not that I think this is a bad point. I simply don't believe it's as 
clear-cut as described.


>> A null object or undefined have significant disadvantages that they are
>> not of the right type.  Downstream code will need to type-check the
>> result if the function is designed like that.

> They’ll have to do worse if they expect to function correctly based on
> the current behavior.  You could perhaps raise it as an exception if you
> prefer, but it’s just plain *wrong* to return a number that wasn’t given
> to you.  

Garbage in, garbage out.  It's no more wrong to do this than to supply a 
function that needs a non-empty list with an empty one.  I assume that 
you would rather throw in this case or to return `null` or `undefined`.  
To my mind, either of these is significantly worse.  By returning a 
number, you allow the user to proceed with numeric calculations, 
including, most importantly, using this result in a further max or min 
calculation.  (This is very much related to the arguments that Stefan Ram 
has made.)


> That’s why this behavior makes for a suitable trick question,
> but a terrible one for finding a JavaScript developer that actually
> thinks about the work they’re doing.

But remember the context of this question: I've already determined that 
the candidate has reasonably strong skills in Javascript.  I'm using this 
to try to determine how well she can think through a strange-sounding, 
but ultimately discoverable fact.  I provide guidance as needed, and 
never leave this until she's either solved it or I've given her the 
answer.  It's simply a way to help me see how she thinks.

This is not a trick question in the sense that I'm asking the candidate 
about the esoterica of the language; I'm not asking her to explore 
obscure corners of the spec.  In fact, I haven't actually bothered to 
check the spec to see if this behavior is required or if it would be 
considered acceptable to throw.  (I guess I'll do that before the next 
interview.)  I intentionally use the phrase "trick-question" when 
describing it to the candidate to put her in the frame of mind it might 
take to think about how such a function might be implemented as opposed 
to what she might want from it.  But I don't think it's actually a trick 
question.  Very much the opposite; this is the only one where I make sure 
that she understands the answer before the interview is complete.  
Because if I get around to asking this one, I've very interested in 
watching her learning process, and seeing the "aha" moment.

  -- Scott

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How would you prepare for javascripting interview? justaguy <lichunshen84@gmail.com> - 2016-07-18 09:10 -0700
  Re: How would you prepare for javascripting interview? Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2016-07-18 18:37 +0200
    Re: How would you prepare for javascripting interview? justaguy <lichunshen84@gmail.com> - 2016-07-18 11:09 -0700
      Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-07-21 01:04 +0000
        Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-07-21 14:24 +0100
        Re: How would you prepare for javascripting interview? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-07-23 16:25 +0200
          Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-07-23 15:56 +0000
            Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-03 19:39 +0000
              Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-04 15:56 +0000
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-05 00:06 +0100
                Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-05 14:49 +0100
                Re: How would you prepare for javascripting interview? $Bill <news@todbe.com> - 2016-09-05 10:01 -0700
                Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-06 09:36 -0700
                Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-05 15:05 +0100
                Re: How would you prepare for javascripting interview? Andreas Bergmaier <andber93@web.de> - 2016-09-05 20:31 +0200
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-06 15:15 +0000
                Re: How would you prepare for javascripting interview? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-09-06 19:40 +0200
                Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-06 19:25 +0100
                Re: How would you prepare for javascripting interview? Andreas Bergmaier <andber93@web.de> - 2016-09-06 22:16 +0200
                Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-07 17:17 +0100
                Re: How would you prepare for javascripting interview? Andreas Bergmaier <andber93@web.de> - 2016-09-07 20:07 +0200
                Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-08 14:36 +0100
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-05 18:46 +0000
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-05 20:32 +0100
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-05 17:27 +0000
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-05 20:12 +0100
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-06 16:48 +0000
                Re: How would you prepare for javascripting interview? Andreas Bergmaier <andber93@web.de> - 2016-09-06 19:56 +0200
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-07 20:16 +0000
                Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-07 10:01 -0700
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-07 20:21 +0000
                Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-09 11:41 -0700
                Re: How would you prepare for javascripting interview? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-09-09 15:35 -0700
                Re: How would you prepare for javascripting interview? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-09-09 20:40 -0700
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-10 15:12 +0000
                Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-12 11:14 -0700
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-13 21:07 +0000
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-06 16:20 +0000
                Re: How would you prepare for javascripting interview? Ken Tilton <kentilton@gmail.com> - 2016-09-05 11:37 -0700
                Re: How would you prepare for javascripting interview? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-09-06 19:26 +0200
                Re: How would you prepare for javascripting interview? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-09-08 12:41 -0700
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-05 20:37 +0000
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-05 22:13 +0100
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-06 02:33 +0000
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-06 16:02 +0000
                Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-06 09:50 -0700
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-07 01:36 +0000
                Re: How would you prepare for javascripting interview? Gene Wirchenko <genew@telus.net> - 2016-09-07 10:07 -0700
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-10 00:03 +0000
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-10 00:12 +0000
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-10 15:34 +0000
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-11 01:32 +0100
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-12 19:26 +0000
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-13 01:02 +0100
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-13 21:38 +0000
                Re: How would you prepare for javascripting interview? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-09-14 00:56 +0200
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-15 15:09 +0000
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-14 00:47 +0100
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-15 15:34 +0000
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-11 02:45 +0000
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-12 19:10 +0000
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-12 21:06 +0100
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-07 03:12 +0000
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-07 19:53 +0000
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-10 02:14 +0000
                Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-10 11:25 +0100
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-10 15:49 +0100
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-10 18:39 +0000
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-11 02:45 +0000
                Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-11 16:23 +0100
                Re: How would you prepare for javascripting interview? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-12 20:32 +0100
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-12 18:49 +0000
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-13 00:27 +0000
                Re: How would you prepare for javascripting interview? Tim Streater <timstreater@greenbee.net> - 2016-09-13 08:51 +0100
                Re: How would you prepare for javascripting interview? Jon Ribbens <jon+usenet@unequivocal.eu> - 2016-09-13 12:33 +0000
                Re: How would you prepare for javascripting interview? Scott Sauyet <scott@sauyet.com> - 2016-09-14 01:17 +0000
                Re: How would you prepare for javascripting interview? Tim Streater <timstreater@greenbee.net> - 2016-09-14 11:15 +0100
                Re: How would you prepare for javascripting interview? Doc O'Leary  <droleary@2015usenet1.subsume.com> - 2016-09-15 15:02 +0000
                Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-13 10:06 +0100
                Re: How would you prepare for javascripting interview? John Harris <niam@jghnorth.org.uk.invalid> - 2016-09-06 19:53 +0100
    Re: How would you prepare for javascripting interview? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-07-18 22:30 +0200
  Re: How would you prepare for javascripting interview? justaguy <lichunshen84@gmail.com> - 2016-07-18 14:56 -0700
  Re: How would you prepare for javascripting interview? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2016-07-19 16:01 -0300
    Re: How would you prepare for javascripting interview? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2016-07-19 16:16 -0300

csiph-web