Datasheet

5
Chapter 1: Defi ning the Language Environment
Considering the C# Language
This book is about using the C# language to develop applications of various types. You’ll work through
the particulars of designing an application that relies on C# as its main language. C# is a great language
for many uses. For example, it’s possibly the best language that Microsoft makes available for develop-
ing applications that use a combination of native code and managed libraries. The Platform Invoke (P/
Invoke) capability of C# is signifi cantly better than other Microsoft languages. However, C# isn’t a per-
fect language, so you need to understand its defi ciencies and consider how you can use other languages
to overcome these de ciencies. The following sections discuss these issues.
Understanding the Benefi ts
In many respects, C# and Visual Basic.NET are very much alike. Both contain all the common coding
elements you might expect. It’s possible to create conditional statements, loops, structures, classes, and
all the other common elements found in applications using either language. The fact that the syntax
differs slightly between languages isn’t a major concern. However, C# does possess certain benefi ts
not found in Visual Basic.NET that may affect your decision to use C# as your main programming lan-
guage. The following sections discuss each of these benefi ts and defi ne why you should consider them
when defi ning your language environment.
C/C++-Like Syntax
The future of development for most organizations is some type of managed code. Using the .NET
Framework provides a considerable number of benefi ts when compared to native code languages such
as C++. For example, working with a managed application means that the developer no longer needs
to worry about memory allocated for managed needs because garbage collection handles that require-
ment for the developer. The vast number of viruses and other nasty software on the market that rely on
memory errors to do their dirty work attests to the need for this kind of automated memory allocation
arrangement.
Unfortunately, most organizations cant simply drop all their native code in favor of a managed alter-
native. Consequently, you may fi nd that you need to maintain that C++ code sitting in your library for
quite some time. Because C# and C/C++ share so many syntax features, it’s easy for C/C++ developers
to move between C# and C/C++ as needed. The transition isnt without some learning curve, but the
curve is signi cantly smaller than moving to some other language. It really is relatively easy to write
code using C# one day and C/C++ the next.
While it’s possible to create managed code using C++, most developers consider the process extremely
diffi cult. Unlike other .NET languages, C++ requires that you follow some absurd coding practices.
Most developers prefer to use C# when needed to create managed applications.
It’s important to note that the brace construction used to delimit blocks of code in C# also appears in a
number of other languages such as Java and JavaScript. In fact, there are enough similarities with these
other languages that a C# developer can probably learn Java or JavaScript with relative ease when com-
pared to learning a language that relies on other construction techniques such as Visual Basic.
The designers of C# and Java both wanted to improve on some primary problems with C++. Here’s
a list of some of the features that C# and Java share that help you create a better language environ-
ment than using C++ as your language of choice (you can fi nd some other interesting comparisons at
15962c01.indd 515962c01.indd 5 1/23/09 5:44:59 AM1/23/09 5:44:59 AM