News for hackers. Stuff that matters.
Re:PowerShell is open sourced and is available on Linux by emodendroket on Thursday August 18, 2016 @12:26PM (#12313877)
The implicit return semantics are insane, since you can implicitly early-exit when you do things like call ArrayList.Add (which returns a bool to indicate whether the thing was added).
Re:PowerShell is open sourced and is available on Linux by JeffreySnover on Thursday August 18, 2016 @12:46PM (#12314091)
I know the problem you are talking about - it has bitten all of us.

The new language mode you use when writing classes in PowerShell shifts the needle more towards programming semantics than shell semantics and addresses this.

Give it a try!

Jeffrey Snover [MSFT]

Re:PowerShell is open sourced and is available on Linux by new_hackers on Thursday August 18, 2016 @03:19PM (#12315555)
I really like the functional approach of PowerShell. The pipeline, while not the end-all-be-all of perfection, is still very, very good and very flexible. Once you get into the functional mindset, it is very easy to write terse, powerful code.

My real wish is that there was a syntax for writing function decorators and function generators. This would be similar to the [cmdletbinding()] syntax, but would allow me to write my own.

Re:PowerShell is open sourced and is available on Linux by emodendroket on Thursday August 18, 2016 @12:52PM (#12314150)
Interesting. I'll have to look into it. Thanks.
Re:PowerShell is open sourced and is available on Linux by JeffreySnover on Thursday August 18, 2016 @01:03PM (#12314274)
Our goal is to be incapable of sustained error. :-)

Jeffrey Snover[MSFT]

Re:PowerShell is open sourced and is available on Linux by new_hackers on Thursday August 18, 2016 @12:31PM (#12313939)
insane in a good way right? You aren't "returning" you are emitting to the pipeline
Re:PowerShell is open sourced and is available on Linux by emodendroket on Thursday August 18, 2016 @12:37PM (#12314003)
Not if you're in a script and declaring a function. So, no, it's a source of confusing bugs. Implicit return works better in, like, Ruby, where it has to be at the end and can't just randomly exit in the middle of a function declaration.
Re:PowerShell is open sourced and is available on Linux by new_hackers on Thursday August 18, 2016 @12:39PM (#12314021)
ArrayList.Add ... whatever ... | Out-Null

Its not implicitly returning. The return value wasn't assigned so it is emitted to the pipeline.

Re:PowerShell is open sourced and is available on Linux by emodendroket on Thursday August 18, 2016 @12:50PM (#12314134)
OK, sorry (there is an explicit "return" keyword that I thought worked the same way). Either way, yes, I know you can avoid it by piping to Out-Null, but that behavior is surprising.
Re:PowerShell is open sourced and is available on Linux by ygra on Thursday August 18, 2016 @02:11PM (#12314973)

    return {expression}
is equivalent to

    {expression}
    return
the only place you have an exit from a function, script block or similar is either at the end or at a return statement. Every value that isn't assigned or piped into nirvana gets pushed to the pipeline. I actually can't remember having used return statements more often than once or twice so far (and I use PowerShell daily, heavily).

Then I rarely found the need to use ArrayList. Sure, you can use it, but you can just as well do

    $array = @()
    $array += $item
A personal pet peeve of mine is actually that lots of people write PowerShell very similar to equivalent VBScript or C# code. And that makes for horrible PowerShell code (in my eyes). The pipeline is immensely powerful and not using it often makes for pretty crappy code.
Re:PowerShell is open sourced and is available on Linux by emodendroket on Thursday August 18, 2016 @03:10PM (#12315465)
Most people writing PowerShell scripts are likely dabblers though. Anyway, I have to admit I don't really appreciate the whole pipeline idea; I just know that `$something = Some-Function` sometimes wouldn't do what I thought it would because of these semantics.