Parameters: You’re Doing It Wrong!

Having parameters for a method is perfectly fine however like anything, they can be used for evil. So let me give you a tip: If your code looks anything like this method signature (and I kid you not, this is a real method) then YOU”RE DOING IT WRONG!

SaveContentSetItem(ContentSetItem,String,String,Int32,Int32,Int32,Int32,DateTime,DateTime,DateTime,DateTime,
    DateTime,DateTime,DateTime ,DateTime,Boolean,Boolean,Boolean,Int32,Int32,Int32,Int32,Int32,Int32 ,Boolean,
    Boolean,Boolean,Boolean,Boolean,Single,Boolean,Boolean ,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,
    Boolean,Boolean ,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,Boolean,
    FileLocation,String,Stream,String,FileDisplayFormat,Boolean,Stream)

Please, for the love of all things good, turn off your computer right now. Pack it in a box.  Put the box in a locked safe.  Put the safe in a bunker under a mountain. Seal the bunker using 40 foot thick concrete and collapse the entrance.  Place a minefield and barbed wire around the bunker, and never EVER WRITE A LINE OF CODE AGAIN!

 

Reader Comments

I found your problem. Simply replace Boolean with bool.

You're welcome.

whoever wrote that...if they drove to work, might I suggest you take their car keys away from them?

This is how I imagine SharePoint APIs..

We have one justification for many parameters.
We write an Excel Addin, and basically write some custom Excel "Functions" eg MYAVG(1,2,3)
It's often necessary, in this scenario, to use 20 arguments on the end, open to the user, to add as many arguments as they need. Keeping in mind that the "API" into creating an Excel function has you creating a C# (or VB) function with the same number of arguments as the mapped Excel Function.

This leaves us with dozens of functions with around 30 or so arguments - which map directly to Excel functions.
Horrendous, but absolutely necessary.

For the record, I agree with (Uncle) Bob Martin, that any more than 1 parameter is a code smell - not wrong, just a smell... that needs sniffing.

Some there is something wrong with this (used here pretty much every day)?

public static SomeType SomeMethod(string, string, double, double, string, bool, bool, string, string, bool, int, string, string, string, string, string, double?, string, int, string, string, string, int, string, string, string, string, string, string, string, string, string, string, string, bool, bool, string, double?, int?, double, string, string, string, string, string, string, bool?, string, string, string, string, string, bool?, bool?, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, string, int?, string, string, string, string, string, string, string, int?, string, int?, string, string, string, string, List>, IEnumerable, string, string, string, string)

I'll leave my current role because I feel sick working on code like this :(

Those lines means that system needs a complete rebuilding because mentality made such mistake sure did other terrible mistakes everywhere in that system.

This is a clear indicator that system had NO *proper* design at first place.

LOL! Ha!

Another example of your great sense of humour - love it.

O Dick, Where are u. Call me.

"any more than 1 parameter is a code smell"

Correlation does not imply causation. Searching for this kind of "code smells" seems to me like you're losing the focus of a code review.

To me, it looks like you're simply replacing one extreme case with another.

Why should you be so extreme in that? There is a problem which can be solved in a simpler way) But still I like the humor with which you write here!

Post a Comment



Welcome

Thanks for dropping by. Enjoy your visit!

MVP Logo Visual Studio 2012 Cookbook
Find out more about Richard.

Richard on Twitter  
profile for Richard Banks on Stack Exchange, a network of free, community-driven Q&A sites

User Groups

My Open Source Projects

Podcast

Blog Archive