Writing Code that Updates Outdated Src Code?

I had an idea today and now I'm confused why it doesn't already exist. I'm sure it would be quite difficult but I don't think impossible? I'm told a large portion of programmers today work jobs that are fixing / updating outdated source code.

Why can't people just write a program that automatically reads program files and updates outdated code?

Maybe the program reads a website to get all of the features from c++98 and compares it to c++17 features and syntax. Then logs the changes between languages so it knows what to look for in the program. Then compares that code to the code the user wants updated. Maybe would require artificial intelligence, I'm not sure.

Adding onto that, are there programs that will update code with new features in C++ to make the code cleaner? If not, why not? For example, adding structured bindings to code when using C++14 and moving to C++17.

Please Note: I tried searching this online but didn't come up with anything (surprisingly). Hence why I am asking here.
Last edited on
I suspect the updates that need to happen are not syntactic, but functional.

When people update source code, it's generally not because they want it to do exactly the same thing. It's because they want it to do something different.
Why can't people just write a program that automatically reads program files and updates outdated code?

to put it into a few words, "abuse" is the first one. A lot of very old code used 'features' that are now, or maybe even were then, illegal. Some common examples hit this forum regularly, like variable length arrays, union hack, getch, and so on. Some of these code examples would not do the same thing as before if updated to be correct. At one time I remember it being *recommended* to return a dead variable's address! yes, that is
int * foo()
{
int x = 3;
return &x; //this was actually recommended, and the rule of the day was that the very next statement had to copy the value before it got damaged.
}.
I could probably write 2 pages on c-string hands on manipulations that would be very, very hard to convert (automatically) into c++ strings with code with 100% assurance that it would do the same thing.

another word is "performance". Some changes would have a negative impact on speed. If your program were smart enough to convert a hand rolled multi-threaded bucket sort to std::sort and it ran 3x slower, for an extreme example.

another word is "readability". Robot code is notoriously bad. Fixing a well commented, easy to understand but old school program into modern c++ bot code may be a net loss of ability to comprehend it. Even if it tried to keep the comments, they could be nonsense after, due to the rewrite.

not a word but a concept "if it isnt broke, dont fix it"... working code, even if ugly, is fine. When it breaks, or when you are trying to modify it and can't read it, etc, then you can look at fixing.

design bungling. Not sure what you have in mind but if something took my math procedural code and stuck classes around it, I would take the offending thing out back and blow it to bits with a shotgun.

at the end of the day, though, the #1 issue is going to be the inability to 100% ensure that the result of your robot is identical to the original. Its a computer theory problem actually, I forget the name but its intractable to ask a computer if 2 pieces of code always do the same thing for all inputs.

Repeater wrote:
I suspect the updates that need to happen are not syntactic, but functional.

When people update source code, it's generally not because they want it to do exactly the same thing. It's because they want it to do something different.

Ah okay. And thanks for responding. :)

---------------
jonnin wrote:
Some of these code examples would not do the same thing as before if updated to be correct.
I could probably write 2 pages on c-string hands on manipulations that would be very, very hard to convert (automatically) into c++ strings with code with 100% assurance that it would do the same thing.
another word is "performance". Some changes would have a negative impact on speed. If your program were smart enough to convert a hand rolled multi-threaded bucket sort to std::sort and it ran 3x slower, for an extreme example.
another word is "readability". Robot code is notoriously bad. Fixing a well commented, easy to understand but old school program into modern c++ bot code may be a net loss of ability to comprehend it. Even if it tried to keep the comments, they could be nonsense after, due to the rewrite.

First, thanks for responding! Second, that makes sense. That hadn't occurred to me.

Not sure what you have in mind but if something took my math procedural code and stuck classes around it, I would take the offending thing out back and blow it to bits with a shotgun.

Haha.

at the end of the day, though, the #1 issue is going to be the inability to 100% ensure that the result of your robot is identical to the original. Its a computer theory problem actually, I forget the name but its intractable to ask a computer if 2 pieces of code always do the same thing for all inputs.

Ah okay. Thanks for the full explanation.

Post solved. :)

Not sure what you have in mind but if something took my math procedural code and stuck classes around it, I would take the offending thing out back and blow it to bits with a shotgun.


Please, youtube that, k?

well we do occasionally take old computers out to the range, but things that contain metal have to be put farther back for safety. I'd have to use buckshot... still, my a5 has been rigged to hold 11 rounds... <g> ... ill see if I can find a dead computer...
That aside, some trivial "replace words" might be possible. An example: https://doc.qt.io/archives/qt-4.8/qt3to4.html
Topic archived. No new replies allowed.