I actually agree, wasn’t being serious
On topic: All LISPs qualify for this thread.
Cas
I actually agree, wasn’t being serious
On topic: All LISPs qualify for this thread.
Cas
Javascript: [icode]undefined = 42;[/icode], which is why we all :persecutioncomplex: are forced to use [icode]if(typeof x === ‘undefined’)[/icode] as opposed to the more concise form: [icode]if(x === undefined)[/icode]
I always thought the syntax for instantiating a non-static inner class from outside an instance of the outer class was weird:
public class Main {
public static void main(String... args){
new Main().new Inner().printMe();
}
private class Inner{
public void printMe(){
System.out.println("Inner class!");
}
}
}
For that matter, people tend to tilt their heads a bit sideways at using
main(String... args)
instead of
main(String[] args)
as well. I just think it looks cooler, and is arguably semantically closer to what’s happening under the hood!
Similarly, odd usages of this
:
class Outer {
class Inner {
void foo() {
Outer o = Outer.this;
}
}
}
I’ve always loved this FORTH:
: ( 41 word drop ; immediate
( The previous defines comments )
JFrame f = new JFrame() {{
setTitle("Test");
setSize(600, 600);
add(new JButton() {{
setText("Button");
setBackground(Color.RED);
}});
setVisible(true);
}};
Its not a syntax feature but an anonymous class using the anonymous class constructor thats weird…
-ClaasJG
That’s called an initializer block. It’s covered in the basic tutorials here, but most people seem to skip over that part.
int [] a [];
17 years of Java, and I still had to check if that was actually valid syntax.
Javascript:
‘’ == ‘0’ // false
0 == ‘’ // true
0 == ‘0’ // true
false == ‘false’ // false
false == ‘0’ // true
false == undefined // false
false == null // false
null == undefined // true
" \t\r\n" == 0 // true
More stuff: https://dorey.github.io/JavaScript-Equality-Table/
MUMPS is essentially an exercise in horrifying language design, here’s some syntactical highlights:
[quote]CASE SENSITIVITY: Commands and intrinsic functions are case-insensitive. Variable names and labels are case-sensitive.
COMMANDS: may be abbreviated to one letter, case-insensitive. Includes commands such as IF, ELSE, GOTO, WRITE, and XECUTE [which is my personal favorite, it allows arbitrary execution of code contained in a variable]
OPERATORS: No precedence, executed left to right, parenthesize as desired. 2+3*10 yields 50.
DECLARATIONS: NONE. Everything dynamically created on first reference.
LINES: important syntactic entities. Multiple statements per line are idiomatic. Scope of IF and FOR is “remainder of current line.”
[/quote]
There’s also some nice non-lexical scoping type problems:
Function pointers to member functions in C++ give you pretty weird syntax:
class Foo{
public:
int f(string str){
std::cout<<"Foo::f()"<<std::endl;
return 1;
}
};
int main(int argc, char* argv[]){
int (Foo::*fptr) (string) = &Foo::f;
Foo obj;
(obj.*fptr)("str");//call: Foo::f() through an object
Foo* p=&obj;
(p->*fptr)("str");//call: Foo::f() through a pointer
}
This is a Chrome problem, the language spec defines a result of “NaN” (Not A Number) which makes kind of sense … not really
A friend of mine once snuck that into someone else’s code, then hurt himself laughing.
This isn’t exactly strange syntax, but you can use reflection so that 2+2 equals 5:
import java.lang.reflect.Field;
public class Main {
public static void main(String[] args) throws Exception {
Class cache = Integer.class.getDeclaredClasses()[0];
Field c = cache.getDeclaredField("cache");
c.setAccessible(true);
Integer[] array = (Integer[]) c.get(cache);
array[132] = array[133];
System.out.printf("%d",2 + 2);
}
}
The above code outputs 5!
(Taken from here.)
EDIT: ninja’d
If you think that’s funny, try hiding this somewhere in a static block:
Field value = Integer.class.getDeclaredField("value");
value.setAccessible(true);
value.set(1, 2); // or similar
System.out.println(Arrays.asList(0, 1, 2, 3));
[quote][0, 2, 2, 3]
[/quote]
Ooops my apologies
I posted about Javascript… but you were asking for “non-joke languages”
Java compared to Javascript is like Scrabble compared to Jenga… Very different, but both of them belong to the same category (programming languages and games) - first of them have very strict rules and requires some experience, second one gives more freedom and requires less learning, but - if you fail even slightly - it is over.