
Strangest Programming Language Feature? - jackhammer2022
http://stackoverflow.com/questions/1995113/strangest-language-feature/2002154#2002154
======
Someone
No mention of "ALTER" ([http://en.wikipedia.org/wiki/COBOL#Self-
modifying_code](http://en.wikipedia.org/wiki/COBOL#Self-modifying_code)) on
the first page?

Self-modifying code was fairly common at the time COBOL was developed, but
incorporating it in a high-level business language was, IMO, a very weird
decision.

I also miss call by name
([http://en.wikipedia.org/wiki/Man_or_boy_test](http://en.wikipedia.org/wiki/Man_or_boy_test))
on the first page.

In general, one should read the Intercal
([http://en.wikipedia.org/wiki/INTERCAL](http://en.wikipedia.org/wiki/INTERCAL))
paper, and figure out from which language each of its features came.

~~~
EvanAnderson
Your mentioning "ALTER" made me think about a dialect of BASIC that I once
used (STARDOS BASIC on a "Micro V" computer, back in the late 1980s). This
BASIC dialect had an "XEQ" function that would pass a string to the tokenizer
and execute it as an immediate-mode command. If you started the string with a
line number you could create self-modifying BASIC code. It was dizzying to my
young mind.

------
antirez
Smalltalk's "become" is a pretty interesting one...
[http://gbracha.blogspot.it/2009/07/miracle-of-
become.html](http://gbracha.blogspot.it/2009/07/miracle-of-become.html)

~~~
BrandonY
Smalltalk also is rather famous for giving developers enough freedom to more
or less destroy the environment with the terrifying looking command "Smalltalk
:= nil"

~~~
rbanffy
I once crashed Squeak by making true := false. It was an interesting
experience.

------
Crito
It logically follows from how arrays in C works, so I don't really know if it
qualifies for weird/suprising, but the old _array[i]_ / _i[array]_ thing is
fun to show to people who haven't seen it before.

The most amusingly weird thing I can think of is INTERCAL's COMEFROM:
[http://en.wikipedia.org/wiki/COMEFROM](http://en.wikipedia.org/wiki/COMEFROM)

~~~
ThatOtherPerson
Can you explain your _array[i] / i[array]_ reference? I can't find it on
Google.

~~~
kps

      By definition, the subscript operator [] is interpreted in such a
      way that ‘‘E1[E2]’’ is identical to ‘‘*((E1) + (E2))’’.  Because
      of the conversion rules which apply to +, if E1 is an array and
      E2 an integer, then E1[E2] refers to the E2th member of E1.
      Therefore, despite its asymmetric appearance, subscripting is a
      commutative operation.¹
    

¹ Dennis M Ritchie, _C Reference Manual_ , 1975 [http://cm.bell-
labs.com/cm/cs/who/dmr/cman.pdf](http://cm.bell-
labs.com/cm/cs/who/dmr/cman.pdf) (A revised version of this became Appendix A
to K&R.)

------
al2o3cr
/me drops the MUMPS reference manual on the table

That whole language is one long-running WTF.

~~~
roywiggins
This line in MUMPS is not only valid, it also actually does something
potentially useful:

    
    
        s:foo'="" foo(foo)=foo
    

It's actually a bit tricky to explain what it does. Everything in MUMPS is
effectively a tree. Each tree has a value in the "root node" and you can set
it like this:

    
    
        set foo="hello"
    

You can also put data deeper into the tree:

    
    
        set foo("fizz")="buzz"
    

So if something is passed to you and you want to know if you can treat it as a
string, you test to see if it's a null string:

    
    
        if foo'="" do [something]

('= means !=)

Two more features: 1) Almost every directive can be reduced to one letter. 2)
If I want to quit based on a condition, I can do either if condition quit or
quit:condition

So the line above is more legibly written as

    
    
        if foo'=""  set foo(foo)=foo
    

So if foo="bar", it's equivalent to:

    
    
        set foo("bar")="bar"

~~~
MetaCosm
It is amazing that MUMPS will be 50 years old in 2 years -- and it still alive
and kicking.

An emergency MUMPS project is still my highest billing project (per hour)
ever.

~~~
dman
What was the rate?

------
jejones3141
Someone's already mentioned COBOL's ALTER X TO PROCEED TO Y, so I'll mention a
programming language called COMAL. A friend with a C64 showed it to me, and it
was very respectable for its time and the available resources; reminded me of
BASIC09.

Apparently it was written by someone from Denmark, and there were commands to
switch back and forth between English and Danish. I don't remember whether it
was just for error messages or for those and for the language keywords as
well; I want to say the latter.

------
mck-
In CoffeeScript I discovered the other day that:

    
    
      0 <= "" <= 0   # True
      "" is 0        # False

~~~
shoo
I guess that is because coffeescript's <= operator is just javascript's <=
operator, which does implicit type conversion.

but coffeescript's "is", aka ==, aka === in javascript, doesn't.

[https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Refe...](https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators)

having "==" be semantically quite different to "<=" doesn't seem a
particularly nice choice of notation.

arguably coffeescript has made things worse in this case compared to plain
javascript, where you're probably not going to expect === to behave similarly
to <=.

not obvious how you'd improve this to make it consistent, without say
redefining how "==" and "<=" work to make them raise type errors or evaluate
to something undefined if the types of the arguments don't match.

------
BlackDeath3
>GOD is REAL, unless declared INTEGER.

I'm stealing the hell out of this.

------
kabdib
: 2 3 ;

... redefines the constant 2 as 3. FORTH. Go figure :-)

~~~
etfb
In Forth, the following are fairly common definitions in the core:

    
    
        0 CONSTANT 0
        1 CONSTANT 1
        -1 CONSTANT -1
    

In an Algolian language like C++ or Java, if the syntax were legal, these
would be:

    
    
        const 0 = 0;
        const 1 = 1;
        const -1 = -1;
    

The reason for this is to do with the interpreter. How the Forth interpreter
works is very simple:

1\. Read one word, where "word" is literally defined as "a sequence of non-
space characters delimited by spaces". Some standard words include DUP 2DROP
1+ - . " and :

2\. Attempt to find the word in the dictionary. If found, execute it.

3\. If it's not found, attempt to interpret it as a number. If that works,
push the number on the stack.

4\. If neither 2 nor 3 succeed, emit an error message.

So the reason for defining a constant named "0" is to save time: it's quicker
to interpret the word "0" if it's in the dictionary; otherwise you have to
search the whole dictionary and then do a text-to-number conversion, which
takes too long.

So really it does make sense.

~~~
Someone
It is about space, not time. What you describe happens interactively. At that
time, performance does not matter much, after compiling, it does.

At compilation time (the word : is one of the ways to switch the system to
compilation mode), Forth doesn't execute words and numbers if finds, but it
adds their addresses (in some form, depending on the implementation) to the
generated code. When running the code later, the runtime simply fetches each
of these function addresses and 'calls' them (that's what makes Forth systems
fast without the need for any convoluted compiler technology. Depending on the
implementation, that 'call' may be an actual call in the CPU, but it typically
is just another 'grab the addresses found there in sequence and execute them'
and yes, it can't be turtles all the way down, but Forth gets awfully close)

Now, the question is: how do you compile "push this constant on the stack"?
Forth does it by compiling the word called LITERAL, followed by the constant.

So, compiling a function called 0 or 1 adds a function address to the compiler
output, but compiling a literal constant adds the address of the function
called LITERAL and that constant. For constants used more than a few (where
the exact limit depends on he particular Forth implementation) times, the
extra space needed for that function gets more than compensated by the gain.
In typical Forth systems, -1, 0, 1, and 2 already are space savers before the
user types his first character. That's why they are predefined. If you use
another constant often, you can easily define it. Many Forth systems even have
a function called CONSTANT for it, but you can define it yourself, if it is
absent.

For those wondering how the system knows that that constant it compiled isn't
the address of a function to call: it doesn't. Instead, the function called
LITERAL, when called, hooks into the runtime, uses the 'current instruction
pointer' to read the value to push on he stack, and then increases that
pointer to point past the constant. When LITERAL returns, the runtime just
reads what it thinks is the next pointer and calls it.

------
spc476
INRAC, the langauge RACTER
([http://en.wikipedia.org/wiki/Racter](http://en.wikipedia.org/wiki/Racter))
has the most bizarre flow control I've ever seen in any computer language,
ever. It can best be described as "a random, pattern matched GOTO/GOSUB" which
is the most succinct description I can come up with.

I have a blog entry about it
([http://boston.conman.org/2008/06/18.2](http://boston.conman.org/2008/06/18.2))
but in short, each line of an INRAC program (unless it ends with a '#' mark in
which case execution continues to the next line) is a subroutine, each with a
label. The label does not need be unique, but when you "call" a subroutine,
INRAC will just pick one line with that label at random to execute. The
pattern matching comes in because you can select the label with wildcard
characters (which just picks a line that matches the pattern at random).

There isn't much about the language on the Internet. In fact, the _only_ other
page aside from my blog entry (which I wrote as I went through the existing
source code I found for Racter) is the Racter FAQ
([https://groups.google.com/forum/#!topic/rec.arts.int-
fiction...](https://groups.google.com/forum/#!topic/rec.arts.int-
fiction/RTV5CUkJ8fs)) which has a few inaccuracies (or perhaps was looking at
a version of the code before processing).

------
zokier
C++ has all sorts of fun stuff. One example is std::vector<bool>, which is not
implemented as a simple array of booleans like every other std::vector, but
instead it is a bitmap. Afaik this behavior is required by standard. One fun
side-effect is that you can't take the address of individual elements of the
vector.

Compare these two:

[http://ideone.com/qC9yOp](http://ideone.com/qC9yOp)

[http://ideone.com/jF4krp](http://ideone.com/jF4krp)

------
eli_gottlieb
I'm the only person thinking of the way MATLAB passes everything by value,
including compound objects and structs?

------
julian_t
Snobol... where patterns are first class constructs, and every line can end
with a GOTO. That definitely lets you write some very, er, compact code. But
it was superb to program in.

And how about the assigned GOTO in older versions of Fortran? "GOTO N" where N
is an integer variable whose value will be known at runtime.

Happy days...

~~~
knome
I'm sure you'll be pleased to find that gcc has kept the assigned goto alive
as a c extension.

    
    
        #include <stdio.h>
    
        int main( int argc, char ** argv ){
    
          void * p = && lol ;
    
         bounce:
          goto *p ;
    
         lol:
          printf("lol %p\n", p);
          p = && wtf;
          goto bounce;
    
         wtf:
          printf("wtf %p\n", p);
          p = && lol;
          goto bounce;
    
        }

------
adamnemecek
Fun fact, this is also the reason why 'i' is commonly used as a name for the
loop counter variable.

~~~
BlackDeath3
Source?

~~~
adamnemecek
I mean google around. It's not "it's definitely from Fortran" more like "it
has been repeatedly suggested that...".

------
protomyth
The control structures in Icon are not quite what you would expect and qualify
as strange:
[http://en.wikipedia.org/wiki/Icon_(programming_language)](http://en.wikipedia.org/wiki/Icon_\(programming_language\))

~~~
raldi
I don't see what you mean; could you spell it out?

~~~
protomyth
I thought the wikipedia article could explain it better than I, but here are
some more references:

[http://blogs.kde.org/2006/10/21/ralph-griswold-icon-
language...](http://blogs.kde.org/2006/10/21/ralph-griswold-icon-language-
designer-passes-away)

[http://dl.acm.org/citation.cfm?id=104659](http://dl.acm.org/citation.cfm?id=104659)

[http://research.microsoft.com/pubs/69724/tr-99-64.ps](http://research.microsoft.com/pubs/69724/tr-99-64.ps)

look at Goal-directed evaluation of icon

------
cratermoon
The COBOL MOVE-CORRESPONDING verb. I'm not going to try to explain exactly how
it works here, but imagine, if you will, copying the contents of one table to
another table with a different column structure, but sort of the same names.

~~~
rst
This is one of the COBOL features that makes a lot more sense if you think of
COBOL as SQL for tape drives than as something that is trying to be, say,
Pascal or Ada and failing. (Along with, say, pretty much the entire DATA
DIVISION...)

------
Pxtl
C switch fallthrough. I know it's old and everybody's used to it and I get why
it's there, but it's freaking weird. I love c#'s response that you must use
goto <case> instead to make fallthrough explicit.

------
dj-wonk
I _heart_ what should be called a "truth injection attack" in Python:
[http://stackoverflow.com/a/2021553/109618](http://stackoverflow.com/a/2021553/109618)

~~~
userbinator
You can do a similar thing with Java, although it's a bit harder...
[http://stackoverflow.com/questions/3301635/change-private-
st...](http://stackoverflow.com/questions/3301635/change-private-static-final-
field-using-java-reflection)

I think you can do something like this in C# too (not surprisingly).

------
eps
Duff's device is certainly a very strange construct.

[http://www.lysator.liu.se/c/duffs-device.html#duffs-
device](http://www.lysator.liu.se/c/duffs-device.html#duffs-device)

------
kyberias
This question is a beautiful invitation for everyone to defend their favorite
languages! :)

------
Pxtl
in vb.net: off-by-one array sizes so people who do one-based arrays don't get
hurt. Also, two sets of boolean operators, the simpler ones don't short-
circuit (or vs orelse, and vs andalso).

------
analog31
Line numbers in BASIC

~~~
ahoge
It kinda made sense, because there wasn't anything fancy like Notepad. If you
wanted to read some section, you had to specify the range. If you wanted to
change a line, you overwrote it by using the same line number. If you wanted
to insert a line, you had to pick a line number which lies between those other
two line numbers. That's why you used an increment of 10 (or whatever) instead
of 1.

------
Thiz
For…else in python.

Weird. or dutch.

~~~
valtron
Cool!

------
runn1ng
"not really a question. closed."

~~~
kps
Here is a route to interesting reading (or HN karma, if you're into that):

[https://www.google.com/search?q="This+question+exists+becaus...](https://www.google.com/search?q="This+question+exists+because+it+has+historical+significance"++site%3Astackoverflow.com+-meta.stackoverflow.com)

------
Fasebook
Javascript's DOM

