Jump to content
Digital

To refactor or start from scratch

Recommended Posts

Peppermint
LV 12

Wanted to get some input on what other programmers on here think about the arguments for/or against refactoring. There are always features that need to be reworked, or work just fine, but feel so wrong in code. Where as a developer do you feel that line is drawn as to whether refactor something existing, or to just say... its time to redo this completely?

Share this post


Link to post
Share on other sites

If you have unit tests already setup, refactoring will save you a lot of time. If you need to refactor more than half of your codebase though, might as well re-write it from scratch.

Share this post


Link to post
Share on other sites
Butterscotch
LV 9

I generally lend towards in place refactoring. 

The cases where a rewrite might be better. 
    - The code is really bad to the point of being broken.
    - The code is incomplete with no significant amount completed
    - The code is really, really bad, not just spaghetti but serious architecture issues that affect the ability to refactor in place as well as the correctness (i.e. works but buggy). Case in mind, new table created everytime a user joins the site and the code relies on that table being in existence.

Refactoring
    - The site is live with users
    - The codebase is siginificant
    - The codebase is more or less working    

Most sites are going to fall under the second set and so to just scrap it would be a waste of resources. It may seem like a great idea to just start everything over, but really it's a significant time investment, time that you aren't working on new features as well. And it is often the case that there is more to the code than your realized/remembered, so the refactor takes longer than you thought too.

Refactoring allows you to work towards this better code base without starting over, so you can allows have the live site without having to manage two different ones. And you don't have to finish it all to see improvement. Working on pet profile? Okay refactor that when you make your change. 

This is the route I went for Animal Acres and I think it's been working out pretty well. There are some quirks to the code now having different paradigms ongoing, but there are so many features and sometimes even ones I don't realize about until I get into the code (was a purchase initially). Had I went the other route, I would still be working on it and new features would have been hard in that time. I'd either have to not have realized them or code them in the old poor style and in the recoded version. Instead I just code it one way which can then be released right away on the new site.

It's not quite as nice as working on Eliyo, but it's really not bad either. Was able to pull in eloquent and blade, so much of it is 
 

Share this post


Link to post
Share on other sites
Peppermint
LV 12

Thanks @Anoua and @txtsd for the feedback. I really asked this question as I see this happen a lot when a site is purchased, or new programmers come into an existing project. All the sudden you have this "this is junk, lets redo it all", and then you see the sites suffer.

I personally like small refactors that improve how something works. I have had to do a lot for novilar over time, to improve or adjust a function. I have not yet had a full case where I have had to point blank redo. Cross my fingers.

Share this post


Link to post
Share on other sites

I'm not a programmer, but owned a few petsite developments. Leave it be if it works and use your time to provide the players a better experience vs same or similar experience reworked for your own back end experience.

We serve the players experience.

We often see the "this is junk, lets redo it" from people who really mean "this is outside my ability to operate, lets waste time and resource to fit it for me".

Edited by Claws
  • Like 1

Share this post


Link to post
Share on other sites
Laureen
LV 5
6 hours ago, Claws said:

I'm not a programmer, but owned a few petsite developments. Leave it be if it works and use your time to provide the players a better experience vs same or similar experience reworked for your own back end experience.

We serve the players experience.

We often see the "this is junk, lets redo it" from people who really mean "this is outside my ability to operate, lets waste time and resource to fit it for me".

I completely disagree, to be honest. I take my game which is online for over 6 years now as an example. The last 2 years I was working on a relaunch to upgrade my complete codebase. When I started 7 years ago I knew nothing about programming and learned a lot in the following years. The code is a weak construct on an even weaker foundation. It won't run on PHP 7, is completely coded procedural which makes it hard to maintain and is not responsive. Does it work? Yes! Should I leave it like that and build more features on this foundation? No! 
Most of the work won't make a difference for most of the players that is true. But I got them excited for the new version anyway.  I developed the new version completely separate from the current version and they were still able to play on what we call version 3.0. There weren't regular updates but still a few and also continued our event schedule (eastern, summer, Halloween, Christmas), so they still got stuff to do on the working 3.0 version. 
What do they get from this new version? First of all, an upgrade to PHP 7 makes the game run faster. Upgrading to OOP makes it more maintainable for me and easier to implement new features and therefore the users will get new features more frequently. Also, the new layout makes it easier for them to use the site on their smartphone. So yes most of the time I invested in the relaunch ist nothing they can "see" but it will make an overall better experience for them. Of course, the time I invested could have been invested in tons of new features instead but then again my game is already very feature-rich and not just starting out. So I feel to update the complete code basis will only bring benefits. And with screenshots of the new layout, you can get the users excited along the way. The launch is in February and we are almost done. I'm very happy that I decided to go this route and would recommend to everyone which is in a similar position.

Edited by Feuerqueen
  • I Approve 1

Share this post


Link to post
Share on other sites
2 hours ago, Feuerqueen said:

I completely disagree, to be honest. I take my game which is online for over 6 years now as an example. The last 2 years I was working on a relaunch to upgrade my complete codebase. When I started 7 years ago I knew nothing about programming and learned a lot in the following years. The code is a weak construct on an even weaker foundation. It won't run on PHP 7, is completely coded procedural which makes it hard to maintain and is not responsive. Does it work? Yes! Should I leave it like that and build more features on this foundation? No! 
Most of the work won't make a difference for most of the players that is true. But I got them excited for the new version anyway.  I developed the new version completely separate from the current version and they were still able to play on what we call version 3.0. There weren't regular updates but still a few and also continued our event schedule (eastern, summer, Halloween, Christmas), so they still got stuff to do on the working 3.0 version. 
What do they get from this new version? First of all, an upgrade to PHP 7 makes the game run faster. Upgrading to OOP makes it more maintainable for me and easier to implement new features and therefore the users will get new features more frequently. Also, the new layout makes it easier for them to use the site on their smartphone. So yes most of the time I invested in the relaunch ist nothing they can "see" but it will make an overall better experience for them. Of course, the time I invested could have been invested in tons of new features instead but then again my game is already very feature-rich and not just starting out. So I feel to update the complete code basis will only bring benefits. And with screenshots of the new layout, you can get the users excited along the way. The launch is in February and we are almost done. I'm very happy that I decided to go this route and would recommend to everyone which is in a similar position.

Then you served the players experience. Well done. That is what I agree with in some cases. Often is not always.

Edited by Claws

Share this post


Link to post
Share on other sites
Scorzdon
LV 13
On 11/30/2018 at 9:50 AM, Digital said:

Thanks @Anoua and @txtsd for the feedback. I really asked this question as I see this happen a lot when a site is purchased, or new programmers come into an existing project. All the sudden you have this "this is junk, lets redo it all", and then you see the sites suffer.

I personally like small refactors that improve how something works. I have had to do a lot for novilar over time, to improve or adjust a function. I have not yet had a full case where I have had to point blank redo. Cross my fingers.

@Digital: The way I handled my code was to add features when the code base was good. However when I ran into issues when I got to 14 controllers something had to give and so I had to refactor the code so that it was cleaner. This worked for a while but once the major bugs cropped up, I had to do a major overhaul of the entire code base meaning I had to rework everything. However by doing this I was able to add new features to my website and the code base way more stable then it used to be.

On 11/30/2018 at 8:18 AM, Anoua said:

I generally lend towards in place refactoring. 

The cases where a rewrite might be better. 
    - The code is really bad to the point of being broken.
    - The code is incomplete with no significant amount completed
    - The code is really, really bad, not just spaghetti but serious architecture issues that affect the ability to refactor in place as well as the correctness (i.e. works but buggy). Case in mind, new table created everytime a user joins the site and the code relies on that table being in existence.

Refactoring
    - The site is live with users
    - The codebase is siginificant
    - The codebase is more or less working    

Most sites are going to fall under the second set and so to just scrap it would be a waste of resources. It may seem like a great idea to just start everything over, but really it's a significant time investment, time that you aren't working on new features as well. And it is often the case that there is more to the code than your realized/remembered, so the refactor takes longer than you thought too.

Refactoring allows you to work towards this better code base without starting over, so you can allows have the live site without having to manage two different ones. And you don't have to finish it all to see improvement. Working on pet profile? Okay refactor that when you make your change. 

This is the route I went for Animal Acres and I think it's been working out pretty well. There are some quirks to the code now having different paradigms ongoing, but there are so many features and sometimes even ones I don't realize about until I get into the code (was a purchase initially). Had I went the other route, I would still be working on it and new features would have been hard in that time. I'd either have to not have realized them or code them in the old poor style and in the recoded version. Instead I just code it one way which can then be released right away on the new site.

It's not quite as nice as working on Eliyo, but it's really not bad either. Was able to pull in eloquent and blade, so much of it is 
 

@Anoua: You should only rework the entire code engine or refactor it if you can't add any new features to the site, otherwise you should touch the code all that much. If you have major bugs a recode of the entire engine from the ground up might be worth investing in. I know its something to not be taken lightly but if you have extremely bad bugs this is kind of your only option. Your on the right path though.

On 12/7/2018 at 11:21 PM, Claws said:

I'm not a programmer, but owned a few petsite developments. Leave it be if it works and use your time to provide the players a better experience vs same or similar experience reworked for your own back end experience.

We serve the players experience.

We often see the "this is junk, lets redo it" from people who really mean "this is outside my ability to operate, lets waste time and resource to fit it for me".

@Claws The big question is what is junk? It can mean many different things to different users.

On 12/8/2018 at 5:31 AM, Feuerqueen said:

I completely disagree, to be honest. I take my game which is online for over 6 years now as an example. The last 2 years I was working on a relaunch to upgrade my complete codebase. When I started 7 years ago I knew nothing about programming and learned a lot in the following years. The code is a weak construct on an even weaker foundation. It won't run on PHP 7, is completely coded procedural which makes it hard to maintain and is not responsive. Does it work? Yes! Should I leave it like that and build more features on this foundation? No! 
Most of the work won't make a difference for most of the players that is true. But I got them excited for the new version anyway.  I developed the new version completely separate from the current version and they were still able to play on what we call version 3.0. There weren't regular updates but still a few and also continued our event schedule (eastern, summer, Halloween, Christmas), so they still got stuff to do on the working 3.0 version. 
What do they get from this new version? First of all, an upgrade to PHP 7 makes the game run faster. Upgrading to OOP makes it more maintainable for me and easier to implement new features and therefore the users will get new features more frequently. Also, the new layout makes it easier for them to use the site on their smartphone. So yes most of the time I invested in the relaunch ist nothing they can "see" but it will make an overall better experience for them. Of course, the time I invested could have been invested in tons of new features instead but then again my game is already very feature-rich and not just starting out. So I feel to update the complete code basis will only bring benefits. And with screenshots of the new layout, you can get the users excited along the way. The launch is in February and we are almost done. I'm very happy that I decided to go this route and would recommend to everyone which is in a similar position.

@Feuerqueen: One of the big things when using OOP is to remember that OOP doesn't make your code more maintainable. OOP for the sake of OOP is bad code and you better off in writing procedural. Its the way that you use OOP in the way that it makes the most sense. Here is my question to you what if you can't add any new features to your website due to the way the coding structure is written, how do you wind up handling it? Do you say lets rewrite the whole thing from the ground up or do you refactor the code?

Share this post


Link to post
Share on other sites
Laureen
LV 5
7 hours ago, Boltgreywing said:

@Feuerqueen: One of the big things when using OOP is to remember that OOP doesn't make your code more maintainable. OOP for the sake of OOP is bad code and you better off in writing procedural. Its the way that you use OOP in the way that it makes the most sense. Here is my question to you what if you can't add any new features to your website due to the way the coding structure is written, how do you wind up handling it? Do you say lets rewrite the whole thing from the ground up or do you refactor the code?

2

Well in my case it makes it definitely more maintainable. And what do you mean of "can't add any new features"? I was always able to add new features because my code worked. I did this 6 years long. I was always adding new features, even bigger ones and doing new events and stuff. But now it is so much easier for me to add new features. And also the PHP 7 compatibility was a huge factor for me. I had to touch every script anyway to make it work on PHP 7, so why not do a complete recode then? For me, it worked out. 
Before I did the complete recode I sometimes refactored some scripts when I couldn't find the bug. That helped a lot along the way too.

Share this post


Link to post
Share on other sites
Scorzdon
LV 13
On 12/10/2018 at 5:20 AM, Feuerqueen said:

Well in my case it makes it definitely more maintainable. And what do you mean of "can't add any new features"? I was always able to add new features because my code worked. I did this 6 years long. I was always adding new features, even bigger ones and doing new events and stuff. But now it is so much easier for me to add new features. And also the PHP 7 compatibility was a huge factor for me. I had to touch every script anyway to make it work on PHP 7, so why not do a complete recode then? For me, it worked out. 
Before I did the complete recode I sometimes refactored some scripts when I couldn't find the bug. That helped a lot along the way too.

@Feuerqueen: Basically what I mean is that say for example in order to add this new feature I need to jump through the hoops of a then I need add said code to b then to c, then all the other features available and so on. Other times the code can be written extremely badly and not be able to see how to get it to work.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...

Important Information

By using this site, you agree to our Guidelines, Terms of Use, and Privacy Policy.