views:

2406

answers:

12

I'm a pretty experienced Java programmer that's been doing quite a bit of Win32 stuff in the last couple of years. Mainly I've been using VB6, but I really need to move to something better.

I've spent a month or so playing with Delphi 2009. I like the VCL GUI stuff, Delphi seems more suited to Windows API calls than VB6, I really like the fact that it's much better at OO than VB6, and I like the unit-testing framework that comes with the IDE.

But I really struggle with the fact that there's no widely-used garbage collector for Delphi - having to free every object manually or use interfaces for everything seems to have a pretty big impact on the way that you can do things effectively in an object oriented way. Also I'm not particularly keen on the syntax, or the fact that you have to declare variables all at the top of a method.

I can handle Delphi, but I'm wondering if C++ Builder 2009 might be a better choice for me. I know very little about C++ Builder and C++, but then I know very little about Delphi either. I know there's a lot to the C++ language, but I suspect it's only necessary to know a subset of it to get things done productively... I have heard that the C++ of today is a lot more productive to program in than the C++ of 10 years ago.

I'll be doing new development only so I wouldn't need to master every aspect of the C++ language - if I can find an equivalent for each of Java's language features I'll be happy enough, and as I progress I could start looking at the more advanced stuff a bit more. (Sorry if that sounds painfully naive - if so please set me straight!)

So, for a Java programmer that's new to both Delphi and C++ Builder, which would you consider to be a better choice for productive development of Win32 exes and dlls, and why? What do you see to be the pros and cons of each?

+2  A: 

Of course java sintax is more like c++ than like delphi, but I think that the object model is more similar to delphi:

  • single inheritance. Interfaces exist but are more like COM than like java interfaces.
  • objects are allocated on the heap and accessed by reference

you can find a paper comparing the three languages here

Giacomo Degli Esposti
Thanks Giacomo. That paper looks pretty useful, although it was last updated in 1997 so I wonder if things have changed much since then? With Boost, for example for C++... I know very little about Boost, but I've seen people talk of it as a "cornerstone of the new C++", or something like that.
MB
+7  A: 

Delphi will be a lot easier for you to come to terms with, sure you have to manage your memory, but its very simple

MyObj = TMyObj.Create;

try
  MyObj.DoSomething;
finally
  MyObj.Free;
end

In Delphi all your objects are allocated on the heap, so the rule is very simple if you create it you free it.

C++ with its stack and heap based objs means you have a little more to learn and more scope for getting into trouble.

Tim Jarvis
I think I'm fine with understanding freeing objects, I'm just finding it a bit of a pain to have to think about what object will own what etc. when I'm designing things. Does the latest C++ Builder have a decent garbage collector to make manual freeing generally unnecessary?
MB
No, C++ builder has no built in garbage collector, I think that there are some 3rd party solutions, but honestly you are much better off learning about how to manage your memory first in any language that creates Native code before starting down the path of an add-in garbage collector.
Tim Jarvis
Cheers Tim J - I've heard garbage collection is becoming part of the C++ standard soon, but what that means in reality I don't know (being a bit clueless about C++).
MB
+7  A: 

Go with Delphi and you can use the Boehm Garbage Collector API written by Barry Kelly so you can have garbage collection in Delphi. Barry wrote this before he went to work for CodeGear as a compiler architect. It does have issues with really large applications, and most likely won't work with 64-Bit Delphi. He talks about it quite a bit in this podcast interview.

Even if you don't use that garbage collecting memory manager, I would still recommend Delphi over C++. The only advantage C++ gives you for general development is the curly brace syntax. If you don't mind the Delphi syntax, then for most things you will find it better. Granted C++ Builder has the whole Delphi VCL and RTL, so it isn't as bad as Visual C++, but I still think Delphi would be a better choice.

For Excel add-ins (as you mentioned in your comment) I would recommend Delphi over C++ builder because it has better COM support (which I believe you need for Excel add-ins).

Jim McKeeth
Excellent, thanks Jim. I'd come across that Garbage Collector, I'd just been put off by the fact that I could hardly find mention of anyone actually using it, or whether it's compatible with recent versions. I'll definitely check out the podcast you mention - that's not something I'd come across.
MB
It's a very informative podcast. I'd advise anyone interested in that Garbage Collector to have a listen.
MB
+4  A: 

Personally, I think there are other important considerations apart from the differences between the languages. For example, the Delphi IDE is totally freakin' awesome for building GUIs in a WYSIWYG fashion. I haven't used the C++ builder IDE, but I'd be really surprised if it has a GUI builder that's as nice as Delphi.

Although superficially the syntax of C++ looks more like that of Java, Delphi's object model is actually closer to that of Java. Although pointers exist in Delphi, in practice object references (like those in Java) are used 99% of the time. Even in modern C++, I don't think it's possible to avoid pointers. Not that there's anything wrong with pointers per se, but in practice....

On a personal note, I'm mostly a Java guy these days, but I spent 2 years working with Delphi and would go back to it in a heartbeat. In contrast, I have only very limited experience with C++ and would prefer to clean toilets than return to that language :)

Don
LOL - great response, thanks Don. I'm very happy to avoid pointers wherever possible so that's a definite plus for Delphi. But I think the GUI building stuff is the same for C++ builder as for Delphi (although I've not actually tried it in C++ builder).
MB
@Don: "I'd be surprised if it has a GUI builder as nice as Delphi."Be surprised. It's identical, except it generates C++ code instead. You can use most 3rd party Delphi components, reuse Delphi forms in C++ applications, etc. You can even add Delphi .pas files to your C++ projects
Roddy
+1  A: 

"For example, the Delphi IDE is totally freakin' awesome for building GUIs in a WYSIWYG fashion. I haven't used the C++ builder IDE, but I'd be really surprised if it has a GUI builder that's as nice as Delphi."

Actually the C++Builder GUI editor is exactly the same editor, and works in the same way. It is fantastic.

.Net has a huge number of classes, much like Java. C# has similar syntax to Java and because of the huge class library works fairly similarly. And it's a perfectly adequate environment to program in. But frankly Delphi is a much more pleasant language, IDE and general environment to work with. C# was designed by the same person who designed Delphi and "feels" very similar in many ways, so don't assume that because Delphi compiles to native code (though you can use Delphi .Net as well) it's fundamentally harder to use. It's not, at all.

My personal recommendation would be for Delphi, because it's a cool language. However if you're interested in learning C++, C++ Builder is probably the nicest way you could do it.

+1  A: 

I think if you go with Delphi you will find it more easier after few times of using, also it has more third party support and some of the features introduced in Delphi before C++ Builder

also read this blog from ex-Java and now the guy behind most of database and datasnap work in Delphi Steve Shaughnessy, about his experience about programming Delphi after 10 years of Java :-) http://blogs.codegear.com/steveshaughnessy/2006/12/03/30193

Mohammed Nasman
Useful link that - thanks.
MB
+17  A: 

Delphi or C++ Builder - it's a difficult choice!

As you're aware, they're basically very similar, from the IDE and RAD point of view.

The pros and cons of each - irrespective of background - are a bit like this. Both share a great 2-way RAD form designer and framework (VCL) that are ideal for native Windows development.

Delphi:

  • FOR: Large, active, enthusiastic community
  • FOR: Delphi 2009 is the best version for many years
  • FOR: Delphi "units" make C source/header file pairs seem archaic
  • AGAINST: No automatic destruction as objects leave scope, hence lots of 'finally's in your code
  • AGAINST: Language can be 'wordy', which is a matter of taste
  • AGAINST: Using third-party DLL's or libraries in other languages (esp. C) requires Delphi header files to be written

C++Builder

  • FOR: C++Builder 2009 is probably the best version ever
  • FOR: RAII idiom simplifies memory management hugely
  • FOR: Templates are incredibly useful and powerful, even if the C++Builder implementation has some bugs with them.
  • FOR: Support for BOOST and other modern template-based libraries (even though the Boost support is not 100%)
  • FOR: Great interop with Delphi means most Delphi components can easily be used.
  • FOR: Easy to use with third-part DLLs/libraries with C/C++ headers.
  • FOR: C++ may look better on a CV than Delphi.
  • AGAINST: CB2009 is "unicode only" - the implications of this for code portability are different and less well thought-out than for Delphi
  • AGAINST: C++Builder user-base is much smaller than Delphi. Maybe 20% or less.
  • AGAINST: Borland/Inprise nearly killed BCB a few years ago, and it was only resurrected after major efforts from the community. (However, Codegear/Embarcadero commitment does seem impressive)
  • AGAINST: C++Builder is not top of the pile within Codegear.
  • AGAINST: Third-party component vendors don't always understand/support C++Builder

That's about it. Just to state my position, I'm a happy BCB2007/2009 user (since BCB5), and I also infrequently use Delphi. A few years back, I considered a switch from C++ to Delphi, but the lack of RAII idiom was the one thing that I found difficult to come to terms with.

Roddy
Many thanks Roddy - that looks like a good, balanced comparison. RAII idiom is a new thing to me, but from a little reading it looks to me like it can only work because C++ automatically destroys stack-allocated objects. Looks a lot better than Create/try/finally/free for every Delphi stack object
MB
Incidentally, have you ever tried using a garbage collector with C++ builder?
MB
@MB: No, I haven't tried Barry's GC with C++Builder. Heap management with Delphi vs. C++ can be a tricky area, so I'd expect it could need some tweaks to work.
Roddy
Cheers Roddy, that's the impression I'm getting too.
MB
+1  A: 

I program professionaly in Delphi for the last 10 years and have a good knowledge of C++. I'd go to the Delphi way. Syntax is much simpler and memory management also. That GC for native Delphi I don't have heard yet... Although I didn't like much the traps on Delphi.Net code introduced because of the .NET gc, I'm not much fond of gcs ;-)

Fabricio Araujo
Cheers Fabricio! I won't argue with your opinion on the garbage collector, but after many trouble-free years with Java I personally adore them ;-)
MB
The VCL's ownership mechanics served me well over the years and not fail. Direct manipulation of memory is always troublesome (as it's needed sometimes when acessing WinAPI).A complaint I have about .NET gc is the lack of a automatic called hook when the object is finally destroyed.
Fabricio Araujo
+1  A: 

One thing I forgot to mention before:

From a cost perspective, you don't really need to choose. Buy the RAD Studio package, and for a modest extra cost over one individual language, you get both Delphi and C++Builder personalities in the same IDE.

And, it's worth mentioning that the C++Builder package includes the Delphi compiler, and you can write/add Delphi .pas files and include them as part of your C++ projects.

Roddy
Oh dear, I've realized that I screwed up and bought the Delphi 2009 package alone, when I thought C++ Builder was bundled with it... Now I shall put Embarcadero's customer support team to the test and see if it's a "sorry too late mate", or a "we're happy to help you".
MB
Help me pay the difference that is, and get the bundle of both together. I hope they're nice about it!
MB
Update: they were cool about it - they cancelled my original order and I placed a new one for the upgrade. Just like I'd expect really, but you never know cos some companies seem to go out of their way to be awkward/rubbish. I'm pleased to see that Embarcardero are good guys though :)
MB
+4  A: 

After working with Borland C and C++ compliers since BCC 4.1/DOS and Delphi from 3.0 thru 2007 I can tell you honestly that you're in for a great adventure either way. Moving from C/C++ on Borland's Builder and RAD IDE's is a substantial paradigm shift (and learning curve) from Microsoft's VC++, C++ and .NET (have used VC from the first MS-DOS release -- the beige three ring mini binders).

The choice between C++ and Delphi is one I suggest you make after getting your feet wet on a few small to mid sized projects in both languages. I started out a C programmer and after about five years switched to Delphi (V3.0) when the VCL just made Windows programming a lot easier and more productive.

Be warned, Delphi is a seductive language for programmers coming from other languages like COBOL, FORTRAN, VisualBasic because its syntax and code rules enforce a kind of discipline that keeps one out of trouble. The terseness and raw metal power of C makes it a great systems programming language (device drivers, O/S code, real-time embedded programming), but in inexperienced hands it can bite you.

Borland's C++ Builder (Delphi's VCL added to C++ compiler) takes many of C++ sharp edges off and is my second favorite language. Since Borland added .NET support to both languages there's a strong argument to use Builder instead of VC++ for MS framework programming. Although C# has a good amount of 'friendliness' built in compared to C++, if pushed I'd still stick to Delphi or Builder if I was just starting out.

For learning the ropes, for prototyping and quick concept programs there is simply not a language out there that can beat Delphi especially with the VCL and the third party components. No hype, just facts.

Prince Riley, I'll take that as a vote for Delphi. Particularly useful since it sounds like you've used both quite a lot. Thanks!
MB
+1  A: 

There is nothing I haven't been able to do in C++ VCL that I couldn't do with Delphi VCL and almost all Delphi components work fine in C++ Builder. Since I program for both Windows and UNIX, C++ is more portable.

If you use C++ STL or an other well designed library for your containers, garbage collection sort of becomes a moot point, and otherwise manual GC is not difficult (one quickly learns good habits - which you should be practicing anyways irrespective of a GC). As long as you use RAII where possible, keep your memory management encapsulated in containers, be clear on object ownership and only use pointers as nilable references (all of which you should also be doing irrespective on the language), GC really should not be an issue.

Roger Nelson
A: 

If you're going to do a lot of Windows programming, learn C++. Would you learn German in preparation for a trip to France? C/C++ is the native language of the Windows API. Dealing with WinAPI data structures and calls is so much simpler in C/C++. As to RAD, I've used MSVC for about 13 years and I can whip together a GUI app as quickly as anybody using Visual Studio's GUI editor.

Rob K