33 parameters for a function?! Seriously!?

Started by
54 comments, last by Krohm 10 years, 11 months ago
Quote:Original post by janta
For a good laugh, turn that function into a variadic one.
Hahaha now that is tempting.

I just had a nice little chat with my boss and a coworker. My boss is all for using a struct/class, but my coworker isn't. He likes having a lot of parameters. He says it's like a shopping list. He also says there would be alignment issues between C and C++. But we're using C++ objects in the API (like std::string and std::vector)... how do I tell him that we aren't even targeting C? And as for possible alignment errors with C++, how do I combat him on that? Surely if there are alignment errors they'll show up in more than the struct we would be passing for that function? So why worry so much about that one struct that would simplify life so, so mch? And we're delivering libraries for all our targeted compilers and platforms, so that shouldn't be an issue. Someone give me some ammo for his alignment issues argument :)
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Advertisement
33 parameters sounds like a severe design WTF if you ask me. Personally, I consider six to be too many.
Quote:Original post by MikeTacular
He likes having a lot of parameters. He says it's like a shopping list.


Oh come on! LOL!
[size="2"]I like the Walrus best.
Quote:Original post by MikeTacular
He also says there would be alignment issues between C and C++.


He's wrong. Structs are aligned in the exact same way in C/C++. You can change the alignment to 1, 2, 4 or 8 bytes with compiler #pragmas anyway. You should ask him what he means specifically by "alignment errors".
while (tired) DrinkCoffee();
But why does you function need 33 inputs anyway? Couldn't you split that up, avoiding the many parameters vs. single struct argument entirely? I've never needed so many arguments in a function! Your program is crazy :)
Quote:Original post by polymorphed
Quote:Original post by MikeTacular
Is this normal?


Nope. The normal thing would be to just pass a pointer/reference to an object containing said 32 arguments. I can't imagine why you'd have any portability issues with plain objects, unless you're planning to port it to FORTRAN. [smile]


Even then, I usually write a wrapper function or macro for the FORTRAN function which takes a struct or two as arguments.
Quote:Original post by MikeTacular
I just had a nice little chat with my boss and a coworker. My boss is all for using a struct/class, but my coworker isn't. He likes having a lot of parameters.
Who cares, it is your task and your boss is happy, just do it your way and if the coworker really whinges, tell him he's welcome to add an override that takes the parameters individually.

But, 33 is nothing.

Quote:Original post by d000hg
But, 33 is nothing.


LOL, I remember that one. It sounds terrible for me to say this, but I hope someone lost their job over that abomination.
SUCCESS!!!!!!!!!!!!!!!!! WOOHOO!!! After my coworker talked to another coworker today, he consented to letting a class be build with accessor methods that we could pass to the function instead of the 34 parameters. Finally! Hopefully management is cool with it too. And I was all ready to rate the 34-parameter function in WTFs/min (obligatory link for those who don't know the reference).

For those who are curious as to what our 34 parameters were, here's the function's declaration (hopefully I don't get in trouble for posting this):

uploadAsset(Application::ApplicationType application, const std::string& applicationVersion,            const std::string& pathToAsset, const std::string& pathToShortPreview,             const std::string& pathToMainThumbnail, const std::string& pathToSummaryThumbnails,            const std::string& shortName, const std::string& description,            const std::string& frameRate, int width, int height, const std::string& audioDataRate,            const std::string& videoDataRate, Asset::AudioBitRateMode audioBitRateMode,            Asset::VideoBitRateMode videoBitRateMode, float videoDuration, const std::string& presetXML,            const std::string& fileType, const std::string& filter, const std::string& audioCodec,            const std::string& videoCodec, const std::string& authorName, const std::string& sourceFileName,            const std::string& sourceFileType, const std::string& sourceAudioCodec,            const std::string& sourceVideoCodec, const std::string& sourceFrameRate, int sourceWidth,            int sourceHeight, const std::string& sourceAudioDataRate,            Asset::AudioBitRateMode sourceAudioBitRateMode, const std::string& sourceVideoDataRate,            Asset::VideoBitRateMode sourceVideoBitRateMode,            bool (*progressCallback)(float))


Imagine trying to call that function off the top of your head haha!

[edit]

Just saw your post d000hg, and that function is a true, bona fide nightmare.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Quote:Original post by d000hg
But, 33 is nothing.


Hmm. Wow. I'm genuinely surprised that the person who wrote that code was able to operate a keyboard.
while (tired) DrinkCoffee();

This topic is closed to new replies.

Advertisement