Programmers - ridic...
 

MegaSack DRAW - 6pm Christmas Eve - LIVE on our YouTube Channel

Programmers - ridicule me...

34 Posts
22 Users
0 Reactions
128 Views
Posts: 1856
Full Member
Topic starter
 

Is it possible to use AI to "convert" from one programming language to another whilst still retaining the same logic (e.g. re-write everything from COBOL to Java by copy/paste into ChatGPT and telling it to get on with it!)?


 
Posted : 25/10/2023 7:30 pm
 Aidy
Posts: 2965
Free Member
 

I've not tried it for very complicated things, but I've had some good results with short examples.


 
Posted : 25/10/2023 7:35 pm
Posts: 4522
Free Member
 

It would probably have a decent go

 I've found it to be very good for simple stuff, although it doesn't always get it right first time. But it's quite good at debugging its own work!


 
Posted : 25/10/2023 7:40 pm
Posts: 12872
Free Member
 

Yes, results will depend on complexity. Try it!


 
Posted : 25/10/2023 7:43 pm
Posts: 1856
Full Member
Topic starter
 

Try it!

Thankfully, I'm not a programmer and have minions for that sort of task 😉


 
Posted : 25/10/2023 8:12 pm
Posts: 1226
Full Member
 

Thankfully, I’m not a programmer and have minions for that sort of task 😉

Ah, so the question is more about how many minions you can afford to fire once ChatGPT is up to speed?


 
Posted : 25/10/2023 8:14 pm
 feed
Posts: 916
Full Member
 

Obviously you've no chance of success if you can't even ask ChatGBT the question 🙂


 
Posted : 25/10/2023 8:15 pm
Posts: 1856
Full Member
Topic starter
 

Another dumb question: is it possible to reverse engineer code?

The company I'm working at has no design documentation and huge chunks of the programming/development/QA was done 15-20 years ago, and the CTO at the time believed in "the code documents the functionality" so everytime I need to review anything, I've got to get a dev to crawl thru the code and tell me what it's doing (then I have to guess WHY it's doing it...)


 
Posted : 25/10/2023 8:16 pm
Posts: 1856
Full Member
Topic starter
 

Ah, so the question is more about how many minions you can afford to fire once ChatGPT is up to speed?

Fortunately, or unfortunately, depending on your view point, this code is so old and developers are so rare, that we can't let them retire! (Yes, these devs are OLD!) and none of the new/younger devs are interested is learning the older technology...


 
Posted : 25/10/2023 8:20 pm
Posts: 13594
Free Member
 

Another dumb question: is it possible to reverse engineer code?

Yes and no...

If you want an explanation of simple code where you don't know the syntax etc it's pretty good.
Eg see: https://www.zdnet.com/article/how-chatgpt-can-rewrite-and-improve-your-existing-code/

However, for a complex system, would it spot all the interactions between different modules / classes or race conditions, I very much doubt it.

The latter are the sort of things which cause headaches. Getting the right regular expression in one function isn't the hard part.....


 
Posted : 25/10/2023 8:28 pm
Posts: 7985
Free Member
 

Although there’s an element of luck to it you may have more success asking it to convert to written English logic statements first (so you can verify). Depending on what the code does you can then ask it to convert that to your new language, or just do it in one step if there are a lot of linked libraries or dependencies that don’t translate well into written English.

Paying for GPT-4 is also beneficial. 


 
Posted : 25/10/2023 11:23 pm
Posts: 1856
Full Member
Topic starter
 

Although there’s an element of luck to it you may have more success asking it to convert to written English logic statements first (so you can verify).

Good idea 👍


 
Posted : 25/10/2023 11:33 pm
Posts: 3293
Full Member
 

Here is a thought for you. Let's say that it could do it, or at least appear to, how could you be certain the result is correct? Solving that kind of stuff is the trick, not translating syntax.


 
Posted : 26/10/2023 12:03 am
Posts: 1226
Full Member
 

Another dumb question: is it possible to reverse engineer code?

The company I’m working at has no design documentation and huge chunks of the programming/development/QA was done 15-20 years ago, and the CTO at the time believed in “the code documents the functionality” so everytime I need to review anything, I’ve got to get a dev to crawl thru the code and tell me what it’s doing (then I have to guess WHY it’s doing it…)

To be fair, I've worked on projects where the CTO /doesn't/ hold that belief and it's still tricky to bottom out the WHY sometimes. That can even be the case when the person deciding the WHY was me two years ago, and I've got testcases and repo commit comments describing what's going on 😀

Although it'd be interesting to find out how far AI could get with this sort of task, my experiments with ChatGPT and inference lead me to believe you'd be on a hiding to nothing getting a general-purpose generative AI to "understand" a large codebase.

Possibly if you trained an AI from scratch using the codebase itself as input, you could then ask it questions about that codebase -- and I can imagine that kind of help being useful (it would effectively replace/support the poor dev having to crawl through the code and tell you what it's doing). I don't know of any such things on the market, but I'd be surprised if they didn't exist TBH.

If I were you (and I'm sure you're doing this, hence the original question) I'd be trying to get the current code better documented now, and doing some feasibility work to look at either how much it'd cost to pay enough to get new devs to work in COBOL v.s. hiving off chunks of the codebase to rework in something with a more active developer population.


 
Posted : 26/10/2023 10:08 am
Posts: 13594
Free Member
 

how much it’d cost to pay enough to get new devs to work in COBOL

Tricky problem that, asking someone at the start of their career to learn an obsolete language, which would then cause them a severe career jolt when the project runs out...

Someone like myself (in their 50s), I'd be more interested in that sort of thing as I only have to worry about the next 10 years and then I'll retire and don't GAS if the thing I'm working on is fashionable or not.....


 
Posted : 26/10/2023 10:19 am
 nbt
Posts: 12404
Full Member
 

I learned COBOL (ANSI '74 I think) when I started (1996) but haven't touched it since. For the right paypacket I could be persuaded to relearn it 😉


 
Posted : 26/10/2023 10:26 am
Posts: 1958
Free Member
 

I've done this before and the answer is yes it can convert it.  But, critically, it cannot do so well enough to be relied upon for any purpose. It gives you a basic layout for a program pretty well though.

A (real) example I've seen is somebody I work with thought they were saving a lot of time by converting some old PHP to Python instead of rewriting it.  ChatGPT converted the code from using PHP array() to using Python dictionaries (IIRC).

In PHP arrays are ordered.  If you put in 'z'=>'hello', 'a'='there' then iterate the array, then you get them out in that order.

In certain versions of Python, dictionaries are not guaranteed to be ordered under some circumstances (I'm not a Python dev & my memory is shot, so I may have got the exact terminology wrong!).

This caused the people involved a great deal of confusion, as side by side, the code looked correct, and stepping through the code revealed no errors, but the results were complete nonsense since the values were being walked in the wrong order!


 
Posted : 26/10/2023 10:42 am
Posts: 15227
Full Member
 

I don't always use AI to code for me, but when I do, I deploy it straight into a live environment.

What could go wrong?


 
Posted : 26/10/2023 10:44 am
Posts: 13594
Free Member
 

I don’t always use AI to code for me, but when I do, I deploy it straight into a live environment.

What could go wrong?

To be fair, fastest way to find all the issues....


 
Posted : 26/10/2023 10:47 am
Posts: 13594
Free Member
 

This caused the people involved a great deal of confusion, as side by side, the code looked correct,

Well, in this case, only if you didn't understand the language you were converting to....

But, yes, generic convert from Lang A to Lang B is never going to be straightforward.


 
Posted : 26/10/2023 10:49 am
Posts: 1054
Full Member
 

I've worked as a COBOL developer in the past. There has always been this theory that as people retire there will be a huge demand (and rates) for people to look after these dying platforms. It never seems to actually happen, anybody that needs COBOL devs now just looks offshore by default. UK rates are, meh.

Anybody trying to analyse a system where they don't know the language is going to come unstuck. Even when you do know the language you may struggle without system specific knowledge - 'oh, don't bother looking at that source code - it is no longer called since project utopia in 1998'

so everytime I need to review anything, I’ve got to get a dev to crawl thru the code and tell me what it’s doing (then I have to guess WHY it’s doing it…)

I mean, that is their expertise - if it was that easy they would probably have already been given the boot.


 
Posted : 26/10/2023 10:55 am
 dazh
Posts: 13302
Full Member
 

I've used chatGPT loads for coding. You won't be able to do a copy and paste and then expect it to work, but it will do most of the grunt work if used in the right way, then you'll need a developer to correct all the problems and hook it all together.

As for reverse engineering code, of course it's possible, but it takes lots of effort depending on the quality of the original codebase. You can get chatGPT to explain what the code does though, which will be helpful in documenting it.

It's probably easier to start from scratch. There'll be a load of technical debt in the old codebase so why would you want to inherit that by migrating into a new language? Far better to go back and do it properly with a blank sheet of paper.


 
Posted : 26/10/2023 10:56 am
Posts: 6707
Free Member
 

+1 for starting from scratch.<br /><br />I think the question of WHY was it done in a certain way will depend heavily on the programming language, and style of coding when it was written, a lot of which will be different now.

ChatGPT is just one of many tools that can speed this up. Copilot or Fauxpilot might also be useful. Fauxpilot runs locally too so don't need to give up access to your source code like ChatGPT. 


 
Posted : 26/10/2023 11:02 am
Posts: 8703
Full Member
 

What could go wrong?

A load of whinging on the forum?


 
Posted : 26/10/2023 11:04 am
Posts: 5055
Free Member
 

When I last worked as a Programmer it was that long ago we were still called Programmers 🙂

Working out what the likes of a COBOL programme does is pretty easy in reality (just follow the logic carrying forward variables using test data - printing the listing and writing on it is how we used to do it TBH), knowing why is the difficult bit and relies on looking at a whole host of programmes and accompanying JCL (or whatever it's called these days).

We use to use the JCL for lots of things, such as to 'carry' data where we knew we'd need the ability to get the programme to do different things but didn't want to hard code it (and go through change management), such as the same programme used for day/weekly/monthly/annual processing.

The above also applies to other 2nd/3rd generation languages I used.


 
Posted : 26/10/2023 11:09 am
Posts: 1958
Free Member
 

footflaps

Well, in this case, only if you didn’t understand the language you were converting to….

But, yes, generic convert from Lang A to Lang B is never going to be straightforward.

The guy involved knows Python inside out, he would happily bore you to death with what's changed between minor versions etc.

The issue is the code looked correct. Unless you know the idiosyncrasies of both languages well enough to see the fault at first glance, then it's very time consuming to ensure its doing the correct thing. In a lot of cases you may as well rewrite it.


 
Posted : 26/10/2023 11:16 am
Posts: 10326
Full Member
 

starting from scratch is usually easiest but you still need to go through the old code to find all the 'special cases'.  It's the 1% that isn't obvious or documented but that fixes a problem you never thought of that kills you in the end 🙁


 
Posted : 26/10/2023 11:17 am
Posts: 1958
Free Member
 

leffeboy
Full Member

starting from scratch is usually easiest but you still need to go through the old code to find all the ‘special cases’. It’s the 1% that isn’t obvious or documented but that fixes a problem you never thought of that kills you in the end 🙁

Exactly, the "why the heck have they done that?! what a load of shit" followed some time later by "ohhhhh, right fair enough then"


 
Posted : 26/10/2023 11:22 am
Posts: 6707
Free Member
 

I worked at a company prototyping some database web stuff we'd not used before. I initialised some date variables with my date of birth because I didn't know what i was doing.

Went back 10 years later, not only was my date of birth still in the code, it had been copied and pasted into loads of other new bits of code as well.

I'd imagine when it's rewritten someone will be wondering why there is a wierdly specific date popping up everywhere.

Maybe it's still there.


 
Posted : 26/10/2023 11:28 am
Posts: 1226
Full Member
 

Yeah, one person's technical debt is another person's "that weird bug that only happened on a certain class of machine when the clocks went back and the job started just before the time change but was going to run until just after it".

I'd personally be tempted to make it nicer by degrees rather than starting from scratch. If the codebase is complex enough that figuring out what's going on takes some degree of effort, re-writing from the ground up is going to be years of effort, assuming one already had documentation, testcases, etc, in place. Which by the sounds of things isn't the case.

Anyway, this is somewhat tangential to OP's question.

I was interested and decided to ask ChatGPT to analyse some code for an open source project I know well. I started off by pointing it at the GitHub repo, and it said it couldn't look at external urls, sorry. So I gave it the contents of one of the smaller files, around 150 LOC and it did a decent job of describing what it was doing. I then gave it a larger file, 1100 LOC or so, and it said the input was too large, sorry.

So it seems to me that leaning on ChatGPT to explain or port anything significant is going to be a challenge. I guess other AIs are available 🙂


 
Posted : 26/10/2023 11:43 am
Posts: 1085
Free Member
 

"I’d personally be tempted to make it nicer by degrees" = strangler fig . This is the way.

ChatGPT won't work, the code it creates looks OK and will execute but there is no chance it will do exactly what you want.

I'm always think that if you want a new system, you shouldn't just rewrite the old one in a different language. Gather the requirements and start again. The world has changed since that code was written.


 
Posted : 26/10/2023 12:51 pm
Posts: 5755
Full Member
 

Bear in mind some companies, mine as an example have a blanket ban on putting any company source code into a tool on the internet they have no control over, given in that code lies lots of important IP.


 
Posted : 26/10/2023 2:44 pm
Posts: 1130
Free Member
 

Bear in mind some companies, mine as an example have a blanket ban on putting any company source code into a tool on the internet they have no control over, given in that code lies lots of important IP.

Same for mine. Nothing apart from Company - Public security classification can be used as a prompt for a GenAI system. Even then we’re encouraged to think very carefully about how we phrase questions.

Generative AI systems keep your inputs and use them to learn. So what you put in could be presented as an answer to someone else, leading to information leakage from an organisation. Some, such as ChatGPT, allow an opt out of this in the settings but whether or not you trust that is up to you.


 
Posted : 26/10/2023 3:12 pm
Posts: 1856
Full Member
Topic starter
 

Gather the requirements and start again. The world has changed since that code was written.

This is my dilemma. For reasons best know to the company owner, the company decided not to do this - rather we are in the process of slapping a new web interface onto a legacy client/server database (actually a Progress database, using Progress code,so even rarer than COBOL).

It's B2B software and we've got a mixture of clients using the legacy client/server product via Citrix and some newer clients using the web front end only (mostly day-to-day activities rather than config items, which our CS team have to do for them).

CEO has given us (the entire dev team) a target of migrating all the legacy functionality (mostly config options) to the web front end and it's all the obscure stuff that remains to be done. Frankly, it doesn't make sense but I've not been able to convince the CEO this is a dumb idea and the ROI of this part of the migration exercise is non-existent...


 
Posted : 26/10/2023 4:55 pm
Posts: 5593
Full Member
 

actually a Progress database, using Progress code,so even rarer than COBOL.

I always used to mention its Progress not Postgres but ABL is well funky and if you mash in the .net fudgerama wowsers, you doing the open edge Web service thang 🙂

I always kept my head down when the progress backend needed work and polished the shiny turd 🙂


 
Posted : 26/10/2023 6:45 pm