Posted By: reinux | Mar 20th, 2006 @ 6:02 PM
page 1 of 1
Comments: 10 | Views: 5649

So I've been playing with MSH, and even though it's awesome, unless I'm wrong, it has some fatal problems. I really don't want to see MSH go down the drain.

I'm not too sure where to take my suggestions for MSH, so it'd be nice if someone could give me a few pointers. Or maybe someone could just tell me if I'm mistaken in one way or another.

 

Two things: code sharing and consistency of syntax. I'll start with code sharing.
Edit: since the code sharing problem seems to be harder to understand than the syntax one (at least the way I've written it), I'll start with syntax instead.

Syntax: From what I understand, MSH is built with the idea of being easy to learn for anyone "1337"; that is, anyone with some UNIX shell knowledge or some programming (specifically .NET) knowledge. Which is pretty evident in the expressiveness, and which I appreciate.

On the other hand, this seems to cause some really awkward side effects. One that really bothers me is the function invocation syntax.

Suppose I have a function defined as follows:
function Pow($var, $exp) { [Math]::Pow($var, $exp) }

Coming from C#,  I try to use Pow like this:
Pow(2,Eye Rolling + 3;

It throws an exception, telling me that the value can't be converted from System.Object[] to System.Double. What happened here is that 2, 8 was tokenized as an array of two objects, rather than two arguments to Pow.

The correct way to use Pow is not
Pow(2,Eye Rolling + 3; (results in an exception)

nor is it
Pow 2 8 + 3; (result is 256)

but it's
(Pow 2 8) + 3 (result is 259)

The correct way to use [Math]::Pow is not
[Math]::Pow 2 8 + 3 (results in an exception)

but it's
[Math]::Pow(2,Eye Rolling + 3 (result is 259)

Apparently the only difference is that Math.Pow is invoked through .NET, whereas Pow is a function defined in MSH. Intrinsically both are identical, yet the correct syntax is totally different. When invoking a .NET method, x, y means "two parameters: x and y", whereas when invoking a MSH function, x, y means "an array of two objects: x and y".

A function like Sqrt($val), which would only take one argument, works fine with the normal C-like call expression. Anything else and it starts getting funky.

Two things that bug me about this:
1. The call Pow 2 8 + 3 throws no error, but the result is 256. Because MSH never complained, I wouldn't have known. This sort of thing is extremely dangerous, especially considering MSH is intended to be used casually for file manipulation.
2. Learning MSH is like learning two languages at the same time. I could learn through trial and error, which is just asking for bugs, or I could learn by studying it intensely -- which defeats MSH's purpose as a quick-to-learn language.

The solution would be, quite simply, to either make Foo 3 5 the only valid syntax, or to ditch instantiating arrays by just CSVing objects. Really, 3; 5 and {3, 5} are good enough. 3, 5 just isn't necessary.


Code sharing: One of the cool things about MSH is that you can share code on a function or script file level. If you have a cool function, you just paste it on your blog or on a forum or what not. The trouble begins when you have scripts that span multiple functions or reference other scripts.

Say Foo is a function that you want to share on your blog. Foo makes a call to Bar, which you also created. You post Foo on your blog, but a reader complains that he needs Bar for Foo to run. So a couple days later, when you're not too busy, you give them Bar. But they already have their own version of Bar, which just got overrided by Bar (for the MSH instance in which it's run). So their version of Bar suddenly doesn't do what they'd expect it to (Edit: okay, this seems to be true only if you have something defined in $profile, since that goes public).

Two problems arise in this example: In sharing anything more than a simple bit of code, you'll easily lose track of which methods, aliases, vars etc you need to provide; and in doing so, you risk a conflict between their existing code and your code. This can be expected to happen very often, since you're essentially relying on luck to avoid name conflicts.

In sharing anything more than a simple bit of code, you'll easily lose track of which methods, aliases, vars etc you need to provide.

A solution to the first problem would be to provide some sort of dependency check mechanism which sharers could run to make sure their audience is given everything they need. A solution to the second problem would be to use some form of namespacing.

Which ever the case, this needs to be fixed ASAP, or MSH will immediately lose its value as an easily shareable language.


I'd get these issues fixed by the first release even if it means breaking CTP code. Otherwise MSH is going to be so bug-prone that it'll be abandoned.

(MSH needs Anders Smiley

staceyw
staceyw
Before C# there was darkness...
You lost me on the Code sharing bit.  This is a potential issue with any language (script or not).  If you don't post the whole program, you left the reader without a complete example.  Sometimes a snippet will do as your just posting a concept.  Sometimes you may want to post the whole thing.  I see no "fix" that needs to be done in that regard.  You post what makes sense in the context of your post, that is about all you can do.
staceyw
staceyw
Before C# there was darkness...
reinux wrote:

Have you read my suggestion on fixing it? And have you read my comment on conflicting names without namespaces or such? And the other issue I noted?

Sure, script or not, a program's only complete so long as it's complete. But that's like arguing that we're all going to die eventually, regardless of whether we treat a sickness or not. Or like arguing that a room's gonna get messy sometime or another, so we should just leave it and let it.

It's a matter of severity. With MSH the implementations are customized more than even Linux distributions are. So it'll turn into a mess quicker than any other "language" (platform, to be exact). Linux has a little bit of protection from that nowadays simply due to its long history.

And I've said there should be a way to trace dependencies and "package" them a little bit so that that sort of thing doesn't happen. VS.NET does this to an extent by putting all an app's references in the Bin folder. Shouldn't MSH do something similar?

Don't tell me I only post what makes sense in my own post when you've acknowledged yourself that you haven't even understood it.


First, you edited your post from the first version and you removed the namespace idea and moved things around so I will not address some of that.  Second, I still don't understand what the issue here is?  How is this different then posting a ksh script?  Either you post the whole thing or you don't.  ksh does not give you some magic copy that follows all the scripts and copies them into the clipboard for you.  I guess you could write such a thing, but why?

You seem to want a Project/Solution IDE like VS for MSH.  I would agree that would be nice.  Then you could do things like zip up all the projects and post that.  If you wanted copy/paste every file, you have to do that manually - even with c#, vb, or ksh.

reinux wrote:

It's a matter of severity. With MSH the implementations are customized more than even Linux distributions are. So it'll turn into a mess quicker than any other "language" (platform, to be exact). Linux has a little bit of protection from that nowadays simply due to its long history."


What do you mean here? What mess?

reinux wrote:

Don't tell me I only post what makes sense in my own post when you've acknowledged yourself that you haven't even understood it.


I am trying, but you also have a responsibilty to explain yourself so people can understand what your ideas are.  You may understand 100%, but don't assume everyone can read your mind.  I still do not understand the code sharing issue.  Can you provide another example of how Code sharing is somehow harder with MSH then with c# or ksh or other?  I think it should be rather easier to share scripts then a c# project for example.
reinux wrote:

Of course ksh doesn't; nor does any other shell language as far as I know. But from the perspective of an app developer, especially a Windows one, that sucks. I don't care if MSH is as good as anything out there else in this regard; I think it should be even better.  "No different" means "no better" just as much as it means "no worse".
 


From the perspective of a sysadmin, I don't see the sharing thing as an issue. We are a cautious breed and tend to avoid dependencies unless we can avoid them. For the most part, I don't expect to see scripts with massively complicated dependency chains - after all, we're admins, not developers.

The syntax issue is a curious one though. I haven't played with MSH yet, but this definately seems worrying. I really don't want to have to mess about with differing syntax for what should essentially work the same. Will have to download it and give it a whirl...

staceyw
staceyw
Before C# there was darkness...
Relax a bit reinux.  We are on the same side here.  Here is what you said:
"I'd get these issues fixed by the first release even if it means breaking CTP code. Otherwise MSH is going to be so bug-prone that it'll be abandoned."

So MSH is bug-prone because you can't find an easy way to share your code on *your blog?  That just seems a bit over the top to me.  That requirement does not really have anything to do with the language itself, but some external tool you want.  So basically, you want a tool that given a .msh script will output all that script, and any other script, or c# cmdlet, or function, that that script called?  That could be an interesting script to write in msh itself.  You would need a way to decompile (i.e. reflector style) the cmdlets and hope they are not obfuscated or something.  If this is your need, you may want to post this on scripting ng.  I am sure some scripts will show up. 
staceyw
staceyw
Before C# there was darkness...
"MSH isn't just a language, it's a shell. It's as much of a Windows application as Office is. The features determine its value as much as the language does. Think practicality."

Yup.  The thing you see is actually a thin c# console app that uses the system console like any console app.  This calls into the msh runtime dlls.  You can host these dlls yourself and IIRC that is documented.  They could use a new/updated console.


"Third-party cmdlets are so rarely added to the shell that installing a cmdlet involves reassembling msh.exe with a reference to your new cmdlet using make-shell.exe. Even if it were necessary to share a custom cmdlet, at worst, it'd involve copying the .dll and making a one-line msh "installer"."

I have not played with it in a while.  But I did a lot of cmdlets in the first two betas.  IIRC, it did not require reassembling msh.exe at all.  Just adding the dll to the right directory and go.  The first version required installer to update a config file, I think it should be xcopy deploy today. At least that was the goal.

"On the other hand, making a script like this would involve parsing MSH scripts and traversing all the scripts and aliases that it references. Since MSH isn't an ECMA standard language with its BNF available in the documentation like C#, the only people who could do this would be the people on the MSH team itself."

It would not be easy, but you could do it in c# or msh.  You can even host msh yourself and maybe make certain hooks that would make this easier.  Did you post this question on the scripts ng?  It would be interesting to see some other ideas on this.


page 1 of 1
Comments: 10 | Views: 5649
Microsoft Communities