Scala Code Trollin’


So, we’ve all heard of “flatmap that sh**”, right? The new, functional, hipster way of saying

You’re doing it wrong

Since we don’t really care about dogma and functional religion that much, let’s just start trolling a little (it’s so much easier anyway), with Scala code. Check out the following piece of useful Scala code, which does compile:

def C = Seq(1, 2, 3)
def Windows = 0
def WAT = (C:\Windows)                                                           /* OK, we also need this */ (_)

Awesome, right? I leave it up to you to figure out what the above piece of code does.

Don’t believe it? Or don’t care about the puzzle? Here’s the solution on ScalaFiddle.

This discussion was inspired by CTMMC

5 thoughts on “Scala Code Trollin’

  1. That’s why I like Python, I can read anyone’s code with no effort, even when using libs that I’ve never heard about.

    The more we diverge from the C-style syntax the more it’s difficult to find people for maintaining a given code-base.

    • Python can be obfuscated: http://blog.brush.co.nz/2009/05/ellipsis/
      also dict/list/generator expressions can be used in non intuitive ways. Odd uses of getattribute can add significant complexity. Add metaclassing and all bets are off.
      Most languages have features that should be used judiciously, scala probably has more of them than python since you can write DSLs, but probably fewer than other languages like Perl. Anyways good programmers are ones who can write code other people understand, the language is secondary imo.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s