Hacker News new | comments | show | ask | jobs | submit login
Delimiters in Programming Languages (peterdonis.com)
2 points by vog 1817 days ago | hide | past | web | 3 comments | favorite



From the article:

> No curly braces, no parentheses, no semicolons. None.

That's not completely true. Strictly speaking, Python does have semicolons. But those are only used to allow for multiple commands in one line:

  a = 1; b = 2; c = 3
However, most style guides discourage this programming style anyway. Also, in this example of mass-assignments usually the tuple style is preferred:

  (a, b, c) = (1, 2, 3)
which can be shortened to:

  a, b, c = 1, 2, 3
> Yes, strictly speaking, there is one delimiter [in Python]: the colon that opens a new indent block. But typing that feels natural, [...] Still, if Python were to upgrade its parser to eliminate the need for the colon, I wouldn't complain.

I think the main reason for the ":" delimiter in Python is to allow for one-liners where the block follows immediately on the same line, so you can write:

  if True: print 'Hello'
instead of:

  if True:
      print 'Hello'
However, I don't think this was a good idea. Most style guides recommend the tow-line version anyway. Thus, I agree that Python could gain even more clarity by abandoning the ":" delimiter.


There's pros and cons, you've highlighted the pros of removing delimiters. Some cons...

1. Cutting and pasting code means we have to manually re-indent every line when it's required. We can't just let a formatter do it.

2. Tabs in the code has better be prohibited by the lexer.

I actually think there's room for a language which allows either all delimiters OR all indentation OR anything in between. An IDE can easily convert code written in one style into the other. Haskell is a good experiment in this.


I fully agree with "2.", as tabs in source code are a pain. However, I don't see what this has to do with the discussion about removing delimiters. Could you elaborate on that?

Regarding "1.", I have yet to find a really good formatter that works well in all edge cases. But pretending there is one, re-indenting copy&pasted Python code is just a matter of selecting it and pressing a few times ">" or "<" until the code is at the correct indentation level. (Replace ">"/"<" with "tab"/"shift+tab" or whatever keystroke your editor provides for adding/removing indentation.) There's absolutely no need to carefully re-indent it line by line, and it's almost as fast as running the formatter.

I agree that the ML languages (Haskell, Ocaml, etc) have a quite liberating approach to delimiters. You need the delimiters almost never, yet the code is unambiguous even without relying on indentation. It would be great to see some good comparisons between Haskell and Python regarding their approach to (almost) eliminating the need for delimiters.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: