I have been using quite a lot of PowerShell lately (I’m mostly a system administrator), and I wondered to myself what type of language it is. I would think it is an interpreted language, but I have heard a whole lot of other names describing languages in general: Strong vs. weakly typed, dynamic, static. What does PowerShell fall under?
Share
A few clarifications first:
The two categories: Compiled and Interpreted refer to the way the source code (or script) is translated into actions.
In an interpreted language, the commands are interpreted directly to actions by the interpreter.
In a compiled language the source code is first translated (or compiled) into a machine language (or an intermediate language like Java’s byte-code or .NET’s assembly) which will be turned into actions when run. In the case of a compiled program, you can look at the compiled code as the source code for an interpreted language and think of the CPU as the interpreter (or JVM in Java’s case and the .NET Runtime for .NET).
The concepts of statically and dynamically typed language refer to the variables of that language.
A statically typed language (like the C family or Java) will define the type of the variable in its source, and the usage of that variable will be derived (usually by the coder) from the type.
A dynamically typed language (like Scheme or VBScript) the type of a variable will be defined by its usage. In some cases the coder simply can’t define a type for a variable (like in Scheme or Bash script), and in others this is just optional (like VBScript).
The third concept-pair is strong vs. weak typed language. These concept refer to the rules imposed upon relation between variable types in the language (most commonly related to casts). The question of typing system "strength" is not as Boolean as other questions, so most languages fall somewhere between having a strong and week type system.
In a loosely (weak) typed language the compiler and the runtime will allow you to treat a variable of one type as if it were of another type and the behavior of such a situation is usually language specific (and in some cases even implementation specific). For instance, you can add together a number with a string and this will be considered valid code.
In a language with a strong type system the compiler and runtime will demand you perform specific actions in order to perform operations between different types of variables. The most common example for this is casting (like casting an int to a float).
Bottom line
To define PowerShell, it’s an interpreted language, but this is a gray area when it comes to .NET. Defining variables in PowerShell does not include defining their type, and so it’s obviously a dynamically typed language, and combining variables can be done seamlessly (as @halr9000 noted), which indicates a loose typing system.
In a sentence, I’d say it’s an interpreted dynamically typed language with a weak type system.