Your boss tells you he needs a big chunk of code in language X converting into code Y. You know code Y but are only vaguely aware of X. You only have limited amount of time.

Do you try and find a code converter? slowly hack through the code until it works? outsource? say you can't?

4 Answers 4



Ideally you will have some tests that can test the code for what it does, regardless of what language it is written in. Ensure it gives full coverage.

Then ensure your new code passes all the tests.

If language-independent tests are not an option, the code-convert the tests first then code-convert the code they are testing.

If the old code doesn't have any tests, write some.

  • +1: You have to test anyway, so get tests first. The actual code (since it's going to be trashed) has no real value. The test cases, however, are solid gold.
    – S.Lott
    Feb 21, 2011 at 11:03
  • If you've got a spec for what the code should do, this is good. Otherwise, you need tests for both the old and the new, and writing the tests for the old is going to be difficult. Feb 21, 2011 at 16:39

In terms of converting to a different language, it doesnt really matter it has never really halted my productivity not knowing anything about the language, syntax is easily translated if you are a competent programmer, one pitfall though is when you convert to a different language there may be a more efficiant way of doing something or the way you implemented in one language is bad in another.

For a full conversion you need to think of it in terms of a reimplementation isntead of just converting code, this is if you have more time, you shouldnt really convert lots of code if not given the proper time to reimplement it, if it is just a small program or a few functions I guess its fine.

You should check what features a language has before conversion, does it have garbage collection? should i handle my objects on my own? things like this.

  • "syntax is easily translated if you are a competent programmer" So learning Haskell must have been a non-brainer for you? Feb 21, 2011 at 11:27
  • I am talking about trivial syntax (c++ to c# etc) convert from haskell to something else... Shif+Del Haskell source, start again in new language... tbh
    – kyndigs
    Feb 21, 2011 at 11:37
  • 1
    learning to read a language is a lot easier than learning to write it, Lenny...
    – jwenting
    Feb 21, 2011 at 13:04


I'd take each process in Code Y, figure out what it does and roughly how to do it in Code X, then Google the Code Y language name + Code X method.

For example, I needed to know what the IsNumeric VB translation was in C# so I just Googled IsNumeric C#

It really depends on the languages though. Converting from VB to C# is quite simple compared to converting from ASP.Net to PHP (I've had to do both)


Depends upon the languages you are working with, this could be a simple matter of basically finding an online tool that does the translation for you to a complex rewrite task.

In all likelihood, if you are looking at a huge block of code that needs to be translated you are more likely looking at a full application that needs to be rewritten in which case you should use the previous application and code-base as a reference, but shouldn't really like it drive the application you are writing. Review the code, see if there are any relevant comments in it as to unusual business logic that you may need to take in to account, but beyond that you can look at things as a new project and just use the former application as a sanity check to ensure you did your job right during testing.

If you are looking at just trying to replication some functionality and port it to another application in a different language, then CashCow's advice to write test cases is very important. Make sure you know what the expected outputs are before you start writing new code and also see if you can figure out how things behave during the edge cases. Likewise, make sure you understand what the code is doing so you don't encounter more problems down the road. Likewise, make sure that the languages translate well between each other, if you are working with code where numeric accuracy is required, you want to make sure that that the double you are using in C# behaves the same way as the double precision in Fortran that it is replacing. In short, some extra time doing research up front may save you from hours of stress due to failing test cases or errors that aren't caught by the test cases you write.

Not the answer you're looking for? Browse other questions tagged or ask your own question.