- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
FIFY
Edit Admin
And, just like tomorrow, it never comes.
Edit Admin
Luckily the amount of method arguments in .NET is limited. But yes, I have also seen methods like this in the wild :-)
For those interested, the theoretical limit is 65535 arguments; however you will not be able to call a method like that because the stack frame is also limited per method call - so you can only use 2000-8000 arguments depending on type and platform architecture.
Addendum 2024-11-07 13:53: BTW in C# you can use readonly value types which will end up in basically the same machine code without any allocations:
Edit Admin
I know this is ugly, but is there anything that would completely eliminate the ugly? If you have 36 pieces of information for an object, at some point you have to pass 36 values into the object. I don't think having 36 separate functions is much better, and trying to split the difference with something like 6 functions with 6 parameters each would be an even bigger WTF.
Edit Admin
You'd rework to use OOP principles, such as encapsulation with structs/classes. You shouldn't need to pass 36 parameters; Probably only two or three that would contain the other information.
Admin
So your solution to having a method with many parameters is to create a bunch of DTO classes that only serve to make the method signature shorter but complicate the calling code. Honestly I would not call that a win. It's just piling on complexity to make things look more to your taste.
Edit Admin
Builder pattern?
Qualif.Create() .SetDocClass("value") .SetTradeId("value") .Insert();
Edit Admin
The builder pattern is far better, since you only touch the specific fields. Patterns like that are much easier to test, write and adding a new one is trivial. Database fields should be updated in a typed fashion, unless of course the (not shown) database is all varchar(256)!
Admin
You're trying to do the wrong thing better. Pass it two fields: Thing to change (ideally, this should be an enum of the fields), what to change it to.
For times when you do need to change the whole record, define a record with all the fields. Pass that.
Admin
Fixing problems in a SCRUM (SCRotUM?) environment means it will never be fixed in a proper way. Quick fixes are the norm
Edit Admin
Another reason Scrum/Agile is dogshit.
Admin
The minimal first step would be default values and named parameters, unless you're using a broken language that doesn't support them. That would at least give you chance of finding bugs such as
int nbUpdates = incoming.saveQualif(docClass, null, null, null, null, multiDeal, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
Admin
To me, this cries out for getting passed a map. Key/value pairs would work wonders. I initially thought string keys, but I think I agree with Conradus that an enum would be better.
It'd probably simplify the underlying code, too. Loop through the map, constructing the structured query and value array in parallel. Not the (I assume) pages of if clauses that the method signature suggests.
Edit Admin
The parameter values come from a form. The form can store the values in the widgets directly into members of a business logic data structure that the form controls. I believe that would be simpler.
As to the second call, I'm not sure. Needs more context.
Admin
"so you can only use 2000-8000 arguments depending on type and platform architecture."
I do not want to know just how you discovered this.
Edit Admin
Ha, like a dev. I wrote a simple console up that generated me the file and then I tried powers of two after 65535 didn't work :-)
Edit Admin
Clearly the best solution is one single string parameter that contains a comma-separated list of values.
Edit Admin
This is nonsense. One of the few rules of SCRUM is that a user story has to be finished before you can work on another (that's called commitment). So if you reopen a story a bug or do a "bug" story, the workflow is pretty clear, this story has always priority. If you don't do that, you are doing not only SCRUM but all agile development methods wrong cause that's one thing all of them have in common ;-)