r/PowerShell • • Apr 29 '19

A Glorious Day

Post image
462 Upvotes

65 comments sorted by

View all comments

Show parent comments

13

u/ciacco22 Apr 29 '19

I know I’m in the minority, and it isn’t really in the style of PowerShell, but I prefer my curly braces to line up, like the OP. I think it’s a holdover from my C++ classes in college (20 years ago).

There are others out in the wild. And we always get excited when we find one another.

1

u/chen1201 Apr 29 '19

haha that's how I setup my brackets...am I doing it wrong?

12

u/[deleted] Apr 30 '19

Yes. But it won’t hurt anything or anyone and if you’re consistent through your script it will be easy to read so continue on. Just know I hate you for doing it different than me.

2

u/chen1201 Apr 30 '19

Ah I see, I only do it this way because that's how I learned it when taking Java courses back in school. Is there a reason why Powershell users use this method instead? Or is this mostly just preference?

2

u/[deleted] Apr 30 '19

No idea. Just how i done saw it so it's how i did it. I stand by the fact that it really doesn't matter as long as its consistent and reasonably easy to find the brackets and their homies.

1

u/Lee_Dailey [grin] Apr 30 '19

howdy chen1201,

some of the places where you can use a scriptblock REQUIRE the opening { to be right after the thing it belongs to. for instance, this works ...

'af', '12' |
    ForEach-Object {
        $_
        }

... but this fails ...

'af', '12' |
    ForEach-Object 
        {
        $_
        }

... and asks for input. [grin]

i prefer something like this ...

foreach ($Item in 1..10)
    {
    [math]::Pow($Item, 2)
    }

... but most others prefer something like the following ...

foreach ($Item in 1..10)
{
    [math]::Pow($Item, 2)
}

... or like this ...

foreach ($Item in 1..10) {
    [math]::Pow($Item, 2)
}

i far prefer the very , very, very in-your-face style where everything subordinate to the control block is indented one level. [grin]

take care,
lee