Delphi 与 C++ Builder - 对于使用 Win32 的 Java 程序员来说哪个是更好的选择
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/180358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delphi versus C++ Builder - Which is Better Choice for a Java Programmer Doing Win32
提问by MB.
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.
我是一个非常有经验的 Java 程序员,在过去的几年里一直在做很多 Win32 的东西。主要是我一直在使用 VB6,但我真的需要转向更好的东西。
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.
我花了一个月左右的时间玩 Delphi 2009。我喜欢 VCL GUI 的东西,Delphi 似乎比 VB6 更适合 Windows API 调用,我真的很喜欢它在 OO 方面比 VB6 好得多的事实,而且我喜欢这个单元-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.
但我真的为 Delphi 没有广泛使用的垃圾收集器这一事实而苦恼——必须手动释放每个对象或为所有对象使用接口似乎对您以面向对象的方式有效地做事的方式产生了相当大的影响. 此外,我不是特别热衷于语法,或者您必须在方法的顶部声明变量这一事实。
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.
我可以处理 Delphi,但我想知道 C++ Builder 2009 是否对我来说是更好的选择。我对 C++ Builder 和 C++ 知之甚少,但我对 Delphi 也知之甚少。我知道 C++ 语言有很多,但我怀疑只需要知道它的一个子集就可以有效地完成工作......我听说今天的 C++ 比 C++ 的编程效率高得多10年前。
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!)
我只会做新的开发,所以我不需要掌握 C++ 语言的每个方面——如果我能找到 Java 语言的每个特性的等价物,我会很高兴,随着我的进步,我可以开始寻找在更高级的东西上多一点。(对不起,如果这听起来很天真 - 如果是这样,请让我直截了当!)
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?
那么,对于 Delphi 和 C++ Builder 都不熟悉的 Java 程序员,您认为哪个是 Win32 exe 和 dll 的高效开发的更好选择,为什么?您认为每种方法的优缺点是什么?
回答by Roddy
Delphi or C++ Builder - it's a difficult choice!
Delphi 或 C++ Builder - 这是一个艰难的选择!
As you're aware, they're basically very similar, from the IDE and RAD point of view.
如您所知,从 IDE 和 RAD 的角度来看,它们基本上非常相似。
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.
每个人的利弊——无论背景如何——有点像这样。两者都共享一个很棒的 2 路 RAD 表单设计器和框架 (VCL),非常适合本机 Windows 开发。
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
- 适用于:大型、活跃、热情的社区
- FOR:Delphi 2009 多年来最好的版本
- FOR:Delphi“单元”使 C 源/头文件对看起来过时
- 反对:当对象离开作用域时不会自动销毁,因此你的代码中有很多“finally”
- 反对:语言可以“罗嗦”,这是一个品味问题
- 反对:使用第三方 DLL 或其他语言(尤其是 C)的库需要编写 Delphi 头文件
C++Builder
C++生成器
- 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
- FOR:C++Builder 2009 可能是有史以来最好的版本
- FOR:RAII 习惯用法极大地简化了内存管理
- FOR:模板非常有用和强大,即使 C++Builder 实现有一些错误。
- FOR:支持 BOOST 和其他现代基于模板的库(即使 Boost 支持不是 100%)
- FOR:与 Delphi 的良好互操作意味着大多数 Delphi 组件都可以轻松使用。
- FOR:易于与带有 C/C++ 头文件的第三方 DLL/库一起使用。
- FOR:C++ 在 CV 上看起来可能比 Delphi 更好。
- 反对:CB2009 是“仅 unicode”——这对代码可移植性的影响与 Delphi 不同,而且没有经过深思熟虑
- 反对:C++Builder 用户群比 Delphi 小得多。也许 20% 或更少。
- 反对:Borland/Inprise 几年前差点杀死 BCB,它在社区的大力努力下才复活。(不过,Codegear/Embarcadero 的承诺确实令人印象深刻)
- 反对:C++Builder 不是 Codegear 中的佼佼者。
- 反对:第三方组件供应商并不总是理解/支持 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.
就是这样。简单说一下我的立场,我是一个快乐的 BCB2007/2009 用户(从 BCB5 开始),而且我也很少使用 Delphi。几年前,我考虑过从 C++ 切换到 Delphi,但我发现缺乏 RAII 习语是我难以接受的一件事。
回答by Jim McKeeth
Go with Delphi and you can use the Boehm Garbage Collector APIwritten by Barry Kellyso 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.
使用 Delphi,您可以使用Barry Kelly编写的Boehm Garbage Collector API,这样您就可以在 Delphi 中进行垃圾收集。Barry 在加入 CodeGear 担任编译器架构师之前写了这篇文章。它在处理非常大的应用程序时确实存在问题,并且很可能不适用于 64 位 Delphi。他在这个播客采访中谈到了很多。
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.
即使你不使用垃圾收集内存管理器,我仍然会推荐 Delphi 而不是 C++。C++ 为您提供一般开发的唯一优势是花括号语法。如果您不介意 Delphi 语法,那么对于大多数事情,您会发现它更好。当然,C++ Builder 拥有完整的 Delphi VCL 和 RTL,所以它并不像 Visual C++ 那样糟糕,但我仍然认为 Delphi 会是更好的选择。
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).
对于 Excel 加载项(正如您在评论中提到的),我会推荐 Delphi 而不是 C++ builder,因为它具有更好的 COM 支持(我相信您需要 Excel 加载项)。
回答by Tim Jarvis
Delphi will be a lot easier for you to come to terms with, sure you have to manage your memory, but its very simple
Delphi 会让你更容易接受,当然你必须管理你的内存,但它非常简单
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.
在 Delphi 中,您的所有对象都分配在堆上,因此规则非常简单,如果您创建它并释放它。
C++ with its stack and heap based objs means you have a little more to learn and more scope for getting into trouble.
C++ 及其基于堆栈和堆的 objs 意味着您有更多的东西需要学习,也有更多的空间陷入困境。
回答by Tim Jarvis
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).
在 BCC 4.1/DOS 和 Delphi 从 3.0 到 2007 年开始使用 Borland C 和 C++ 编译器之后,我可以诚实地告诉您,无论哪种方式,您都将进行一次伟大的冒险。在 Borland 的 Builder 和 RAD IDE 上从 C/C++ 迁移是从 Microsoft 的 VC++、C++ 和 .NET(使用了来自第一个 MS-DOS 版本的 VC——米色三环迷你活页夹)的实质性范式转变(和学习曲线)。
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.
C++ 和 Delphi 之间的选择是我建议您在两种语言的一些中小型项目中涉足之后做出的选择。我最初是一名 C 程序员,大约五年后切换到 Delphi (V3.0),当时 VCL 使 Windows 编程变得更加容易和高效。
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.
请注意,对于来自 COBOL、FORTRAN、VisualBasic 等其他语言的程序员来说,Delphi 是一种诱人的语言,因为它的语法和代码规则强制执行了一种可以避免麻烦的纪律。C 的简洁性和原始金属能力使其成为一种出色的系统编程语言(设备驱动程序、O/S 代码、实时嵌入式编程),但在没有经验的人手中它可能会咬你。
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.
Borland 的 C++ Builder(Delphi 的 VCL 添加到 C++ 编译器)去掉了许多 C++ 锋利的边缘,是我第二喜欢的语言。由于 Borland 为这两种语言都添加了 .NET 支持,因此使用 Builder 而不是 VC++ 进行 MS 框架编程是一个强有力的论据。尽管与 C++ 相比,C# 内置了大量的“友好性”,但如果我刚开始使用,我仍然会坚持使用 Delphi 或 Builder。
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.
对于学习绳索、原型设计和快速概念程序,根本没有一种语言可以击败 Delphi,尤其是在使用 VCL 和第三方组件时。没有炒作,只有事实。
回答by Dónal
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.
就个人而言,我认为除了语言之间的差异之外,还有其他重要的考虑因素。例如,Delphi IDE 以 WYSIWYG 方式构建 GUI 简直太棒了。我没有使用过 C++ builder IDE,但如果它有一个和 Delphi 一样好的 GUI 构建器,我会很惊讶。
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....
虽然表面上C++的语法看起来更像Java,但Delphi的对象模型实际上更接近Java。尽管 Delphi 中存在指针,但在实践中对象引用(如 Java 中的那些)在 99% 的时间里都被使用。即使在现代 C++ 中,我也不认为可以避免使用指针。并不是说指针本身有什么问题,而是在实践中......
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 :)
就我个人而言,这些天我主要是一个 Java 人,但我花了 2 年的时间在 Delphi 上工作,并且很快就会回到它。相比之下,我对 C++ 的经验非常有限,宁愿打扫厕所也不愿回到那种语言:)
回答by Giacomo Degli Esposti
Of course java sintax is more like c++ than like delphi, but I think that the object model is more similar to delphi:
当然java sintax更像c++而不像delphi,但是我觉得对象模型更像delphi:
- single inheritance. Interfaces exist but are more like COM than like java interfaces.
- objects are allocated on the heap and accessed by reference
- 单一继承。接口存在但更像是 COM 而不是 Java 接口。
- 对象在堆上分配并通过引用访问
you can find a paper comparing the three languages here
您可以在此处找到比较三种语言的论文
回答by Mohammed Nasman
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
我认为如果你使用 Delphi 你会发现它在使用几次后会更容易,而且它有更多的第三方支持和一些在 C++ Builder 之前在 Delphi 中引入的功能
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
还阅读了这篇来自前 Java 的博客,现在是 Delphi 中大部分数据库和数据快照工作的幕后推手 Steve Shaughnessy,关于他在使用 Java 10 年后编写 Delphi 的经验:-) http://blogs.codegear.com/steveshaughnessy/ 2006/12/03/30193
回答by Roger Nelson
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.
在 C++ VCL 中没有什么是我无法用 Delphi VCL 做的,而且几乎所有的 Delphi 组件在 C++ Builder 中都可以正常工作。因为我同时为 Windows 和 UNIX 编程,所以 C++ 更具可移植性。
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.
如果你为你的容器使用 C++ STL 或其他精心设计的库,垃圾收集有点成为一个有争议的问题,否则手动 GC 并不难(一个人很快就会养成良好的习惯——不管是什么 GC,你都应该练习)。只要您在可能的情况下使用 RAII,将内存管理封装在容器中,明确对象所有权并仅将指针用作可空引用(所有这些都应该与语言无关),GC 真的不应该是问题。
回答by Rob K
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.
如果您要进行大量 Windows 编程,请学习 C++。你会为了去法国旅行而学习德语吗?C/C++ 是 Windows API 的本地语言。在 C/C++ 中处理 WinAPI 数据结构和调用要简单得多。至于 RAD,我已经使用 MSVC 大约 13 年了,我可以像使用 Visual Studio 的 GUI 编辑器的任何人一样快速地组合一个 GUI 应用程序。
回答by Fabricio Araujo
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 ;-)
在过去的 10 年里,我在 Delphi 中进行专业编程,并且对 C++ 有很好的了解。我会去德尔福的方式。语法更简单,内存管理也更简单。本地 Delphi 的 GC 我还没有听说过...虽然我不太喜欢 Delphi.Net 代码上的陷阱,因为 .NET gc,但我不太喜欢 gcs ;-)

