Horrific Kotlin-specific syntax that still compiles (and nested if-expressions)

I really love the way Kotlin is a rather pragmatic programming language. Even though it’s syntax might look weird sometimes (especially if abused), it makes code much easier to read. Not too long ago, I wrote my own programming language that implements some of the concepts I really like about Kotlin. One of them are if-expressions. While thinking about the Backus-Naur definition of Kotlin and my own language, I thought, that someone who really doesn’t like their code reviewers could possibly write some horrific code that perfectly runs and compiles. Here is an example of some truely nested if-expressions:

data class Visitor(val age: Int) fun Visitor.checkId() = true // should be some sort of true ID check val visitor = Visitor(19) if (if ((if (visitor.age > 16) { visitor.checkId() } else { false }) && visitor.age > 18) { println("We can sell you Vodka if you want");true } else { println("Sorry, only beer for you m8");false }) { println("Have a great night") } 

I really like this example and thats why i wanted to share it with you guys. You can add more ifs if you would like to make it even more stupid haha.

Do you have any other horrific syntax ideas with which we could make the world a little bit worse? I think the do-while loop, that allows variables defined in the loop body to be used in the condition, has some potential as well.

submitted by /u/SomeRandomGuy096
[link] [comments]