You are not logged in.

#1 2009-04-01 19:18:57

corrupt
Member
Registered: 2007-06-25
Posts: 74

how to deal with poorly designed code

Hello, everyone.

I have a problem with some program that I wrote starting my career as a programmer.
At first I studied a lot and wrote this program in java with poor design solutions in mind.
My code looked like procedural(I studied c before) object oriented freak.
And as a result even I could hardly modify my code. I had to spend hours
remembering what each function in class did.

And some time after that my boss asked me to write one new feature which actually changes
architecture a lot. Even if it was good object oriented code, it would take some time. But now
it takes a great amount of struggle and patience to rewrite my ugly code and implement this
new feature.
So I'm asking you developers out there: How do you deal with such situations when for example
someone wrote very bad piece of code and you have to change/modify it to support new requirements?

Offline

#2 2009-04-01 19:24:16

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: how to deal with poorly designed code

If you're the one who wrote it, it's probably time for a full refactoring. Hacking through a jungle of messy code every time you need to change it is a bad idea. Refactoring isn't fun and it takes a lot of time, but you'll almost certainly end up with much more manageable code and a better insight into how the code works globally and locally.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#3 2009-04-01 19:41:42

tam1138
Member
Registered: 2007-09-10
Posts: 238

Re: how to deal with poorly designed code

Agreed.  You'll save time and pain in the long run by doing it the Right Way (tm) now.

Offline

#4 2009-04-01 19:46:15

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: how to deal with poorly designed code

Xyne wrote:

Refactoring isn't fun

I'm filing this under 'complete and utter bullshit' I read on the first of the fourth month. :-P

I love refactoring, taking something good and making it great. The eternal search for perfection just outside your grasp.

Dusty

Offline

#5 2009-04-01 19:49:01

moljac024
Member
From: Serbia
Registered: 2008-01-29
Posts: 2,676

Re: how to deal with poorly designed code

Drag them by the ears so that they can get you out of that mess.
And give them a few slaps for writing sloppy code. Then throw them inside a Blendtec blender

"Will it Blend ? - Sloppy Coder"


The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...

Offline

#6 2009-04-01 19:49:57

signor_rossi
Member
Registered: 2007-08-24
Posts: 257

Re: how to deal with poorly designed code

Dusty wrote:
Xyne wrote:

Refactoring isn't fun

I'm filing this under 'complete and utter bullshit' I read on the first of the fourth month. :-P

Depends alot on how bad the code to refactor is... wink
Code that is really bad should be rewritten... tongue

Offline

#7 2009-04-01 19:56:22

Shunpike
Member
From: France
Registered: 2009-01-28
Posts: 47

Re: how to deal with poorly designed code

signor_rossi wrote:
Dusty wrote:
Xyne wrote:

Refactoring isn't fun

I'm filing this under 'complete and utter bullshit' I read on the first of the fourth month. :-P

Depends alot on how bad the code to refactor is... wink
Code that is really bad should be rewritten... tongue

Rewriting code could introduce bugs.

Offline

#8 2009-04-01 20:26:16

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: how to deal with poorly designed code

Shunpike wrote:
signor_rossi wrote:
Dusty wrote:

I'm filing this under 'complete and utter bullshit' I read on the first of the fourth month. :-P

Depends alot on how bad the code to refactor is... wink
Code that is really bad should be rewritten... tongue

Rewriting code could introduce bugs.

Writing code could introduce bugs. Not writing code on the other hand...

Offline

#9 2009-04-01 20:33:26

corrupt
Member
Registered: 2007-06-25
Posts: 74

Re: how to deal with poorly designed code

Shunpike wrote:
signor_rossi wrote:
Dusty wrote:

I'm filing this under 'complete and utter bullshit' I read on the first of the fourth month. :-P

Depends alot on how bad the code to refactor is... wink
Code that is really bad should be rewritten... tongue

Rewriting code could introduce bugs.

There are big classes with many redundant functions.
I want to move them to new classes.
Also it's swing application that does not follow mvc pattern.

Offline

#10 2009-04-01 20:45:26

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: how to deal with poorly designed code

Dusty wrote:
Xyne wrote:

Refactoring isn't fun

I'm filing this under 'complete and utter bullshit' I read on the first of the fourth month. :-P

I love refactoring, taking something good and making it great. The eternal search for perfection just outside your grasp.

Dusty

Yarrrr, because what's more fun than pouring effort into something to end up with the exact same functionality that you started with?

Finding new and better ways to do things is fun and you definitely improve your coding skills when you go back and pick apart the hack-n-slash stuff you've written before, but overall I don't think it's fun (unless you're truly doing it only for yourself, i.e. no obligations, no deadlines, etc).


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#11 2009-04-01 22:02:28

vkumar
Member
Registered: 2008-10-06
Posts: 166

Re: how to deal with poorly designed code

@Xyne: +1


div curl F = 0

Offline

#12 2009-04-03 16:42:17

signor_rossi
Member
Registered: 2007-08-24
Posts: 257

Re: how to deal with poorly designed code

corrupt wrote:

There are big classes with many redundant functions.
I want to move them to new classes.

That should be easily possible with the appropiate functionality of an IDE.

corrupt wrote:

Also it's swing application that does not follow mvc pattern.

Oh my GOD! yikes:o Good luck!

Offline

Board footer

Powered by FluxBB