RamblingCookieMonster / PSRabbitMq

PowerShell module to send and receive messages from a RabbitMq server
http://ramblingcookiemonster.github.io/RabbitMQ-Intro/
MIT License
47 stars 29 forks source link

Possibility to reduce parameter definitions #15

Closed derekmwright closed 7 years ago

derekmwright commented 7 years ago

One thing I've been working on lately is DRY'ing out my PowerShell code, especially when it comes to defining parameters. Coming from Ruby, I can't stand how a PowerShell function isn't able to inherit parameter declarations from another base function. This feeling was unpleasant so I attempted to work around it. I noticed the code here has quite a few repeat parameters. This will allow you to define some common parameters and load them into a function:

https://gist.github.com/derekmwright/91504970eb876ca4ff9c6c5714ada2ef

It's still a little bit of a work in progress, but I figure more eyes is a good thing and maybe it can benefit. Esp w/ the chatter of a possible version bump.

gaelcolas commented 7 years ago

Although I agree that the Parameters are very verbose, I think it's a good thing to keep it that way. The main problems I have with over-using the Dynamic parameters are the following:

When using a single file functions design as this project follows, I found it actually easier to maintain, as when you come back to the project after a while, if you only need to change a function you have to only check one file.

The hardest part with this approach is to be consistent with the name and type of parameters, which is an interesting and relatively easy thing to handle with Pester.

When the signature of a function is partly or completely the same, or as you put it, a function extend another one, then I'd rather resort to proxy functions.

derekmwright commented 7 years ago

Ooo thanks for Proxy Functions, I'm still learning PowerShell so I appreciate the guidance there.