Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

If you have several million lines of Delphi code and want to incrementally migrate to .NET/C#, what strategy would you use?

share|improve this question
2  
This is a very, very bad idea, and tends to be a massive failure everywhere it's tried. See Ryan Hayes's answer. – Mason Wheeler Oct 7 '10 at 20:39
2  
@Mason, you can't possibly know that it's a bad idea if you haven't seen the code. Maybe it needs to be rewritten anyway, and the company decided that if they're going to rewrite it, it will be easier to recruit .NET programmers than Delphi programmers. I'm only speculating, of course, but then so are you; the difference is, I'm stating my assumptions. – Aaronaught Oct 7 '10 at 21:11

9 Answers

I'd take a long hard look at Delphi Prism to migrate to .NET without rewriting in C#.

share|improve this answer
+1 That looks like a good hybrid solution. Nice find! – Ryan Hayes Oct 7 '10 at 20:37
1  
Don't migrate if at all possible. But if people with pointy hair are forcing it on you, this is probably your best bet. Prism is closer to the original code, and it's also simply a more powerful language than C#. (See prismwiki.codegear.com/en/Delphi_Prism_vs._CSharp for details) – Mason Wheeler Oct 7 '10 at 20:54
1  
@Mason: Right, a page on the CodeGear wiki - another totally unbiased source. Could you please get over your anti-.NET crusade? It's not just advocated by people with "pointy hair", it's a thriving development community. – Aaronaught Oct 7 '10 at 21:09
2  
@Mason, it's not inaccurate so much as woefully incomplete. And I'm not here to debate the merits of Delphi vs. .NET and you shouldn't be either. It would really be nice if people could confine their evangelism to discussions where it's actually on topic. – Aaronaught Oct 7 '10 at 21:16
1  
@Mason: I can read perfectly well, and I think you know that when I say ".NET" I am referring to the Microsoft stack. I don't know anybody that actively develops .NET applications in Delphi/Prism today. If I needed to develop a native Win32/64 app then Delphi would definitely be a contender, but choosing Prism effectively negates most of the advantages of .NET (in particular, the community around C#). – Aaronaught Oct 7 '10 at 23:23
show 2 more comments

Option1:

  • Step 1: Find what pieces of the application can be broken off and rewritten individually.
  • Step 2: Get cracking. (It may take a while)

Option 2:

share|improve this answer
1  
+1 for option 2. Every Delphi-to-.NET rewrite story I've heard has been a horror story that validates everything Joel talked about in that post and worse. – Mason Wheeler Oct 7 '10 at 20:38
I'm sure that's not a biased statement at all, @Mason. Well, I guess there's a first time for everything, and my story is definitely not a horror story. Now, Delphi .NET, there was a horror story... – Aaronaught Oct 7 '10 at 20:42
1  
+1 (can't vote up anymore for today, but will tomorrow) for option 2 – user2567 Oct 7 '10 at 20:44
3  
@Aaronaught: Yes it was. Borland never should have tried it, and plenty of people in the community tried to warn them. And now Borland is dead, and Delphi For .NET is dead, but Delphi is still alive and kicking. ;) – Mason Wheeler Oct 7 '10 at 20:44
Really, Borland shopuld have just written something Prism themselves - Delphi syntax, but using WebForms and other .net libraries/runtime (no TStrings etc, use .net equivalents (ListDictionary from memory) – Gerry Oct 7 '10 at 23:22

I had to do exactly this, although it wasn't several million lines, it was an order of magnitude lower than that.

I did it by implementing web services in .NET. Even the old versions of Delphi have decent SOAP support, so you can just start swapping out entire modules for web services written in .NET (just use the basic profile, no WS-* extensions).

And when you're done, you have a beautiful loosely-coupled SOA.

share|improve this answer
I actually did something similar for a VB6 -> C# conversion. The key here is incrementally swapping out modules. Now to make this easier I had to do a bit of careful refactoring but as long as you think before you act it is highly possible. – ChaosPandion Oct 7 '10 at 22:19

Here is another alternative that I have found to be very effective. Now keep in mind that no matter what you do it will be a hell of a lot of work but by taking in all this advice I think you can pull it off.

One of the great things about C# is that it can register your assemblies for COM interop and will generate all of those nasty interfaces for you. What we did was take modules from our poorly designed VB6 application and have them use functionality from .NET.

Something you really need to remember is to keep your interfaces simple. Try to only require simple types to be passed to .NET. Also you will need to have a considerable amount of upfront planning to layout what functionality you will expose from .NET. You will need to perform extensive refactoring to make sure your new objects will integrate properly with the legacy code.

Once again there is no way you can turn this into an easy task but it can be done.

share|improve this answer

I've seen several attempts at this. So far I can't call any of them a success.

Why do people suggest to spend tons of man-hours to port something to another language?

Usually it's a combination of these:

  • lacking programming skills and knowledge of the original language

  • developers not wanting to learn another language, so instead they want to convert all code to their favourite language.

  • developers not understanding the existing code base, so they underestimate the amount and complexity of existing features

  • overestimating the advantages that a port would bring

  • people not having read Joel Spolsky's "things you should never do" :-)

Slap those together, and you've got yourself a recipe for disaster.

share|improve this answer
Hey, Wouter! Good to see you here on Programmers. – Mason Wheeler Dec 28 '10 at 19:26

Identify the part of the delphi code not being used and mark it to not be converted. Press those in charge to make a solid commitment to keeping any of the functionality. When they say, "Well we may need it." get rid of it and promise to add it back to the new version.

See if you can rework any current change requests to the new language. There have been good suggestions on creating services.

Identify problematic pieces of code that has had a lot of bugs identified. It may be worth a rewrite.

It is tough to justify converting what is left, but eventually, the rest of the code may fall under the first three suggestions as time goes by. Business rules may change along the way.

share|improve this answer

The two methods I've used in the past are

  • COM interop (i.e. register either/or/both Delphi and C# for COM and then each can instantiate each others' objects pretty easily)

  • Use mixed-mode C++ as an intermediary to marshal data between Delphi and C#. The C++ can be spoken to from Delphi as a standard DLL and spoken to by C# as a standard .NET library.

share|improve this answer

You can actually use RemObjects Hydra to combine Delphi and .NET code into a single application. It lets you create plugin modules with either tool, and then combine them together. I've talked to people who have used it to add .NET features to legacy Delphi applications, as wall as others who have used it to move parts of their legacy Delphi application into a new .NET application.

Full disclosure: I work for RemObjects, but I honestly think Hydra is a great tool. More Delphi developers need to know about it because it means you can keep using the best tool for each part of the application: .NET or Delphi.

share|improve this answer

I just started working with Hydra and in my view you still have to expose interface yourself. Because I didn't need much it was not a problem for me, but it might be a pain if you need a bunch.

That said I think Hydra is great for having the opportunity of using .net in Delphi fast. I was forced to implement a .net SAML client because Microsoft not always follows the exact standard. For this purpose Hydra worked fine.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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