开发者

Delphi developer switching to C#

开发者 https://www.devze.com 2023-02-05 12:39 出处:网络
I\'m a Delphiholic for quite some time now and lately I was thinking of learning some C# as well, however I\'m kinda\' \"afraid of the unknown\", I\'ve done some simple apps as a test drive for C# and

I'm a Delphiholic for quite some time now and lately I was thinking of learning some C# as well, however I'm kinda' "afraid of the unknown", I've done some simple apps as a test drive for C# and I have to admit that I've liked it, HOWEVER I do not really like the IDE... that being said h开发者_StackOverflow社区ere's the question that I would appreciate if others who went down this path would answer:

As a Delphi developer what are the "main basic" changes from the Delphi language(by basic I mean basic -- utility functions, streams, etc.), I'm used to add "System, Classes, Windows" to uses not "use System.XXX.YYY.ZZZ", I'm trying to make a partial equality in my mind from Delphi to C# until I can see where does Delphi go hand-in-hand with C# and so on...

I hope the question is pretty clear, if not, do not hesitate to swear me and I'll try to clarify as well as I can :-)


I heavily use both for software development.

Development speed of server apps (web apps, web services, windows services) is much higher in .NET.

Development speed of business apps (pure Windows UI) is much higher in Delphi.

Development of sexy apps is a pain in both environments.

A few things you should know:

  • Learning the .NET framework will take a lot of time: it is huge, but contains a lot of gizmos (some gems are really well hidden).
  • Don't lose yourself in following all new trends at once: generics, lambda, LINQ, each are nice, but grasping them all at once is only for a few of us
  • For web apps, skip WebForms, but learn ASP.NET MVVC (yes, the Ruby guys were right after all); learn HTML 5 and JavaScript too.
  • For sexy Windows apps, learn WPF, but be prepared for a steep learning curve (designer, and framework are radically different)
  • Don't get a too sexy UI: it costs you a disproportional amount of time while your users are waiting for functionality
  • Like the market has been bashing Delphi since version 1, the market is bashing SilverLight too
  • Skip WinForms; if you need something like WinForms, then Delphi is way more productive (even more so if you have an existing Delphi VCL codebase).
  • WPF is just as thread-friendly as the VCL or WinForms (read: neither of the 3 is thread friendly)
  • Don't perform rewrites of your Delphi stuff in .NET (or for that matter any other 1:1 rewrite from platform A into platform B): it is a waste of your time.
  • Threading and synchronization are a pain in all development environments. The pain is not so much in the general stuff (the Concurrent Collections in the .NET 4 framework helps, as do the Delphi OmniThreadLibrary), but in getting the final details and exception cases right is the real pain.
  • Garbage collection does not mean that you won't leak memory: it means that you won't leak when your app terminates, but while it runs the leaks are way harder to detect (boy, I wish I had the FastMM memory monitor for .NET)

--jeroen


The "main basic" changes are that .NET's library is object-oriented. For example, instead of global string functions that are spread between System, SysUtils, StringUtils, etc., they're all just static methods on the String class. Instead of global path-manipulation functions, they're static methods on the Path class or the File class. Instead of TextFile/AssignFile/Rewrite, you create a StreamReader (or just call the static File.ReadAllLines or ReadAllText if the file is small). Most things are fairly discoverable with a bit of poking around. There are a few things missing; for example, there's no IncludeTrailingPathDelimiter method in .NET (though you usually don't need it -- Path.Combine is better).

I'll second the suggestion to skip WinForms. If you've used the Delphi VCL, WinForms will be familiar and yet frustratingly, maddeningly inadequate. They took the basic ideas from the VCL but never bothered to give it the slightest depth, or even usability. There's no equivalent for TAction/TActionList, the Dock property (equivalent to Delphi's Align) likes to hide controls behind each other until you mess around with "Bring to Front" / "Send to Back", tooltips require an extra component on your form, there's only a tiny handful of controls, and that's just off the top of my head. Take the time to learn WPF; it's got all the richness of the VCL and more, and will have you spend much less time beating your head against the wall.

The IDE takes some getting used to, but I like it far better than Delphi. You have to learn a different set of keystrokes, but that's no big deal. The IDE is more responsive (none of that locking up during "background" compilation). It also has some kick-ass add-ons -- after you've used ReSharper for a while, you won't miss the Delphi IDE a bit.

0

精彩评论

暂无评论...
验证码 换一张
取 消