Archive

Archive for the ‘PowerShell Feature Request’ Category

The trouble with the tribbles

September 20, 2007 6 comments

After looking at the new cmdlets shown in the presentation that accompanied VMWare’s recent announcement and discussing the announcement with my friend Dmitry, he mentioned how confusing things might become as more and more companies release cmdlets that don’t use product prefixes in their nouns.  I agree with this to a certain extent, but there are pros and cons either way.

Captain Kirk with tribbles  On one side, if someone develops a cmdlet that no one else has produced that will get tribbles as part of a Star Trek product, and if the type of tribbles they are retrieving are what 90% or more of the users would expect them to be, then why shouldn’t they name their cmdlet Get-Tribble?

On the flip-side though, lets say they also have cmdlets to retrieve replicators, phasers, communicators, and tricorders and they also include a generic “get all” cmdlet that retrieves everything.  As with the tribbles, if the replicators, phasers, communicators and tricorders are what 90% or more of the users would expect them to be, then they could name those cmdlets Get-Replicator, Get-Phaser, Get-Communicator and Get-Tricorder.  But what about the generic “get all” cmdlet?  Should they call it Get-Object?  That certainly wouldn’t be intuitive for an end user.  Maybe instead they should name the cmdlet Get-STObject, but then you could circle back and argue that for consistency the other cmdlets should be named similarly.  This would result in them using Get-STTribble, Get-STReplicator, Get-STPhaser, Get-STCommunicator and Get-STTricorder as well.  Those names then become clearly defined but not very pretty to look at (especially if your product name is actually Star Trek: The Next Generation and you have to distinguish your cmdlets from the Star Trek: Deep Space Nine product cmdlets, in which case you might have to name them Get-STTNGTribble, Get-STTNGPhaser, …ugh!).

What is really the right approach to take then?  Adding support for namespaces and for a using keyword in PowerShell?  If PowerShell supported namespaces, you could do this:

StarTrek::Get-Tribble | StarTrek::Activate-Transporter -Destination $klingonVessel

Alternatively, if Powershell supported a using keyword that would take a script block as a parameter, you could do this instead:

using -NameSpace StarTrek -Process {
    Get-Tribble | Activate-Transporter -Destination $klingonVessel
    Fire-Torpedo -ship $klingonVessel -targetSystem WarpDrive
    Activate-WarpDrive -warpFactor 10
}

I think this approach would give the best end-user experience for both snapin developers and script authors.  Snapin developers could continue to publish cmdlets, functions and aliases using intuitive, meaningful names without having to worry about prefixes.  Script authors could write scripts using intuitive, self-documenting cmdlet and function names.  This seems to be the best of both worlds.

Does anyone have other suggestions?  Microsoft, what do you say, can we get namespace and using keyword support in 2.0?

Kirk out.

P.S. A little known fact about me: In my early University days (pre-graphical MMORPGs – seems like eons ago now) I spent the vast majority of my free time (and often a good portion of my class time) playing a text-based MUD called Worlds of Carnage using the moniker “Nystul”.  I played it so much in fact that I finished it and went on to design areas for the MUD.  Aside from the areas I developed for people to explore on their own, I went so far as to create a virtual Enterprise ship that was completely disconnected from the rest of the MUD, complete with 10-Forward, a transporter room, a captain’s quarters and a functioning holodeck that I could tell to load programs.  It was one of the first text-based MUDs to offer a sophisticated scripting system that allowed for this sort of thing.  And no matter where I was in the game, I could just communicate with Chief O’Brien and say “Beam me up”, and he would teleport me into the transporter room.  Life used to be so simple…

P.P.S.  Hey, maybe someone should make a PowerShell-based MUD!  You could script everything you do (not that you can’t in existing MUDs, at least to some extent, but it would be cool to see it in PowerShell, at least to me)!

Go-East -count 2
Go-South -count 1
Get-Phaser | Set-Phaser -Stun
Go-South -count 1
Fire-Phaser -target $romulanGuard

:)

Technorati Tags: , ,

Follow

Get every new post delivered to your Inbox.

Join 47 other followers