发信人: heaven (2003的第一天), 信区: Npsos
标  题: java  VS  .net(转载)
发信站: 哈工大紫丁香 (2003年01月03日15:28:17 星期五), 站内信件

【 以下文字转载自 Java 讨论区 】
【 原文由 yangxile 所发表 】
<image src=http://www.java.com.cn/img/logo.gif>                 
               Java will beat Microsoft .NET
Newcomers to Java and .NET might be struck by how similar the two competing pl
atforms are. This is no accident: Microsoft and the Java community are engaged
 in an arms race. Neither platform can take a good idea very far without the o
ther side's noticing. 

Therefore, while many comparisons of Java and .NET focus on the goals and capa
bilities of the two platforms, that approach seems pointless. The two competin
g technologies can pretty much do the same things, and they share the same goa
l: to attract as many developers as possible. Indeed, their differences are mo
stly stylistic and aesthetic. However, as someone who researches and develops 
technologies for a living, I've come to a clear decision: Java suits me, and m
ost people I encounter, better than .NET. In this short article, I'll explain 
some of the reasons why. 

Wait! What is .NET?
If you're a Java developer -- and perhaps even if you work with Windows -- you
 might not yet know what .NET is. In fact, Microsoft uses the term ".NET" to d
escribe two completely different things. First, .NET is a framework for web se
rvices, or XML-accessible components. However, web services are actually one t
hing Microsoft doesn't have a monopoly on. They represent a simple, platform-i
ndependent concept that can be realized just as easily with Java as with .NET.
 The topic is therefore not a useful way to distinguish the two platforms, and
 I won't discuss it much in this article. 

Instead, we'll focus on the other meaning of ".NET", which centers on Microsof
t's Common Language Runtime (CLR). This is a new framework for developing and 
executing software, and it represents .NET's technical core. This is the half 
of .NET that we can sink our teeth into and compare to Java. 

1. C# versus Java
We'll begin the comparison by looking at C#, the CLR's core language. Although
 .NET allows developers to use multiple languages -- as we'll discuss later --
 C# in many ways represents .NET's design center. Broadly, C# is a successor t
o C++, and it actually borrows many good ideas from Java. 

However, in the words of James Gosling, Java's founder, it also adds a number 
of features that are "outright stupid." 

For example, one of the things that motivated me to begin to use Java, many ye
ars ago, was strict error checking, known as exception handling. In fact, this
 issue became so important to me that I consider poor exception handling a sho
w-stopper for a programming language. 

Java's exception handling has the same goal as professional accountants: it ma
kes sure no item is forgotten or swept under the rug. The exception handling i
n C#, however, is closer in spirit to the accounting practices of Enron: in C#
, a programmer can simply ignore exceptions if it suits his immediate purposes
. More technically, a C# method that throws an exception doesn't have to -- an
d, in fact, can't -- declare formally that it throws it. The end result is tha
t it's much harder to answer the simple question, "Does your program work?" If
 I don't even know what errors an API I use might encounter, how can I reasona
bly be expected to account for them? Java's exception handling does allow slop
piness in the wrong hands, but overall, it helps ensure that potential errors 
are handled properly. 

As an example of another major problem, the fact that C# lets you use C-style 
pointers is disastrous. C# lets you write error-prone code, with the potential
 to wreak havoc with your program's address space, as long as you mark the cod
e as "unsafe." This is reminiscent of a sign I recently saw at a restaurant in
 the Chicago airport: "By law, we are required to post that we have failed a h
ealth inspection within the last two months." (Guess whether I ate there or no
t.) The fact that a library might contain "unsafe" code should be enough reaso
n to avoid using it in the first place. 

In fairness, C# does add a number of useful syntactic features beyond what Jav
a provides. You can write code to loop over data a little more easily in C# th
an in Java. C# makes it easy to set up JavaBean-style properties, and its 'swi
tch' statement works better than C's and Java's. But these features are insubs
tantial; they represent minor syntactic conveniences rather than major, revolu
tionary changes. The significant differences between Java and C# all point in 
one direction: C# facilitates the poor programming practices that Java's desig
n intentionally avoids. 

2. Multiple languages
Microsoft presents .NET as a platform that supports interoperability and porta
bility. In practical terms, the true cross-platform portability of .NET -- tha
t is, the chance that you'll ever run any C# code on your OpenBSD laptop -- is
 somewhat negligible. But .NET does support multiple general-purpose programmi
ng languages, and this raises an interesting question: Is it important to let 
languages interact at the API level in order to meet the needs of diverse prog
rammers? 

Ultimately, I think the answer is "no" and that this ability of .NET is illuso
ry. The computing industry isn't currently limited by the failure of languages
 like COBOL, Perl, and Eiffel to interact programmatically. Most languages can
 already read the same files as one another, write to the same databases, and 
interact with the same users. .NET doesn't magically transport legacy applicat
ions to the modern world. Instead, it simply allows new extensions to be added
 to languages like COBOL so that they finally work satisfactorily on Windows. 
The end result is a series of languages that can all do the same thing, in sli
ghtly different words and with slightly different organizational concepts. 

Java takes a different approach. Instead of promoting a collection of overlapp
ing, general-purpose languages, the Java platform seems to be moving decisivel
y in favor of focused, task-specific languages. Programmers recognized long ag
o that some tasks deserve special languages of their own. For instance, we acc
ess databases with the Structured Query Language (SQL); we manipulate XML docu
ments using XSL Transformations (XSLT) and the XML Path Language (XPath); we s
olve quick systems-related issues using shell scripts. This spirit manifests i
tself in upcoming Java standards like the JSP Standard Tag Library (JSTL), whi
ch provides essentially a new, high-level language for web development. The fo
rce is seen also in the next revision of JSP, which will likely include a type
less language for referring to objects stored in memory. 

Thus, with the Java platform, programmers can choose a language with as much s
tructure and type safety as they want. Instead of being presented with general
 languages that overlap or whose designs contradict one another, they can choo
se from an array of focused languages designed, from the ground up, with them 
in mind. For instance, HTML designers who know some JavaScript can pick JSTL a
nd a typeless expression language; advanced developers, by contrast, can work 
on application frameworks using servlets and the full power of Java. 

The languages currently available to the .NET developer suggest no such foreth
ought. Instead of providing true flexibility and ordered division of labor, th
ey merely provide alternative syntaxes for the same basic tasks. For those of 
you who invest your money in the stock market, the difference is a little bit 
like having to pick from among a dozen similar mid-cap stock funds (on the .NE
T side) versus an array of choices with meaningfully different risks and rewar
ds (with Java). 

Finally, Java and the languages it supports can run everywhere. .NET is still,
 for all practical purposes, stuck with Windows. 

3. Community support
The Java community has a major advantage: it's a community. Java isn't develop
ed by a single organization; it's a growing architecture supported by most of 
the industry. 

If you're skeptical of the open software "community", keep in mind that the Ja
va Community Process (JCP) isn't some self-important collection of unkempt und
ergraduates and geeks trying to overthrow corporate America. In fact, the JCP 
is driven by professional collaboration among major firms like Sun, Oracle, IB
M, HP, Macromedia, BEA, and Compaq. This situation -- and, I freely admit, the
 infusion of ideas from unkempt undergraduates and lifelong geeks! -- promotes
 interoperability and good design. 

Is community-driven support slow or inefficient? Experience suggests that it i
sn't; so far, Java has been able to adapt quickly to the changing marketplace.
 For instance, Java developers can often download "early-access" releases of n
ew technologies. (One good example of this is the new "Web Services Pack" from
 Sun, which makes it easy to develop web services with Java.) Packages like th
is both facilitate quick adoption of new standards and promote community feedb
ack. 

Summary
.NET represents a number of new ideas, and it borrows some good existing ideas
 from Java. However, it's crippled by technical missteps and a design centered
 on a single operating system. 

Since it lacks a clear technical advantage, the only way for .NET to rise to p
rimacy is for Microsoft's sheer marketing force to propel it there. This might
 be possible, but in this age of increasingly savvy developers, I wouldn't bet
 on it. 

Shawn Bayern is the JSTL reference-implementation lead, is the author of the p
ending JSP Standard Tag Library and co-author of Web Development with Java Ser
ver Pages. 





--

※ 来源:.哈工大紫丁香 http://bbs.hit.edu.cn [FROM: 202.118.235.56]
--
※ 转载:.哈工大紫丁香 bbs.hit.edu.cn.[FROM: 202.118.228.100]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:4.345毫秒