7 ms·
Strangest language feature
- jrajav 14y agoPrevious discussions: https://news.ycombinator.com/item?id=1601062 https://news.ycombinator.com/item?id=1601062 https://news.ycombinator.com/item?id=1032077 https://news.ycombinator.com/item?id=1032077
- Liongadev 14y agoSo much javascript in this stackoverflow thread.
- pja 14y agoSuch a shame these kinds of questions are banned from StackOverflow these days. Takes all the fun out things...
- JohnLBevan 14y agoThere's Code Golf and Programmers to cater for some of these things - but I'm a little blurry on the rules of exactly what the boundaries of each site are. http://codegolf.stackexchange.com/ http://codegolf.stackexchange.com/ http://programmers.stackexchange.com/ http://programmers.stackexchange.com/
- JohnLBevan 14y agoI think Hume may have argued with the 'Cogito ergo sum' statement.
- zxcdw 14y agoWeirdly 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.
- swift 14y agoI 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.
- georgemcbay 14y agoI 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.
- mikeash 14y agoSort 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.
- podperson 14y agoPerhaps, as with PHP, there are simply too many obvious options.
- mylons 14y agoI really like this one in C++: http://stackoverflow.com/a/2024573/710332 http://stackoverflow.com/a/2024573/710332
- bkanber 14y agoConway's Game of Life in APL blew me away: http://www.youtube.com/watch?v=a9xAKttWgP4 http://www.youtube.com/watch?v=a9xAKttWgP4
- ufmace 14y agoFound 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.aspx 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?
- kvb 14y agoString constants are interned at compile time. Dynamically created strings are typically not interned.
- LoneWolf 14y agoI 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.
- ufmace 14y agoIt'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://en.wikipedia.org/wiki/String_interning http://msdn.microsoft.com/en-us/library/system.string.intern.aspx http://msdn.microsoft.com/en-us/library/system.string.intern...
- vor_ 14y agoIt'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.
- andrewflnr 14y agoIt 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?
- derleth 14y ago> 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.
- frou_dh 14y agoA dozen people scramble to make that "original" observation any time Stack Overflow is mentioned anywhere.
- Dewie 14y agoOpen-ended and subjective questions tend to be more interesting than questions that have a definite answer.
- mehrzad 14y agoSurprised to not see Erlang there.
- Argorak 14y agoErlang is rusty and sometimes very different, but rarely strange.
- mehrzad 14y agoI 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.
- kragen 14y agoIt'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.
- andrewflnr 14y agoSpeak for yourself ;). Erlang's conditionals are weird, by any mainstreamish standard. And that's ok, they're sorta cool once you get them.
- Argorak 14y agoAs 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?
- andrewflnr 14y agoFair enough. I don't consider ML and prolog to be "mainstreamish", and I'm defining "strange" to mean "unusual".
- protomyth 14y agoControl / Conditionals in Icon and anything in MUMPS
- deleted 14y ago[deleted]
- edanm 14y agoThe 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.
- reeses 14y agoPointer arithmetic via syntactic sugar is definitely fun. I still love the occasional "variable index of a literal".
- mikeash 14y agoWhat 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.
- edanm 14y agoHonestly, 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...
- mikeash 14y agoExcept 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.
- huhtenberg 14y agoFor 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 http://en.wikipedia.org/wiki/Duff%27s_device
- niggler 14y agoI wouldn't necessarily call this strange if you think about how this directly translates to assembly instructions.
- podperson 14y agoIt'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.
- smsm42 14y agowhile() 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.
- podperson 14y agoThey'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.
- jbert 14y agoNot 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 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.
- victorh 14y agoIf 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.
- hrydgard 14y agoOn Error Resume Next. http://msdn.microsoft.com/en-us/library/aa266173(v=vs.60).aspx http://msdn.microsoft.com/en-us/library/aa266173(v=vs.60).as...
- epmatsw 14y agoOh god. I've seen way to many bugs as a result of this stupid feature.
- teleological 14y ago"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.