JAVA程序员眼里的C#
September 03, 2004
There are two ways to compare programming languages: a religious war and a "we just don't care" type of attitude. I will try to find the middle ground and start with generalities. The key feature of both Java and C# is automated memory management. Of course this makes both languages useless for writing an operating system kernel, but it makes application development significantly easier because
Chances of a memory leak are minimized
We don't have to write code to free up memory
We can write f(g(x)) and not worry about freeing up memory used by the return value of g(x).
So, we have two popular software development platforms. Each of the two is used by millions of software developers and is backed by a world famous software giant, but neither one carries any revolutionary advantages.
Influence of Microsoft
Historically Java came about earlier than .NET and slowly captured not only the server-side software market, but also the market of corporate client oriented GUI applications. The reasons were that C++ is too complex for making forms, Visual Basic doesn't feel like a cool developer's language, and Borland invested more into Java than into Delphi.
However, the more Java applications there are, the smaller the demand for Windows. So Microsoft decided not to support Java, and to create .NET in order to stimulate the development of software designed to run on Windows. Of course .NET has some cross-platform compatibility, but from the point of view of Windows, .NET is trying to become a part of the operating system like Internet Explorer. The career of a .NET developer supposes a close partnership with Microsoft including the use of the Visual Studio Development Environment, MS SQL database, and the versioning control system Visual SourceSafe.
Microsoft marketing deserves a lot of credit for the fact that many software development companies tend to think about software entirely within the Microsoft framework. Because of that, sometimes we have to put aside beloved Java, and make use of C#. The good news is, the experience gained while working with Java is helpful with .NET, and development of .NET is motivating progress of Java.
CVS vs. VSS
The majority of Java developers have gotten used to CVS, after which a move to Visual SourceSafe combined with its integration into Visual Studio and the solutions-projects concept is perceived as quite painful. To be fair we must note that the use of CVS in a large project is theoretically possible, but triggers a negative reaction of people, used to working with VSS.
Here I could throw some punches on the subject of "why is CVS better than VSS", but I will not do that because CVS isn't perfect either. Then there is a project called "Subversion" which is openly positioned as the replacement for CVS. Neither does Microsoft consider VSS as its flagship product, and is working on a replacement for it in the form of the Visual Studio 2005 Team System.
The influence of VB.NET
Many languages can be compiled into byte code for JVM, but practically all the software for the Java platform is written in Java itself. A project for .NET can equally likely be written in either C# or VB.NET, and quite often both languages are used.
Clearly C# and VB.NET have very few differences, except for the syntax, but create a divide in the community of developers. Even if you write exclusively in C#, in the results of a support documentation search you will always find material related to VB.NET. In a desktop version of MSDN one can filter the content by programming language, yet I still find the Java documentation much more convenient and helpful.
GUI development
GUI development in C# is a typical example of RAD, like Delphi. In Java the GUI is usually done with Swing. Even though Swing is quite large and complex, the fact that the architecture is well thought out and scalable combined with the availability of the source code allows for development of GUI of any complexity.
Web application development
I have a lot of experience in web application development in Java, and never have I worked with ASP.NET. However I readily accept ASP.NET having some minor advantages when it comes to creating small scale web sites. However these advantages separate web-applications into a distinct segment of software. Many developers specialize in either web development or GUI development. In Java web-applications can easily be created without the use of special technologies like JSP, JSTL or Struts. All you have to say is extends HttpServlet.
Of course Java will not easily give up the market of web development. We can expect more news from JavaServer Faces and Fabrique. In any case web page development is not among the most complicated problems for a modern programming language.
Is everything object?
In Java there is a popular slogan "Everything is object", in C# this would not be true. The first thing that stands out is the existence of structures in C#. Obviously we are motivated to use structures to increase productivity, but I think modern computers are productive enough not to require the addition of another entity in a programming language.
Also anonymous classes are replaced by delegates in C#. This is the idea that if a method has a definite set of arguments and a given return type, it is absolutely unimportant what its name is and whether or not it is static, or any other nonsense. You can just call it.
While we are on the subject of delegates, we should also mention events. They really do decrease the code volume in GUI development. However this comes at a price of going against OOP principles.
In addition C# has some added abilities, which are not present in Java. Without going into much detail, I will mention operator overloading, and keywords such as virtual, override, ref, out and param.
The influence of the development platform on the programmer's self-consciousness
Without a doubt, the one thing that influences the quality of software is the quality of software developers, and not the programming language. Nevertheless, my experience tells me that in the majority of Java projects Ant is used for build management. On the other hand in .NET, builds are often done with tools built into Visual Studio, even though analogous instruments exist for .NET. Besides, C# does not have clear rules for naming classes and storing them on disk. This often creates additional confusion (which qualified programmers successfully overcome).
C# doesn't have checked exceptions, the reasons for which are explained here. This decision has its reasons, but if the compiler doesn't control handling checked exception, there needs to be more information on how to work with errors through other communication channels. Otherwise some programmers will not even know what exceptions are.
The tigers are charging forward
There are certain areas where Java is clearly dominating, for example cellular phone games and the JavaCard technology. However, the struggle for market share between C# and Java will go on for a long time to come. Both platforms will be improved. For example both Java 5 and .NET 2.0 will support generics.
It is obvious that the success of every individual project will depend not on the programming language used, but on the understanding of the task, knowing how to give understandable names to methods, ability to avoid repetitious code, and other universal virtues.
Acknowledgements
I really appreciate the help of Dmitry Jemerov, thanks to whom you didn't have to read any of the nonsense which I wrote at first. I also thank DataArt company, which gave me a chance to study C# on the job, my colleagues at DataArt, who gave me intellectual help and boosted my moral, and the JetBrains company for good timing in developing the ReSarper tool, which allows me to have almost as much fun with C# as I am used to having with IntelliJ IDEA. A special thanks to Alexey Pchelintsev for editing the Russian version and to Pavel Sokolov for the translation.
References
The C# Programming Language for Java Developers
http://msdn.microsoft.com/vstudio/java/gettingstarted/csharpforjava/
J2EE fundamentals for .NET developers
http://www-106.ibm.com/developerworks/java/library/j-roadmap1/
Yakov Sirotkin
Senior Developer, DataArt
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论