3 ms·
I would agree that Powershell has less quirks than bash which sometimes feels like one big quirk. But I think they could do much better. During my project we ra
by Ididntdothis 7y ago
I would agree that Powershell has less quirks than bash which sometimes feels like one big quirk. But I think they could do much better. During my project we ran into a ton of issues around scope, return values from functions and other stuff that were really hard to deal with. You don’t see that with small scripts but our project has thousands of lines and becoming hard to manage. Now some smartass will say that Powershell is not designed for a project of that size but the cmdlets almost force you to use it for certain types of tasks. It would be pretty difficult to rewrite that code in another language.
- animalnewbie 7y agoOnce you realize that you need classes to return values and functions don't return values I (admittedly not an expert) don't see anything more complex beyond that. This thing itself seems like a quirk but again I'm not an expert so don't know how this was designed.
- Ididntdothis 7y agoI don’t remember the exact details but for example loading classes that reference each other was hard unless they were all in the same file. I ended up writing a preload step that would combine all library files into one big file and execute that. In general I found it hard to write reusable code once that code started referencing each other. Maybe there are ways around that but it seems kind of stupid to create a new way of achieving what other languages have already solved decades ago. If cmdlets were easier to use i would probably have used a proper language like csscript or C# instead of Powershell.
- infamia 7y agoFunction return values is among the worst ideas the PowerShell designers dreamed up. A function will (more or less) return anything output to the terminal. This is a particularly bizarre decision considering how difficult it can be to get many Windows commands to be completely silent. Error handling, redirecting output, etc. all fail in many circumstances. It was completely aggravating. It has been a few years, so hopefully that's changed.
- zaat 7y agoOf course it didn't, look at my sibling comment for a link to the updated doc.
- zaat 7y agoI wrote quite a lot of PowerShell code. I really like the language, except when I don't. And return and outputs in general are among the most infuriating points. > In PowerShell, the results of each statement are returned as output, even without a statement that contains the Return keyword. Languages like C or C# return only the value or values that are specified by the return keyword. I don't want all output, no, please, I don't want it. I want something specific and not all the junk around it. So you have to turn into ugly measures like out-nulling everything or searching through your output because there is always possibility that some commandlet outputed something you were not expecting and it will return before the value you actually wished to returned. And classes are nice and all, but lot's of stuff are not compatible PowerShell 5. And there is also the added complexity. https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_return?view=powershell-7 https://docs.microsoft.com/en-us/powershell/module/microsoft... Reading through the examples of the unexpected behavior in so many cases is flabbergasting.