API's that Suck

January 1, 2010

Foundry – Block Terminators II

Filed under: Foundry — Grauenwolf @ 8:03 pm

Ok, so here are our candidates from round 1.

Candidate A

Candidate B

Candidate C

Candidate D

  1. Program Test1 {
  2.     References {
  3.         mscorlib
  4.     }
  5. }
  6.  
  7. Main {
  8.     Print "Hello World"
  9. }

  1. Program Test1
  2.     References
  3.         mscorlib
  4.     }
  5. }
  6.  
  7. Main
  8.     Print "Hello World"
  9. }

  1. Program Test1
  2.     References
  3.         mscorlib
  4.     End References
  5. End Program
  6.  
  7. Main
  8.     Print "Hello World"
  9. End Main

  1. Program Test1
  2.     References
  3.         mscorlib
  4.     End
  5. End
  6.  
  7. Main
  8.     Print "Hello World"
  9. End

Candidate A

A is better than B because…

  • There is a clear syntax for arbitrary blocks.
  • It doesn’t have unmatched braces.

A is better than C because…

  • It takes less characters to express the same concept.
  • There is a clear syntax for arbitrary blocks.

A is better than D because…

  • It takes less characters to express the same concept.
  • There is a clear syntax for arbitrary blocks.

Candidate B

B is better than A because…

  • It takes less characters to express the same concept.
  • It takes less tokens to express the same concept.

B is better than C because…

  • It takes less characters to express the same concept.

B is better than D because…

  • It takes less characters to express the same concept.
  • It takes less tokens to express the same concept.

Candidate C

C is better than A because…

  • Easier for users to know which block is being closed.
  • Easier for the compiler to give meaningful feedback.
  • Keywords are easier to spot than semi-colons.

C is better than B because…

  • Easier for users to know which block is being closed.
  • Easier for the compiler to give meaningful feedback.
  • Keywords are easier to spot than semi-colons.
  • It doesn’t have unmatched braces.

C is better than D because…

  • Easier for users to know which block is being closed.
  • Easier for the compiler to give meaningful feedback.

Candidate D

D is better than A because…

  • It takes less tokens to express the same concept.
  • Keywords are easier to spot than semi-colons.

D is better than B because…

  • Keywords are easier to spot than semi-colons.
  • It doesn’t have unmatched braces.

D is better than C because…

  • It takes less tokens to express the same concept.
  • It takes less characters to express the same concept.

Conclusion… not yet

It is too soon to pick a winner, though my personal bias tends towards one. I’m looking for some thoughts from others before I commit myself.

Advertisements

7 Comments »

  1. You could do what Ruby does, which is either A or D. It’s nice to be able to switch between which one feels more naturally, generally A is used for one liners and D for multiline functions.

    Comment by Steve — January 1, 2010 @ 8:56 pm

    • I have no problem with offering multiple options, but I’ve got something entirely different in mind for line-liners. Most constructs are going to have a well defined one-line version in addition to the block version.

      What do you think about replacing the ending brace with a different character?

      Comment by grauenwolf — January 1, 2010 @ 10:16 pm

      • Well, I’m of two minds.

        First reaction is “Sure, whatever. Syntax is easy to learn.”

        But the second (and louder) side of me says “Why break 40 years of convention?” A language isn’t interesting if it’s just substitutions, you know? There has to be an actual advantage to using a different character, otherwise, you’re just being different for difference’s sake.

        Comment by Steve — January 1, 2010 @ 10:27 pm

      • When the best reaction I can get is “sure, whatever”, it tells me I’m going down the wrong path. While I certainly don’t feel bound by convention, it is fair to say I should wait until I have a good reason before abandoning it.

        Comment by grauenwolf — January 1, 2010 @ 10:44 pm

  2. I personally picked solution D for my language, except that it applies to code blocks only, not data structures (delimited by simple [ ] at the moment).

    I left out the braces (solution A) because I find it more readable to have a plain word instead of a sign; also there’s a lot multiple indentation styles in common usage. Not using them avoids this problem, and I expect users to follow the indentation style I’ve adopted; for instance:

    proc min Int x, Int y -> Int r
    if x<y
    set r, x
    else
    set r, y
    end
    end

    Furthermore, one doesn't have to have a start-of-block delimiter; it is good because it is obvious from the context. Solution B is a non-option IMHO, because it is simply ugly and one may loose some IDE facilities.
    As for solution C, I find "end if" too redundant. If your users really want them, they can always add it as a comment (one often sees that in C code written by former Pascal programmers).

    There's actually a fifth solution: if…fi and such. I find it eeew-ful, but some people don't.

    Comment by Astrobe — January 2, 2010 @ 7:44 am

  3. You didn’t consider python-style indentation based blocks. One of the ideas I had for this was to use a colon to start an indentation-based block so you could tell the difference between that and a single line statement.

    Also smalltalk style blocks use square brackets.

    Comment by Blacktiger — January 2, 2010 @ 7:44 am

  4. WordPress killed the indentations in my previous comment. There’s no preview, there no formatting tips, so excuse me if I’m a bit rude here.

    proc min Int x, Int y -> Int r
    __if x<y
    ____set r, x
    __else
    ____set r, y
    ____end
    __end

    Comment by Astrobe — January 2, 2010 @ 7:49 am


RSS feed for comments on this post. TrackBack URI

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

Blog at WordPress.com.

%d bloggers like this: