As I’ve begun to dig into PowerShell, I’m reminded again of a whole cluster of themes: why programming languages differ, how they can share a common foundation, and what influences our ability to use a mix of languages according to their strengths and our preferences.
In this example I used a combination of PowerShell and Python because each afforded convenient access to a familiar idiom. In the case of PowerShell, the idiom was a certain style of XML processing. Of course the idiom is available in Python too, but even as a regular Python user I need to stop and think which module provides it.
In the case of Python, the idiom was a certain use of the regular expression machinery. I wasn’t familiar with the PowerShell/.NET idiom, but I knew it in Python, so I used what I knew.
Of course any programming language can be used to accomplish any programming task. You can write a game of Tetris in XSLT, for example, and people have. But each language has its sweet spot. Once you get comfortable in that zone, you want to stay there. It takes effort to be open to other languages’ sweet spots, and to the possibility of combining them.
When I suggested that a pattern dictionary of idioms could help grease the skids, Kevin Reid pointed to RosettaCode.org. Very cool! This would be a great place to enumerate variations on, for example, the regular expression idiom that allows the dot (period) character to match newlines. I have probably learned and forgotten a half-dozen times that SingleLine is not to be confused with multiline, SingleLine is a perl regex term, it corresponds to dotall in java regex. If we could reliably find patterns like allows “.” to match newlines and map from them to implementations in any language, we’d be in a better position to use multiple languages according to their strengths and our preferences.
Note that although my original example was done using the standard C-based version of Python, I later switched to IronPython in order to use the .NET regular expression machinery. It’s true that there are some idioms to be mastered in order to use that machinery from different .NET languages. But there’s also a large foundation of idioms shared by all .NET languages. Because PowerShell and IronPython rest on that common foundation, I’ll think we’ll be able to discover, as both evolve, more about what is essentially Pythonic and essentially PowerShellish.
Thanks for the link, Jon! I often find myself doing similar comparisons of idioms between C# (my “work” language) and Python (my “home” language). I hope to contribute some of my own mappings to this site.
“C# (my “work” language) and Python (my “home” language)”
You’re well placed then to see what roles IronPython might play. Curious to know your thoughts about that.
Thanks for pointing out Rosetta Code. I’ve been needing something like that. I added PowerShell to the site’s list of languages and contributed a few examples. Maybe you or your readers could help bring PowerShell up to snuff with the other languages on Rosetta Code by contributing code snippets.
“I added PowerShell to the site’s list of languages and contributed a few examples.”
Thanks!
“Maybe you or your readers could help bring PowerShell up to snuff with the other languages on Rosetta Code by contributing code snippets.”
As I discover idioms I’ll pop them in there. I’m actually trying to keep code out of this blog these days, it tends to freak out the wider audience I’m trying to write for :-)
Okay, I’m intrigued. Where is this implementation of Tetris in XSLT?
“Where is this implementation of Tetris in XSLT?”
Damned if I can find it now. But I could swear I saw it :-)