Question:
is calling methods from another method considered bad coding style?
Fadi
2012-02-03 06:17:24 UTC
I'm doing a huge Java project for school and I thought of spitting up my methods into mini-methods just to make my code easier to read. I've been writing codes since I had my first computer, back in 2000, and I don't really know the difference between good coding style and bad coding style, because I always code as I go.
Four answers:
?
2012-02-03 07:53:13 UTC
Calling methods is not bad coding style at all, as long as that it that methods purpose, say for instance if i have a method

get_information();

say that there are many types of information such as phone, email, name, address

well then get_information(); has the task of getting all the info as a whole, not individually

so

get_information() {

get_name();

get_email();

get_name();

get_address();

}

is good
deonejuan
2012-02-03 06:54:03 UTC
Man, you should wade through some of the freakin C++ code I had to edit



rasterize( results( randomGamma( getRGBtoBytes( (int)r[],(int)g[],(int)b[], noAlpha()));



But no, often you see method calls inside methods. Usually the laundry-list method will return a boolean to make an easy test of the successful completion. Otherwise, you see mucho assertion, which is required of commercial code any more and lots of try{}catch( Exception) {} finally{};



My usual style is to load a Splash screen, do all my data inits, destroy the Splash and call the constructor of my application frame.
?
2012-02-03 06:30:30 UTC
good coding style:

-------------------------------------------

think of the problem as a whole , then decide what methods you must come up with.

each method should certainly focus on one thing.

So if your methods are meaningful and short , that's awesome.

calling methods from another methods is perfect too.

your code must look as one unit, connected through different methods.
JoaquĆ­n
2012-02-03 06:25:20 UTC
If you mean something like this:



void InitializeCity()

{

InitializeTerrain();



InitializeBuildings();



InitializeHouses();



return;

}



then that is just fine, it helps keeping the code clear and it is easier to maintain.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...