- Nice Classes
5 weeks 5 days ago - If you have a lot of table
6 weeks 2 days ago - No bad post, write more
7 weeks 6 days ago - Landscap issue
8 weeks 3 days ago - Landscap issue
8 weeks 3 days ago - Very good sample
9 weeks 1 day ago - very helpful
11 weeks 4 days ago - You are a saviour
12 weeks 2 days ago - Easy Gradient Backgrounds for UITextViewCells - Selected Cell BG
15 weeks 1 day ago - Saving button position when app terminates
17 weeks 4 days ago
How Not to Refactor a Function That Has Too Many Parameters
Most programmers know that having functions with too many parameters can be confusing. However, fixing such problems requires some intelligence. A programmer once saw some code like this:
SetObjectParams(obj, foo, bar, baz, quux, xyzzy, abra, cadabra, hocus, pocus, presto, shazam);
Finding a stylistic rule somewhere that said a function should have no more than five parameters, the programmer “refactored” it to this:
SetObjectParams1(obj, foo, bar, baz, quux);
SetObjectParams2(obj, xyzzy, abra, cadabra, hocus);
SetObjectParams3(obj, pocus, presto, shazam);
No, that's not how one resolves this problem. You fix this problem by defining functions that each do something simple, give each function a name that describes what it does, and let them take however many parameters make sense.
Comments
Missed Something
Someone smarter than I once said "If your function has 5 arguments... you forgot some."
uh
you made this all up
Did not make it up
The names of the functions and parameters in my article are fictional, but it is otherwise true.