params in C# Are Evil

Friday, January 17, 2014

So there I was, minding my own business, coding away when - BAM, it hit me - params! Like a lot of short cuts they can shrink your code down a lot, but what you don't realize is that you now have a method with multiple signatures. You can create other methods with those signatures and the compiler won't say a word. I know, I know, when you write it you will be aware of the issues, but what about 3 months later or 6 months later? What about the poor shmuck (me) that needs to modify the code 2 and a half years later? No complaints from the compiler. I'm sure at one point I knew about 'params', but I hardly use them and it never even crossed my mind. And for the record it's a bit pernicious and subtle. This one can be very hard to trace.

BAM - bug.

Comments