Passion * Technology * Ruthless Competence

Thursday, April 24, 2008

Morning Coffee 164

  • Big news since my last Morning Coffee post was the announcement of Live Mesh. I've been running it for about a month, and I'm really digging it. Make sure you check out the team blog and watch the developer tour video (be on the lookout for IPy about half way thru the video)

ALT.NET

  • I had a great time @ the ALT.NET open space conference last weekend. I was somewhat distracted on Saturday as due to a family communication mixup, I had to bring my son Patrick with me. Jeffrey Palermo shot a cute video of him (3 minutes in) where he explains that he's at the conference "to be with my dad". Having a five year old is a little distracting, but everyone was amazingly cool with having him around. When he gets a little older I have no doubt he'll be attending conferences and leading open sessions.
  • I did a session on F#, but it felt kinda all over the place. I hadn't touched F# in a few months and it showed IMO. Matt Podwysocki was there to help keep the session from devolving into mass chaos. Thanks Matt.
  • My favorite session of the conference was Scott Hanselman's "Are We Innovating?" talk, which I think originated from a question I asked him: There are many examples of large OSS projects in other dev communities that get ported to .NET (NHibernate, NAnt, MonoRail, etc). Can you name one that's gone the other way? I can't.
  • I took Matt's advice and joined the local ALT.NET Seattle group.

DyLang Stuff

  • Martin Maly posts about how dynamic method dispatches are cached in three different layers by the DLR. You shouldn't care about this stuff if you're a DLR language user, but you will certainly care about it if you're a DLR language builder.
  • I'm really excited to see Phil Haack (whom I met F2F @ ALT.NET) is experimenting with IronRuby & ASP.NET MVC. True, I'd rather it was IPy, but his Routes.LoadFromRuby would work with Python with very little code change.
  • Note to self, take a deeper look at Twining, the IPy database DSL by David Seruyange.
  • Daily Michael Foord - Ironclad 0.2 Released. Ironclad is a project to implement Python's C extension API in C# so that IronPython could load standard Python C modules like SciPy and NumPy. So far, they're able to load the bz2 module

Other Stuff

  • Congrats to Brad and Jim for shipping xUnit.net 1.0.
  • Everyone seems to be jumping on the functional C# coding bandwagon. Bart De Smet's series on pattern matching in C# is currently at eight posts. Now Luca Bolognese is in on the action, with three posts so far on functional code in C#. I like how Luca keeps writing that the C# syntax is "not terrible" for functional programming. Again, why suffer thru the "not terrible" syntax when you could be using F# instead? (via Charlie Calvert)
  • I need to take a look at VLinq. Charlie and Scott Hanselman both mentioned it recently.
  • I would like to have been in the conversation with Ted Neward, Neal Ford, Venkat Subramaniam, Don Box and Amanda Silver.
  • I haven't had any time to play with XNA of late, which means the great list of GDC videos Dave Weller posted on the XNA team blog will remain beyond my ability to invest time for now.
  • There's a new drop of Spec# from MS Research. IronRuby is using Spec# heavily as I recall.
Posted By Harry Pierson at 10:53 AM Pacific Daylight Time

Monday, December 10, 2007

Practical Parsing in F#

I'm interested in parsing because I'm interested in Domain Specific Languages. F# is pretty good for internal DSLs, but internal DSLs are obviously limited by the syntax of the host language. If you want complete control over the language, you've got to build your own parser.

The defacto standard for parser development is Yet Another Compiler Compiler, or yacc. There's a version of yacc for .NET as well as one specifically for F#. However, I'm not a fan of yacc. Yacc parsers are specified using context-free grammar (aka CFG). But CFG's can be ambiguous - actually, it's nearly impossible to build an unambiguous CFG. Personally, I'm a big fan of Parsing Expression Grammars (or PEGs) which among other advantages makes it impossible to develop ambiguous grammars. Furthermore, PEGs don't require a separate lexical analyzer like lex, so I think they're more suitable for building modular compilers.

Since I like PEGs and F# so much, I developed a parser for the PEG grammar from the original PEG whitepaper using F#. The grammar is much simpler than a language like C#, but with twenty nine grammar productions it's certainly not trivial. The F# implementation is fairly straightforward backtracking recursive decent parser, which makes it easy to understand even if you're not a parser guru. It's also small - around 400 lines of code including comments. But I think the code illustrates both the general value of Functional Programming as well as the specific value of F#. Here's how the series is shaping up (though this is subject to change):

I was originally planning to post the code for the parser itself with this post. However, i find that I'm revising the code as I write the articles in this series, so I'm going to hold off for now. If you're really desperate, drop me a line and I'll see what I can do.

Update - Almost forgot, if you're going to follow along at home, I'm using the latest version of F#, v1.9.3.7. Note, the F# Downloads page on the MS Research is woefully out of date, so go to the MS Research Downloads page. Currently, it's the most recent release. It snaps into VS 2005 and 2008 plus has command line tools. If you're an VS Express user, Douglas Stockwell explained how to roll your own F# Express.

Much Later Update - The code is now available on my Skydrive.

Posted By Harry Pierson at 2:40 PM Pacific Standard Time

Thursday, October 18, 2007

Morning Coffee 118 - ITARC SoCal Edition

I'm not back on blog sabbatical, but between finishing my presentation and attending ITARC SoCal earlier this week - not to mention being sick - I didn't have time to write anything. Normal Morning Coffee resumes tomorrow, here's a summary of my notes from on my two days at ITARC.

  • Scott Ambler did the opening keynote on agile enterprise architecture strategy.
    • He claims that success is more prevalent in the industry that people think, because the industry has a narrow definition of success. If you change (aka widen) the definition, the success rate goes way up! That's not exactly useful, but he referred to an as-yet-unpublished survey on project success rate that should be up on DDJ "soon". I'd like to see that raw data.
    • While I agree with most of his points, Scott's presentation style is very abrasive. For example, he makes the point that there is no one-size-fits-all process, which I couldn't agree with more. But does he say it like that? No, he says "Repeatable processes? What an incredibly stupid idea!" even though the room is full of folks who probably think repeatable process is actually a good idea.
    • Scott suggested that unit tests are the best way to specify requirements. I've heard this before from agile practitioners, but something nags at me about it. Certainly, having executable requirements is a huge plus. But how can you be sure they're the right requirements if the stakeholders can't read them?
    • This keynote setup what turned out to be a major theme for the conference - traditional vs. non-traditional enterprise architecture. Or as I would characterize it: Industrial vs. Post Industrial architecture.
  • Simon Guest presented on user experience in architecture, which is his specialty these days. He lays out a UX model that was very compelling. I'm not sure if there's a whitepaper version of this model (there should be) but you can see the model as he lays it out in powerpoint. I've seen Simon's UX decks, but never actually seen him present it, so that was a treat.
  • I skipped Ted Neward's session in order to take in something new. So I went to see Daniel Brookshier of No Magic talk about DoDAF - the Dept. of Defense Architecture Framework. I had met Daniel the night before at dinner and while No Magic primarily sells UML modeling tools, we seemed to agree that UML is most useful (in my opinion "at all useful") when you imbue the vanilla models with custom semantics - aka you turn them into a DSL. So while I liked hanging out with Daniel, his DoDAF session did nothing except ensure I never work for the DoD. There's no amount of money that's worth dealing with the two dozen or so bureaucratic models that are all wholly isolated from anything that actually executes. Daniel kept saying how easy these models are to build. I'm sure they are, but that's not the problem. Since they're not an intrinsic part of a construction process, they won't stay up to date. This was a very industrial approach - Daniel even stated at one point that he was "anti-Ambler".
  • David Chappell did the second keynote on grid-enabled SOA.
    • When did David join Oracle? I guess I haven't been paying much attention to competitors since I moved to MSIT.
    • There's an article version of this presentation available, but I haven't read it yet.
    • For me, the best part of this presentation was him acknowledging that there's a need for non-stateless services, something he has blogged about recently. I'm not sure I agree with his framework for stateful interaction, but at least he's admitting that it's needed. Now if I could only convince the Connected Systems Division...
    • The rest of his talk was basically a sales pitch for the Coherence product Oracle recently bought. Basically, it's a huge, multi-node, redundant, in-memory database. While I'm sure there are a few high-end problems out there - my immediate thought was travel and David mentioned SABRE is one of their customers - this is not a good general purpose solution, though David was positioning it as such.
  • My talk on "Moving Beyond Industrial Software" was after the second keynote. It was good, if sparsely attended. I'm doing it again @ the p&p Summit so I'll post the slides and hopefully a recording after that.
  • I skipped the last session of the day to decompress, so the next session I went to was the day two opening keynote by Fred Waskiewicz, OMG's Director of Standards. His talk, unsurprisingly, was on the value of standards - in particular, OMG's standards. This was about as anti-Ambler, anti-agile, pro-industrial a presentation as you could make. I'd heard this spiel before, so I mostly tuned out. I did challenge Fred on his point that the UML models are at a higher level of abstraction than code. They're not - they're a visualization and they're very useful, but they're at the exact same level of abstraction as code. That's why you can automatically generate the visualization in tools like Visual Studio's class designer. Fred didn't have much of a response to my question, though he did point out that some models like Business Process Models are, in fact, higher levels of abstraction.
  • Next was what I thought was the best presentation of the entire show, IASA Founder Paul Preiss on what architects need to know. Note, I'm not brown-nosing Paul here - I'm the guy that first decided to commit Microsoft as an IASA sponsor, so he has to like me even if I thought his session was crap. Paul talked about architect as a career, comparing it to doctors. He worries that he's over-using that analogy, but software architect has much more in common career wise than it does with building architects IMO. I wonder where one might do their architecture residency? He also thinks of architects as "living governance", saying that project managers answer to the stakeholders while architects are beholden to the stockholders. I like that approach to governance.
  • Finally, I attended Vince Casarez's session on Web 2.0 in the enterprise. Vince is an Oracle VP and this turned into a sales pitch like David Chappell's keynote did. I'm not sure what product it was, but it reminded me of QEDWiki from IBM that I saw at ETech last year, which isn't a complement. If you're going to build an enterprise mashup designer, is it just me or is "lots of code spew" a poor model. Why not go for something like Popfly or Pipes?
  • I left early the second day in order to get home before my kids went to sleep (which I failed at due to lack of naptime). Overall, the conference was pretty good, though a bit sparsely attended in part I think because they held it in San Diego. The Orange Country IASA user group is very popular, so I don't understand why they didn't just hold it around there somewhere. Live and learn, I guess. They did have to postpone the DC event until next year sometime. Here's hoping I get invited to that as well as well as ITARC SoCal '08 (note, that *is* brown-nosing a bit)
Posted By Harry Pierson at 12:18 PM Pacific Daylight Time

Friday, August 03, 2007

Morning Coffee

  • Libor Soucek continues our conversation about durable messaging. We still don't agree, but he says he "fine" with durable messaging. He does go out of his way to differentiate between *enterprise* and *supporting* systems. But when you're building connected systems, does that differentiation still matter?
  • After taking a few months off, John deVadoss is back at the blog. Check out his Big SOA/Little SOA post. I especially like his snowball analogy "How do you build a big snowball? You start with a small snowball.") though he's also on this "middle out" bandwagon. Do we really believe "middle out" works, or are we just saying it because we know top down and bottom up don't? And John: You're welcome!
  • Anyone coming to the Microsoft SOA & Business Process Conference this fall? Maybe we can have a shindig / blogger dinner / unconference / something?
  • Remus Rusanu writes about SSB's dynamic routing. One of the (many) cool things about SSB is that all the addressing is logical, not physical. Routing is what binds logical addresses to physical addresses, and it's extensible.
  • Martin Fowler discusses the value of sticking to one language. I agree with his points about large frameworks being as difficult to learn as a new language. I've said for a long time "If you build a framework, build tools to make it easy to use your framework". Language is obviously a core example of a tool. Another interesting point Martin makes is the traditional "intimate relationship" between scripting languages and C, but that the rise of JVM & CLR makes them impossible to ignore. Does the need to play well in a managed environment hinder a C based language like Ruby when compared to a natively managed scripting language like Powershell? Finally, Martin's "jigger of 80 proof ugliness" quote made me laugh.
  • Politics 2.0 Watch: EJ Dionne says that DailyKos is doing for Democrats what Rush Limbaugh did for Republicans almost twenty years ago: mobilization. Josh Marshall points out that "what's happening today is vastly more participatory and distributed...than anything happening back then."
Posted By Harry Pierson at 11:34 AM Pacific Daylight Time

Tuesday, July 31, 2007

Service Factory Customization Workshop Day One

No morning coffee posts for the first half of this week, because I'm in training thru Wednesday. Day one was mostly overview of GAT and DSL, which was review for me. Today we're starting to dig into some of the new stuff they've build for the new version of WSSF, so I'm paying much more attention today.

This isn't your typical workshop in that the content is sort of being generated on the fly. As I type, we're voting on what we're going to cover for the next two days. Most classes I've been in are pre-programmed, the teacher doesn't ask the class what topics should be covered and what order. There isn't even one "teacher" - there are five folks from p&p including the architect, dev lead and PM of WSSF that are tag-teaming. Even the hands-on labs aren't completely ironed out - they're evolving the lab directions as we do the labs. It's atypical, but it works.

Thursday, July 12, 2007

Thoughts on C# Fluent Interfaces

Martin Fowler points to a couple of articles by Anders NorĂ¥s on building internal / embedded domain specific languages in C#. Anders has built a DSL for creating calendar events and tasks, like you might expect to do in Outlook. Here's an example:

ToDoComponent planningTask =
   Plan.ToDo("Plan project X").
      StartingNow.
      MustBeCompletedBy("2007.08.17").
      ClassifyAs("Public");
planningTask.Save();

EventComponent planningMeeting =
   Plan.Event("Project planning meeting").
      RelatedTo(planningTask).
      WithPriority(1).
      At("Head office").
      OrganizedBy("jane@megacorp.com", "Jane Doe").
      StartingAt("12:00").Lasting(45).Minutes.
      Attendants(
         "peter@megacorp.com",
         "paul@megacorp.com",
         "mary@contractor.com").AreRequired.
      Attendant("john@megacorp.com").IsOptional.
      Resource("Projector").IsRequired.
      ClassifyAs("Public").
      CategorizeAs("Businees", "Development").
      Recurring.Until(2008).EverySingle.Week.On(Day.Thursday).
      Except.Each.Year.In(Month.July | Month.August);
planningMeeting.SendInvitations();

It may not be as clean as a say a Ruby version might be, but even with all the parens and periods it's still pretty readable. Fowler calls this a fluent interface, a term I like better than "internal DSL".

Two things jumped out at me reading Anders' entry on how he built this fluent interface. First, there's a lot of code to make this work. Anders didn't publish the code, but he did admit:

"Believe me, there will be a lot of code when you're done. I'm almost there with this DSL, and at the time of writing it consists of 58 classes not including the API and tests."

That's 58 classes just to implement the fluent interface, not counting the underlying EventComponent API. That's a lot of non-business logic code to write. How many projects are willing to invest that kind of time and effort to build a fluent interface? (I would guess "not many")

However, I bet there's a lot of template-izable code in Anders fluent interface. When he writes about keeping the language consistent by "creating branches within our grammar using different descriptor objects", I can help but think about parser development with YACC and the like. These tools typically use a DSL like BNF. Maybe we could build a DSL for building fluent interfaces?

Second, Anders makes a very interesting point about the structure of the fluent interface code:

Writing DSLs is a little different from the regular object oriented programming style. You might have noticed that the Plan class has a verb for its name rather than the usual noun. This allows us to have a natural starting point for writing out the "sentence" explaining our intention.

Where have you seen this verb based approach before? Powershell cmdlets.

Windows PowerShell uses a verb-noun pair format for the names of cmdlets and their derived .NET classes. For example, the Get-Command cmdlet provided by Windows PowerShell is used to retrieve all commands registered in the Windows PowerShell shell. The verb part of the name identifies the action that the cmdlet performs. The noun part of the name identifies the entity on which the action is performed.
[Cmdlet Verb Names, MSDN Library]

I've written about this aspect of PowerShell before:

In OO, most of the focus is on objects, naturally. However, administrators (i.e. the target audience of PS) tend to be much more task or action focused than object focused. Most OO languages don't have actions as a first class citizens within the language. C# and Java don't even allow stand alone functions - they always have to be at least static members of a class.

I'm fairly sure there are many reasons why strongly typed OO languages aren't popular among administrators. I'm not going to go down the static/dynamic typing rat hole here, but I would guess the object/action language tradeoff is almost as important as the typing tradeoff. What's nice about PowerShell is that while it has strong object support, it also has strong action support as well. In PS, actions are called Cmdlets. While I'm not a big fan of the name, having first class support for them in PS is one of the things I find most interesting.
[Perusing Powershell Part 1: Get-SQLServer, DevHawk]

While there is no first-class support for verbs or actions in C#, it looks like Anders has essentially rolled his own. For example, his Plan.Event() method returns a new EventDescriptor object. Subsequent calls on this object (RelatedTo, WithPriority, OrganizedBy) change the internal state of this EventDescriptor object. When you reach the end of the chain of calls, EventDescriptor has an implicit EventComponent cast operator that creates a new EventComponent with all the data that's been collected along the chain by the EventDescriptor.

Again, I can help but think a significant amount of code in this approach can be generalized and the creation automated. Also, I wonder if any of the new C# 3.0 capabilities could be used to improve the implementation. For example, would Extension Methods make it easier to build the fluent interface? Maybe / Maybe not. Regardless, Anders has given me a lot to noodle on.

Posted By Harry Pierson at 2:38 PM Pacific Daylight Time

Monday, June 18, 2007

Morning Coffee 91

  • My wife loves me. I'm a very lucky man.
  • I'm starting to really dig Safari Books Online. Having a tablet really helps here, I can sit in bed and read and it's ALMOST like reading a real book. Is there an offline experience? Something like the NYTimes WPF Reader app would be killer.
  • I'm not a Twitter guy, but I like the idea of using it to publish CI results. Not quite as cool as using the Ambient Orb, but close. (via DotNetKicks)
  • Soma details the dogfood usage of TFS in Developer Division. Sorta interesting if you're into knowing that stuff. Brian Harry apparently has much more.
  • I realize that linking to Pat Helland every time he writes something is fairly redundant. If you want his feed, you know where to find it. But he writes great stuff! The latest is Accountants Don't Use Erasers, which talks about append-only computing. His point that the database is a cache of the transaction log is mind blowing, yet makes total sense.
  • Bruce Payette blogs a PS DSL for creating XML documents.
  • Jesus Rodriguez details WCF's new Durable Service support in .NET 3.5. I get the need for the [DurableServiceBehavior] attribute, but do I really have to adorn each of the service methods with [DurableOperationBehavior] too? That seems redundant. Also, I wonder how this looks at the channel layer?
  • Speaking of WCF's channel layer, I recently picked up a copy of Inside Windows Communication Foundation by Justin Smith. This is the first book I've found that has more coverage of the channel layer than the service layer, so I like it.
  • Dare writes about Web3S, Windows Live's general purpose REST protocol. Apparently, WL started with Atom Publishing Protocol, but found that it didn't meet their needs around hierarchy and granular updates. David Ing says it's "not that similar" to my concept of REST, but I going to read the spec before I comment.
  • Scott Hanselman writes about how he learned to program and some thoughts about teaching his son. Patrick has recently started expressing interest in programming (he want's to do what Daddy does). At four, I'm thinking I'll start him on Scratch (though ToonTalk looks interesting). As he gets older, I was thinking about Squeak, though I'm a smalltalk noob. I really like Scott's idea of creating a connection to the physical world via something like Mindstorms. Patrick loves Lego almost as much as his dad, so that would be cool.
Posted By Harry Pierson at 11:03 AM Pacific Daylight Time

Thursday, March 22, 2007

Morning Coffee 50

  • Nick Carr on net neutrality: "Protocol is neutral. Infrastructure isn't." This is a more complicated issue than it appears on the surface.
  • Nick Malik on enterprise architecture: "Enterprise Architecture is not about 'building solutions right'. Enterprise Architecture is about 'building the right solutions'.
  • If there had been a good quote on Nicholas Allen's blog today, then I could declare it "Quote a Nick" day. Alas, his posting on how to respond to GetProperty isn't very quotable.
  • Hot on the heels of the new GAT CTP is the new Software Factories Toolkit CTP from Clarius. Among other new features is a Recipe Designer. Having mucked around in the Recipe XML, this is A Good ThingTM (via Larkware)
  • Politics 2.0 Watch: Phil de Vellis - the guy that made "Vote Different", the Hillary Clinton/Apple 1984 video mashup - said he made said video in part because he "wanted to show that an individual citizen can affect the process". Furthermore, "This shows that the future of American politics rests in the hands of ordinary citizens." Personally, Bush as Big Brother would have been more appropriate, but I think the video got more attention becuase it cast Hillary in that role.
Posted By Harry Pierson at 10:41 AM Pacific Standard Time

Wednesday, March 07, 2007

Morning Coffee 40

  • My boss let me borrow a Tecra M4 that he scavenged from his boss. The display is fairly twitchy, I think it's a motherboard issue. But it's very intermittent and I'll get help desk to take a look. In the meantime, it sure is nice to driving a Tablet PC again. And it's Vista ready to boot.
  • Speaking of Vista, Visual Studio 2005 Service Pack 1 Update for Windows Vista. It's a mouthful but it's now available. Soma answers questions about the new release on MS PressPass.
  • The DSL tools team keeps on rolling with the power toys. First it was the Designer Integration PowerToy, now it's the DSL Tree Grid Editor PowerToy. Jeff Santos has the details.
  • I missed the TechFest keynote yesterday, but it's available on demand. They also have descriptions and videos of some of the technologies on display. (well, only one video so far, but I assume since the page is labeled "TechFest 2007 Videos" that more are on the way.)
  • There's new support for integrating WCF and WF coming in VS "Orcas". Moustafa Khalil Ahmed has the details on what's new for WF & WCF in the latest CTP drop. For me personally, the WCF/WF integration is some of the most important stuff coming in Orcas, second only to LINQ.
Posted By Harry Pierson at 11:28 AM Pacific Standard Time

Tuesday, February 20, 2007

Internal DSLs in PowerShell

(Harry is on a secret mission in uncharted space this week, so instead of the daily Morning Coffee post, you get a series of autoposted essays. This post combines both some leftover learnings about Ruby from Harry's Web 2.0 days with his recent obsession with PowerShell.)

My first introduction to the idea of internal DSLs was an article on Ruby Rake by Martin Fowler. Rake is Ruby's make/build utility. Like most build tools like Ant and MSBuild, Rake is a dependency management system. Unlike Ant and MSBuild, Rake doesn't use an XML based language. It uses Ruby itself, which has huge benefits when you start doing custom tasks. In Ant or MSBuild, building a custom task requires you to use a external environment (batch file, script file or custom compiled task object). In Rake, since it's just a Ruby file, you can start writing imperative Ruby code in place.

Here's the simple Rake sample from Fowler's article:

task :codeGen do 
  # do the code generation 
end 

task :compile => :codeGen do 
  # do the compilation 
end 

task :dataLoad => :codeGen do 
  # load the test data 
end 

task :test => [:compile:dataLoad] do 
  # run the tests 
end

The task keyword takes three parameters: the task name, an array containing the task dependencies and a script block containing the code to execute to complete the task. Ruby's flexible syntax allows you to specify task without any dependencies (:codegen), with a single dependency (:compile => :codegen), and with multiple dependencies (:test => [:compile,:dataLoad])

So what would this look like if you used Powershell instead of Ruby? How about this:

task codeGen { 
  # do the code generation 
}

task compile codeGen {
  # do the compilation 
}

task dataLoad codeGen { 
  # load the test data 
}

task test compile,dataLoad {
  # run the tests 
}

Not much different. PS uses brackets for script blocks while Ruby uses do / end, but that's just syntax. Since it lacks Ruby's concept of symbols (strings that start with a colon), PS has to use strings instead. Otherwise, it's almost identical. They even both use the # symbol to represent a line comment.

There is one significant difference. For tasks with dependencies, Rake uses a hash table to package the task name and its dependencies. The => syntax in Ruby creates a hash table. Since the hash table has only a single value, you can leave of the surrounding parenthesis. The key of this single item hash table is the task name while the value is an array of task names this task depends on. Again, Ruby's syntax is flexible, so if you have only a single dependency, you don't need to surround it in square brackets.

In Powershell, the hash table syntax isn't quite so flexible, you have to surround it with @( ). So using Rake's syntax directly would result in something that looked like "task @(test = compile,dataLoad) {...}" which is fairly ugly. You don't need to specify the square brackets on the array, but you having to add the @( is a non-starter, especially since you wouldn't have them on a task with no dependencies.

So instead, I thought a better approach would be to use PS's variable parameter support. Since all tasks have a name, the task function is defined simply as "function task ([string] $name)". This basically says there's a function called task with at least one parameter called $name. (All variables in PS start with a dollar sign.) Any parameters that are passed into the function that aren't specified in the function signature are passed into the function in the $args variable.

This approach does mean having to write logic in the function to validate the $args parameters. Originally, I specified all the parameters, so that it looked like this: "function global:task([string] $name, [string[]] $depends, [scriptblock] $taskDef)". That didn't work for tasks with no dependencies, since it tried to pass the script block in as the $depends parameter.

Here's a sample task function that implements the task function shown above. It validates the $args input and builds a custom object that represents the task. (Note, the various PS* objects are in the System.Management.Automation namespace. I omitted the namespaces to make the code readable.)

function task([string$name)     
{    
  if (($args.length -gt 2-or ([string]::isnullorempty($name)))    
  {    
    throw "task syntax: task name [<dependencies>] [<scriptblock>]"    
  }    
       
  if ($args[0-is [scriptblock])    
  {    
    $taskDef = $args[0]    
  }    
  elseif ($args[1-is [scriptblock])    
  {    
    $depends = [object[]]$args[0]    
    $taskDef = $args[1]    
  }    
  else    
  {    
    $depends = [object[]]$args[0]
    #if a script block isn't passed in, use an empty one    
    $taskDef = {} 
  }    

  $task = new-object PSObject    
  $nameProp = new-object PSNoteProperty Name,$name    
  $task.psobject.members.add($nameProp)    
        
  $dependsProp = new-object PSNoteProperty Dependencies,$depends    
  $task.psobject.members.add($dependsProp)    
        
  $taskMethod = new-object PSScriptMethod ExecuteTask,$taskDef    
  $task.psobject.members.add($taskMethod)    
        
  $task    
}

Of course, you would need much more than this if you were going to build a real build system like Rake in PowerShell. For example, you'd need code to collect the tasks, order them in the correct dependency order, execute them, etc. Furthermore, Rake supports other types of operations, like file tasks and utilities that you'd need to build.

However, the point of this post isn't to rebuild Rake in PS, but to show how PS rivals Ruby as a language for building internal DSLs. On that front, I think PowerShell performs beautifully.

I'm looking forward to using PowerShell's metaprogramming capabilities often in the future.

Posted By Harry Pierson at 11:08 PM Pacific Standard Time

Friday, February 16, 2007

Morning Coffee 33

I realize yesterday I said I was on vacation starting today. In reality, I'm not going to the office today, but I have time to post this before my vacation starts in earnest.

  • I hit Zero Email Bounce in advance of my vacation. It's been quite a while since the last time I got here and I hope to hit it much more often in the future.
  • The DSL tools team shipped a Designer Integration PowerToy that allows you to integrate models from multiple DSL designers into a single authoring tool. Gareth has more here.
  • Assorted PowerShell links: PowerShell Analyzer and PowerShellIDE. Both look interesting.
  • Personally, I like Notepad2 but apparently the only way to add a new syntax highlight scheme requires modifying the source code. Ugh. Anyone out there already added PS support to Notepad2? How about a suggestion for a simple text editor that supports extensible syntax highlighting?
  • Steve, Nick and Tomas all commented on my long running services WCF post. Tomas mentions Advanced Message Queuing Protocol (AMQP) which looks to be developing an open spec queuing system like MSMQ or MQ series. Interesting, but given the lack of involvement of the major MQ and DB vendors, I'm hard pressed to imagine this gaining any kind of critical mass.
Posted By Harry Pierson at 8:59 AM Pacific Standard Time

Tuesday, August 01, 2006

Lang .NET 2006 Symposium

Yesterday, I attended the Lang .NET 2006 Symposium - basically a public version of the CLR Compiler Lab I went to back in March. Unfortunately, with my new job, I couldn't attend all three days, but I did attend day one. Here we're my thoughts on the various sessions.

Anders Hejlsberg - LINQ and C# 3.0

  • This was basically a rehash of his talk from the March Compiler lab. Makes sense as it was a new audience, but the "Query the Running Processes" demo is getting pretty old. Check out my notes from March for more details.

John Gough - Dealing with Ruby on the CLR

  • John is a professor from the Programming Languages and Systems group at Queensland University of Technology. They're the ones building Ruby.NET. He's also the author of Compiling for the .NET Common Language Runtime, a great if somewhat dated (i.e. .NET 1.0) book.
  • Much of John's talk covered the ground that Jim Hugunin covered back in March around the difficulties of mapping dynamic languages to the static CLR. For example, most Ruby.NET objects are instances of Ruby.Object, with their link to a class - a Ruby.Class - managed by the Ruby.NET runtime rather than leveraging the CLR's built-in class structure.
  • He didn't spend much time talking about the really hard problems like continuations, which I was really hoping he would.
  • There are a series of "allied" tools coming out of this project which look really interesting in their own right:
    • PE File Reader/Writer - a managed component for reading writing DLL and EXE files.
    • Gardens Point Parser Generator (GPPG) - a Yacc/Bison style parser generator, written in and generating C#
    • Gardens Point LEX (GPLEX) - companion to GPPG for generating C# scanners, a la LEX or Flex. Not released yet, but John indicated it would be available in the next couple of weeks.

Christopher Diggins - Cat Programming Language: A Functional Optimization Framework for the CLI

  • I'm fairly sure Christopher doesn't present often. Otherwise he would have know that there's no way to present 107 slides in 30 minutes.
  • Christopher had a hard time expressing why someone would use Cat, even when asked point blank by an audience member. Most of his 107 slides were describing various features of the language. I don't know about the rest of the audience, but I got lost pretty quickly.
  • It's too bad Christopher was so obtuse as a speaker, as Cat seemed pretty interesting. If you skip the first 78 slides (!) of his deck, you get to a slide named "Transformation Engine" which seems to be the primary reason for Cat's existence. The idea seems to be to build a large number (Chris said potentially thousands) of little optimization transformations which are used to "prune" the tree during the binary generation stage of a compiler.
  • The only problem with this (other than the difficulty of following the presentation) is that I don't think compiler optimization is a particularly useful area of study. I subscribe to "Proebsting's Law" on this one: "Advances in compiler optimizations double computing power every 18 years." This implies that programmer productivity is far more important than compiler optimization. Ruby is the latest great example of this phenomenon.

Mark Cooper - Page XML : An XML based domain specific language for developing web applications

  • Page XML is a DSL for building web apps. Unfortunately, it isn't released yet and it was hard to get a sense of what a solution built with Page XML would look like from the individual features described on slides. But I was certainly intrigued.
  • As a DSL, Page XML needs to encode domain-specific abstraction. One example they provided that I thought was cool was their URL handling. Good URL design is an important usability feature. URLs in PageXML are split into constant and variable parts, so in a URL like mysite.com/news/somechannel/4, the "somechannel" and the "4" would be variable parts that would map into parameters that are passed to a page handler. Very cool.
  • There were a large number of what felt like small and simple yet eminently usable features. Too many for me to write down.
  • The only think I didn't like is the use of XML. No only are domain specific concepts like URLs encoded in XML, but also relatively mundane things like loops and if statements. This gets ugly really quickly. I imagine, the creators of Page XML did this so they wouldn't have to build their own parser, but it really hurts the usability of the language.
  • The last point really points to the need for a simple meta-language - a language for building languages. Lex/Yacc and their derivatives just don't cut it. Ruby is good for building internal DSLs, but I'd like something faster and amenable to static typing as well as something more light weight for building external DSLs.

This post is long enough and I have "real" work to do (the downside of leaving evangelism! :) ). I'll post about the afternoon sessions later.

Posted By Harry Pierson at 1:48 PM Pacific Daylight Time

Friday, June 02, 2006

June DSL CTP

Congrats to the team for their latest version of the DSL Toolkit, integrated into the June CTP of the VS SDK. According to the published product plans of the VS SDK, they're suppoesd to ship their next release - including the final DSL toolkit - next month. Looking forward to it.

Posted By Harry Pierson at 7:56 AM Pacific Daylight Time
DevHawk
World Tour 2008
DevDays 2008

Change Congress
Recent Bookmarks
Tags .NET Framework (2) ADO.NET (5) Agile (7) AJAX (3) Architecture (282) Guidance (6) Interop (2) Modelling (61) Patterns (7) Process (4) SOA (93) Web Services (5) ASP.NET (18) Battlestar Galactica (3) BI (2) BizTalk (4) Blogging (113) dasBlog (11) Podcasting (4) BPM (1) C# (5) C++ (3) Capitals (5) CardSpace (3) CLR (2) College Football (10) Comedy Central (1) Community (81) Concurrency (6) Consumer Electronics (1) Database (12) Dependency Injection (2) Development (115) C Plus Plus (1) Embedded (5) Lanugages (36) Media (2) P2P (11) Rotor (1) SharePoint (6) SOP (3) DIY (1) DLR (8) Domain Specific Languages (13) Durable Messaging (5) Dynamic Languages (9) Dynamic Silverlight (1) Education (3) Enterprise 2.0 (1) Entertainment (14) ETech (15) F# (38) Functional Programming (11) Game Development (2) Guidance Automation (3) Hardware (8) HawkEye (3) Hockey (29) Home Electronics (1) Home Network (4) Humor (5) IASA (1) Idempotence (3) infrastructure (5) Instrumentation (4) Integration (2) IronPython (14) IronRuby (3) Java (2) Job (3) LINQ (19) Lost (1) Master Data Management (1) Media 2.0 (6) Microsoft (27) MIX06 (2) Mobile Phone (1) Morning Coffee (165) Object Oriented (4) Office (5) Open Source (4) Open Space (2) Operations (3) Other (135) Art (1) Books (1) Family (30) Games (17) General Geekery (25) Home Theater (1) Movies (22) Music (20) Politics (3) Society (1) Sports (37) Working at MSFT (15) Parsing Expression Grammar (15) patterns & practices (2) Politics (39) PowerPoint (2) PowerShell (28) Presentation (4) Projects (1) HawkWiki (1) Python (3) Quote of the Day (4) Refactoring (1) Research (2) REST (18) Reuse (5) Robotics (1) Rome (5) Ruby (23) Sci-Fi (2) Scripting (4) Security (3) Service Broker (14) SharePoint (2) Silverlight (15) Social Software (1) Software + Services (2) Software Factories (11) Software Industry (1) Spark (1) SQL Server (2) Stephen Colbert (1) TechEd (7) TechEd06 (1) TechRec League (1) Television (6) Travel (5) Unified Client (1) Unit Testing (3) UX (1) Virtual PC (2) Visual Studio (19) Volta (2) Washington Capitals (33) WCF (31) Web 2.0 (64) Web Services (5) WF (20) Windows Live (21) Xbox (1) Xbox 360 (51) XML (7) XNA (13)
Disclaimer: The information in this weblog is provided "AS IS" with no warranties, and confers no rights. This weblog does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion. Inappropriate comments will be deleted at the authors discretion.