This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
This is a stupid question but when writing a program with many methods is there a special placement of the methods. I have a program with about 10 methods and don't know what order to put them in is there a rule.
Dear Donna, I guess that WAS really a stupid question as far as I am concerned. There is no rule or convention for specifying their order. Though I guess its always good to place the main() function either at the beginning of the file or at the end.
Originally posted by Shyam Murarka: Dear Donna, I guess that WAS really a stupid question as far as I am concerned.
I don't want to hear you, or anyone else, say anything like this again hear at the Ranch, understand? There are no stupid questions.
There are a number of conventions that people use. I've see public, followed by protected, followed by private; I've seen the opposite, with private first. The convention I tend to use is for each public method to be followed by any private helper methods that it uses.
Originally posted by Ernest Friedman-Hill: ... There are a number of conventions that people use. I've see public, followed by protected, followed by private...
Note the reasoning behind this: It allows someone else to look at your code and see all of the public methods -- i.e., those available for outside use (sometimes called the "public interface") -- grouped together up front, so they don't need to look through a lot of supporting code to find something.
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Originally posted by Donna Bachner: Hi Guys, Thanks for letting me know I can put them whatever way I choose. It makes life easier for me.
Yes, you can do it however you choose. Like others have said, there are lots of ways to do it. Just make sure it is in some logical order of your choosing. If each class you write is organized randomly, it will make life harder.
"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra