Morning Coffee 143

  • I’ve been sick for three days, hence the lack of posting around here.
  • As a Redskins fan, it’s hard to root for any other NFC East team. On the other hand, it sure was easy to root against the Patriots. Congrats to the Giants on their Super Bowl victory. Favorite headline: 18 and uh-oh!
  • Sounds like there’s cause for optimism regarding the writer’s strike. But is it already too late? Will the 9% drop in viewers ever come back? Personally, I think the studios have hastened their own irrelevance.
  • With last night’s win, the Caps are one game above .500. In and of itself, that’s nothing to be proud of – Coach Boudreau remarked when we reached .500 that the Caps had “officially reached mediocrity”. However, the Caps are the only team in the SE conference that’s above .500. If hockey used baseball standings, Carolina, Atlanta and Florida would each be 1/2 game back of the Caps. It’s going to be a fight to the finish.
  • In fairly big managed Ruby news, Wayne Kelly has decided to contribute to the IronRuby effort, effectively walking away from the Ruby.NET which helped get off the ground. One the one hand, obviously this is great for IronRuby. On the other hand, I liked the idea of multiple managed implementations of Ruby, so here’s hoping Ruby.NET doesn’t fade away.
  • Speaking of the DLR, I know I mentioned Martin Maly’s blog in my Lang.NET Morning Coffee Post, but I didn’t actually get to read his posts on targeting the DLR until I unexpectedly had several days off sick. If you are at all interested in writing your own language for the .NET platform: Go. Read. Now. You should also check out Tomas Restrepo’s blog, he has also started writing about targeting the DLR.
  • Larry O’Brien’s blog is currently offline, but he commented that he doubted my ToyScript F# parser would be more than 600 lines of code. Currently, the parser is clocking in at 287 lines of code plus about 50 more for the AST. It’s not done yet – see earlier statement about being sick – but I’m fixing bugs not writing additional code at this point. To be completely accurate, that’s 287 lines of FParsec code. It’s taken me a little bit to learn FParsec, but so far I’m pretty happy with it.
  • Scott Hanselman points to the new MS Deploy project, a tool for managing content and configuration on web servers. I’ve never understood why this wasn’t a standard part of IIS. It seems every hosting company I’ve used has rolled their own web-based management tool like DotNetPanel.
  • Oh yeah, Vista SP1 and Windows Server 2008 shipped Monday. Congrats!
  • I fired up Inside Xbox the other day, and there was a page about the new Disney Channel show “Phineas and Ferb“. Of course, with two kids under five, anything new on the Disney Channel is notable in my house. What made this blog-worthy is the fact that it’s directed and written by Dan Povenmire, who I knew from my USC days. I used to go see his band Keep Left and groan loudly at the bad puns in their song “PSA”. Dan, if you found this searching for yourself online: Awesome work, my kids love the show!

Morning Coffee 141 – Lang.NET ’08 Edition

header

I was hoping to blog my thoughts on Lang.NET as the event went along. Obviously, that didn’t happen, though I was pretty good about dumping links into my del.icio.us feed. The talks were all recorded, and should be up on the website in a week or two. Rather than provide a detailed summary of everything that happened, here are my highlights:

  • The coolest thing about conferences like this is what John Rose called “N3″ aka “Nerd-to-Nerd Networking”. It was great to meet in person, drink with and geek out with folks who’s blogs I read like Tomas Petricek, Wesner Moise and Larry O’Brien. Plus, I got to meet a bunch of other cool folks like Gilad Bracha, Stefan Wenig and Wez Furlong. That’s worth the price of admission (which was admittedly nothing) right there.
  • Coolest MSFT talk: Martin Maly “Targeting DLR”. I was wholly unaware that the DLR includes an entire compiler back end. Martin summarized the idea of DLR trees on his blog, but the short version is “you parse the language, DLR generates the code”. That’s pretty cool, and should dramatically lower the bar for language development. Of course, I want to write my parser in F#, so I’m going to port the DLR ToyScript sample to F#.
  • Runner-up, Coolest MSFT talk: Erik Meijer “Democratizing the Cloud with Volta”. Erik is a great speaker and he really set the tone of his session with the comment “Division by zero is the goal, not an error”. He was referring to an idea from The Change Function that user’s measure of success is a function of perceived crisis divided by perceived pain of adoption. Erik wants to drive that adoption pain to zero. It’s a laudable goal, but I remain unconvinced on Volta.
  • Coolest Non-MSFT talk: Gilad Bracha “Newspeak”. Newspeak is a new language from one of the co-authors of Java. It’s heavily smalltalk influenced, and runs on Squeak. He showed developing PEGs in Newspeak, and they were very compact and easy to read, easier even than F#. He calls them Executable grammar, and you can read his research paper or review his slides on the topic. Unfortunately, Newspeak isn’t generally available at this time.
  • Runner-up, Coolest Non-MSFT talk: Miguel de Icaza “Moonlight and Mono”. The talk was kinda all-over-the-place, but It’s great to see how far Mono has come. Second Life just started beta testing a Mono-based script runner for their LSL language (apparently, Mono breaks many LSL scripts because it runs them so fast). He also showed off Unity, a 3D game development tool, also running on Mono.
  • Resolver One is a product that bridges the gap between spreadsheets and applications, entirely written in IronPython (around 30,000 lines of app code and 110,000 lines of test code, all in IPy). Creating a spread-sheet based app development environment is one of those ideas that seems obvious in retrospect, at least to me. If you do any kind of complicated spreadsheet based analysis, you should check out their product.
  • If you’re a PowerShell user, you should check out PowerShell+. It’s a free console environment designed for PowerShell and a damn sight better than CMD.exe. If you’re not a PowerShell user, what the heck is wrong with you?
  • Other projects to take a deeper look at: C# Mixins and Cobra Language.
  • I thought my talk went pretty well. It’s was a 15 minute version of my Practical Parsing in F# series. Several folks were surprised I’ve been coding F# for less than a year.

Practical F# Parsing: Recursion and Predicate Functions

To prep for my Lang.NET talk, I went back and reviewed my PEG parser. One thing I was not happy with was that all the recursion was handled in a one-off manner. When I needed to match multiple characters in the comment rule, I wrote a special one-off function to recursively process the comment until it reached an EOL. When I needed to parse a series of ranges, characters or definitions, I wrote special one-off functions to handle that recursion. Obviously, that’s not the best approach. So, I wrote the following active pattern functions to handle recursion.

//ZOM == Zero Or More
let rec (|ZOM|) f input =
    match f input with
    | Some(i,input) ->
        let j,input = (|ZOM|) f input
        (i :: j, input)
    | None -> [], input

//OOM == One Or More
let (|OOM|_|) f input =
    match (|ZOM|) f input with
    | [], input -> None
    | v, input -> Some(v,input)

//ZOO == Zero Or One
let (|ZOO|) f input =
    match f input with
    | Some(i,input) -> Some(i), input
    | None -> None,input

With these functions at the ready, I can stop writing one-off recursion functions. Instead, I write a function that matches a single item, which I pass as an argument to one of the three functions above. For example, here is the original and new version of the top level Grammar function.

//Original version
let (|Grammar|_|) input =
    let rec ParseDefinitions dl input =
        match input with
        | Definition (d, input) -> ParseDefinitions (dl @ [d]) input
        | _ -> Some(dl, input)
    let (|OneOrMoreDefintions|_|) input =
        match input with
        | Definition (d, input) -> ParseDefinitions [d] input
        | _ -> None
    match input with
    | Spacing (OneOrMoreDefintions (dl, EndOfFile)) ->
          Some(List.to_array dl)
    | _ -> None

//New Version
let (|Grammar|_|) = function
    | Spacing (OOM (|Definition|_|) (dl, EndOfFile)) ->
          Some(List.to_array dl)
    | _ -> None

The new version is much shorter, because there’s already a function to match a single definition, which we can pass into OneOrMore (aka OOM). Note, when I pass an active pattern function as a parameter, I have to use it’s real name (with the pipes and parameters). Having to use the real name is pretty ugly, but F# need to be able to differentiate between using a function as an active pattern vs using it as a function parameter. If you could just call OOM Definition (dl, EndOfFile), would F# realize Definition is a parameter?

I also defined syntactic predicate functions. If you’ll recall, these syntactic predicates will try to match but automatically backtrack, returning success or failure depending on which function you called.

//FP == Failure Predicate
let (|FP|_|) f input =
    match f input with
    | Some(_) -> None
    | None -> Some(input)

//SP == Success Predicate
let (|SP|_|) f input =
    match f input with
    | Some(_) -> Some(input)
    | None -> None

To see this in action, here’s the original and updated Primary function. Only the first rule is relevant, so I’ve omitted the others.

//Original version
let (|Primary|_|) input =
    let (|NotLEFTARROW|_|) input =
        match input with
        | LEFTARROW (_) -> None
        | _ -> Some(input)
    match input with
    | Identifier (id, NotLEFTARROW (input)) ->
        Some(Primary.Identifier(id), input)
    //rest of function omitted for clarity

//new version
let (|Primary|_|) = function
    | Identifier (id, FP (|LEFTARROW|_|) (input)) ->
          Some(Primary.Identifier(id), input)
    //rest of function omitted for clarity

Instead of writing a special function to match “not left arrow”, I just pass the left arrow function as a parameter to Failure Predicate (aka FP). With these recursion and syntactic predicate functions, I was able to remove all the one-off recursion functions from my parser. (Note, I posted an updated version of PegParser on my SkyDrive so you can see this in action.)

These five functions significantly reduced the complexity of the code. Unfortunately, I’m not sure it’s much easier to read. The conciseness is offset IMO by the ugliness of using the active pattern’s true names. Also, I would have liked to use custom operators for these five functions, but operators aren’t allowed to be active pattern functions. Hopefully, that will change at some point in the future, though if we’re going to dream of better syntax, can we do something about all the parens? Personally, I’d love to be able to write the following:

//This doesn't work, but I can dream, can't I?
let (|Primary|_|) = function
    | Identifier (id) !!LEFTARROW (input) ->
        Some(Primary.Identifier(id), input)
    //rest of function omitted for clarity

let (|Grammar|_|) = function
    | Spacing ++Definition (dl) EndOfFile ->
        Some(List.to_array dl)
    | _ -> None

Note to self, talk to F# team members who come to LangNET about this…

Morning Coffee 140

  • I only posted one Morning Coffee post last week. It wasn’t a lack of content, it was a lack of drive on my part. I had 20-30 items flagged in my news reader, but for some reason I couldn’t work up the interest in posting them. So some of these are a bit old.
  • I’m at the Language.NET Symposium this week, so look for lots of language blogging. I’ve already chatted with Tomáš Petříček and John Lam. If someone kicks Ted Neward’s ass because he hates Perl, I’ll try and liveblog it.
  • Speaking of Ted Neward, he discusses the question “Can Dynamic Languages Scale?” without devolving into a flame-fest. I agree 100% with his point about the difference between performance scaling and complexity scaling. Personally, I tend to err on the side of better complexity scaling, since buying hardware is easier than hiring developers.
  • Nick Malik responds to me calling his shared global integration vision flawed. He points to NGOSS/eTOM as an example of a shared iterative model that works. I know squat about that shared model, so I’ll refrain from commenting until I do a little homework on the telco industry.
  • Speaking of shared interop models, Microsoft is joining DataPortability.org. Dare Obasanjo and Marc Canter are skeptical that so far this effort is all hype and no substance. Reminds me a bit of AttentionTrust.org. But if DataPortability.org can get off the ground, maybe there’s hope for Nick’s vision (or vis-versa).
  • Don Syme lists what’s new in the latest F# release. As I said, this release is pretty light on features. Hopefully, I’ll get some details
  • Tomas Restrepo shows how to change your home folder in PowerShell. I need to do this.

Morning Coffee 139

  • Big news on the WGA strike front: the AMPTP reached a deal with the Directors Guild last weeks. Initial reaction from United Hollywood is mixed, but I’m hopeful this will at least get the AMPTP / WGA talks started again.
  • Speaking of new media, Xbox 360 Fanboy has a rundown of 45 short films from Sundance that are getting released on Xbox Live Marketplace. That’s pretty a-typical content for XBLM. Typically, new content on XBLM has been from “Hollywood Heavyweights“. I’m pretty excited to see them branch out content wise.
  • Speaking of Xbox 360, seems they had a good year. Congrats!
  • Still speaking of Xbox 360, everyone gets a free copy of Undertow this week.
  • Scott Guthrie announces the availability of the .NET Framework Source Code. Shawn Burke has instructions for how to use it with VS08. So far, they’ve made the core base class libraries, ASP.NET, Windows Forms, WPF, ADO.NET and XML available. LINQ, WCF and WF are expected to become available “in the weeks and months ahead”.
  • Ted Neward wonders if Java is “Done” like the Patriots, or “Done” like the Dolphins? If you want my opinion (I’m guessing yes, since you’re reading my blog), definitely done like the Dolphins. OpenJDK was a desperation move to make Java “cool” again, but it won’t work. People who want an open source stack are using LAMP and language wonks who saw Java as mainstream SmallTalk have moved on to Ruby. The question will be if Sun buying MySQL will make Sun cool or MySQL uncool by association. I’m guessing the latter.
  • Speaking of Ted, he’s got a great post about the relevance of game programming to the mainstream or enterprise developer.
  • Speaking of game development, David Weller points to all the new XNA GS 2.0 content up on Creators Club Online.
  • There’s a new version (1.9.3.14) of F# out, but no announcement from Don regarding what’s new. I reviewed the release notes, seems like this is primarily a bug-fix release with only very minor feature additions.
  • Speaking of F#, Don points to Greg Neverov’s implementation of Software Transactional Memory in F#. This immediately reminded me of Tim Sweeney’s Next Mainstream Programming Language talk. Tim suggested said language would need to support a combination of side-effect free functional code and software transactional memory. F# is looking to be closer to that language all the time.
  • Still speaking of F#, Don Syme’s Expert F# book is out. I read the draft version – it rocks – but I’m still going to get my own real copy. You should too.
  • With their win Saturday, the Caps are back to .500 for the first time since late October. Since Thanksgiving, the Caps are 15-7-4. Only four teams in the league have a better record over that time span. We play one of them tonight – the Penguins – and it’s on Versus, so I’ll even get to see it. In HD no less.