• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

calling method inside method inside method inside method and so on

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the problem? (beside the poor choices for names)
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. One is not better than the other. It totally depends on what makes sense for specific scenarios.
 
Sheriff
Posts: 17734
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like I got the answer.
Thanks Wong and others who answered me!
reply
    Bookmark Topic Watch Topic
  • New Topic