11.07.2015 Views

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

Encyclopedia of Computer Science and Technology

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C++ 67C#Introduced in 2002, C# (pronounced “C sharp”) is a programminglanguage similar to C++ <strong>and</strong> Java but simplifiedin several respects <strong>and</strong> tailored for use with Micros<strong>of</strong>t’slatest programming platform (see Micros<strong>of</strong>t.net). C# isa general-purpose language <strong>and</strong> is thoroughly objectoriented—allfunctions must be declared as members <strong>of</strong>a class or “struct,” <strong>and</strong> even fundamental data types arederived from the System.Object class (see class <strong>and</strong> objectorientedprogramming).Compared with C++, C# is stricter about the use <strong>and</strong>conversion <strong>of</strong> data types, not allowing most implicit conversions(such as from an enumeration type to the correspondinginteger—see data structures). Unlike C++,C# does not permit multiple inheritance (where a type canbe derived from two or more base types), thereby avoidingan added layer <strong>of</strong> complexity in class relationships inlarge s<strong>of</strong>tware projects. (However, a similar effect can beobtained by declaring multiple “interfaces” or specifiedways <strong>of</strong> accessing the same class.)Unlike Java (but like C++), C# includes pointers (<strong>and</strong>a safer version called “delegates”), enumerations (enumtypes), structs (treated as lightweight classes), <strong>and</strong> overloading(multiple definitions for operators). The latest version<strong>of</strong> the language, C# 3.0 (introduced in 2007), providesadditional features for list processing <strong>and</strong> functional programming(see functional languages).The canonical “Hello World” program looks like this inC#:using System;// A “Hello World!” program in C#namespace HelloWorld{class Hello{static void Main(){System.Console.WriteLine(“Hello World!”);}}}Essentially all program structures must be part <strong>of</strong> aclass. The first statement brings in the System class, fromwhich are derived basic interface methods. A program canhave one or more namespaces, which are used to organizeclasses <strong>and</strong> other structures to avoid ambiguity. This programhas only one class (Hello), which includes a Mainfunction (every program must have one <strong>and</strong> only one). Thisfunction calls the Console member <strong>of</strong> the System class, <strong>and</strong>in turn uses the WriteLine method to display the text.C++ <strong>and</strong> Micros<strong>of</strong>t DevelopmentC# is part <strong>of</strong> a family <strong>of</strong> languages (including C++, J#[an equivalent version <strong>of</strong> Java], <strong>and</strong> Visual Basic.NET). Allthese languages compile to a common intermediate language(IL). The common class framework, Micros<strong>of</strong>t.NET,has replaced earlier frameworks for Windows programming<strong>and</strong>, increasingly, for modern Web development (seealso Ajax).Although it has been primarily associated with Micros<strong>of</strong>tdevelopment <strong>and</strong> Windows, the Mono <strong>and</strong> Dot GNUprojects provide C# <strong>and</strong> an implementation <strong>of</strong> the CommonLanguage Infrastructure, <strong>and</strong> many (but not all) <strong>of</strong> the.NET libraries for the Linux/UNIX environment.Further Reading“The C# Language.” MSDN. Available online. URL: http://msdn2.micros<strong>of</strong>t.com/en-us/vcsharp/aa336809.aspx. Accessed April28. 2007.Davis, Stephen R<strong>and</strong>y. C# for Dummies. New York: Hungry Minds,2002.Hejlsberg, Andres, Scott Wiltamuth, <strong>and</strong> Peter Golde. The C# ProgrammingLanguage. 2nd ed. Upper Saddle River, N.J.: Addison-Wesley,2006.C++The C++ language was designed by Bjarne Stroustrup atAT&T’s Bell Labs in Murray Hill, New Jersey, starting in1979. By that time the C language had become well establishedas a powerful tool for systems programming (seeC). However Stroustrup (<strong>and</strong> others) believed that C’s limiteddata structures <strong>and</strong> function mechanism were provinginadequate to express the relationships found in increasinglylarge s<strong>of</strong>tware packages involving many objects withcomplex relationships.Consider the example <strong>of</strong> a simple object: a stack ontowhich numbers can be “pushed” or from which they can be“popped” (see stack). In C, a stack would have to be implementedas a struct to hold the stack data <strong>and</strong> stack pointer,<strong>and</strong> a group <strong>of</strong> separately declared functions that couldaccess the stack data structure in order to, for example“push” a number onto the stack or “pop” the top numberfrom it. In such a scheme there is no direct, enforceablerelationship between the object’s data <strong>and</strong> functions. Thismeans, among other things, that parts <strong>of</strong> a program couldbe dependent on the internal structure <strong>of</strong> the object, orcould directly access <strong>and</strong> change such internal data. In alarge s<strong>of</strong>tware project with many programmers working onthe code, this invites chaos.An alternative paradigm already existed (see objectorientedprogramming) embodied in a few new languages(see Simula <strong>and</strong> Smalltalk). These languages allow for thestructuring <strong>of</strong> data <strong>and</strong> functions together in the form <strong>of</strong>objects (or classes). Unlike a C struct, a class can containboth the data necessary for describing an object <strong>and</strong> thefunctions needed for manipulating it (see class). A class“encapsulates” <strong>and</strong> protects its private data, <strong>and</strong> communicateswith the rest <strong>of</strong> the program only through calls to itsdefined functions.Further in object-oriented languages, the principle <strong>of</strong>inheritance could be used to proceed from the most general,abstract object to particular versions suited for specifictasks, with each object retaining the general capabilities<strong>and</strong> revising or adding to them. Thus, a “generic” list foundationclass could be used as the basis for deriving a variety<strong>of</strong> more specialized lists (such as a doubly-linked list).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!