Why C#?
Introduction
On your mark, get set, GO! That pretty much describes how quickly and easily you are about to begin understanding and writing C# (pronounced C-sharp) code. Whether you are new to programming, or an old-salt at it, Microsoft's new, refreshing, powerful, and fun programming language, C#, will make a believer out of you!
Fun? Yes! C# provides the ease of GUI (Graphical User Interface) design and layout that has been available to Visual Basic programmers for years. This component of C# allows you to visually create an application or applet user interface by simply clicking on a control toolbar, dragging a control onto a design page, and setting the control's properties from intuitive drop-down lists.
With more of today's programs demanding a financially profitable and educationally informative Web presence, C# stands poised as the pinnacle of development languages. Incorporating the best of Java or J++, CGI, PERL, C/C++, and Visual Basic with the architecture independence of Java's bytecode, or native code format, code solutions have the potential to endure and evolve without total rewrites.
No longer will a Web-enabled solution require a Visual Basic programmer for interface design, a C++ programmer for pure, raw, data-crunching horsepower, and a Java, CGI, or PERL expert to make an entire package available worldwide.
To see just how familiar C# syntax is to today's state-of-the-art programming languages take a quick tour of Chapter 2, "Unique C+," then come right back to this chapter. What follows is a very brief but interesting history of programming languages leading up to the development of C#.
It All Began with Algol
Algol, CPL, BCPL, B, Basic, PL/I, Assembly Language, COBOL, Fortran, PL/I, Pascal, Modula-2, Ada, SmallTalk, Lisp, Java, J++, CGI, PERL, Visual Basic, C, C++, and now C#the list is quite impressive. Why are there so many languages? Why can't someone invent one language to do it all? Which programming language or languages should I learn? Where will this all end?
C# is an easy-to-learn, easy-to-use, all encompassing problem solver. Before delving into this new language, let's take an historical look at how C# evolved. This journey will answer all of the questions posed in the previous paragraph.
As we look back, you will discover the roots and building blocks of many of today's languages. This information allows us to properly use these new development tools by explaining where each fits into the big picture. You will explore many individual language features that are included in C#. Reading between the lines of the travelogue you will also uncover secrets to predicting how programming languages will advance in future evolutions and/or revolutions!
Why I See C in C#!
A study of C's history is worthwhile because it reveals the language's successful design philosophy and helps you understand why C# may be the language of choice for years to come. Our archaeological dig for the origins of the C# language begins with Algol 60.
Algol 60 appeared in 1960 only a few years after FORTRAN was introduced. This European-based language was more sophisticated and had a strong influence on the design of future programming languages. Its authors paid a great deal of attention to the regularity of syntax, modular structure, and other features usually associated with high-level structured languages. Unfortunately, Algol 60 never really caught on in the United States. Many say this was due to the language's abstractness and generality.
The inventors of CPL (Combined Programming Language) set out to bring Algol 60's lofty intent down to the realities of an actual computer. However, just as Algol 60 was hard to learn and difficult to implement, so was CPL, which led to its eventual downfall. Still clinging to the best of what CPL had to offer, the creators of BCPL (Basic Combined Programming Language) wanted to boil CPL down to its basic good features.
When Ken Thompson, of Bell Labs, designed the B language for an early implementation of UNIX, he was trying to further simplify CPL. He succeeded in creating a very sparse language that was well suited for use on the hardware available to him (namely the DEC PDP-7, with an impressive 8-bit register size [small grin]!). However, both BCPL and B may have carried their streamlining attempts a bit too far; they became limited languages, useful only for dealing with certain kinds of problems.
As an example, no sooner had Ken Thompson implemented the B language on the Dec PDP-7 than a new machine, called the PDP-11 (a 16-bit word-size), was introduced. While the PDP-11 was a larger machine than its PDP-7 predecessor, it was still quite small by today's standards. It had only 24 K of memory, of which the system used 16 K, and one 512 K fixed disk. Some thought it was given to rewriting UNIX in B, but the B language was slow because of its interpretive design. There was another problem as well: B was byte-oriented, but the PDP-11 was word-oriented. For these reasons, work began in 1971 on a successor to B (just the Basics), appropriately named C (the Combined best of its predecessors).
At this point we need to discuss the UNIX operating system, since both the system and most of the programs that run on it are written in C. The UNIX OS was originally developed at Bell Laboratories in Murray Hill, New Jersey. By design, this operating system was intended to be "programmer friendly," providing useful development tools, lean commands, and a relatively open environment. However, this does not mean that C is tied to UNIX or any other operating system or machine. The UNIX/C co-development environment has given C a reputation for being a system programming language because it is useful for writing compilers and operating systems. C is also very useful for writing major programs in many different domains.
Dennis Ritchie is credited with creating C, which restored some of the generality lost in BCPL and B. He accomplished this through a shrewd use of data types, while maintaining the simplicity and direct access to the hardware that were the original design goals of CPL.
Many languages developed by a single individual (C, Pascal, Lisp, and APL) contain a cohesiveness that is missing from those created by large programming teams (Ada, PL/I, and Algol 60). It is also typical for a language written by one person to reflect the author's field of expertise. Dennis Ritchie was noted for his work in systems softwarecomputer languages, operating systems, and program generators.
Given Ritchie's areas of expertise, it is easy to understand why C is a language of choice for systems software design. C is a relatively low-level language that allows you to specify every detail in an algorithm's logic to achieve maximum computer efficiency. But C is also a high-level language that can hide the details of the computer's architecture, thereby increasing programming efficiency.
C versus Older High-Level Languages
At this point you may be asking, "How does C compare to other programming languages?" A possible continuum is shown in Figure 11. If you start at the bottom of the continuum and move upward, you go from the tangible and empirical to the elusive and theoretical. The dots represent major advancements, with many steps left out.
Figure 11 Theoretical evolution of programming languages.
Early ancestors of the computer, like the Jacquard loom (1805) and Charles Babbage's "analytical engine" (1834), were programmed in hardware. The day may well come when we will program a machine by plugging a neural path communicator into a socket implanted into the temporal lobe (language memory) or Broca's area (language motor area) of the brain's cortex.
The first assembly languages, which go back to the original introduction of electronic computers, provided a way of working directly with a computer's built-in instruction set, and were fairly easy to learn. Because assembly languages force you to think in terms of hardware, you had to specify every operation in the machine's terms. Therefore, you were always moving bits into or out of registersadding them, shifting register contents from one register to another, and finally storing the results in memory. This was a tedious and error-prone endeavor.
The first high-level languages, including FORTRAN, were created as alternatives to assembly languages. High-level languages were much more general and abstract, and they allowed you to think in terms of the problem at hand rather than in terms of the computer's hardware.
Unfortunately, the creators of high-level languages made the fallacious assumption that everyone who had been driving a standard, so to speak, would prefer driving an automatic. Excited about providing ease in programming, they left out some necessary options. FORTRAN and Algol 60 were too abstract for systems-level work; they were problem-oriented languages, the kind used for solving problems in engineering, science, or business. Programmers who wanted to write systems software still had to rely on their machine's assembler.
In reaction to this situation, a few systems software developers took a step backwardor lower, in terms of the continuumand created the category of machine-oriented languages. As you saw in C's geneology, BCPL and B fit into this class of very low-level software tools. These languages were excellent for a specific machine but not much use for anything else; they were too closely related to a particular architecture. The C language is one step above machine-oriented languages but still a step below most problem-solving languages. C is close enough to the computer to give you great control over the details of an application's implementation, yet far enough away to ignore the details of the hardware. This is why the C language is considered at once a high- and low-level language.
Advantages of C
Every computer language you use has a definite look to its source code: APL has its hieroglyphic appearance, assembly language its columns of mnemonics, and Pascal its easily read syntax. And then there's C. Many programmers encountering C for the first time will find its syntax cryptic and perhaps intimidating. C contains very few of the friendly English-like syntax structures found in many other programming languages. Instead, C presents the software engineer with unusual-looking operators and a plethora of pointers. New C programmers will soon discover a variety of language characteristics whose roots go back to C's original hardware/software progenitor.
If you are already familiar with C/C++'s set of operators, you will be happy to know that C# uses the same definitions. Or, if you are learning C# for the first time, you will summarily learn C/C++'s operator set. And, since there will still be ample opportunity for your C# application/applet to interface with C or C++ code, you'll reap a double benefit.
At this point it is helpful to review the origins and history behind Ken Thompson's B language, a direct predecessor to C. Following is a comprehensive C lineage:
Language |
Origins/Inventor |
Algol 60 |
Designed by an international committee in early 1960 |
CPL |
Combined Programming Language; developed at both Cambridge and the University of London in 1963 |
BCPL |
Basic Combined Programming Language; developed at Cambridge by Martin Richards in 1967 |
B |
Developed by Ken Thompson, Bell Labs, in 1970 |
C |
Developed by Dennis Ritchie, Bell Labs, in 1972 |
Then, in 1983, the American National Standards Institute (ANSI) committee was formed for the purpose of creating ANSI Ca standardization of the C language.