9
Chapter 1: Defi ning the Language Environment
Code Reliability Concerns
When you add the power to work with unsafe code to any language, you also make it possible for the
developer to create unreliable code. The low-level functionality that makes C# attractive also makes it a
dangerous tool in the wrong hands. A developer needs to know how pointers work before using them
in a production environment. The detailed level of debugging that C# provides is only useful when
the developer understands what the debugging displays are showing. It’s possible for a well-meaning
developer to create a terrifying time bomb using the wrong techniques in C#.
C# also assumes developer profi ciency in other areas. For example, Visual Basic checks math opera-
tions and provides the developer with feedback about errors that result in overfl ows or underfl ows. By
default, C# doesn’t check numeric operations. The result is an application that can execute faster than a
comparable Visual Basic application, but this feature is only useful in experienced hands. You can over-
come this C# defi ciency by using the
checked and unchecked contexts within your application.
Another potential code reliability concern is that C# doesn’t automatically correct variable name
punctuation. If you use the wrong case for a variable name in Visual Basic, the Integrated Development
Environment (IDE) automatically corrects the name to use the correct case. Consequently, you could
write a C# application that contains
myVariable, Myvariable, and MyVariable, all three of which are
different variables.
Visual Basic has its own code reliability concern in that strong typing is optional. Without strong
typing, an application can handle data incorrectly and corrupt them. Fortunately, the default in Visual
Basic is to rely on strong typing. In addition, converting
True to a numeric value could yield 1 or -1
depending on the conversion used.
Too Much Information
A Visual Basic developer doesn’t see anything other than essential information. Although the Visual
Basic developer can optionally reveal this information, the default is to keep the programming environ-
ment simple. Consequently, while a C# developer spends time looking through unneeded entries, the
Visual Basic developer can locate a needed item quickly. For example, Visual Basic hides certain project
fi les from Solution Explorer and hides namespace information from the editing area.
Microsoft has embraced information hiding as a means of simplifying interfaces. The information hid-
ing appears more often in user applications such as Offi ce (where, as an example, unused menu options
disappear from view), but it’s interesting to see how the same approach can help developers. Of course,
information hiding also means that a developer has to search for a particular item on the few occasions the
item is necessary for development. Consequently, information hiding is a two-edged sword that normally
works for the developer, but on rare occasions can turn against the developer as well.
Coding Complexities
Anyone will tell you that C# isn’t as complex as C++ when it comes to creating programming constructs,
but you’ll also discover that languages such as Visual Basic make coding even easier. For example,
creating delegates is considerably simpler in Visual Basic than in C# because Visual Basic lets you use
AddressOf MyObject.MyFunction to access the delegate function.
One of the major missing elements in C# is optional parameters. Both Visual Basic and C++ support
optional parameters. The lack of this feature makes it considerably harder to create Offi ce applications
using C#. In addition, C# lacks support for variables in property methods, which may make it harder to
create certain classes of application.
15962c01.indd 915962c01.indd 9 1/23/09 5:45:00 AM1/23/09 5:45:00 AM