📜 ⬆️ ⬇️

Unfinished transition history from Delphi to C #

Foreword


Good day to all. Since 2003, and to this day, I have been professionally developing application software in the Delphi 7 environment - Delphi 2010. And I must say that this work allows me to earn good enough bread and enjoy the respect of my colleagues in several organizations with which I work.
But many certainly know about the difficulties of the company Borland, and as a result of the disastrous fate of several, released in a row, versions of Delphi. All Delphi, from version 8 (~ 2003) to 2007, were not just unpopular. Their IDEs were extremely unstable. Fatal development environment crashes requiring a restart have become an integral part of the programming process. The language itself was changing so slightly that most developers could only vaguely mumble a question: “What has changed in the new version?”: “Well, it seems, new components have been added ...”. And only in 2009, CodeGear, which separated from Borland, was able to bring to the market a relatively stable RAD Studio 2009, including a new version of Delphi. Summing up, we get more than 6 years of stagnation, against the background of rapidly developing information technologies.
Therefore, to this day, a significant percentage of professional developers Delphi works in the 7th version. I can only sympathize with their perseverance and advise (if they continue to want to work with Delphi) to learn Delphi 2010 as soon as possible. Compared to Delphi 7, the 2010 version is a qualitative leap forward. I will not dwell on the comparison, because it does not diverge with the topic of the article, but I can not keep silent. Such people need to be motivated more often, because addiction can be a significant obstacle to professional development. Turning to version 2010, you will get a stable IDE that is significantly superior to Delphi 7 in terms of operating comfort. From the language features, you will get unicode support , the ability to work with generic types, and anonymous methods that can also fruitfully affect the quality of the code and speed of work.

Start


Many of you are aware of the heated discussions caused by themes like Firefox vs Opera, iOS vs Anrdoid, Intel vs AMD, ATI vs NVidia, Oracle vs MsSql, etc. And, at times, it seems that such discussions are extremely useless and even destructive: the passions overwhelm, it is difficult for people to resist insults and becoming personal, but to no avail, everyone remains in their opinion. In the programming world, such discussions are not uncommon. Remember: Java vs C #, Delphi vs C ++, HTML 5 vs Silverlight, Perl vs Python.
Starting around 2003, after the release of Visual Studio 2003, the debates of Delphi vs C # have not subsided. I must say that Delphi programmers have always managed to give a fitting rebuff to their opponents. Since 2006, I have gone head over to work and have almost stopped attending forums, and even more so to participate in such disputes. In my opinion, in the fall of 2009, I pulled away from the next project and was surprised to find that in the disputes between the developers of Delphi and C #, the latter are confidently winning. Delphi programmers have virtually nothing to oppose the innovations of Visual Studio and C #. And even with the release of Delphi 2009, the situation has not changed, but only worsened. To the comments that support for Unicode was added to Delphi 2009, supporters of C # could answer: “Not even 10 years have passed. C # supports Unicode from the very first version. ” With someone's light hand, Embarcadero began to be called “bydlokadero,” and many Delphi programmers began to write that they were switching to C ++, Java or C #.
There were a couple more points that made me come to grips with learning C #. The first of them occurred in 2009, when I was sent to Delphi 2009 courses. In these courses, the teacher and just the smartest person Volkov Vladimir Borisovich noted with sadness how Microsoft actually crushed Borland, and that the .NET Framework already contained a much richer set classes, rather than modules and Delphi components.
The second point was the information that Anders Hejlsberg, who was the chief architect of Borland and who worked on translating Turbo Pascal into object-oriented object-oriented object language (later Delphi), works on C # architecture. This man was the driving force behind the development of Delphi, and perhaps without it, Delphi developers have been treading water for so many years. I think that in the C # architecture, he was able to implement everything that he wanted to invest in the development of Delphi, but could not because of Borland’s policies and financial problems.

Studying C #


Perhaps due to the common two-language architect Anders Hejlesberg, for me, as a Delphi programmer, it was not too difficult to learn C #. I think that an important role was played here by the fact that I began studying C # by reading the Andrew Troelsen book C # 2008 Programming Language and Platform. NET 3.0. The availability and detail of the presentation makes this book a very good starting platform for preparing a C # programmer.
Here I want to make a small digression, and tell you that Delphi, in my time, I studied more with practical examples while working, asking advice from more experienced colleagues and asking questions in the forums. And now I understand that for more fruitful work I lacked a good theoretical basis. My big mistake was that I was too lazy to buy quality literature and study in detail several books on Delphi. This would allow me to master the language at least a couple of times faster. By the way, now, if you try to search for books on Delphi, you will hardly find anything. Is that Osipova, the price of the book which fell to 50 rubles per 1000 page book, simply because no one buys them.
A completely different picture takes shape in the C #, Visual Studio, and .NET areas. Literature a huge amount for every taste. There are also very high-quality books that are not difficult to find among the total abundance of readers reviews. I’ll name a few more books that allowed me to familiarize myself and adequately master C # and its surrounding technologies:

I read them in that order, after reading Troelsen. Some parallel at home and at work. Trying to understand each example, repeating after reading the key points studied. There were other books, but I included in the list only those read and liked. They have a good theoretical foundation that allows me to solve problems in C # quickly and efficiently, even in comparison with the speed of my work in Delphi. And this is despite the fact that I have been working with Delphi for more than 8 years, and this language is the main one at my current place of work, and C # I came to grips less than a year and a half ago.
Mr. Schildt provides a good basic knowledge of the .NET Framework namespaces and classes. Mac-Donald reveals the essence of Microsoft's new approach to building a user interface through the XAML markup language, which is almost universal for both Windows and Web applications.
The book Trey Nesha has probably made the strongest impression on me due to the high level of the author’s skill. It will give you knowledge of functional programming in C #, describe the paths and levels of synchronization of a multi-threaded application, and lay the foundation for writing safe code. I think that professionals, having read his book, will be able to climb a couple of steps higher. But it needs to be read, having a good preparation on C # behind shoulders.
Albahari’s book will help you learn in detail about the new LINQ integrated query language introduced in C # 3.0. His knowledge will allow you with the least effort to extract the necessary information from arrays, collections, XML documents and databases (mainly MsSQL, but thanks to the Entity Framework, the list of supported databases can be expanded).
Arsenovski reveals the current refactoring theme. But unlike other authors, his book focuses on the specifics of the C # language, as well as using the features of the language and the Visual Studio environment to implement refactoring techniques. All examples are given in C #.
You can talk a lot about books. And here on Habré I came across articles about the benefits of reading for professional development. I just want to encourage those who take up the study of a new area for him to have patience, choose and buy several books on a given topic, and every day at least half an hour a day to devote reading and study. For myself, I chose this strategy. If the book that I read is quite complicated, then I read it 10 pages per day, diluting it with lighter literature (such as the best-selling book “Joel on Programming”). Otherwise I try to read special literature at least 20 pages per day. With this approach, almost no book is left behind for you for more than 2 months, and, as a rule, it will be read even faster.

What I miss in C # and Visual Studio


Having worked closely with two languages ​​and two programming environments, and making a clear choice for C # and Visual Studio, I naturally began to notice some features of the language and IDE, which in Delphi I was more comfortable with. This is about the same feeling as if for four years in a row to ride a single bike, which basically suited you almost everyone, and then buy and transfer to a new, more modern one, with hydraulic disc brakes, a lightweight frame, 27 speeds and other twists . Almost immediately, the nuances that were realized better on the old bike will be visible: the seat doesn’t bite into the nth place, the foot sits on the pedals better, the handlebars do not rub their hands like that, etc.
So. The list of what I lack in C # and Visual Studio versus Delphi and RAD Studio:
')
Check for hit in the set

In Delphi, it is possible to check for a number (within one byte, i.e. about 0 to 255), or an ANSI character into a set, like this:
  1. procedure CheckID;
  2. var
  3.  id: byte;
  4.  
  5.  function GetID: byte;
  6.  begin
  7.   result := Random(256);
  8.  end;
  9.  
  10. begin
  11.  id := GetID;
  12.  if id in [37..75,100] then // <-
  13.   ShowMessage(', : ' + IntToStr(id));
  14. end;

, , , .
C# . :
  1.     private void CheckID()
  2.     {
  3.       HashSet<byte> set = new HashSet<byte>(new byte[] {100});
  4.       for (byte i = 37; i <= 75; i++)
  5.         set.Add(i);
  6.  
  7.       byte id = GetID();
  8.  
  9.       if (set.Contains(id))
  10.         MessageBox.Show(", : " + id);
  11.     }
  12.  
  13.     private byte GetID()
  14.     {
  15.       Random random = new Random();
  16.       return (byte)random.Next(256);
  17.     }

, - C#, , . , Delphi 12- “[37..75,100]”, C# 3 , .


Delphi , , , ( “” Delphi , , , C# , Delphi ). GetID . , , . C# - , , Delphi, :
  1.     private void CheckID()
  2.     {
  3.       Func<byte> getID = () =>
  4.       {
  5.         Random random = new Random();
  6.         return (byte)random.Next(256);
  7.       };
  8.  
  9.       HashSet<byte> set = new HashSet<byte>(new byte[] {100});
  10.       for (byte i = 37; i <= 75; i++)
  11.         set.Add(i);
  12.  
  13.       byte id = getID();
  14.  
  15.       if (set.Contains(id))
  16.         MessageBox.Show(", : " + id);
  17.     }



, , Delphi . , , . C#:
  1.   class Employee
  2.   {
  3.   }
  4.  
  5.   class Manager : Employee
  6.   {
  7.     public byte GetBonus()
  8.     {
  9.       return 5;
  10.     }
  11.   }
  12. //…..
  13.     private void ShowManagerBonus()
  14.     {
  15.       Employee manager = new Manager();
  16.       MessageBox.Show(" : " + ((Manager)manager).GetBonus());
  17.     }

Manager. Delphi :
  1. Manager(manager).GetBonus;
C#:
  1. ((Manager)manager).GetBonus();

, Delphi . , C# as. , Delphi .

TStringList

Delphi TStringList, . ( StringReader, StreamReader) C#, StringBuilder.
, C:\1.txt : “ !”. Delphi :
  1. procedure ChangeFile;
  2. const
  3.  fileName = 'C:\1.txt';
  4. var
  5.  stringList: TStringList;
  6. begin
  7.  try
  8.   stringList := TStringList.Create;
  9.   stringList.LoadFromFile(fileName);
  10.   stringList.Insert(0, ' !');
  11.   stringList.SaveToFile(fileName);
  12.  finally
  13.   FreeAndNil(stringList);
  14.  end;
  15. end;

C#. , , .


, .NET Framework POP IMAP. . , . MSDN . . , .NET  .. Delphi, Indy, .


, , Visual Studio . , RAD Studio : Shift + Ctrl + , Ctrl + . , . - , . , Visual Studio. , , .


, . , Visual Studio . , . , Delphi, 2009. RAD Studio Ctrl + f , , . Enter , . «» «» .
image

, Delphi ? , , firefox .

, Delphi. , C# . , C#.


. , , Delphi . Delphi C#, Delphi C#. . , . , - . C# , . : « , ».

Source: https://habr.com/ru/post/111424/


All Articles