Namepaces in Powershell

I was wondering, how we can organise the functions within namespaces in powershell.

I thought since we can create key-value pairs  in powershell, we should be able to use that for organising namespaces and with help of the powerful “&” we can evaluate the values of the corresponding keys.  so in the end the code we get what looks more javascripty.

so, we can organize the functions and variables in powershell within namespaces in the following manner :

namepaces_in_powershell_2

wow….I love this….looks more javascripty to me.. 🙂

I was also thinking that since “&”  is jus like an “eval” function in javascript, we can do something like this in powershell:

namepaces_in_powershell

I’ve not thought where exactly can i use them, but they look promising and at times could be very  handy 🙂

Now, i’m thinking how we can simulate polymorphic behavior 🙂

[updated: code formatting was messy, so i had to put that in an image for ease of readability.]

Advertisements

5 Responses to Namepaces in Powershell

  1. Jeffrey Snover says:

    What a timely blog. We are currently working through a design to deal with this and other related issues. We don’t have anything to say about it now but we hope to address it in our next release so “watch this space”.

    If/when we release the next CTP, please jump on it and kick the tires on this feature to let us know if it does what you want it to do.

    BTW – I’m very pleased to see this blog. One of the way I judge how we are doing is by the requests/complaints that we are getting. We knew that namespaces where an issue that needed to get addressed. This tells me that people (well at least you :-)) are beginning to think about using PowerShell for the things we want people to use it for.

    Jeffrey Snover [MSFT]
    Windows Management Partner Architect
    Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
    Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

  2. Antonio Dias says:

    Glad to see the team’s looking at this. I did a little thought experiment around this some time back in a slightly different direction.

    http://blogs.vmware.com/vipowershell/2007/09/powershell-name.html if you’re interested.

  3. PowerShell Namespaces (RE: The trouble with the tribbles)

    Poshoholic raises the question of PowerShell namespaces. I’ve been thinking about this, too. I think it’s important for usability to keep the naming uncluttered, which is why you’ll find Get-VM as opposed to Get-VMWVM or some such in the VMworld

  4. imaverick says:

    @Jeff:

    WOW…its great to hear from *you* that you guyz are working on these issues in the next version of powershell and i’m quite excited about it and i think its quite an exciting time for people like me who are hooked up with powershell 🙂

    THANKS for your comments and i’m glad to know that you’re happy with my blog :).

    @antonio:
    thats an interesting approach, but i think that namespaces primarily not only solve the name conflicts but also aid in clearly specifying the expression of intent, if we have 2 functions with similar name in different namespaces, i would rather love to see explicitly where they are coming from, just the same way if i’m using 2 diff classes in diff namespaces, it would lead to amibiguity and hence i would be forced to specify atleast some information about where they are coming from.

  5. Antonio Dias says:

    No arguments on the substance. I was playing around trying to see if it was possible to produce the rough equivalent of a “using,” which I would hope would be part of a language-based solution to this.

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

%d bloggers like this: