972
votes

What is, in your opinion, the most surprising, weird, strange or really "WTF" language feature you have encountered?

Please only one feature per answer.

1
  • 5
    @gablin I think if you combined LISP delimiters with PERL regex using javascript parsing you would cover 90% of the WTF... Sep 19, 2010 at 23:41

320 Answers 320

1 2 3
4
5
11
17
votes

In Java you might expect

byte b = 0;
b++;

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++;

becomes

b = (byte) b + 1;
16
votes

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
7
  • 4
    Not really a language feature insomuch as it is a framework feature. Pedantic, I know... Jan 5, 2010 at 16:48
  • I would call it a framework design oversight - but it's definitely a WTF Jan 6, 2010 at 2:25
  • 3
    It works with C# 4.0 due to new co- and contravariance features. Jan 6, 2010 at 9:17
  • 2
    @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). Jan 7, 2010 at 2:39
  • 1
    @Allon: no, that doesn’t use type inference and hence already worked pre-3.5. Oct 1, 2010 at 14:10
16
votes

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.

7
  • 33
    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, 2010 at 13:24
  • 1
    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. Jan 7, 2010 at 11:45
  • 4
    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. Jan 7, 2010 at 13:01
  • Mehrdad: Since auto properties can't have an initial value, the typical solution is to implement the property yourself.
    – Gabe
    Jun 9, 2010 at 16:05
  • VB .NET will raise an ERROR in this case.
    – Joshua
    Aug 13, 2010 at 20:43
16
votes

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.

2
  • this happens because of hoisting of the variable & function declarations
    – gion_13
    Nov 22, 2011 at 8:36
  • This is simply an example of hoisting. Adequately Good gives a very in-depth article about hoisting.
    – Kevin Ji
    Dec 7, 2011 at 2:17
16
votes

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
8
  • Scala has XML literal notation. def xmlString = <xml>foo bar <b>baz</b></xml>
    – user240438
    Jan 5, 2010 at 1:00
  • why is this still so rare? because literal date is not needed often -- time span literals would be more useful. Jan 5, 2010 at 1:52
  • 3
    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# Jan 5, 2010 at 3:18
  • @fennec: So does VB.NET 9, now that you mention it.
    – brianary
    Jan 5, 2010 at 16:13
  • 2
    @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, 2010 at 16:18
15
votes

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.

1
  • This would seem like a good idea to me (it allows things like ccw to be defined based on what is in actual data), but only if all such assignments are the same. Differences should be flagged as conflicts, unless there's some awesome way for the compiler to translate between modules. It does seem pretty out there at first glance, I'll agree, but it's a neat idea if you're dealing with input data whose sense you have no control over.
    – Mike D.
    Jan 4, 2010 at 3:37
15
votes

ActionScript 3:

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

IInterface interface = getInterface();
interface.toString();

gives a compilation error. The workaround is casting to Object

Object(interface).toString();

PHP:

. 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

11
  • It also means PHP has to use -> for qualifying objects instead of the prettier ..
    – cdmckay
    Jan 4, 2010 at 7:45
  • 3
    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, 2010 at 8:08
  • 8
    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. Jan 4, 2010 at 13:28
  • 9
    And it's not a Java WTF, it's WTF for any correct(!) implementation of IEEE754. Jan 4, 2010 at 14:14
  • 1
    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. Jan 7, 2010 at 15:29
15
votes

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:

ANIMAL = 'DOG'
DOG = 'BARK'
output = $ANIMAL

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

$DOG = 'SOUND'

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. "

6
  • 6
    PHP allows that aswell, $animal = "dog"; $dog = "bark"; echo $$animal; Jan 5, 2010 at 13:38
  • 2
    I should've also mentioned that my university didn't have a SNOBOL compiler. Instead, we had a SPITBOL compiler.
    – Jeff Siver
    Jan 5, 2010 at 14:40
  • 3
    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). Jan 6, 2010 at 16:12
  • @Kris It would be more useful as an array $animal[$dog][$bark]=$sound; or class $animal->dog->bark=$sound; Jun 11, 2010 at 3:40
  • 1
    I heard a SNOBOL anecdote of smartass programmers who used to bring their stacks of SNOBOL cards to the card reader, make a show of dropping them all on the floor, picking them up in a random pile, and drop the whole lot into the reader. SNOBOL would happily run their program as intended with no problem, while the other languages on the machine would invite the programmer to spend the evening manually sorting cards.
    – sarnold
    Jul 11, 2010 at 7:14
15
votes

In Haskell:

let 2 + 2 = 5 in 2 + 2

yields 5.

3
  • Can I get an explanation to this?
    – Bobby
    Aug 17, 2010 at 10:17
  • 2
    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.
    – fuz
    Aug 17, 2010 at 10:54
  • 4
    this is the same as let (+) = \2 2 -> 5 in (+) 2 2
    – user954298
    Aug 17, 2010 at 12:14
15
votes

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:

print "Hello $_!\n" foreach qw(world Dolly nurse);
8
  • 8
    Ruby allows the same if-structures. It's one of my favourites from that language. Jan 4, 2010 at 18:06
  • Ruby allows this, but personally I think that consistently putting the "if" first makes code easier to read. It's just as grammatically pleasing, anyway, and you don't have to reorder if you need to add an else. Jan 4, 2010 at 21:03
  • 7
    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, 2010 at 14:22
  • fyi, this is called mutator syntax, and is syntactically awesome: last unless defined $row Jan 5, 2010 at 18:24
  • Good thing I can control myself, or I would start to rant on Perl... odd, sure. Neat? Not by a... okay, I shut up. Jan 14, 2010 at 3:34
15
votes

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
}
1
  • If it was global, define("TRUE",false,false);define("true",true,false); would be echo(TRUE==false);//echos true and echo(true==false);//echos false... TRUE would then mean not really true, unless its lowercase. Jun 11, 2010 at 2:39
14
votes

LOLCODE!

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

HAI
CAN HAS STDIO?
IM IN YR LOOP UPPIN YR VAR TIL BOTHSAEM VAR AN 10
    VISIBLE SUM OF VAR AN 1
IM OUTTA YR LOOP
KTHXBYE
1
  • Well, the language is ment as a joke, just as INTERCAL. I don't see such a great "weird feature in there"...
    – polemon
    Aug 29, 2010 at 17:32
14
votes

In PHP:

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...

1
  • If it's not clear above, true and false are equal to 1 and 0, respectively (and their names aren't case sensitive. TRUE or FALSE or True or False also work.)
    – pib
    Jan 16, 2010 at 20:04
13
votes

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.

9
  • 9
    #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, 2010 at 7:24
  • 3
    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... Jan 4, 2010 at 20:49
  • 11
    I've seen someone on stackoverflow mention #define private public.
    – luiscubal
    Jan 4, 2010 at 21:50
  • 3
    @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. Jan 4, 2010 at 22:37
  • 1
    I've heard that this is actually undefined because having the decrement/increment operator(s) occur more than once in a statement apparently isn't defined. Unconfirmed.
    – bambams
    Jan 11, 2010 at 21:49
13
votes

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'".

1
  • 3
    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. Jan 31, 2010 at 7:42
12
votes

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
['h', 'e', 'l', 'l', 'o']

These slice assignments also give the same results:

a[:] = "hello"
a[42:] = "hello"
a[:33] = "hello"
2
  • I agree that the a[0:] and a[42:] should raise an IndexError - but both the a[:] and a[:33] style make sense and can be usefull.
    – jsbueno
    Jan 7, 2010 at 12:51
  • If a[:33] can be useful, why not a[42:]? Don't see the big difference. (And a[:] is of course incredibly useful) Jan 12, 2010 at 6:35
12
votes

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

a_function(SomeVariable) ->
  statements_end_with_commas(),
  case PatternMatching of
    0 -> now_we_end_with_semicolon;
    true -> except_the_last_one
  end.

%%  Function definitions end with periods!
2
  • I guess I should add that this isn't a language feature, per se, more of an odd choice in syntax. If I had to pick an odd language feature of Erlang, it would be the representation of strings as lists of integers. Meaning [80,97,117,108]. => "Paul". I wonder what implications this had for Facebook Chat, if any? Jan 6, 2010 at 21:26
  • A C string is also just a list of integers, sort of.
    – Tor Valamo
    Jan 10, 2010 at 19:55
12
votes

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.

2
  • 11
    +1 for best use of iPhone other than paperweight or thrown missile
    – iandisme
    Jan 15, 2010 at 21:56
  • I have an idea for an app… :)
    – user142019
    Aug 8, 2011 at 21:09
12
votes

C/C++:

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);
}
3
  • 6
    Ah, this is the one that came out of Quake code, right? Love it, though it's not quite a language feature... Oct 11, 2010 at 20:26
  • 1
    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, 2010 at 20:55
  • 1
    What's the relation to Cs language features?
    – Nils
    Dec 6, 2010 at 6:22
12
votes

Bracket identifiers in VBScript

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

[Foo]

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?"

For[For[i=0]=[0]To[To[To[0]
  [Next[To]([For[i=0])=[For[i=0]
Next

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:

1
  • Hm... In pure mathematics, [x] is sometimes used to denote a very "formal" interpretation of x, as in [0/0] and [∞/∞] (two interesting cases of limits of fractions). Although I am aware of no precise definition of [], I would say something like "I mean exactly what I write, but do not try to interpret it literally". Related? Jul 6, 2010 at 13:46
12
votes

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!

2
  • That's because sizeof is not a function, it's a macro. Jan 7, 2010 at 12:17
  • 13
    It's not a macro, it's an operator. But that doesn't explain the discrepancy. Jan 7, 2010 at 13:10
12
votes

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, \
world";
9
  • 2
    The same as good old C syntax. But remember that standard HTML expects CR+LF ("\r\n") newlines. Jan 7, 2010 at 3:28
  • 10
    @Loadmaster: sure you didn't mean HTTP? afaik HTML is line-separator-agnostic
    – Christoph
    Jan 10, 2010 at 14:01
  • It's quite handy, actually, when you need to define a veeeeery long string without messing with string concatenation operators.
    – Helen
    Feb 8, 2010 at 19:26
  • @Helen except that it kind of breaks down if you want to minify or do any other sort of automated whitespace manipulation.
    – Breton
    Feb 8, 2010 at 21:57
  • Beware, that while this works in many browsers, it is not part of the ECMAScript standard. See: google-styleguide.googlecode.com/svn/trunk/…
    – martineno
    Dec 15, 2011 at 19:13
11
votes

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

This lead to the most crazy debugging sessions back when I had to deal with this language on a daily basis.

3
  • 3
    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. Jan 4, 2010 at 20:21
  • I'd say the return statement that lets you return a value is one of my favorite improvements of VB.NET over VB6. (My #1 favorite is exceptions vs. On Error Goto.)
    – Nate C-K
    Jan 7, 2010 at 5:35
  • This is also one of python's features. In a strongly typed language it wouldn't be so bad, and one could actually argue that it's good because it makes things more uniform (all functions have a return value), but with dynamic typing it always causes me headache. Jan 7, 2010 at 15:47
11
votes

String math in Perl is pretty weird.

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

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

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

$ perl -E '$string = "money"; $string--; say $string'
-1
1
  • 3
    Also, incrementing "z" gives "aa".
    – dan04
    Jul 16, 2010 at 10:10
11
votes

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
3
  • Yeah, PowerShell drives me mad. I wrote to them about the syntax one time. They responded, somewhat evasively: blogs.msdn.com/b/powershell/archive/2006/07/23/… Nov 20, 2010 at 0:20
  • The worse part is that, despite the WTFs, PowerShell looks clean when compared to other shells (sh, bash, csh, tcsh, comd.exe, etc.) and Perl. Ever tried to understand Bash's $(()), $(), [[]], etc.?
    – marcus
    Jun 13, 2011 at 20:48
  • @marcus: Yes, see my answers here and here for examples. Jun 15, 2011 at 11:25
11
votes

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.

1
  • "=UTF-8 vs '=ASCII. $i will render as an integer/byte Jun 11, 2010 at 1:46
10
votes

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

0
10
votes

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.

10
votes

Ruby

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
9
votes

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.

6
  • 11
    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. Jan 4, 2010 at 9:18
  • So only one person can update a package? Considering how large even some Java base packages are, that's a tall order.
    – Makis
    Jan 4, 2010 at 10:49
  • @Makis: "the maintainer" is the group that's responsible for the package (perhaps it should have been "the maintainers"). Programmers writing subclasses outside this group shouldn't have to worry about package internals.
    – outis
    Jan 5, 2010 at 14:11
  • 1
    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, 2010 at 18:53
  • I always considered this strange too. The only reason I could thought up is the strict order of modifiers: public > protected > package > private
    – user57697
    Jan 7, 2010 at 11:10
1 2 3
4
5
11

Not the answer you're looking for? Browse other questions tagged or ask your own question.