What step would you take to reorganize the ball from the mud of a CF application into something modern and supported

I am going to pick up a task that no one has ever tried to try at my workplace. This is a CF application, first written using CF 2.0 (yes, 2.0!) 10 years ago with s> 10 cfscheduler tasks. We explored the idea of ​​rewriting an application, but 10 years of work simply cannot be rewritten in 2-3 months.

What steps should be taken to upgrade an application in a supported, extensible state? The one I keep hearing is “write tests,” but how can I write tests when it wasn’t even in MVC?

Any advice would be appreciated, thanks!

ps I have to thank Allaire, Macromedia and Adobe for keeping CF backward compatible up to 2.0!

btw, what is the most up-to-date, maintained state for a CF application without an MVC framework? or should my ultimate goal ultimately reorganize it into an MVC application? I can’t imagine how many links I’ll break if I make ... it seems impossible ... thought?

update: found 2 related Q ...

+6
source share
8 answers

I'm not sure if you need to move the whole site to an MVC application. I recently helped with a site that was not MVC, which still had a library with models, services, and assemblers in a clean and organized homestead. It worked perfectly, and we did not need to do anything other than what was needed.

Saying, my first step would be to arrange the spaghetti code for their different purposes. It's hard to create models correctly, but at least you could snatch services like functions from pages. With this done, it should be much cleaner already.

Then I will try to take the duplicate code and put it in user tags. This will make the code more reusable and easier to read.

Good luck

+4
source

Consider whether a complete structure is really needed. In its basic form, a structure is just a highly organized code. Therefore, if a procedure that is well organized leaves it.

Keep in mind something like FW / 1, as the migration path might be better than saying Coldbox if you don't need all the other things.

Finally, consider that I was able to transfer 4.5 almost 70% of the way to Coldbox (very simple and really more about organizing directories and files compared to IOC, plugins, modules, etc.), just using a few extra lines in the file plus functions onMissingMethod.

Good luck.

+3
source

I had to deal with a similar situation for about two years at my last job, however, it was not as old as yours. I think I was dealing with code from 4.0 to. There is no silver bullet here, and you need to be careful that you are not too keen on re-factoring the code and cost your company tons of money in the process. If the application works as it is being rewritten, it will be a fairly large amount of money.

What I did was update small pieces at a time, I would not even reorganize whole patterns at a time, only small portions one at a time. If I saw some ugly loop or nested statements, I would try to clear it as much as I could. If the application can be broken down into smaller modules or areas of functionality, and you have extra time, you can try to clear the code of the module at a time.

The good practice that I heard from the Hearding Code podcast is to create a test harness template that will use a specific cfm page that has a known output that you can re-run to make sure it still has the same result you did refactoring. It's not as important as unit test, but something and something is almost always better than nothing, right?

+3
source

I suspect that the reason this application has not been affected for years is because for the most part it works. Therefore, probably, the old saying is applied "if it is not violated, do not correct it"; However, the code can always be improved :)

The first thing I would like to do is go to Application.cfc and add a good error log. This way you can learn about things that need to be fixed, and also if you make changes, you know if they break something else.

The next thing I would like to do is, before you change any code, use selenium to create some tests - you can use it as a FireFox plugin and write down what you are doing. This is really useful for testing legacy applications with little effort on your part.

Most likely, you will not have much protection against SQL injections, so you will want to add cfqueryparam to everything !!

After that, I will look for duplicate code - eliminating duplicate code will simplify maintenance.

Good luck

+3
source

Oddly enough, I'm currently involved in converting an old CF application to an MVC3 application. Now this is not CF2, it was updated recently, just like a year ago, so all this may not apply to your script at all, sorry if that is the case.

The main thing was that I needed to combine mixed CFQuerys and their calls into logical units of code, which I could then start porting in terms of functionality to either C # or JavaScript.

Fortunately, it was a very simple application, most of the logic was called in the database using the Ajax DWR library; what was not was basically combined in the functions.cfm file.

Obviously, a lot of this behavior does not need to be replicated, since the packaging of the individual logic components (such as they were) in the CF application was really quite accurately compared with the various partial representations and editor templates that I provided for the MVC application.

After that, it was just a case, over the pages, of figuring out what logic was called up, when, what he relied on, then, finally, creating a series of diagrams of UML classes and sequences.

Honestly, I think I got the most out of it when I just clicked on File-New Project and started trying to replicate the behavior of the application from the top of index.cfm.

+2
source

I would break the logical parts of the application into CFC

Choose one view, look at the logic inside. Move it to CFC and call it.

Continue to do things that will make it much easier for you to work, and this can be connected to MVC later. There is almost no work for this, just copy and paste the sections of code and call them.

+2
source

You can use the factory object to align your application. We have a similar situation at work, and we started the reorganization by setting the scope for Lightwire DI.

First we moved the entire sql statement to the gateways, then we started using services and extracted a lot of code from the templates for services.

The work is not finished yet, but the application looks better.

+1
source

For large, really complex applications, I would prefer ColdBox for a project with a repeat factor. However, I just saw a presentation at the D2W conference on F / W 1 (Framework One) , a VERY simple ColdFusion MVC framework. Check out the code from the presentation here .

This is 1 (one) CFC file and a set of conventions for organizing your code. I highly recommend evaluating it for your project.

0
source

Source: https://habr.com/ru/post/893093/


All Articles