I just finished the 1st Chapter in Head First, but came to a different sollution to the PoolPuzzle. Mine is more complicated. Will this pose a problem as I, hopefully, delve deeping into Java? Examples: Mine:
[code]
int x = 0; while (x<4) { System.out.print("a"); if (x<1) {System.out.print(" ");} x = x - 1;System.out.print("n"); if (x<0) {System.out.print("oise"); x = x + 1;} if (x==1) {System.out.print("noys");} if (x>1) {System.out.print(" oyster");} System.out.println(""); x=x+2; [//end code]
Head First: [code]
int x = 0; while (x<4) { System.out.print("a"); if (x<1) {System.out.print(" ");} System.out.print("n"); if (x>1) {System.out.print(" oyster"); x = x + 2;} if (x==1) {System.out.print("noys");} if (x<1) {System.out.print("oise");} System.out.println(""); x=x+1; [//end code]
Thanks, Charlie [ April 29, 2008: Message edited by: Charlie Newman ]
In general, if you can do things in a more simple way then that's better.
One of the difficult problems in software development is maintenance of the software. When you've done a project and built some software, then there will be programmers after you who will have to maintain the software - make some changes, fix bugs, add new features etc.
The more complex your software is, the harder it will be for other programmers (or even for yourself if you're looking at your code later) to understand and maintain.
However, don't worry. When you gain more experience with programming, you'll learn how to do things in a more simple and efficient way.
Thank You Jesper, My wife is an Oracle/data base gal and hasn't been able to answer all of my questions. I appreciate the short, direct, and timely, I might add, answer. I've learned a lot from coming to this site. Thanks, Charlie
Sometimes, discovering the simpler way can be a whole process of simplifying one small step at a time.
Most of the first programs (assignments) I wrote were long, convoluted, and when I tried to read them 2 weeks later I had trouble figuring out what I had been trying to do.
I remember once I spent - literally - three days trying to debug my program. I needed to manipulate 60 values stored an array, and I just couldn't get the darn things out of it. When I finally managed to pick my way back to the right portion of the code, and add a debug statement, I was seeing printed, over and over (60 times altogether)
Oh, yeah. I was referring to the length of the array rather than what was in it.
After that I started getting a little more interested in maintainable code and refactoring. Actually, I think the day after that 60, 60, 60 thing I went to the bookstore and found Head First Java.
So complicated isn't a bad place to be! It means that you thought about it, came up with a solution, and that solution even worked.
In my humble opinion, thinking about it - struggling a bit - that is very valuable.
And if you can later rework your code to be simpler, then all the better!