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


Groups > comp.programming > #10200

Re: What is the current state-of-the-art?

From Louis Valence <lvalence@example.com>
Newsgroups comp.programming
Subject Re: What is the current state-of-the-art?
Date 2019-09-13 17:11 -0300
Organization Aioe.org NNTP Server
Message-ID <86impwdki1.fsf@example.com> (permalink)
References (1 earlier) <86r24rv5mi.fsf@example.com> <36e07578-b7ae-4755-b7d7-ed054066b9e5@googlegroups.com> <80f98799-26de-4cf6-95ae-a1815d5893f9@googlegroups.com> <868squgy22.fsf@example.com> <a2204568-0eb2-45d3-ab26-9f12a4bb2ade@googlegroups.com>

Show all headers | View raw


Chad <cdalten@gmail.com> writes:

> On Wednesday, September 11, 2019 at 5:26:01 PM UTC-7, Louis Valence wrote:
>> Chad <cdalten@gmail.com> writes:
>> 
>> > On Sunday, September 8, 2019 at 1:56:30 PM UTC-7, Mark
>> > Rosenblitt-Janssen wrote:
>> 
>> [...]
>> 
>> >> > You talk to a computer science student nowadays and they ``surely
>> >> > learned their c programming language'', but never heard of Dennis
>> >> > Ritchie or Brian Kernighan, nor have read the book.  They prefer to
>> >> > learn from badly written essays and poorly crafted paragraphs.  It makes
>> >> > no sense.
>> >> 
>> >> For sure, ask a Javascripter:  What is the binary digit for one?  They
>> >> think it's a trick question.
>> >
>> > It actually turns out to be a tricky in JavaScript. Seriously. I could
>> > probably give you two cases that would make you go wtf.
>> 
>> Show me the money!
>
> Try the following in the JavaScript console..
>
> "10" + "1"
> right after that, do
> "10" - "1"
>
> And you're welcome -).

Thanks! (Please, don't top post!) :P

Allegedly, these are examples of tricky ``questions'', which to me
implies the behavior of these statements should be tricky.  But what's
tricky about them?  Do you think a plus sign should always mean
addition?  There's perhaps many programming languages that define their
meaning to be concatenation of strings, of lists et cetera.  So the
first example concatenates the two strings.  Now, why should we expect
that the minus sign would mean anything other than subtraction?  So the
second statement coerces the strings to numbers and subtracts them.  Is
there a well-defined inverse operation to concatenation?  If so, the
minus sign could take that role.

In fact, given we've seen + does string concatenation in Javascript, we
should also expect that, for example, [] + [] should either yield a type
error or it should coerce these arguments into strings and concatenate
them.  That's what in fact it does.  The coercion of [] produces the
empty string, so two empty strings concatenated yield an empty string.
Not too tricky of a question, I say.

Now let's ask the following question.  Given all the above as an
introduction to the question, we then prompt the candidate with what
should be the result of {} + "something".

So far, it seems the plus sign is the string concatenation operator, so
it could probably coerce {} into a string, if it does not produce a type
error (which would probably be the most natural behavior), and
concatenate it to "something".  Perhaps, as in [], it will coerce {} to
the empty string and so the final result will be "something".  But,
alas, that's not what happens.

  > {} + "something"
  NaN

That I call a tricky question.

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What is the current state-of-the-art? Mark Rosenblitt-Janssen <dreamingforward@gmail.com> - 2019-09-07 09:23 -0700
  Re: What is the current state-of-the-art? Pankaj Jangid <pankaj.jangid@gmail.com> - 2019-09-07 23:16 +0530
  Re: What is the current state-of-the-art? Melzzzzz <Melzzzzz@zzzzz.com> - 2019-09-07 17:51 +0000
    Re: What is the current state-of-the-art? Chad <cdalten@gmail.com> - 2019-09-08 06:31 -0700
    Re: What is the current state-of-the-art? fir <profesor.fir@gmail.com> - 2019-09-13 07:42 -0700
  Re: What is the current state-of-the-art? Louis Valence <lvalence@example.com> - 2019-09-08 00:17 -0300
    Re: What is the current state-of-the-art? Mark Rosenblitt-Janssen <dreamingforward@gmail.com> - 2019-09-08 13:56 -0700
      Re: What is the current state-of-the-art? Louis Valence <lvalence@example.com> - 2019-09-08 23:54 -0300
      Re: What is the current state-of-the-art? Chad <cdalten@gmail.com> - 2019-09-11 06:12 -0700
        Re: What is the current state-of-the-art? Louis Valence <lvalence@example.com> - 2019-09-11 21:25 -0300
          Re: What is the current state-of-the-art? Chad <cdalten@gmail.com> - 2019-09-13 10:25 -0700
            Re: What is the current state-of-the-art? Louis Valence <lvalence@example.com> - 2019-09-13 17:11 -0300
  Re: What is the current state-of-the-art? fir <profesor.fir@gmail.com> - 2019-09-13 07:47 -0700

csiph-web