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


Groups > comp.lang.javascript > #31265

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-07 03:12 +0000
Organization A noiseless patient Spider
Message-ID <nqo0jf$a4v$2@dont-email.me> (permalink)
References (6 earlier) <nn044b$e69$1@dont-email.me> <nqf8t7$h37$1@dont-email.me> <nqhg6o$st6$1@dont-email.me> <nqkl2e$6bt$1@dont-email.me> <nqmpag$kit$1@dont-email.me>

Show all headers | View raw


Doc O'Leary wrote:
> Scott Sauyet wrote:
> 
>> 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.
> 
> Then I wonder if you’ve ever done any sort of sophisticated programming.

I believe I have.  I've also been training programmers in advanced 
techniques for a number of years.

>  There is a *reason* why languages developed mechanisms other than
> “return a valid value and let the programmer figure out if it’s
> *actually* a good result, or just some kind of error”.

I've argued (most recently in a response to Gene Wirchenko) that this is 
not only a good result, but the only reasonable value.

It allows us to assert laws such as

    max([max(list1), max(list2)]) === max(concat(list1, list2))



>> 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’s best dealt with abstractly, because the concept applies to things
> other than numbers.  If you can order it, you can determine a “max”
> value.  And if there is *no* values to order, it is ludicrous to say the
> correct result is a valid value you have simply fabricated.

This is no more fabricated than 0 is fabricated as the sum of an empty 
list of numbers, than 1 is fabricated as the product of an empty list of 
numbers, or than `true` is fabricated as the result of a call to `all` on 
an empty list.  These are the obvious and useful results.  While `max
([]); //=> -Infinity` is slightly less obvious, the same sort of 
reasoning demonstrates why it is correct.


> But even restricted to numbers, the abuse of infinity remains an
> implementation hack.  NaN is also a number, and also already used by
> min/max to signal an error.  It makes zero sense (beyond the hack) to
> return an infinity.

There is an argument to be made for `- Number.MAX_VALUE`, and for 
`Number.MAX_VALUE` for `min`, but there might be a slight boundary 
condition issue, and more importantly, these fail if your list includes 
Infinity or -Infinity.  Other than that, there is no reasonable option.


>> 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.
> 
> You’re missing an infinity of objects that developers can define for
> themselves.  Or just the infinity of uses a Number can have. 


You clipped the bit where I mentioned custom types and how since the user 
would already have to do the ordering, asking her to also signal the 
proper behavior here is not unreasonable.


> You’re
> stuck thinking about the objects you have rather than the *uses* the
> objects are put to.  Stop and actually *think* about what you actually
> have to do to write a program that behaves properly when you define
> functions that fabricate “valid” results.

I'm suggesting that those who define the types to be used with a generic 
`max`/`min` would have to define their own boundary values, or signal 
that they don't exist, not that such a function could do it for an 
arbitrary type.  But I also insist that ±Infinity is the only reasonable 
choice for Javascript's Number type.



>> 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.
> 
> That’s an utter mess.  

This is simply the result of my suggestion that this should be left to 
those implementing ordering for the types.  I don't know better than they 
do; neither do you.


> You should never be allowed to write a software
> library that is used by anyone else.

:-)

Check out Ramda [1], "a practical functional library for Javascript 
developers."  It's being downloaded around 8500 times per day [2].  I am 
the original author and one of the three primary contributors to it.  I'm 
sure there are those that will say it's utter crap, but I'm pretty fond 
of it.  It's not as principled as Sanctuary [3], preferring to better 
bridge the gap between work-a-day Javascript programmers and FP 
enthusiasts than to fall too heavily on the pure FP side.  But it is a 
much purer FP library than something like Underscore [4].


>> It's not that I think this is a bad point. I simply don't believe it's
>> as clear-cut as described.
> 
> It is.  Perhaps one day you’ll be experienced enough to understand why.

It is not.  Perhaps one day you'll understand enough math to recognize 
why.



>>> 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`.
> 
> I would seek to define a consistent behavior.  The *way* garbage comes
> out is important.  That’s the entire issue of why an infinity is the
> wrong result.

I was simply being flip here.  I apologize.

To me `null` or `undefined` would be true garbage.  Instead of a function 
whose results I can simply use, I would get something that then requires 
type-checking, and then manual intervention if I get the wrong type.  If 
this throws, I cannot compose it with other functions, and need to build 
complex logic flows rather than simple functional pipelines.

I have no fundamental issue with the thought of instead offering a `Maybe 
Number` type (or more generally a `Maybe a` one) for an API, but this 
whole discussion is in the context of a function already documented to 
return a number.


>> 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.)
> 
> Compounded errors are not the better solution.  I want to know when and
> where something went wrong, not just *guess* at when the final result
> looks a bit off.

But I don't think this is a signal that something went wrong, any more 
than `sum([]); //=> 0` signals that something went wrong.  `sum([]); //=> 
null` would be much worse, as would `sum([]); //~> Error`, the first 
because it really could compound, and the second because I can no longer 
comfortably compose that function with others.


>>> 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 doubt you objectively have.

Of course not.  But given the limited time of an interview, I've don't 
the best I could.  Over the years I've read literally thousands of 
resumes, performed some awful number of phone screens, held full-on 
interviews about 200 times, and hired about 25 developers.  In two cases, 
the candidate managed to get past this vetting process without having the 
necessary skills.  But that's still a 90%+ success rate.  I'll take it.


>> 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.
> 
> But that’s exactly what you’re doing.  You’re asking them about a hack
> that has, unfortunately, remained in the Math object for far too long.

Of course, again, I disagree here.  I think this is the best possible 
solution.


> If you legitimately want them to think, you’d do something like I have
> done, and explore ways to provide a min/max function for abstract
> collections of any type.  

I find that a trivial problem, honestly.

If you have a solution for it, do you always throw on an empty list, do 
you always return a `null`/`undefined` signal, or do you leave it up the 
type to decide?


> My bet is that none but the *least* qualified
> candidates will come up with solutions that fabricate results the way
> Math does for numbers.

I'm not asking them to come up with that solution.  I tell them how it 
is, and offer them as many hints as are necessary for them to understand 
why it works as it does.

I don't know what sort of position you hold.  I work in a large company 
with an ongoing mix of old and new software for developers to work on.  A 
very important skill is trying to figure out how a system or a component 
works, and why it's written the way it is.  Watching a candidate go 
through this exercise, I believe, helps me determine how skilled she is 
at this.

  [1]: http://ramdajs.com/
  [2]: https://npm-stat.com/charts.html?package=ramda&from=2016-01-01
  [3]: http://sanctuary.js.org/
  [4]: http://underscorejs.org/

  -- 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