Friday, January 25, 2019

Power Shell script, a review

$mailman = New-Object Chilkat.MailMan

#  Any string argument automatically begins the 30-day trial.
$success = $mailman.UnlockComponent("30-day trial")
if ($success -ne $true) {
    $($mailman.LastErrorText)
    exit
}

$mxDomain = $mailman.MxLookup("support@chilkatsoft.com")
if ($mailman.LastMethodSuccess -ne $true) {
    $($mailman.LastErrorText)
    exit
}

$("MX Domain: " + $mxDomain)


Overall, they did well with the verb, object format, they develop a set of common verbs.

 The dollar is unnecessary, all tokens are a look up, and the assignment of a symbolic value always accompanies a dollar and equal so I would dump the dollar sign all together, in Bash and everywhere.

The same holds for the dot, if a token needs looking up, then the type determines if the next token is a method. In general, the number of arguments following a namespace token is determined by the look up type. Parenthesis are used only for expression grouping. We end up with a free form format on the command line that can be called a language.

PS uses the dash in get-object, for example. Get is a common form, so is object. I would dump the dash and order it, object get.  The prior name:  prior object get, prior in this case knows hao to handle the object get pair.  One could replace onject get with keyvaue objectname object.

A readable, plain text sequence of actions, the tokens themselves having the methods to collapse and execute the line.  The engine needs t look up the common forms anyway, so just assign them names by key and the object is in val, keyval becomes the most common form, used on every token implicitly.  Tokens key values default to undefined, a valid type meaning pass through. Token can be immediate string integer, by detection.  String constants are a pain, they exist outside of the closed syntax, and I would leave them last in developing the language, make them an after thought.

Tokens can have dual meaning:

stacks mystack push;

Can become:

Mystack push;

Macros one the command line are first class, that is all it does is look up and tokens and consume the forward sequence.  Macro definitions easily detected from their execution. Free form sequential functional language, each token a function.

Default, as a syntax engine, goes away in thei scenario because faults value dded was just the while loop, macro definitions and expressions. All it did with expressions was run them through shunt. But we need simple expressions on the command line anyway. And the mar definition is the same syntax, just position dependency makes it a definition, like in c. So why bother with all the semantics of Default as a language, is was designed to go away, there is not much left to disappear.

Do we need the while loop grouping brackets?

No, the semi-colon works as an end of of statement indicator:

while x < 6 while y < 7 stacks mystack push;


What about the other engines?  They have to decide whether they want the command line complexity.  But adding complexity to protect the syntax engine, with the typeface explosion, does not work in the modern Moore's law regime.  Plain text sentences with grammar school expressions,  not other punctuation, except the semi-colon, and some might suggest we use the dot for that. We are not software engineers because we memorize Morse Code, the opposite, we are software engineers because we make plain text work.

I am not the first to figure this out, function plain text languages have been around. Nor am I the first to complain about typeface explosion, it has been one of the major hindrances to linux acceptance. Plain text is a well worn syntax preferred by humens and bots, software engineers need get a clue about the command line.

No comments: