• Post Reply Bookmark Topic Watch Topic
  • New Topic

calling method inside method inside method inside method and so on  RSS feed

 
Sriram Sharma
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I would like to have the views/opinions on the type of coding here below.
Could someone suggest if this type of coding is good or not so good.
Let me know your views.



Thanks!

Regards,
Sriram
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's the problem? (beside the poor choices for names)
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming you are talking about the concept of calling methods from other methods to multiple depths then this is very common practice. If it wasn't then for anything but the most basic program you would end up with programs with a few methods each containing hundreds of thousands of lines of repeated code in.
 
Sriram Sharma
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Would this be better than the earlier one?
Reason I see is that, having all the calls in one method makes my life simpler to understand what is happening at a higher level rather than having to go down method by method.
(provided the method names make sense)
Just something striked my thought and hence posted the question.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think they do different things - or at least do them in a different order.

In your first example. methods B, C, and D all complete before the code on line 4 runs - and C and D both finsih before all of B finishes.

in your second example, B runs to completion, then there is some other code, then C and D run...

so depending on what exactly is in those "......" lines, you're going to get different stuff happening.
 
Sriram Sharma
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think they do different things - or at least do them in a different order.

Agreed! But, let me say that I am achieving the same result in either case.
In such case, is there any choice that one is better than the other?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. One is not better than the other. It totally depends on what makes sense for specific scenarios.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Always consider context. Your example doesn't give a context. They're just nonsense names and nonsense methods so you can't really say that one way is better.  What you need to consider is whether it makes sense to organize the method calls in one way or another and what the goal is at each level of organization. Are you trying to write a composed method or are you delegating to another method? The answer to those questions would help determine how you'd structure the calls.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Correct me if I am wrong, but I think what you are trying to say is... In your current learning point of the Java language, where your application is mostly on the simpler side, and where you are mostly working on your own, perhaps a more "flat" design is better. Perhaps, or perhaps not. I think it is debatable.

Of course, this kinda doesn't make much sense when you are part of a team of dozens, working with lots of jar files, and on a complex application.

My concern here is, can this be generalize? Is there a point where this "flat" concept is more hurtful than helpful? When there are jar files involved? When there are more than 2 people on the project? 3 people? My speculation is that it is more complex than that, and this generalization probably more trouble than it is worth.

Henry
 
Sriram Sharma
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like I got the answer.
Thanks Wong and others who answered me!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!