PowerShell Complexity

By Xah Lee. Date: .

PowerShell Complexity from .NET Object Oriented System

PowerShell is based on .NET Object Oriented system. [see PowerShell: Object Type, Properties, Methods] This is a big source of its complexity, because, since each value is an object, it means they have methods. So, computation are done by method call such as x.m(). But this make it very inconsistent with many shell way of operations and syntax.

For example, a string, can be split to a array by its method

"a.b".split(".")

or an PowerShell operator

"a.b" -split "\."

or, in the shell style of piping. e.g. Split-Path

another good example is the Equals method of many objects vs the operater -eq

So, you have a bewildering complexity of syntax, and burden on user about which one is the correct choice.

Powershell would be much simpler, if it is not based on a class/object hierarchy, but a system of independent functions (much like Wolfram Language (Mathematica) ) , possibly with a type system. but it is easy to understand why PowerShell is based on .NET, because .NET is Microsoft's core computing tech engine, its foundation, and it is pure Object Oriented as in Java.

PowerShell Complexity

pwsh object error 2022-06-13 gQDFk
pwsh object error 2022-06-13 gQDFk

Been coding powershell kinda semi seriously for a year now. I'd say, it's fairly complex. Far more so than golang. [see Golang Tutorial]

It's complex for 2 major reasons, i think. One is that, the whole thing work on objects, each is object a .NET object hierarchy. As opposed to unix just strings.

So, everything is a object, has methods, and properties. But more than that. The object that powershell deals with, is more complex than java or python's OOP object. Because the object in PowerShell has lots types, every elaborate. Not just methods and properties. e.g. a special type of property or such called noteproperties.

Then, each value, also have very elaborate types. Not just int float string. But u got file object, object for dir, object for enum types, type for special things... Perhaps hundreds of types. Then, you also have array type.

When u deal with objects in a shell lang used in terminal, u immediately got the issue of display presentation. So that adds a layer of complexity. Text output are not really text. They are object that got converted to text for display purposes in some automated way. The detail of this, is complexity. But powershell, is also fully backed by .net.

As far as i know , u can call every .net method, and every value is a .net value type, meaning, u have the complete access to .net methods of that value/object. This makes pwsh a full bloat with power, that i think may even surpass python.

This also means that, there are many ways to do the same thing. U can actually almost just call .net functions as the main way u code pwsh, and or, for every value, u can use .net methods, but u can also use powershell cmdlets. And, another major reason of complexity is that, pwsh is a shell lang, meaning, it has a linearized syntax to let u type things and work things interactively. That is, reduce nesting in syntax, or many ways to omit brackets or params. This, linearization of syntax, necessarily made the syntax very complex, with many variations.

Programing Language Design