54 comments

[ 3.0 ms ] story [ 63.8 ms ] thread
So much javascript in this stackoverflow thread.
Such a shame these kinds of questions are banned from StackOverflow these days. Takes all the fun out things...
I think Hume may have argued with the 'Cogito ergo sum' statement.
Weirdly many people loathe C++ for it's weird parts and complexity and all, but there's very little of C++ in that thread. I honestly expected people to run circles around templates and operator overloading.
I don't really feel either of those features are that 'strange'. Most of C++'s features are not bizarre considered in isolation. Their ugliness comes from the fact that they have surprising limitations, unpleasant syntax, and don't compose well.
I almost feel like C++ gets a pass because people just expect it to have weird fucked up stuff. People expect weirdness out of it thus wouldn't be surprised by examples.

OTOH, by that same logic there should have been less JavaScript representation, because JavaScript is downright goofy.

Sort of like how if you asked about weird stuff in biology, you won't get a lot of Platypus answers, even though the Platypus is really weird.
Perhaps, as with PHP, there are simply too many obvious options.
Found a few interesting bits there. A reference to a Quiz about C# and object equality: http://blogs.msdn.com/b/jmstall/archive/2005/03/06/386064.as...

The last one makes me wonder a bit. Given local int variable x, what does this evaluate to?

(object) x.ToString() == (object) x.ToString()

When I run it, I get false, and the author says that it's false, because we're doing reference comparison of two independently created objects. But I thought strings were interned in .NET, so if you independently create 2 strings with the same contents, then they are actually the same object, which would make this true?

String constants are interned at compile time. Dynamically created strings are typically not interned.
I would say that it is because each time ToString() is called a new string is created, and at least in the Java I believe that is what will happen, comparison will be false because they are not the same instance.
It's a bit trickier than that due to string interning. That's where there is only one instance framework-wide of a string of a particular value. Try to create a second string with the same value as one you have created already, and you get back a reference to the first string instance.

As an example:

(object)"XYZ" == (object)"XYZ"

returns true. So does:

(object) String.Intern(x.ToString()) == (object) String.Intern(x.ToString())

The trick is to know exactly which strings are interned, and when. I initially thought that all strings were, but it seems that string literals in code are always interned, and dynamically-created strings are mostly not interned automatically, but can be manually.

http://en.wikipedia.org/wiki/String_interning http://msdn.microsoft.com/en-us/library/system.string.intern...

It's amusing how nearly all of the most interesting and popular questions I see on StackOverflow are closed by moderators for not being good or constructive.
It makes perfect sense in light of StackOverflow's stated reason for existing, which is to answer closed-ended questions.

Can we please not turn this thread into a complaining session about SO's policies?

> Can we please not turn this thread into a complaining session about SO's policies?

No, because every website has to be all things to all people, even if it means the destruction of the few things it was actually good at.

A dozen people scramble to make that "original" observation any time Stack Overflow is mentioned anywhere.
Open-ended and subjective questions tend to be more interesting than questions that have a definite answer.
Surprised to not see Erlang there.
Erlang is rusty and sometimes very different, but rarely strange.
I think "[x]." returning a certain character when 7<x<256 is pretty strange. There's probably a reason for this, but I'm pretty new to the language.
It's that Erlang doesn't have strings or characters. It has string syntax on input, which turns into lists of small integers, and also on output. But under the covers, those apparent strings are just lists of integers.
Speak for yourself ;). Erlang's conditionals are weird, by any mainstreamish standard. And that's ok, they're sorta cool once you get them.
As someone who started programming in ML and later in Prolog, they are far from weird.

Other than that, they are not a "strange language feature", they don't behave in unexpected or unclear ways.

While `!` is certainly a very special piece of erlang, its also not strange as well, as in say.... Ruby flipflops?

Fair enough. I don't consider ML and prolog to be "mainstreamish", and I'm defining "strange" to mean "unusual".
It's strange in the sense that Willy Wonka's fizzy lifting drinks are strange in a factory with oompa loompas and chocolate rivers. Any good experience is going to change your brain and feel strange at first. :-)
Control / Conditionals in Icon and anything in MUMPS
(comment deleted)
The closest I am to being famous is this question on SO, to which I gave the #1 answer. I'd been waiting years to get that piece of trivia off my chest, and it was oh-so-rewarding. The answer was that you can use arrays like so: 5[arr], not just the usual way (arr[5])

Funny enough, several people gave interesting places where this kind of syntax is a good thing. Goes to show that even meaningless pieces of fun on SO still end of enriching the reader.

Pointer arithmetic via syntactic sugar is definitely fun. I still love the occasional "variable index of a literal".
What places is this syntax a good thing? I read through the comments on your answer, but every single one that claimed this was either pointless (e.g. 0[x] instead of (x)[0]) or not even an example of the trick in question (e.g. "blah"[index] is not this). I was hoping for something interesting, thus my question.
Honestly, I wrote this because I remembered that somebody had a use for this. A funny use, but a semi-legitimate one none the less.

Unfortunately, I can't really find it now - there is a link to a question which claims to have a use for this syntax, but it's been removed.

There are these 2 comments: "Don't forget "Hello World"[i]. Or i["Hello World"] – Richard Pennington Jan 3 '10 at 15:12"

"Or, more usefully, "0123456789abcdef"[x & 0xf] "

Their basic point is that you can use this trick to find the i'th character in a string. Which I guess is useful sometimes...

Except that "0123456789abcdef"[x & 0xf] is just normal array dereferencing syntax, not the backwards kind you pointed out. The backwards version would be (x & 0xf)["0123456789abcdef"], which isn't really useful, I think.

Oh well. If you happen to find the funny but semi-legitimate one, I'd love to see it.

You're right - that is the normal way (although not commonly seen). I'll update if I find it.
The answer on the deleted question (http://stackoverflow.com/questions/469696/what-is-your-most-...), by Josh Kelley, gives this:

---

Get the number of elements in an array:

    #define ITEMSOF(arr)    (sizeof(arr) / sizeof(0[arr]))
(0[arr] is identical to arr[0] for arrays but will intentionally fail if it's used against a C++ object that overloads operator[].)

He gives a C++ template version, too.

---

... 10k+ users on Stack Overflow can see deleted stuff. Or you can probably get them out of the CC data dumps (but that's a lot more work than you want, probably). Or maybe out of the data explorer.

Ah! I saw that #define but didn't see the bit about failing on C++ objects that overload operator[]. I don't do C++ much so that really didn't occur to me.

I personally prefer sizeof(*(arr)), which is the same as arr[0], but I suppose C++ lets you overload that as well.

For C it should most certainly be the ability to interleave the switch-case and a block statement as per Duff's device:

    register n = (count + 7) / 8;
    switch(count % 8) {
    case 0: do {    *to = *from++;
    case 7:         *to = *from++;
    case 6:         *to = *from++;
    case 5:         *to = *from++;
    case 4:         *to = *from++;
    case 3:         *to = *from++;
    case 2:         *to = *from++;
    case 1:         *to = *from++;
        } while(--n > 0);
    }
[0] http://en.wikipedia.org/wiki/Duff%27s_device
I wouldn't necessarily call this strange if you think about how this directly translates to assembly instructions.
It's pretty strange nonetheless that it compiles at all. Underlying it is that a switch statement isn't a proper control structure but syntax sugar for goto.
while() loops are really syntax sugar for goto too. And whole C is arguably just a syntax sugar for assembler :) That's why we use it.
They're not syntax sugar for goto the way switch is though. You can't pull stunts like that with two intermingled while loops because a while loop operates on a single block.
Not in the sense of "wrong", but in terms of difficulty of comprehension, for me it's call/cc in scheme:

http://en.wikipedia.org/wiki/Call-with-current-continuation

The main thing which helped me get some kind of grip on it was having worked through longjmp/setjump in C some time ago.

If you check with Oleg, it actually is wrong! Delimited continuations are strictly more powerful and composable. We're supposed to be using shift/reset or prompt/abort.
"Context" in Perl. Values undergo implicit conversion when assigned depending on whether the LValue receiving the assignment is a scalar or a list type. Perl functions can detect context at runtime (using "wantarray") and may vary behavior for different contexts.