I’ve run across two problems as far as coding style goes and I’m just wondering what is the best way to resolve them?
The first is methods with many parameters, I’ve been doing one of two things (using Java for the sake of demonstration).
someObj.bigMethod(someData,
moreData,
evenMoreData,
moar,
andMore);
and
someObj.bigMethod
(
someData,
moreData,
evenMoreData,
moar,
andMore
);
Sometimes also intended all the way back.
As for declaration of methods I’d favor #1
class SomeClass
{
public void someMethod(int someData,
int moreData,
int evenMoreData,
int moar,
int andMore)
{
// Blah
}
}
For calls I like #2 because it’s quicker to write out (yeah, I’m lazy) and get’s the job done. But obviously this can be confusing because it uses a similar style to the way I format curly braces, and on first sight one could think it’s a declaration of something maybe, I don’t know, it’s hard to tell when I’m the one actually writing it.
The other problem I run into, though not often, is when a method is in a class within a class within a class and so on. I don’t even know how to format this mess, I’m just guessing it’s bad practice to have it in the first place, but hey, it happens.
someObj.anotherObj.yetAnotherObj.betterThanTheNextObj.nextObj.someMethod();
Maybe not to such an extreme extent but similar, especially when names are large.
For declarations, I would also definitely be in favor of method 1
for method calls : if the indirection chain gets too long, you can always cut it by using variables :
var currentAnotherObj = someObj.anotherObj.yetAnotherObj;
var currentNextObj = currentAnotherObj.betterThanTheNextObj.nextObj;
currentNextObj.someMethod();
HTH