31

Periodically we get questions in the javascript tag like this:

Why does this show the word "fail"?

function foo() {
  return (![] + [])[+[]] + (![] + [])[+!+[]] +
    ([![]] + [][
      []
    ])[+!+[] + [+[]]] + (![] + [])[!+[] + !+[]];
}

document.getElementById("result").innerHTML = foo();

This is clearly not a practical, answerable question based on an actual problem. It's answerable, but no one's going to run into this in a real programming situation. They might well run into it in an interview.

Obviously, most of these specific ones are duplicates now — but are they, and the ones they duplicate and other similar questions in other languages, off-topic for SO?

18
  • I think we can close them as dup of one of the specific ones, if the conversion rules used in the expressions are the same.
    – nhahtdh
    Jun 24, 2015 at 10:57
  • @nhahtdh: Right, of course, but that's not the question. Jun 24, 2015 at 11:14
  • is there an example of an accepted answer somewhere? I just can't even imagine how you would answer something like this.
    – Gimby
    Jun 24, 2015 at 13:14
  • 7
    Impressive. I must admit. I'm learning from that answer myself: tricks on how to clearly answer questions. Besides that point it may not be a realistic example of something you'd see out in the wild, but the explanation of the puzzle really does apply in a far broader scope. As such I'd say: very good answer, good enough question.
    – Gimby
    Jun 24, 2015 at 15:04
  • 3
    Questions like this are not at all practical, but I think they are fine because of two reasons. 1. We don't exactly have a close reason for those. 2. We sometimes encourage users to provide an MCVE and maybe they didn't want to post their actual code that they found in their software that they have to maintain. So they looked for similar things online, found something without an explanation and asked with that hoping that answers could apply to their situation. I think we don't need to rehash those questions again and again, so it's best to create a canonical answer (yours seems pretty close).
    – Artjom B.
    Jun 24, 2015 at 21:39
  • 2
    That shows the word fail !!?
    – xrisk
    Jun 24, 2015 at 21:50
  • 1
    Whoa. This is too deep, lol.
    – xrisk
    Jun 24, 2015 at 23:15
  • 3
    My instinct is to push these over to PCG as fast as possible, but I'm not sure how best to do that, given the lack of an obviously applicable close reason to start with. Jun 25, 2015 at 1:30
  • 1
    How about treating them as on-topic, but considering answers of the form "Don't do that; it's better to write function foo() { return 'fail'; } instead" to be acceptable answers? :-)
    – ruakh
    Jun 25, 2015 at 2:16
  • 10
    I think there are plenty of questions and answers that are based on things that are not an actual problem. Yet these questions help us to gain a better understanding of the language/system. In other words, they are educational and therefore clearly beneficial.
    – user562566
    Jun 25, 2015 at 2:59
  • 1
    What I'd like to see though are links to actual examples of what you're talking about, not just repeatedly pasted in links to your answer, because with only what you've provided here, this just seems self promoting.
    – user562566
    Jun 25, 2015 at 3:00
  • @TechnikEmpire: Re your first comment: Very well put. Would you post it as an answer? It echoes my thoughts, but I hadn't managed to put those thoughts into words as well as you did. Jun 25, 2015 at 5:57
  • @T.J.Crowder yeah I wasn't meaning to imply that you are self promoting or rep fishing. You're a very active and high rep user anyway. :) I was just saying, seeing something else as an example would be great.
    – user562566
    Jun 25, 2015 at 5:59
  • @TechnikEmpire: Re your self promotion comment: I hear that. :-) That's why I didn't link it in the first place, and searched hard for a different one I hadn't answered before posting the link. (I know they're there, but I couldn't find them -- these are very hard to find.) If you run across one, I will happily link to it. I rep-cap just about every day, if that's worth anything, so the linking is unlikely to have actually given me rep. But rep is just one aspect of self-promotion. I just didn't want to leave Gimby and Rishav hanging. Now that they've seen them, I've removed the links. Jun 25, 2015 at 6:00
  • @TechnikEmpire: Sorry, I split that comment in two. Didn't realize you'd answer so fast. :-) Jun 25, 2015 at 6:01

2 Answers 2

11

One of the major issues with these sorts of questions is that they have infinite permutations. Historically this has caused a lot of discussion and arguments in the comments, along with close/re-open wars.

More broadly, puzzle questions are often perceived as being written for one of two reasons:

  • To get a popular post
  • To gain reputation for the OP (a high amount, as one of these questions will very well take you in to your quota for the day and likely the week).

These posts generally take the form:

  • Write about some basic, but well known construct of a language
  • Show an ambiguous case with little to no 'real world' application
  • Ask why

Where these questions are often interesting is that they have the potential to get good answers (of course, so could any question, so this is hardly an argument for keeping them around). More often than not, they become the WAT of the Stack Overflow Community for a brief time, and are then forgotten (WAT is awesome because it happened once and was executed well. We hate fun, so we don't want too much of it).

So this variation should be rare.

Another variation of the "Weird feature that produces unexpected result" question is where someone finds a bug in the compiler.

These questions are similar to the first type; but their minor differences make all the difference:

  • They generally deal with an actual bug; not a quirk, an actual bug in the compiler.
  • They have a real world impact
  • And like the above, they're interesting and counter-intuitive.

We embrace actual problems programmers face because they're the problems that affect more than just the asker (and aren't contrived). For that reason and the other reasons I listed, 'puzzle' questions like the above should be off-topic and closed.

6
  • 2
    "puzzle questions are often perceived as..." By whom? I've never perceived them that way. I haven't seen them reacted to in that way. "To gain reputation for the OP" If so, it's spectacularly unsuccessful in the cases I've seen, which have been either left largely unvoted or downvoted. I think I might, once, have seen one of these questions upvoted significantly. Maybe. Sadly these things are so hard to search for, it's hard to find examples either way. Jun 25, 2015 at 15:00
  • 3
    "Sadly, these things are so hard to search for, it's hard to find examples either way." - Thanks another argument for closing them; if you can't find it, how can it be useful to others? Jun 25, 2015 at 15:14
  • 2
    Or: If they're hard to find, we should be glad we get lots of duplicates to increase the search area; we just need to be sure to close them referring to a canonical one. Jun 25, 2015 at 15:18
  • 2
    @T.J.Crowder I also perceive these kinds of puzzle questions as George does. There is no pragmatic reason for these questions. If you rely on JavaScript's coercion of empty arrays in code, you've got brittle code. The only stretch I can see in this being a good question is if it elucidates an issue in the language itself. In the case of the question in question, the quirks of JavaScript are well documented. Jun 25, 2015 at 16:41
  • 4
    @MikeMcCaughan: "If you rely on JavaScript's coercion of empty arrays in code, you've got brittle code..." To put it mildly. :-) (Well, other than the one coercion: To true in conditions. Which people use a lot. And to string, if you're happy with the default join. Hmmm, all these caveats -- which I didn't intend when I started this comment -- suggest an educational value after all.) Jun 25, 2015 at 16:46
  • 2
    @T.J.Crowder, back before we kicked such things off to PCG, they did gain a great deal of rep very quickly on a very regular basis, and didn't provide much value. The "get that out of here!" response that old-timers tend to have is a reflection of remembering that experience, and why we decided to kick code golf out. If such questions get quickly downvoted now, that's a reflection of that evolution among local culture -- in my view, for the better. Jun 26, 2015 at 0:08
9

TLDR
I think you're given a pretty clear exception here:

Constructive subjective questions:

inspire answers that explain “why” and “how”

The long version
There are plenty of questions on stackoverflow already that are based on problems that you wouldn't really encounter "in the wild" per se. These questions however, much like the question/answer that you reference, offer a great deal of insight into the nature of the language or platform in question. They are therefore educational to the majority and thus clearly beneficial to the community.

You referred to the guidelines set forth in the Help Center and ask if, based on the remarks there, such questions and answers would be off-topic. I think this is simply a case of the letter of the law versus the spirit of the law.

The true underlying intention of the "law" here is to prevent the creation of chatty threads that offer no real value to the majority of users. Posting code unique to a single user, where the question of "why" or "how" is raised definitely off-topic, but this isn't the case.

To clarify that last statement, I'd compare this question to a "why isn't this code working" type of question. Answering such a question is really just debugging someones code, and we have a specific close vote just for that. This type of question may seem similar in nature, but I believe the defining difference is the fact that this question drives answers that explain the inner workings of something, rather than explaining how something broken should work.

1
  • Another guideline from the Help Center, however, is that example code should be as short and direct in illustrating an issue as possible. Making it longer and harder-to-read for the virtue of creating a more clever puzzle that illustrates the exact same behavior is contrary to this goal. Jun 27, 2015 at 19:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .