I love you but sometimes…

I am all in for Powershell.
I have embraced psake for my local builds.
But, somehow, someone finds a way to spoil the moment and wastes my time.

TL; DR

Powershell ISE’s console is evil. Do not use it when invoking third party line utilities.

Composition over… well, anything else

The reason command line is embraced is not because its sexiness, but, in part, due the reminiscence of that old mantra “write small programs that do one thing well and compose them to solve complex problems” (or something like that).
Command line programs are pretty easy to script and track in source control, whereas GUIs are not.

So builds I create tend to be a mixture of: call a command line program that does the job and was written by someone else because is a solved problem; plus call a function that does the job written by me to solve a problem that I created for myself.

External is beautiful

The former I like very much, because I can blame someone else if it does not work and claim medals when I have to rewrite it to make it work well enough.

But in order to do that I have to invoke an external program and deal with its outcome.
Sounds easy enough and abides with the principles of the venerable UNIX operative system and all those bearded hippies.

But it seems not to be the case in Powershell/psake. And I am not pointing fingers here to any.

Blaming by example

Let’s take the straightforward task of transforming a configuration file to match the constraints of a different deployment environment.
There is this simple LoveButSometimes.config that targets a development environment:

And Microsoft finally gave us a sensible way to patch and poke configuration files that most of us can agree upon, wrapped up into a (surprise, surprise) terrible name: Web.config Transformations.

We can write very simple code that uses the libraries… or we can call a simple command line tool that does it for us and all that’s left is invoking that tool from our build script.

That simple and innocent action must be tricky enough to deserve a blog post by the author of psake and a help page in psake’s project page. When invoking a third party tool, the communication is done via non-zero error codes (if we are lucky, and programmers stuck to that convention: I am looking at you robocopy!) and those do not make a psake build fail unless something extra is done to check the output of the call. Lucky for us, Powershell comes with the handy exec {} that performs that checking and stops the build when the external programs complains.

Toolbelt

Powershell, like 99.9% of programming languages, is text and as such can be edited with whichever text editor. Blame my upbringing, but I would choose any editor that provides pretty colors and auto-complete over anything else and, 99% of the time, I use the Powershell Integrated Scripting Environment aka. ISE.

Writing canvas is slick and the integrated console for quick tests looks pretty good but, as a text editor, sucks pretty badly (searching within a script is a terrible experience). I have a weakness for pretty.

Did I mention the integrated console as something good? Let me rewrite that phrase: it wasted two hours of my life, hence is evil.

Find the differences

Let’s see what’s in a task that does the job flawlessly and make birds sing in the sunny background:

And it’s ISE output:

Let’s see another task, written with the same love, but slightly less care that brings Mordor-like clouds and circle vultures around:

And its dreaded ISE output:

Can you spot the error? No? Neither could I.
And –Verbose helps naught either.

Let’s execute the same command inside a plain old Powershell shell:

I totally do!! I have an extra ‘A’ in the transformation file name!
Blame me for my poor typing, but TELL ME WHAT’S WRONG, for Fonz’s Sake!

Whoever in the ISE team thought that stripping external tools exceptions was a good idea should have its programmer’s license handed over to the authorities. And with him, his boss and the boss of his boss. And if any of them try to argument back the “feature”, there must be a constitutional amendment that justifies the use of the “elbow in the face” maneuver.

Now, I want my two hours back, please.

Kategorier: Udvikling

Tagged as:

1 kommentar »

Skriv et svar

Udfyld dine oplysninger nedenfor eller klik på et ikon for at logge ind:

WordPress.com Logo

Du kommenterer med din WordPress.com konto. Log Out / Skift )

Twitter picture

Du kommenterer med din Twitter konto. Log Out / Skift )

Facebook photo

Du kommenterer med din Facebook konto. Log Out / Skift )

Google+ photo

Du kommenterer med din Google+ konto. Log Out / Skift )

Connecting to %s