What is, in your opinion, the most surprising, weird, strange or really "WTF" language feature you have encountered?
Please only one feature per answer.
What is, in your opinion, the most surprising, weird, strange or really "WTF" language feature you have encountered?
Please only one feature per answer.
The many name spaces of C:
Or with characters:
I'm surprised that no one has mentioned Visual Basic's 7 loop constructs.
Because sticking an ! in front of your conditional is way too complicated!
Perl’s many built-in variables:
$#
— not a comment!$0
,$$
, and$?
— just like the shell variables by the same name$ˋ
,$&
, and$'
— weird matching variables$"
and$,
— weird variables for list- and output-field-separators$!
— likeerrno
as a number butstrerror(errno)
as a string$_
— the stealth variable, always used and never seen$#_
— index number of the last subroutine argument... maybe@_
— the (non)names of the current function... maybe$@
— the last-raised exception%::
— the symbol table$:
,$^
,$~
,$-
, and$=
— something to do with output formats$.
and$%
— input line number, output page number$/
and$\
— input and output record separators$|
— output buffering controller$[
— change your array base from 0-based to 1-based to 42-based: WHEEE!$}
— nothing at all, oddly enough!$<
,$>
,$(
,$)
— real and effective UIDs and GIDs@ISA
— names of current package’s direct superclasses$^T
— script start-up time in epoch seconds$^O
— current operating system name$^V
— what version of Perl this isThere’s a lot more where those came from. Read the complete list here.
Let's have a vote for all languages (such as PL/I) that tried to do away with reserved words.
Where else could you legally write such amusing expressions as:
(
IF
,THEN
,ELSE
are variable names)or
(
IF
is a variable,THEN
andELSE
are subroutines)I would say the whole whitespace thing of Python is my greatest WTF feature. True, you more-or-less get used to it after a while and modern editors make it easy to deal with, but even after mostly full time python development for the past year I'm still convinced it was a Bad Idea. I've read all the reasoning behind it but honestly, it gets in the way of my productivity. Not by much, but it's still a burr under the saddle.
edit: judging by the comments, some people seem to think I don't like to indent my code. That is an incorrect assessment. I've always indented my code no matter what the language and whether I'm forced to or not. What I don't like is that it is the indentation that defines what block a line of code is in. I prefer explicit delimiters for that. Among other reasons, I find explicit delimiters makes it easier to cut and paste code.
For example, if I have a block indented 4 spaces and paste it at the end of a block that is indented 8 spaces, my editor (all editors?) have no idea if the pasted code belongs to the 8-space block or the outer block. OTOH, if I have explicit delimiters it's obvious which block the code belongs to and how it should be (re-)indented -- it does so by intelligently looking for block delimiters.
edit 2: some people who provide comments seem to think this is a feature I hate or that I think makes python a poor language. Again, not true. While I don't like it all that much, that's beside the point. The question is about the strangest language feature, and I think this is strange, by virtue of it being something very, very few (but >0) languages use.
In JavaScript:
Luckily the kind folks at stackoverflow.com explained the whole thing to me: Why does 2 == [2] in JavaScript?