Given that .NET is such a radical departure from previous technologies, Microsoft has developed
a new programming language, C# (pronounced “see sharp”), specifically for this new platform.
C# is a programming language that looks very similar (but not identical) to the syntax of Java.
However, to call C# a Java rip-off is inaccurate. Both C# and Java are based on the syntactical
constructs of C++. Just as Java is in many ways a cleaned-up version of C++, C# can be viewed as
a cleaned-up version of Java—after all, they are all in the same family of languages.
The truth of the matter is that many of C#’s syntactic constructs are modeled after various
aspects of Visual Basic 6.0 and C++. For example, like VB6, C# supports the notion of formal type
properties (as opposed to traditional getter and setter methods) and the ability to declare methods
taking varying number of arguments (via parameter arrays). Like C++, C# allows you to overload
operators, as well as to create structures, enumerations, and callback functions (via delegates).
Due to the fact that C# is a hybrid of numerous languages, the result is a product that is as
syntactically clean—if not cleaner—than Java, is about as simple as VB6, and provides just about
as much power and flexibility as C++ (without the associated ugly bits). In a nutshell, the C# language
offers the following features (many of which are shared by other .NET-aware programming
languages):
• No pointers required! C# programs typically have no need for direct pointer manipulation
(although you are free to drop down to that level if absolutely necessary).
• Automatic memory management through garbage collection. Given this, C# does not support
a delete keyword.
• Formal syntactic constructs for enumerations, structures, and class properties.
• The C++-like ability to overload operators for a custom type, without the complexity (e.g.,
making sure to “return *this to allow chaining” is not your problem).
• As of C# 2005, the ability to build generic types and generic members using a syntax very similar
to C++ templates.
• Full support for interface-based programming techniques.
• Full support for aspect-oriented programming (AOP) techniques via attributes. This brand of
development allows you to assign characteristics to types and their members to further qualify
their behavior.
Perhaps the most important point to understand about the C# language shipped with the
Microsoft .NET platform is that it can only produce code that can execute within the .NET runtime
(you could never use C# to build a native COM server or a unmanaged Win32 API application).
Officially speaking, the term used to describe the code targeting the .NET runtime is managed code.
The binary unit that contains the managed code is termed an assembly (more details on assemblies
in just a bit). Conversely, code that cannot be directly hosted by the .NET runtime is termed
unmanaged code.
Additional .NET-Aware Programming Languages
Understand that C# is not the only language targeting the .NET platform. When the .NET platform
was first revealed to the general public during the 2000 Microsoft Professional Developers Conference
(PDC), several vendors announced they were busy building .NET-aware versions of their
respective compilers. At the time of this writing, dozens of different languages have undergone
.NET enlightenment. In addition to the five languages that ship with Visual Studio 2005 (C#, J#,
Visual Basic .NET, Managed Extensions for C++, and JScript .NET), there are .NET compilers for
Smalltalk, COBOL, and Pascal (to name a few).
Although this book focuses (almost) exclusively on C#, Table 1-1 lists a number of .NET-enabled
programming languages and where to learn more about them (do note that these URLs are subject
to change).
Table 1-1. A Sampling of .NET-Aware Programming Languages
.NET Language Web Link Meaning in Life
http://www.oberon.ethz.ch/oberon.net Homepage for Active Oberon .NET.
http://www.usafa.af.mil/df/dfcs/bios/ Homepage for A# (a port of Ada to the .NET platform).
mcc_html/a_sharp.cfm
http://www.netcobol.com For those interested in COBOL .NET.
http://www.eiffel.com For those interested in Eiffel .NET.
http://www.dataman.ro/dforth For those interested in Forth .NET.
http://www.silverfrost.com/11/ftn95/ For those interested in Fortran .NET.
ftn95_fortran_95_for_windows.asp
http://www.vmx-net.com Yes, even Smalltalk .NET is available.
Please be aware that Table 1-1 is not exhaustive. Numerous websites maintain a list of .NET-aware
compilers, one of which would be http://www.dotnetpowered.com/languages.aspx (again, the exact
URL is subject to change). I encourage you to visit this page, as you are sure to find many .NET
languages worth investigating (LISP .NET, anyone?).
Life in aMultilanguage World
As developers first come to understand the language-agnostic nature of .NET, numerous questions
arise. The most prevalent of these questions would have to be, “If all .NET languages compile down
to ‘managed code,’ why do we need more than one compiler?” There are a number of ways to answer
this question. First, we programmers are a very particular lot when it comes to our choice of programming
language (myself included). Some of us prefer languages full of semicolons and curly brackets,
with as few language keywords as possible. Others enjoy a language that offers more “human-readable”
syntactic tokens (such as Visual Basic .NET). Still others may want to leverage their mainframe skills
while moving to the .NET platform (via COBOL .NET).
Now, be honest. If Microsoft were to build a single “official” .NET language that was derived
from the BASIC family of languages, can you really say all programmers would be happy with this
choice? Or, if the only “official” .NET language was based on Fortran syntax, imagine all the folks out
there who would ignore .NET altogether. Because the .NET runtime couldn't care less which language
was used to build a block of managed code, .NET programmers can stay true to their syntactic preferences,
and share the compiled assemblies among teammates, departments, and external
organizations (regardless of which .NET language others choose to use).
Another excellent byproduct of integrating various .NET languages into a single unified software
solution is the simple fact that all programming languages have their own sets of strengths and weaknesses.
For example, some programming languages offer excellent intrinsic support for advanced
mathematical processing. Others offer superior support for financial calculations, logical calculations,
interaction with mainframe computers, and so forth. When you take the strengths of a particular programming
language and then incorporate the benefits provided by the .NET platform, everybody wins.
Of course, in reality the chances are quite good that you will spend much of your time building
software using your .NET language of choice. However, once you learn the syntax of one .NET language,
it is very easy to master another. This is also quite beneficial, especially to the consultants of
the world. If your language of choice happens to be C#, but you are placed at a client site that has
committed to Visual Basic .NET, you should be able to parse the existing code body almost instantly
(honest!) while still continuing to leverage the .NET Framework. Enough said.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment