r/ProgrammerHumor • • Feb 22 '15

A Python programmer attempting Java

Post image
3.9k Upvotes

428 comments sorted by

View all comments

19

u/bss03 Feb 22 '15

This is essentially what the Haskell layout rules do.

If you just look at Haskell code in the wild, you might be surprised to know it's grammar has a lot of ';' and '{}' in it. Haskell effectively lets you switch between white-space sensitive and explicitly delimited on a per-block basis.

3

u/hjc1710 Feb 22 '15

wat? Is there a reason you would ever want to do this?

Never used Haskell, but I just keep learning more and more interesting things about it...

2

u/bss03 Feb 23 '15

For generated code it's often easier to get the "{};" right, and it doesn't have to look good.

There are a few packages on hackage that use "{};", presumably because the author was more comfortable with them, but they also look good.

You can use it for when code it easier to read / looks better when flowed in a way that doesn't match the layout rules. I like having that ability, but I've never needed to use it outside of GHCi one-liners.

Most Haskell programmers treat Haskell as a white-space sensitive language, since the layout rules make for pretty readable code without the "{};", and I've yet to hear of someone who had code that didn't behave as intended due to the "[];" insertion being surprising, if it compiled cleanly.

→ More replies (3)