This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Agile and Other Processes and the fly likes The demands of perfectionism.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Agile and Other Processes
Bookmark "The demands of perfectionism...." Watch "The demands of perfectionism...." New topic
Author

The demands of perfectionism....

Linda Thomas
Ranch Hand

Joined: Jun 21, 2004
Posts: 36
Not quite sure where to put this post but this is where the last general one was moved to so I'm taking it on faith this is where to ask.

I find when I have to go back to code I've created that I find a ton of stuff I want to change. I have a program that is running, runs well and I am quite proud of it. Webmaster hasn't uploaded it to production so it can go through testing by the staff who will eventually use it. They just want time to play with it to get used to it and see all it has to offer.

One of the other students programs went on production and crashed the server 2x. Now we are all asked to go back to our code to make sure we are closing all our connections properly. The only thing I can find in my code that isn't being closed are my statements (Statement statement = con.createStatement( ); where con gets the connection from a class our supervisor created). So I'm going back over my code closing all these statements. Everything else is closing properly on database connection end.

But I am finding more and more code that I think I did sloppy. My supervisor was away (and couldn't make stored procedures for me) and I made a lot of pages to just grab values from the database to display one name/value/field. I look back now and wonder what kinda weed I was smoking. I did just finish an Oracle course and see now how I could have used joins to grab the information from that table while I was filling my resultset with other information. I just see pages that I could eliminate and code that could be so much cleaner and its really bothering me.

So my question, lol....
*************************************
If my program works, should I worry about the code not being as efficient and as elegant as it could be?
*************************************

I could eliminate files and unnecessary access to the database if I tweaked things but my supervisor wants me to move on and do other stuff. It just bothers me soooo much!

Any advice from other programmers? I know I can't do work the boss says don't do but any advice on how I can just accept this and get over it? Or should I work on the code in free time between projects?
[ January 21, 2005: Message edited by: Linda Thomas ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
It's a tough call.

Spending time on code without providing business value (adding functionality/fixing bugs) is a bad thing.

Having code that isn't as well designed as it could be is a bad thing, too.

What I *typically* try to do is improving the code *while* adding business value. That is, take this as a lesson learned and next time you write something similar, refactor your code more early. Also think about wether you should reflect on your code more often (not only when someone else tells you to... ). And definitely when you next need to work on that bad existing code, try to improve it on the way. Doing all the changes in one big swoop might be too much even then, but with some practice it's often not too hard to find a way to change it in small little steps.

Read "Refactoring" by Martin Fowler! A great book on the topic!


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Udayan Patel
Ranch Hand

Joined: Oct 14, 2004
Posts: 94
Originally posted by Linda Thomas:
(and couldn't make stored procedures for me)

don't use stored procedures unless it is absolutely necessary. It's not good architecturally. You may end up putting business logic all the way in database.

So my question, lol....
*************************************
If my program works, should I worry about the code not being as efficient and as elegant as it could be?
*************************************


In order to follow good programming practices, yes you should worry about your working code. thats what people talk about when they say refactoring. But then it depends on manager and organization that tehy want to run crappy code that breaks often or they want to run a good stable code that is maintainable, scalable and extendable.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Udayan Patel:
In order to follow good programming practices, yes you should worry about your working code. thats what people talk about when they say refactoring.


Well, what those people (hell, at least me ) mean when they say that, typically is that you should worry about it *while* you are implementing the system. Refactoring is something that is better done every couple of seconds, not at the end of the project.

But then it depends on manager and organization that tehy want to run crappy code that breaks often or they want to run a good stable code that is maintainable, scalable and extendable.


Yes, that really is mainly a business decision that needs to be made by business people. Perhaps the code really is stable enough now, and investing into changing it *now* would just be a waste.

That changes, of course, once you need to touch that code again, and refactoring helps you to understand it again, and to make it easier to incorporate changes.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I have a tendancy to fiddle with code endlessly. I consider it a weakness and don't recommend it. It also happens fairly often that I read some code from several years ago and think, "Wow, I'd never come up with such a simple solution today," so I leave that stuff alone!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Udayan Patel
Ranch Hand

Joined: Oct 14, 2004
Posts: 94
Originally posted by Ilja Preuss:


Refactoring is something that is better done every couple of seconds, not at the end of the project.


point well taken. But I also believe that, code changed with fresh set of eyes will be more effective refactoring than done frequently. It is always nice to revisit your code at the end of the day and see if there is any place where you can extract a method or convert your magic strings or numbers to constants.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Udayan Patel:
I also believe that, code changed with fresh set of eyes will be more effective refactoring than done frequently. It is always nice to revisit your code at the end of the day and see if there is any place where you can extract a method or convert your magic strings or numbers to constants.


I agree to the amount that it's beneficial to have a kind of "mode switch", a time where you deliberately stop developing and explicitely look out for opportunities to refactor.

In my experience, though, it's better to have that more often than once a day - perhaps every time you finished a small task, just before you commit your changes to the shared repository, for example.

Personally, I prefer the practice of Test-Driven Development, where you switch every couple of minutes between writing a test, writing code to make it pass, and refactoring the code you just wrote. That doesn't mean that I don't take a closer look at the code at the other mentioned occasions, though.
 
 
subject: The demands of perfectionism....
 
Similar Threads
Javabeans and socket error?
Eclipse as an IPE?
Need help, out of my league
RSA encryption
Newbie help - forms and javabeans