API's that Suck

January 1, 2010

Foundry – Block Terminators I

Filed under: Foundry — Grauenwolf @ 6:50 pm

First an introduction. Foundry is meant to be a general purpose programming language that targets the CLR. I call it Foundry because there will be a heavy emphasis on making intelligent data objects. Building data objects tends to be very tedious. I especially when you start looking at wiring in update events for WPF, creating immutable variants of each class, tagging everything for serialization, etc.

Block Terminators

The construction of blocks is vital for most programming languages.  Popular options include keywords, braces, and whitespace. In order to test the options, I am looking at a hello world program. Using three block we see the program name, the list of assemblies that the program references, and the main function.

Whitespace 

  1. Program Test1
  2.     References
  3.         mscorlib
  4. Main
  5.     Print “Hello World”

I’m discarding this option because every time I try to copy and paste it the white spaces gets messed up.

Braces and Parens

There are three commonly used format for braces and parens.

Variant 1 – Suffix

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

Variant 1 is in the running for now.

Variant 2 – Suffix on new line

  1. Program Test1
  2. {
  3.     References
  4.     {
  5.         mscorlib
  6.     }
  7. }
  8.  
  9. Main
  10. {
  11.     Print “Hello World”
  12. }

Burning two lines for each block header just seems stupid to me, so this one it out.

Variant 3 – Prefix

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

Placing the braces before the the block keyword makes it obvious that they pretty redundant. So how about a fourth variant instead.

Variant 4 – Closing only

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

Very succinct, though perhaps a different closing character is in order. Definitely in the running.

Keywords

Variant 1 – End keyword with block identifier

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

This is redundant, but it does allow for a smarter compiler. If you see “end program” before “end references”, then you can tell the user what’s going on. Or you could even implicitly end the previous block. So this one is in the running.

Variant 2 – End keyword

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

This isn’t quite as clear as the other one, but it is nice and terse.

Advertisements

1 Comment »

  1. […] Foundry – Block Terminators II Filed under: Uncategorized — grauenwolf @ 8:03 pm Ok, so here are our candidates from round 1. […]

    Pingback by Foundry – Block Terminators II « API's that Suck — January 1, 2010 @ 8:03 pm


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: