Lessee if I can get my point across without a spoiler... I'm trying to decide where to split up a process into methods. I have a Long. I want to split it into three-digit chunks, then further process the chunks. Does it make more sense to split up the Long in main(), then pass the chunks to a processor method, or to pass the Long to some method, split it up, process it in that method or pass the chunks to some tertiary method? I can argue it to myself each way, please somebody weigh in. tanks
I would separate processes into methods. Personally, I put processing in main only when it's some simple output or very basic logic needed (ie testing to make sure an input is within the scope of the program). Otherwise, I group related processes in a method and return values or call other methods as needed. Figure out what processes you are going to need, divide those into logical groupings, and design your methods around those. Just to give you an idea, I had a total of 4 methods in my 4b code. Hope this helps, Jason [This message has been edited by jason adam (edited August 08, 2001).]
I sent the long to a method to be processed. Like Jason, I also ended up with 4 methods besides main to do all of the processing. Take Jason's advice on this he seems to be a wiz when it comes to the Assignments Best of Luck to you Dean [This message has been edited by Amber Woods (edited August 08, 2001).]
"Happiness is a way to Travel, <b>Not</b> a Destination" -- Unknown
Joined: Apr 20, 2001
What made y'all decide on passing a Long? I was starting to gravitate toward handling the thing as a String, because it doesn't stay Long very long.
i ended up with 5 methods. i converted the string to a long in the first method and dealt with the math from then on using other containers for each segment... my long did not stay long after the first method.
Chicken Farmer ()
Joined: May 08, 2001
I dealt with a number instead of a String through most of the program just because that is the way I think. If we're talking about numbers, it was easier for me to write code that dealt with the number pattern versus how to break apart the String, but it can be done relatively similar either way. I guess it all depends on how you view things. I actually had 3 extra methods, and then main(). main() just checked the range of the input, and then sent the number on for processing. I'd probably be giving away too much if I even hinted at what the others did Jason
HI, I do a little processing in the main() which I supppose could be an excuse for a separate method - though personally I think its OK. The rest then is done by just one method... Course I haven't been nitpicked yet... I'm sure I'll be posting back with a different structure once I get on to sending it in.
Hi Dean, For what it's worth, here's my own 2 cents. The rough guide I've been using is that if I'm repeating code more than I need to, I use a separate method; otherwise, I use main(). Since I'd break the argument into three-digit chunks only once, and doing it is not essential to some other procedure demanding a separate method, I'd favor doing it in main(). As for String vs. long: I don't see any special advantage to using String, because it seems to me that, in the case of Say, to break a String up into three-digit chunks is more trouble than it's worth. Say has to be able to either add chars to the front of the String to make it divisible by 3 w/o remainder, or take a less-than-three-digit chunk. Also, the chunks have to be converted to ints separately. None of this is necessary if long is used instead of String. --Adam