syntactic sweeteners, part ][

(A small update to yesterdays thoughts on syntactic sugar)

First here's a chunk of Linq, that i think might be fairly valid (though i haven't (a) compiled it or (b) ever actually compiled any linq code... so whadda i know??)

(continues....)

List people = DB.GetAllPeople();
var oldPeople =
   from p in People
   where p.Age > 29
   select new {p.FirstName,
             p.PensionCardNumber};

Console.WriteLine("Some old People:");
foreach (var x in oldPeople) {
   Console.WriteLine(x.FirstName + " is old.");
}

Now here's my idea for how the syntax could get even simpler, by using more "inferences"....

List people = DB.GetAllPeople();
var oldPeople =
  from People
  where value.Age > 29
  select new {value.FirstName,
            value.PensionCardNumber};

Console.WriteLine("Some old People:");
forevery (oldPeople) {
   Console.WriteLine(value.FirstName + " is old.");
}

Okay -- so this is a bit like yesterday's "in (people visit Person p)" example -- except here we simply say "forevery (people)" and then access the keyword "value" to refer to the member within the collection.

Also in the linq query instead of "from p in People" we just say ""from People" and then rather than use the variable 'p' we use the keyword 'value', (much like in a property setter).

I'm really gonna stop thinkin about silly syntax soon. This is perhaps not as bad as the time a few months ago when i started trying to invent ancestors for xml.

 

I'm currently writing a book about how to build your first product. If you want to build your first product, please sign up to be notified when the book is available.

(By the way, I read every comment and often respond.)

Your comment, please?

Your Name
Your Url (optional)
Note: I may edit, reuse or delete your comment. Don't be mean.