Take the 2-minute tour ×


Please only one feature per answer.


locked by Will May 1 '13 at 21:13



320 Answers 320

In Java you might expect

byte b = 0;

to be equal to

byte b = 0;
b = b + 1;

But it is not. In fact you get a compiler error, as the result of the addition is of type int and therefore not assignable to the byte variable b. When using the compound operator ++ The compiler automatically inserts a cast here. So



b = (byte) b + 1;

Why does C#'s List<T>.AddRange() not let me Add elements of a subtype of T? List<T>.Add() does!
All it would take would be ONE extra line of code on Microsoft's part:

public void AddRange<S>(
    IEnumerable<S> collection
) where S : T
Not really a language feature insomuch as it is a framework feature. Pedantic, I know... –  Erik Forbes Jan 5 '10 at 16:48
It works with C# 4.0 due to new co- and contravariance features. –  Michael Damatov Jan 6 '10 at 9:17
@Denis: Try it yourself. That single line of code does solve this particular example because it is basically mimicking covariance (or contravariance, I never know which one is which). –  R. Martinho Fernandes Jan 7 '10 at 2:39
@Allon: no, that doesn’t use type inference and hence already worked pre-3.5. –  Konrad Rudolph Oct 1 '10 at 14:10

In C#, this should at least generate a compiler warning, but it doesn't:

public int Something
    get { return Something; }
    set { Something = value; }

When called, it causes your app to crash, and you don't get a good stack trace, since it's a StackOverflowException.

It's simple recursion, and one could write a perfectly valid recursively evaluated property. While the compiler could potentially be hard coded to catch some very simple cases of infinite recursion, to enforce it as a rule in the language would require a solution to the Halting Problem. Are you a bad enough dude to solve the Halting Problem? –  David Jan 6 '10 at 13:24
This particular case is simple, though. If the property does nothing but get or set itself (you'd need more than that for a valid use of a recursive property), generate a warning. I've seen too many developers and even whole teams stuck on a "mysterious crash" because of this issue, which is very hard to spot in a large code base. –  Eric Z Beard Jan 7 '10 at 11:45
I think this issue is considered fixed in the current version of the language. You should be using auto properties if your property is trivial. –  Mehrdad Afshari Jan 7 '10 at 13:01

Variable/function declarations in Javascript:

var x = 1;
function weird(){
  return x;
  var x = 2;

weird() returns undefined... x is 'taken' even though the assignment never happened.

Similarly, but not so unexpectedly

function weird2(){
   var x;
   return x();
   function x(){ return 2 };

returns 2.


VBScript's date/time literals (why is this still so rare?):

mydate = #1/2/2010 5:23 PM#

If mydate > #1/1/2010 17:00# Then ' ...

Edit: Date literals are relative (are they technically literals, then?):

mydate = #Jan 3# ' Jan 3 of the current year

VB.NET, since it is compiled, does not support relative date literals. Date only or time only literals are supported, but the missing time or date are assumed to be zero.

Edit[2]: Of course, there are some bizarre corner cases that come up with relative dates...

mydate = #Feb 29# ' executed on 2010-01-05, yields 2/1/2029
My issue with DateTime Literals is that they can be ambiguous - mydate = #10/9/2009 18:35# - October 9 or September 10? Nowadays I'm guessing it's always mm/dd/yyyy, but for non-US users it's always very odd to have a date not in dd/mm/yyyy format. In languages that have a Date constructor, you at least can always refer to the signature, but I guess it's not that different from just looking it up in the help or memorizing it. On the other hand: A whole language construct for Dates seems very "heavy". I can understand why Visual Basic has it (Office VBA), but I wouldn't see much use i.e. in C# –  Michael Stum Jan 5 '10 at 3:18
@Michael Stum: Agreed. ISO 8601 should probably be used, just to keep things clear. I guess the relative weight of language features depends a great deal on how it impacts the programmer personally. –  brianary Jan 5 '10 at 16:18

I've written a programming language for a client (used for experimentally driving custom hardware) with some custom types (Curl, Circuit, ...) that each have only 2 values. They are implicitly convertible to boolean, but (at the request of the client) the exact boolean value of a constant of such a type can be changed at runtime.

E.g.: The type Curl has 2 possible values: CW and CCW (clockwise and counterclockwise). At runtime, you could change the boolean value by a simple assignment statement:

ccw := true

So you could change the boolean meaning of all values of those types.


ActionScript 3:

When an object is used by its interface, the compiler doesn't recognize the methods inherited from Object, hence:

IInterface interface = getInterface();

gives a compilation error. The workaround is casting to Object



. and + operators. It has its reasonable explanation, but still "a" + "5" = 5 seems awkward.

Java (and any implementation of IEEE754):

System.out.println(0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1 + 0.1);

Outputs 0.9999999999999999

It's great that PHP didn't do what Javascript did with overloading the + operator for both string concatenation as well as addition. In PHP, if you see + you know you're talking about adding numbers. ...(unless you've got arrays...) –  nickf Jan 4 '10 at 8:08
The first one isn't a WTF - it's a gotcha that catches most people sooner or later regarding the finite-precision floating point representation on computers. –  Joris Timmermans Jan 4 '10 at 13:28
And it's not a Java WTF, it's WTF for any correct(!) implementation of IEEE754. –  R. Martinho Fernandes Jan 4 '10 at 14:14
C# just gives me a 1 :) –  Snake Jan 7 '10 at 11:44
That's because in C# the default type for a number with a floating point is Double. Having 0.1f instead of 0.1 would give the same result. –  Allon Guralnek Jan 7 '10 at 15:29

When I was in college, I did a little bit of work in a language called SNOBOL. The entire language, while cool, is one big WTF.

It has the weirdest syntax I've ever seen. Instead of GoTo, you use :(label). And who needs if's when you have :S(label) (goto label on success/true) and :F(label) (goto label on failure/false) and you use those functions on the line checking some condition or reading a file. So the statement:

H = INPUT :F(end)

will read the next line from a file or the console and will go to the label "end" if the read fails (because EOF is reached or any other reason).

Then there is the $ sign operator. That will use the value in a variable as a variable name. So:

output = $ANIMAL

will put the value 'BARK' on teh console. And because that isn't weird enough:


will create variable named BARK (see the value assigned to DOG above) and give it a value of 'SOUND'.

The more you look at it, the worse it gets. The best statement I ever found about SNOBOL (from link text) is "the power of the language and its rather idiomatic control flow features make SNOBOL4 code almost impossible to read and understand after writing it. "

the name of the language alone deserves an upvote here –  kristof Jan 5 '10 at 10:52
Perl has all those features... –  Andrew McGregor Jan 5 '10 at 13:18
PHP allows that aswell, $animal = "dog"; $dog = "bark"; echo $$animal; –  Kristoffer S Hansen Jan 5 '10 at 13:38
I should've also mentioned that my university didn't have a SNOBOL compiler. Instead, we had a SPITBOL compiler. –  Jeff Siver Jan 5 '10 at 14:40
The one time I wrote a class assignment in SNOBOL, it wasn't any fun at all. That language desperately needs better control structures, and that's far more important than having only one sort of statement (including label, main variable/value, pattern matching part or all of the former, equal sign, value to assign, and labels to jump to). –  David Thornley Jan 6 '10 at 16:12

In Haskell:

let 2 + 2 = 5 in 2 + 2

yields 5.

The reason is very straightforward: In haskell, (like in most other languages) you can simply redefine a function locally (haskell treats operators in the exact same way as "normal" functions), this lets the outer operator be hidden. After this, he just pattern matches against the values 2 and 2, like it's common in haskell. For instance, let 2 + 2 = 5 in 2 + 3 would yield a pattern matching failure. –  FUZxxl Aug 17 '10 at 10:54
this is the same as let (+) = \2 2 -> 5 in (+) 2 2 –  user954298 Aug 17 '10 at 12:14

Perl is full of odd but neat features.

if may be used before or after the statement like this:

print "Hello World" if $a > 1;    
if ($a > 1) { print "Hello World"; }

The same is true for foreach:

Ruby allows the same if-structures. It's one of my favourites from that language. –  Matt Grande Jan 4 '10 at 18:06
I actually like the if modifier as it makes the programs more expressive and readable. it lets you place the more important part of the statement (the condition or the action) before the other so it is prominent. Like any feature, it is useful if used judiciously and not abused. –  Prakash K Jan 5 '10 at 14:22

In PHP "true", "false" and "null" are constants which normally cannot be overridden. However, with the introduction of namespaces in PHP >=5.3, one can now redefine these constants within any namespace but the global namespace. Which can lead to the following behaviour :

namespace {
    define('test\true', 42);
    define('test\false', 42);
    define('test\null', 42);

namespace test {
    var_dump(true === false && false === null); // is (bool) true

Of course if you want your trues to be true, you can always import true from the global namespace

namespace test {
    var_dump(\true === \false); // is (bool) false


The whole language itself. While not exactly a WTF thing, I've never come across a language which plays out in my head in a squeeky cartoony voice. Nor have I ever looked at code before and want to exclaim "aaaawwww cuuute!"

This program displays the numbers 1–10 and terminates



echo 'foo' == 0;    // echos '1'
echo 'foo' == true; // echos '1'
echo 0 == true;     // echos '0'
$foo = 'foo';
echo $foo['bar']    // echos 'f'

PHP has some of the most annoying type coercion...


In C or C++ you can have a lot of fun with Macros. Such as

#define FOO(a,b) (a+b)/(1-a)

if FOO(bar++,4) is passed in it'll increment a twice.

or #define false true –  RCIX Jan 3 '10 at 15:49
#define while if (who needs loops?) #define void int ("Why is the compiler complaining about no explicit return from my void functions?") #define main(argv, argc) (main)(argc, argv) (switch argv and argc for no apparent reason) –  Chris Lutz Jan 4 '10 at 7:24
While there are dumb things you can do with #define, there ARE perfectly valid reasons for defining it the way it was defined. As opposed to some of the other entries here... –  Brian Postow Jan 4 '10 at 20:49
I've seen someone on stackoverflow mention #define private public. –  luiscubal Jan 4 '10 at 21:50
@wheaties: A long time ago, in a computer lab far away, some people came up with the C language. And C was without void at first; void only really appeared with standard C. That meant there were a heck of a lot of people with old compilers who wanted to run modern C code, and #define void int worked well enough to run some C90 code in K&R compilers. –  David Thornley Jan 4 '10 at 22:37

Perl filehandle-style operator calls.

In the beginning, there was

print "foo", "bar", "baz"; # to stdout
print STDERR "foo", "bar", "baz";

Notice the ostentatious lack of a comma so that you know that's a filehandle to print-to, not a filehandle to print in a stringified manner. It's a dirty hack.

Language upgrade rolls around, they make proper OO filehandles and turn x FOO y, z, abc into FOO->x(y, z, abc). Kinda cute. The same print statement effectively runs

STDERR->print("foo", "bar", "baz");

Mostly you notice this when you miss a comma, or try to run something like hashof $a, $b, $c (subroutine call without parentheses) and forget to import the hashof function into your namespace from its utility package, and you get a weird error message about "Can't call method 'hashof' via package 'contents of string $a'".

oh god, the horror is beautiful. : ) –  Aaron Fi Jan 5 '10 at 11:41
Dealing with filehandles in Perl is inconceivably awkward. They are not scalar values or objects, but a 3rd category that lacks decent syntactical support. So, a bunch of Perl modules like IO::Handle were created to make them more sensible -- except these objects don't work everywhere a real filehandle would. It's a good thing programmers don't need to work with files much. –  j_random_hacker Jan 31 '10 at 7:42

In Python:

>>> a[0] = "hello"
NameError: name 'a' is not defined
>>> a[0:] = "hello"
NameError: name 'a' is not defined
>>> a = []
>>> a[0] = "hello"
IndexError: list assignment index out of range
>>> a[0:] = "hello"
>>> a

These slice assignments also give the same results:

a[:] = "hello"
a[42:] = "hello"
a[:33] = "hello"

Easy pickins, Erlang is full of them. For example, 3 forms of punctuation,

a_function(SomeVariable) ->
  case PatternMatching of
    0 -> now_we_end_with_semicolon;
    true -> except_the_last_one

%%  Function definitions end with periods!

More of a platform feature than a language feature: on the iPhone, create an infinite loop with a few computations inside and run your program. Your phone will heat up and you can use it as a hand-warmer when it's cold outside.

I don't think that that is very good for the phone, though... –  Maximilian Mayerl Jan 7 '10 at 10:10
+1 for best use of iPhone other than paperweight or thrown missile –  iandisme Jan 15 '10 at 21:56


The Fast Inverse Square Root algorithm takes advantage of the IEEE floating-point representation (code copied from Wikipedia):

float InvSqrt(float x)
    union {
        float f;
        int i;
    } tmp;
    tmp.f = x;
    tmp.i = 0x5f3759df - (tmp.i >> 1);
    float y = tmp.f;
    return y * (1.5f - 0.5f * x * y * y);
Ah, this is the one that came out of Quake code, right? Love it, though it's not quite a language feature... –  Rei Miyasaka Oct 11 '10 at 20:26
Yes, it's from Quake. You're right, this has more to do with the IEEE 32-bit floating-point representation than C/C++. –  Jaime Soto Oct 11 '10 at 20:55
What's the relation to Cs language features? –  Nils Dec 6 '10 at 6:22

Bracket identifiers in VBScript

VBScript has so-called bracket identifiers, which are identifiers defined enclosed in square backets, like this:


They're quite handy, actually, as they allow you to name variables and routines after reserved words, call methods of third-party objects whose names are reserved words and also use almost any Unicode characters (including whitespace and special characters) in identifiers. But this also means that you can have some fun with them:

[2*2] = 5

[Здравствуй, мир!] = [Hello, world!]

[] = "Looks like my name is an empty string, isn't that cool?"


On the other hand, bracket identifiers can be a gotcha in case you forget the quotes in a statement like this:

If MyString = "[Something]" Then

because If MyString = [Something] Then is a perfectly legal syntax. (And that's why an IDE with syntax highlighting is a must!)

More info on bracket identifiers in Eric Lippert's blog:

Love the examples! –  Christian Hayter Jun 9 '10 at 7:23

In C or C++, parentheses are optional for the argument to sizeof ... provided the argument isn't a type:

void foo() {
  int int_inst;

  // usual style - brackets ...
  size_t a = sizeof(int);
  size_t b = sizeof(int_inst);
  size_t c = sizeof(99);

  // but ...
  size_t d = sizeof int_inst; // this is ok
  // size_t e = sizeof int; // this is NOT ok
  size_t f = sizeof 99; // this is also ok

I've never understood why this is!

It's not a macro, it's an operator. But that doesn't explain the discrepancy. –  tragomaskhalos Jan 7 '10 at 13:10

In JavaScript (and Java I think) you can escape funny characters like this:

var mystring = "hello \"world\"";

If you want to put a carriage return into a string though, that's not possible. You have to use \n like so:

var mystring = "hello, \nworld";

That's all normal and expected- for a programming language anyway. The weird part is that you can also escape an actual carriage return like this:

var mystring = "hello, \
The same as good old C syntax. But remember that standard HTML expects CR+LF ("\r\n") newlines. –  David R Tribble Jan 7 '10 at 3:28
@Loadmaster: sure you didn't mean HTTP? afaik HTML is line-separator-agnostic –  Christoph Jan 10 '10 at 14:01

In earlier version of Visual Basic, functions without a "Return" statement just "Return None", without any kind of compiler warning (or error).


Oh man this sucked. I was so glad they pulled that out in later versions of VB.NET. They really should have just created VB.Sharp and left the compatibility argument on the table. –  Jeff Atwood Jan 4 '10 at 20:21

String math in Perl is pretty weird.

$ perl -E '$string = "a"; $string++; say $string'

$ perl -E '$string = "abc"; $string++; say $string'

$ perl -E '$string = "money"; $string++; say $string'

$ perl -E '$string = "money"; $string--; say $string'
Very well-known, but still cool. –  Andreas Rejbrand Jul 6 '10 at 13:42
Also, incrementing "z" gives "aa". –  dan04 Jul 16 '10 at 10:10

In PowerShell, you can rename variables:

> $a = "some value"
> $b = "a"
> $c = "d"
> Rename-Item variable:$b $c
> $d
some value

Indirect indirection! Take that, PHP!

Literals work, too:

> Rename-Item variable:d e
> $e
some value

in PHP the strings letters cannot be used like in C, you need to use ord() and chr() in order to convert from number to char and vica versa: "a" != 97, but ord("a") == 97.

Although, there is one exception:

for ($i = 'a'; $i < 'z'; $i++) {
    print "$i ";

will print letters a to y. just like you would expect as if it was C style datatypes.

however if the test condition is changed to <= it will not print a to z as you would think, but a to yz! (total 676 items printed)

also if you change the 'z' to 'aa' which came out next after 'z' in the 676 items list, and change test condition to < again, you will see only "a" being printed out! not a to z as you would expect.

And if you change the incrementor to $i+=2 it will print only "a" again! only way to do that is to use $i++, $i++ in sequence, and now it works like expected.

Nevertheless, this is a nice way in PHP to output combinations of letters a-z, although its very hard to actually use it.

ZOMGWTF!! My already low opinion of PHP just cratered. –  n8gray May 2 '10 at 7:30

The bigest collection (today 1313) of decent and weird programming languages I know, you will find here: http://99-bottles-of-beer.net/ be prepared to see real weird stuff ;-) Everybody should make his one choice

esolangs.org/wiki/Main_Page –  Thomas Eding Jan 4 '10 at 8:08

Early FORTRAN where whitespace was not significant. (The anti-Python!)

DO 20 I = 1, 10

Meaning: loop from here to line 20 varying I from 1 to 10.

DO 20 I = 1. 10

Meaning: Assign 1.10 to the variable named DO20I.

Rumors are that this bug crashed a space probe.



Time.parse often pretends that the parsing did not fail, returns now instead

require 'time'

Time.parse '2000-01-01 12:00:00'
# -> 2000-01-01 12:00:00 +0100

Time.parse '2000-99-01 00:00:00'
# -> ArgumentError: argument out of range ...

Time.parse 'now'
# -> 2010-08-13 21:26:13 +0200

Time.parse 'yesterday'
# -> 2010-08-13 21:26:18 +0200

Time.parse 'billion years ago'
# -> 2010-08-13 21:26:37 +0200

Java's access modifiers are a recent WTF to me (as I had to learn a bit of it).

Apparently packages are more intimate than class hierarchies. I can't define methods and attributes that are visible to sub-classes but not to other classes in the package. And why would I want to share the insides of a class to other classes?

But I can define attributes and methods that are visible to every class inside the package, but not to subclasses outside the package.

No matter how hard I think about this, I still can't see the logic. Switch over the access modifiers and make protected act like it works in C++ and keep the package private modifier as it is and it would make sense. Now it doesn't.

The logic is pretty obvious to me: not a class, but a package is a unit of maintenance. Hiding members from subclasses effectively reserves the right for the maintainer to remove or rename them without breaking code in subclasses, which is pretty useful if those subclasses are in a different package, and were probably written by completely different people at a completely different time and place. The package maintainers may not even know the subclass exists at all. –  reinierpost Jan 4 '10 at 9:18
Well, I still don't understand why that is better. Unless we keep packages really small, the problem is the same as in any application development: what you want to use OO for is exactly what this is countering. –  Makis Jan 5 '10 at 18:53
