You're looking at Less Wrong's discussion board. This includes all posts, including those that haven't been promoted to the front page yet. For more information, see About Less Wrong.

loup-vaillant comments on More intuitive programming languages - Less Wrong Discussion

4 Post author: A4FB53AC 15 April 2012 11:35AM

You are viewing a comment permalink. View the original post to see all comments and the full post content.

Comments (89)

You are viewing a single comment's thread. Show more comments above.

Comment author: loup-vaillant 16 April 2012 01:43:53PM *  1 point [-]

You can also mix approaches: optional semicolons, but use indentation to guess if it's the same instruction or not. That way:

// 3 instructions
blah; blah
blah
// 2 instructions
blah blah
blah
// 1 instruction (indentation is significant!)
blah blah
blah
// This one is tricky. Id' say syntax error, or a warning
blah; blah
blah
// This looks better, more obvious to me: 2 instructions
blah; blah
blah
// Alternatively, this one may also count for 2 instructions
blah; blah
blah
// begin of a new block
appropriate_keyword blah blah
blah
// end of a block (one instruction in the inner block,
one instruction in the outer block).
blah
blah
// 2 instructions (but frankly, I'd provide a warning for the superfluous ";")
blah;
blah;

This should be flexible enough and unambiguous enough.

Comment author: Viliam_Bur 18 April 2012 11:52:47AM 1 point [-]

In Python, you are supposed to write a colon before you start a block, right?

So the rules can be rather simple:

  • colon, with indentation = start of a new block

  • colon, no indentation = an empty block (or a syntax error)

  • no colon, with indentation = continuing of the previous line

  • no colon, no indentation = next statement

  • semicolon = statement boundary

Block ends where the indentation returns to the level of the line that opened the block. Continued line ends when indentation returns to the level of the starting line. (Where "to the level" = to the level, or below the level.)