Path: csiph.com!aioe.org!.POSTED.8HgiFb/MgTrhK5G3iINCWQ.user.gioia.aioe.org!not-for-mail From: Louis Valence Newsgroups: comp.programming Subject: Re: What is the current state-of-the-art? Date: Fri, 13 Sep 2019 17:11:34 -0300 Organization: Aioe.org NNTP Server Lines: 67 Message-ID: <86impwdki1.fsf@example.com> References: <3a72a169-3ce4-498f-a5e3-dd21cc318b1a@googlegroups.com> <86r24rv5mi.fsf@example.com> <36e07578-b7ae-4755-b7d7-ed054066b9e5@googlegroups.com> <80f98799-26de-4cf6-95ae-a1815d5893f9@googlegroups.com> <868squgy22.fsf@example.com> NNTP-Posting-Host: 8HgiFb/MgTrhK5G3iINCWQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (windows-nt) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:Q/MXZsHZHOd5mk/enJIoCInEWAk= Xref: csiph.com comp.programming:10200 Chad writes: > On Wednesday, September 11, 2019 at 5:26:01 PM UTC-7, Louis Valence wrote: >> Chad 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.