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.

I am intending to purchase some source code for my Delphi program. It is not too big an algorithm, but it is not available in Delphi and I'll have to translate it to Delphi.

However, I have not worked in any of the languages it is offered in and I don't know which I should buy. I want the one that will translate to Delphi most easily and accurately.

The three languages are: C++, Java, and C#.

Which one would be easiest to convert?

share|improve this question
14  
This may not assist you, but C# was designed by the same person who designed Delphi (Anders Hejlsberg). – Gabe Jun 6 '11 at 0:35
3  
And he quit developing Delphi a long time ago. – Seth Carnegie Jun 6 '11 at 0:37
8  
Knowing nothing of Delphi, I think I'd pick C#. C++ can have some serious black magic and Java feels very verbose for common tasks. I'd think the algorithm would stand out clearest in C#. – sarnold Jun 6 '11 at 0:38
1  
@Seth, your actual experience in this matter definitely counts for a lot :) I'm just saying I'd rather learn an algorithm from C# than C++ or Java. If the code can be more mechanically converted, so much the better; but I wouldn't necessarily want to reproduce some of the darker corners of C++-based code elsewhere if I could avoid it. – sarnold Jun 6 '11 at 0:45
1  
Without seeing the code it's impossible to say which one will be easier to modify. Probably, the efforts will be the same because it's unlikely the said library is written individually using the best facilities each language offers. Such (multilanguage) libraries are typically written for the lowest common denominator and just replicated to other languages. In this case Java is the lowest denominator and other versions may differ only syntactically. – Gene Bushuyev Jun 6 '11 at 4:07
show 5 more comments

migrated from stackoverflow.com Jun 6 '11 at 5:46

8 Answers

up vote 13 down vote accepted

C++ will probably be the easiest, since most C++ constructs have a Delphi equivalent and I don't think Delphi is missing any features that will require a large workaround.

I have ported a lot of C++ code (several small applications and one really huge complicated one) to Delphi and it wasn't hard at all.

The C++ and Delphi standard libraries (I don't know if Delphi calls it that, but whatever) are very similar (Delphi has a larger one, if anything), and I don't remember encountering anything in C++ that Delphi didn't have or that didn't directly translate to Delphi. Delphi also has the Ansi* functions for use with C strings. C#'s standard library (again, may be incorrect term) and the .NET stuff doesn't have such a correlation to Delphi's, and I would imagine Java is the same.

I would also imagine that people who have programmed in C++ are more likely to have programmed in Delphi at some point than people who major in C# or Java, which means you might get more help porting from C++ than the other two. That is pure speculation and my opinion though.

The only problems I can think of would be multiple inheritance which Delphi does not support (but you can use interfaces instead to make it less drastic of a change) and templates, for which Delphi doesn't have that great support (it supports it mostly, but you're only allowed to have templates inside classes (not free template functions like C++) and you can't use templates to make a function return the parameterized type), (thanks elder_george).

Also, Delphi only supports operator overloading for records IIRC, so you'd have to change those into named functions.

share|improve this answer
5  
For starters, Delphi lacks C++-style templates (and until very recent time lacked C#-style generics) and multiple inheritance. So, if the purchased code depends on templates (e.g. STL) on MI, there could be problems. On other hand, it's relatively easy to compile C++ code as DLL to use it as is. – elder_george Jun 6 '11 at 0:57
@elder actually I thought Delphi was only a little worse than C++ at templates (or generics, whatever Delphi calls them). The only problem I had with templates in Delphi was making a function with a return type of type T. And yes, you'd have to use an interface for MI issues. – Seth Carnegie Jun 6 '11 at 0:59
4  
Delphi is absolutely nothing like C++. Even if you limit yourself to subset of C++ without templates, etc. you still will have a completely different construction mechanism, no function/operator overloading, no specific to C++ lookup rules, etc. – Gene Bushuyev Jun 6 '11 at 5:11
2  
@Seth Carnegie, there is almost nothing in common between generics and C++ templates. You won't be able to translate an arbitrary template code into Delphi. Try to start with porting Boost::Spirit, if you think I'm wrong. – SK-logic Jun 6 '11 at 9:45
1  
@Seth Carnegie: I'm sorry, the question doesn't make sense. Try converting the library that was mentioned, that experience should remove all doubts. – Gene Bushuyev Jun 6 '11 at 18:39
show 7 more comments

Neither of them are too close to Delphi, and as such I don't think you should have any preferences.

If you buy the code in C++ though, you might be able to use the code from Delphi if it is in .DLL file. Interoperability with Java or C# have additional dependencies.

share|improve this answer
6  
Boris has your answer. If you're going to be buying code, you're not going to want to convert it, else why not just write it yourself. Rather you'll want to simply use it, and C++ offers the easiest route for that. – Hovercraft Full Of Eels Jun 6 '11 at 2:06
This really is your answer. You'll be up and running the quickest and you'll know that the code is correct. When the developer brings out an upgraded version you'll be able to use it and not have to port again! – David Heffernan Jun 6 '11 at 6:38
This depends on the type of algorithm. If it has very simply input/output format, this is usable, but if it needs to be adapted to work with the application's data, a proper conversion might be needed. – Paŭlo Ebermann Jun 6 '11 at 10:57

I would choose java, for the following reason:

Java has the least features. You should not have any problems converting the code, since most Java features have a direct equivalent in Delphi. I can only think of two features (inner classes and generic wildcard constraints) that are unique to Java.

Modern C#, although from the same language designer, has many, many more features. If they are using LINQ or Lambdas, you are going to have to reimplement those. (Actually, I don't know if Delphi has Lambdas or not, it didn't when I worked with it.)

C++ has templates, which are superficially similar to generics, but actually very different. If the library's code uses templates in a big way, the porting is going to be difficult.

That said, it is very likely that the library uses a common style, and a common language subset for all three languages. If that is the case, I would recommend C#, because it will be marginally more familiar to a Delphi programmer.

share|improve this answer

If you have Delphi Prism, you can use it to convert C# code to Pascal, although I've never tried this myself.

share|improve this answer
+1 Cool, I didn't know this. I wonder how well it works. – Seth Carnegie Jun 6 '11 at 0:56
Anyone else know of translation programs from C++, Java or C# to Delphi? – lkessler Jun 6 '11 at 1:00
+1 Prism must've been written by Anders Hejlsberg ;-) – TheFogger Jun 6 '11 at 1:01
@TheFogger: No, actually it was written by the RemObjects team, independent of Microsoft. – Mason Wheeler Jun 6 '11 at 4:42

As you can see, you've got no clear answer - each one has made some good points.

I think that's because without seeing the source code itself, it's tough to answer definitively. So rather than trying to guess, I'd ask the principal engineer @ http://www.amorphics.com/about.html what he thinks.

HTH

share|improve this answer
... except, if he's not familiar with Delphi, he may not be able to say. – lkessler Jun 6 '11 at 2:19
2  
Judging from the site and the credentials of that fellow, I'm pretty sure he knows some Pascal/Delphi - if he doesn't, ask him about the different issues mentioned here: are there a lot of templates or pointers, or CLR specific structures and operations, etc - tell him that Delphi supports A,B, and C well but not X,Y, and Z... You're both technicians and you're a potential customer - he, or someone over there, should be able to guide you. – Mikey Jun 6 '11 at 2:26

Your best bet is a free Java 2 Pascal convertor. There is also free C# to Oxygene convertor, which is actually a convertor to Prism (which is pretty close to Delphi Pascal language).

In both cases don't expect converting a full application, but rough converting of units and then using parts in your code will work with some manual corrections.

share|improve this answer
These both sound interesting as alternatives. – Warren P Jun 12 '11 at 3:23

I don't really have an answer about converting, but given that it's the Metaphone algorithm you want to purchase, I wanted to make sure you're aware that there is already an implementation for Delphi:

http://sourceforge.net/projects/metaphone/

Even if for some reason the commercial version is preferable and you want to port it to Delphi, it would probably help to compare the other language's implementation to the Metaphone already available for Delphi.

share|improve this answer
This is the third version of the Metaphone algorithm by the same author that I'm looking at. This version is not free. – lkessler Jun 7 '11 at 4:02
@kessler -- The version is free but is under the GPL, which may not work if you have a commercial product. There are other totally free versions in Delphi that you have probably found. In any case, it's not a huge algorithm and porting from c++/c#/java should not be huge deal. I suspect the c# version would be most direct. Why not offer to sell your work back to the vendor so they can potentially profit from offering new language version? Maybe they wouldn't pay you, but instead would offer you all three of their versions for free. – Herbert Sitz Jun 7 '11 at 15:35

You can use Delphi2CS http://www.netcoole.com/delphi2cs.htm

It will help you, but you will probably need to do some work on your own.

share|improve this answer
3  
Actually, that conversion program goes the wrong way. :-( – lkessler Jun 6 '11 at 1:33

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.