Jump to content

  • Log In with Google      Sign In   
  • Create Account


Obsessive Compulsive/Refactoring Disorder


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
27 replies to this topic

#1 mind_wipe   Members   -  Reputation: 100

Posted 05 March 2011 - 06:16 PM

I know I have this. Why me!? I hate it... Sometimes I feel like I can't get anything done. Like it takes hours to do the simplest task I've done before. I'm always changing code to make it look pretty or other things. It's too much! Please someone tell me I'm not the only one going through this here? I've read that I have to face the fear and not allow my self, or ignore the OCD. I don't know man...

So I've been working on this game for a while and I keep getting stuck on basic architecture. I keep re-writing or changing the image & sound loaders. Constantly loading up thesaurus.com looking for a different word that would align with other variable names... see what I mean? It's bad. I know its most important to deliver a working product, NOT what the source code OF the working product looks like. I've seen lots of professional products and it seams that these guys don't suffer like I do.

There is a catch though. If I re-factor to much then, the OCD part of me, gets all pushed out of shape because to code looks to clean or to procedural if you know what I mean. So it seams that OCD has double standards... or maybe double edged. Either way its holding me back and I'm not able to complete what I want to do. Anyone else feel my pain? I just don't know what to do with my self...

Sponsor:

#2 Sirisian   Crossbones+   -  Reputation: 1626

Posted 05 March 2011 - 06:28 PM

I'd like to believe it's a stage, but I do the same thing. I've never seen it as a problem though. I value clean organized code and it bothers me when code I work on is not formatted correctly. I've gone through tens of thousands of lines of code and formatted them all to a strict style in the past when I had time. It's important to realize that everyone else is wrong and that you are right when it comes to these changes. B)

Naming problems are common problems. It gets easier to name methods and classes with experience.

Also refactoring code to make it better is a good practice. As said a thousand times evolution, not revolution.

As a tip I recommend coding with whitespace hidden characters on. It helps to relieve the anxiety of not knowing. :unsure:

#3 mind_wipe   Members   -  Reputation: 100

Posted 05 March 2011 - 06:46 PM

?

that actually kinda cheered my up a little bit maybe...

#4 alnite   Crossbones+   -  Reputation: 2038

Posted 05 March 2011 - 11:11 PM

I know I have this. Why me!? I hate it... Sometimes I feel like I can't get anything done. Like it takes hours to do the simplest task I've done before. I'm always changing code to make it look pretty or other things. It's too much! Please someone tell me I'm not the only one going through this here? I've read that I have to face the fear and not allow my self, or ignore the OCD. I don't know man...

I think it's just you. Posted Image


So I've been working on this game for a while and I keep getting stuck on basic architecture. I keep re-writing or changing the image & sound loaders. Constantly loading up thesaurus.com looking for a different word that would align with other variable names... see what I mean? It's bad. I know its most important to deliver a working product, NOT what the source code OF the working product looks like. I've seen lots of professional products and it seams that these guys don't suffer like I do.

Well, if you rewrite modules and make them faster or better, there's nothing wrong with it...If you are just changing variable names, then you've got issues.


There is a catch though. If I re-factor to much then, the OCD part of me, gets all pushed out of shape because to code looks to clean or to procedural if you know what I mean. So it seams that OCD has double standards... or maybe double edged. Either way its holding me back and I'm not able to complete what I want to do. Anyone else feel my pain? I just don't know what to do with my self...

Yes and no, but does your IDE has a code formatting tools? Don't use freaking notepad or vim or gedit just because they are fast. So many times I have looked at source code that others have written, and so many times I have seen them improperly formatted. This shit would bug me as hell:

if (someFlag)
      doSomething();

if( someOtherFlag ) {
  do_something_else();
}

Select All -> Reformat Code. Then refactor do_something_else() to doSomethingElse(). Done.

#5 MaulingMonkey   Members   -  Reputation: 1556

Posted 06 March 2011 - 09:57 AM

I've had this for ages. Something I've started experimenting with recently is schedules. Turns out the same thing that the games industry is so often decried for: unreasonable deadlines and milestones -- are a good way to cajole oneself into coding up a storm with little regard for good architecture. Of course, this way potentially lies unmaintainable spaghetti. A solution for that is obvious: Schedule time specifically for refactoring too. Not so much that you spend all your time in refactoring hell, not so little that you spend more time trying to understand your code than add to it.

I've been doing 3 hour "jaunts" for personal projects off and on, with 30 minute scheduling intervals. Of course, I could spend forever comming up with an ideal schedule: So I schedule myself 10 minutes to come up with a schedule. I coded up a small program to help me keep track of exactly how far behind I'm getting, even.

It seems to work best when I have a clear idea of what I want done. This includes refactoring too: for me, I can't just add a 30 minutes task, "Herp derp refactoring", and hope to get something good done. On the other hand, when I've got a pile of spaghetti in mind, and I know I want to split it up into 4 classes along obvious lines -- sure, I'll throw 30 minutes for "refactoring" onto the list. If I overbudgeted for that specific change, great -- start the next task early. If I underbudgeted, that's another class or two worth of behavior I can refactor out of my mess tomorrow.

Consider trying it :)

#6 irreversible   Crossbones+   -  Reputation: 1182

Posted 06 March 2011 - 10:04 AM

Frigging whitespaces at the ends of lines. Running a macro on them every 5 seconds is slow and looking at them when a block of text is selected burns the eyes even more. Horrible. Just horrbile.

#7 Jeff Grigg   Members   -  Reputation: 100

Posted 06 March 2011 - 10:28 AM

What I've found most useful is 50/50 as a guide: Do not spend more time refactoring than developing new functionality.

Sure, one could spend hours, or days, or weeks improving the functionality, here and there, just a little... But you do need to get something done and deliver it.

If it's taking significantly longer to refactor than to write real functionality, then something is really wrong. Even if it's really bad code that someone else wrote, then it's time to recognize that some of the correction and repair of their bad work will have to be put off until later. If it's one's own work, then maybe a little more discipline while doing the work is in order. ;->

#8 Jeff Grigg   Members   -  Reputation: 100

Posted 06 March 2011 - 10:38 AM

And here I thought I was just about the only person who still cared about spaces at the ends of lines! ;->

I knock them off when I happen to be working on those lines for other reasons. And any good editor that can handle regular expressions can kill them easily enough. And formatting tools can do it for you too.

Still, it puzzles me as to how and why people keep adding spaces to the ends of lines -- seemingly by habit, at times. Some behavior is just odd.

What I've found most helpful is to get the team to agree to an automatic formatter, and then apply it consistently -- preferably automatically at check-in. Yes, I dislike automated formatters too. But I've found the inability of some programmers to keep with anything like a consistent style, even all the way through a single line of code, to be quite annoying. Code is read much more than written. It has to be readable.

#9 Tachikoma   Members   -  Reputation: 548

Posted 06 March 2011 - 10:49 AM

There are a lot of things that annoy me: Unimaginative or slightly inconsistent variable/function names, or perhaps the organisation of code blocks are somewhat weird compared to the rest of the project. In my world, these problems tend to appear when I work on something for a long time, or perhaps I revisit a project that was shelved a while back. I noticed my coding style can change over time, which is probably the primary reason why I have these issues. But these a minor issues. I have to discipline myself not to polish too much, and rather focus on getting things done. Therefore, I tend to refactor things when adding a new feature to a section of code. More importantly, I limit refactoring to that part of the code only. I mean, new features need a fair bit of work anyway, so might as well improve the stuff around it at the same time.... with care.

Still, it puzzles me as to how and why people keep adding spaces to the ends of lines -- seemingly by habit, at times. Some behavior is just odd.

Virtual spaces. It usually happens to me when I comment code, then for whatever reason I remove them later, but forget to cull the whitespace before the comment. Another reason, leftovers from indentation.

I'm actually surprised most code editors don't have a feature that strips whitespaces for you (at least in VS i cant find it). I remember Borland Pascal and C had it a while back.
Latest project: Sideways Racing on the iPad

#10 rip-off   Moderators   -  Reputation: 7632

Posted 06 March 2011 - 10:55 AM

At work I apply a simple rule: I do not allow myself to cleanup or refactor code unless I have something that needs to be done in the file. So if I'm not fixing a bug or adding a feature, then I leave well enough alone. I don't quite have the disciple to force myself to do this with my own code, but I'm trying.
MaulingMonkey's points are good. If you don't have a schedule, or a bug tracker to prioritise work, then you end up wasting time doing this kind of thing. Refactoring feels like work, but rarely gets the project closer to release. Refactoring is supposed to be a time saver, making the code easier to read, debug, maintain and extend. If you aren't saving time doing it (in the long run), then something is wrong.

#11 WreckSector   Members   -  Reputation: 103

Posted 06 March 2011 - 02:55 PM

For a time, when working on a project, I would feel slightly displeased with how some code look, that I would start completely from scratch. This compulsion was so disruptive on my projects... it's tough, but I'm trying very hard to keep what I have, and make minimal, surgical changes, as needed, without throwing the baby out with the bath water.

Regarding code refactoring, it is important to have clean, organized code, but it's also important to get your deliverables out there! Users care about the final product, not the code =)

#12 teutonicus   Members   -  Reputation: 518

Posted 06 March 2011 - 03:14 PM

As a tip I recommend coding with whitespace hidden characters on. It helps to relieve the anxiety of not knowing. :unsure:


I feel your pain brother!

#13 irreversible   Crossbones+   -  Reputation: 1182

Posted 06 March 2011 - 03:18 PM

Whitespaces at line ends are usually byproducts of automatic formatting or, more commonly, copy-pasting into an already formatted line. Repeated copy-pasting compounds the effect and eventually (eg after you've reformatted your loop like 10 times) you'll end up with more spaces trailing after the closing brace than there are actual characters in the statement. Nasty (well, not really - just annoying) stuff that I think The IDE should take care of automatically.

#14 way2lazy2care   Members   -  Reputation: 782

Posted 06 March 2011 - 03:21 PM

I've seen lots of professional products and it seams that these guys don't suffer like I do.

That's just because they can lose their jobs if they miss their deadlines. If they had money and time they'd probably be at least nearly as bad.

#15 irreversible   Crossbones+   -  Reputation: 1182

Posted 06 March 2011 - 03:45 PM

Mindwipe - I know I probably shouldn't write this. And I know this will look all too ironic as soon as I click Submit and it loads up in my shiny Firefox web browser, which I've grown to hate so fondly; and I know - I know - you would never consider anything like this - not seriously at least -, because you're a socially responsible male human.

Nevertheless, having re-read your post and analyzed its apparent cry for reason in a universe that is bordering so close to madness, I have to ask - if only to suggest an alternative solution: have you tried using alcohol to keep your OCD in check and to write more creative code? I know it's not much, but for inspiration, look at Charlie Sheen. Just look at him. Not a worry in the world. Zero refactoring problems. I mean, you can't just come up with that stuff. You need a muse. Let the good old A-hol be your muse.

#16 mind_wipe   Members   -  Reputation: 100

Posted 06 March 2011 - 05:51 PM

Yeah I think I screwed up when I wrote the topic. By refactoring I met changing code to make it look more pleasing to the eye; not just functionality. I don't know why, but for some reason ugly code reminds me of ex-lax. It irritates the *** out of me. Then OCD kicks to change, reword or event rewrite things to make them look neater then a skeeter's peter....lol This is what I'm talking about(the code, not skeeter). I get too obsessive/compulsive about cleanliness and order. Not just in architecture as I said before, but in code formatting, spacing, caps on *certian* comments, where the code hands over 80(column) characters or not, adding spaces at the ends of lines(hehe j/k). Stuff like inserting tabs so that all the variables align to the 29th column, But then that doesn't do because 29 is an odd number so I add a space to make it 30....gawd that sounds so bad when I write it out... but that is what I do sometimes.

I have gotten better because I forced my self to slap some things together and ignore what it looked like, only looking at it functionality wise. Its seams when I just slap stuff together for tests and/or other stuff I get the most successful code. Successful as it only took like 10-15 minutes and its working. So any ways... sorry for the bad news guys

#17 dpadam450   Members   -  Reputation: 830

Posted 06 March 2011 - 06:30 PM

Its called designing on paper. You can spend a day designing and a week of coding, or no design and a month of coding blindly on the fly.

#18 Kaptein   Prime Members   -  Reputation: 1843

Posted 08 March 2011 - 10:17 AM

Ive been programming 6 hours every single day since I was 12 and got my first 286 laptop with monochrome monitor :)
I probably spend 5.5 of those hours optimizing code.
I never read tutorials, manuals, references, but I find myself asking a few awesome programmers I know on IRC alot about stuff now and then.
Its probably the worst way to code there is, and my projects average on 3-5 years from start to finish. But I like it! I must code!!

Happy coding!

#19 staticVoid2   Members   -  Reputation: 218

Posted 08 March 2011 - 07:00 PM

I think if you ever want to get anything done just stick with a certain convention and follow it through no matter what.

Sticking with a convention (or even an initial concept) for the entirety of a project makes you a better programmer than any new architectural design ever could, as it generally means you get the project finished.

I was recently working on a project with a guy that was a bit too much of a perfectionist when it came to coding and it made me realize just how stupid it is to be perfect when it comes to code. The language you write in is not perfect, The programming language you write in is not perfect, the whole idea of programming as a means of developing a program is not perfect so why should your code be?

#20 Tachikoma   Members   -  Reputation: 548

Posted 08 March 2011 - 08:10 PM

The language you write in is not perfect, The programming language you write in is not perfect, the whole idea of programming as a means of developing a program is not perfect so why should your code be?

That doesn't mean you have to aim low. ;)
Latest project: Sideways Racing on the iPad




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS