Friday, March 27, 2015

blocked

http://www.reddit.com/r/ProgrammingLanguages/comments/309db8/blocks_syntax/
I've been programming for the last five years, and I came across (definitely not learnt) a bunch a languages... So, in your opinion, which syntax (for blocks) it the best ? And why ? (b'cause without explanations, any advice is pointless...)
Here's the syntaxes I'm aware of :
do .... end

{curly braces}

    indentation (like Python)

Okay, first off there is no "best." The "style" of your block is a style and a preference. There is a quote about preferences that I can't find right now.

At the expense of readability, but for ease of creating a parser and lisp macros that generate lisp code, there is lisp and all of those wonderful parentheses which, of course, brings up the question of which brackets? )<{[()]}>(

Since you are going to indent anyways, the brackets become redundant. Of course, indentation brings up the question of tab vs. spaces?

"do ... end" is stylish, almost a beautiful prose in some coders' eyes, because the block can even be a short one-liner. But, this brings up the question of which keywords to use? Which "language" to use? English? Indentation and brackets are more "international" like math.

So, another way is using various editors that parse the code for you and put the code into the style that you prefer which, of course, brings up the question of which editor to use? Beautiful how emacs, or your preferred editor, matches the parentheses for you, but maybe not. Why do I need a special editor just to read my own code?

Using an editor that "parses" the code for you, brings up yet another question: Why not create a language that parses away some or all of the redundant begin and end block punctuation and/or keywords? ie. if x < 3 print less than three else print greater than or equal to three

Ooh, that just brings up a quagmire of questions...

No comments:

Post a Comment