7 ms·
> Do you really want to convert the lines one-to-one? This seems pretty wasteful. I did this once - converting a few kloc of Java to C# - I'm sure it helped th
by MaulingMonkey 10y ago
> Do you really want to convert the lines one-to-one? This seems pretty wasteful.
I did this once - converting a few kloc of Java to C# - I'm sure it helped that these are very similar languages in many respects. I actually copied the Java source code into C# source files, and then tweaked them until they compiled. The initial commit even had e.g. a "polyfill" for Java's ArrayList<T> class.
https://github.com/MaulingMonkey/poly2tri-cs https://github.com/MaulingMonkey/poly2tri-cs
By virtue of being such a mechanical translation, it went very fast. I intentionally avoided translating into C# idioms - or even naming conventions - in the initial commit. I wanted to avoid refactoring the entire codebase simultaneously - my experience has been that multi kloc refactors are a great way to bite off more than I can chew, and spend a lot of time in refactoring or debugging hell, and to create an unreviewable mess, all of which is very slow.
By saving all the refactoring into C# idioms etc. for followup changelists, the translation went so smoothly that I still haven't learned the math behind constrained Delaunay triangulation. A non-1:1 translation I'm sure would've forced me to learn it, if only for debugging purposes. ArrayList<T> is now gone - replaced with standard List<T> and IEnumerable<T> from .NET's standard libraries, foo.setX(value) replaced with foo.X = value;, etc.
This isn't an approach I'd recommend for all such projects, but I'm surprised just how well it worked for that conversion. The initial translation took maybe a few hours (if that), and the subsequent cleanup a few more.
- candiodari 10y agoGiven how powerful it is, when used correctly, it's tough to see why refactoring has such a bad reputation amongst software developers. For instance, using refactoring, when possible, provides far better guarantees of correctness than tests do.