Jump to content

Recommended Posts

Posted

In my last job and for a number of private projects I needed to port huge amounts of code between languages. I'm specifically talking about ports on one and the same platform. Here are some tips I consider useful (from experience) in no particular order:

a) Pre-porting

Obviously, create a safe (sandbox) copy of whatever you are about to port. Separate it completely from anything important, even if this means setting up another production environment.

b ) While porting

  • Never try to fix something on the fly
  • If you need to substitute some paradigm (e.g. nested structures) not available in the target language, write a substitute and test it before starting to translate
  • Back up target code on almost every new LOC, use git and write an auto-commit script when in doubt
  • Go on a module by module basis, never translate whole code pages the same time
  • Never change any variable / constant etc. names on the fly
  • If time and budget allows, always write test wrappers for longer modules to verify every code path in source and target code (unless dependent on user input, of course)
  • Always assume the code you are porting was written by a person desperately trying to confuse you, even if it was you who wrote it!
  • Some languages have a (or multiple) different array base(s)
  • Don't trust automated translation (I know C#<->VB.NET is tempting) tools, never attempt to create any automated translation tools
  • Recreate not only code, but also file-structure, even if this is bad practice in the target language
  • Keep the case-sensitivity of the target and source language in mind
  • Don't delete anything on the way, just comment out
  • You don't want to care about any best practices or conventions, you care about a 1:1 copy; everything else is post-porting

c) Post-porting

Create a whole backup of the new code and put it somewhere safe. Then, and only then, start working with a fresh copy of the new code.

After all the projects I've been through, I can only say the above also applies when the source (no pun intended) code is only 200 LOC long. If the source language is complex enough, you'd be surprised how bad one can f*ck things up. If you have any additional tips or stories regarding ports, leave them here. :) 

 

I will answer every single PM, and you are free to ask anything anytime.

Posted (edited)
  On 7/21/2015 at 7:24 AM, Xandy said:

It was a good read.  Seemed like pretty good practices for any code projects. :)

I agree.

Can you or me make new Wiki Page of course copy Paste ?

EDIT: the question was adressed to @minxomat

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 7/21/2015 at 8:02 AM, mLipok said:

Can you or me make new Wiki Page of course copy Paste ?

If you feel like it, go for it.

I will answer every single PM, and you are free to ask anything anytime.

Posted

Thanks.
If no other members have any objective I will handle this in few days.

Cheers,

mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

If you're not proficient in both languages, you're going to have a bad time.

Even simple things like data types can be different in closely related languages. Maximum value of a char in C++ is 0xFF, but in C# it is 0xFFFF.  The correct way to translate is to use a byte in C#, which has a maximum value of 0xFF. These are closely related languages. Good luck handling overflows and "bitfucking" in other languages.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...