1.8 C#

In 2000, Microsoft announced the C# programming language. C# has roots in the C, C++ and Java programming languages. It has similar capabilities to Java and is appropriate for the most demanding app-development tasks, especially for building today’s desktop apps, large-scale enterprise apps, and web-based, mobile and cloud-based apps.

1.8.1 Object-Oriented Programming

C# is object oriented—we’ve discussed the basics of object technology and we present a rich treatment of object-oriented programming throughout the book. C# has access to the powerful .NET Framework Class Library—a vast collection of prebuilt classes that enable you to develop apps quickly (Fig. 1.5). We’ll say more about .NET in Section 1.9.

Fig. 1.5 Some key capabilities in the .NET Framework Class Library.

Some key capabilities in the .NET Framework Class Library
Database Debugging
Building web apps Multithreading
Graphics File processing
Input/output Security
Computer networking Web communication
Permissions Graphical user interface
Mobile Data structures
String processing Universal Windows Platform GUI

1.8.2 Event-Driven Programming

C# graphical user interfaces (GUIs) are event driven. You can write programs that respond to user-initiated events such as mouse clicks, keystrokes, timer expirations and touches and finger swipes—gestures that are widely used on smartphones and tablets.

1.8.3 Visual Programming

Microsoft’s Visual Studio enables you to use C# as a visual programming language—in addition to writing program statements to build portions of your apps, you’ll also use Visual Studio to conveniently drag and drop predefined GUI objects like buttons and text-boxes into place on your screen, and label and resize them. Visual Studio will write much of the GUI code for you.

1.8.4 Generic and Functional Programming

Generic Programming

It’s common to write a program that processes a collection of things—e.g., a collection of numbers, a collection of contacts, a collection of videos, etc. Historically, you had to program separately to handle each type of collection. With generic programming, you write code that handles a collection “in the general” and C# handles the specifics for each different type of collection, saving you a great deal of work. We’ll study generics and generic collections in Chapters 20 and 21.

Functional Programming

With functional programming, you specify what you want to accomplish in a task, but not how to accomplish it. For example, with Microsoft’s LINQ—which we introduce in Chapter 9, then use in many later chapters—you can say, “Here’s a collection of numbers, give me the sum of its elements.” You do not need to specify the mechanics of walking through the elements and adding them into a running total one at a time—LINQ handles all that for you. Functional programming speeds application development and reduces errors. We take a deeper look at functional programming in Chapter 21.

1.8.5 An International Standard

C# has been standardized through ECMA International:


http://www.ecma-international.org

This enables other implementations of the language besides Microsoft’s Visual C#. At the time of this writing, the C# standard document—ECMA-334—was still being updated for C# 6. For information on ECMA-334, visit


http://www.ecma-international.org/publications/standards/Ecma-
   334.htm

Visit the Microsoft download center to find the latest version of Microsoft’s C# 6 specification, other documentation and software downloads.

1.8.6 C# on Non-Windows Platforms

Though C# was originally developed by Microsoft for the Windows platform, the language can be used on other platforms via the Mono Project and .NET Core—both are managed by the .NET Foundation


http://www.dotnetfoundation.org/

For more information, see the Before You Begin section after the Preface.

1.8.7 Internet and Web Programming

Today’s apps can be written with the aim of communicating among the world’s computers. As you’ll see, this is the focus of Microsoft’s .NET strategy. In online chapters, you’ll build web-based apps with C# and Microsoft’s ASP.NET technology.

1.8.8 Asynchronous Programming with async and await

In most programming today, each task in a program must finish executing before the next task can begin. This is called synchronous programming and is the style we use for most of this book. C# also allows asynchronous programming in which multiple tasks can be performed at the same time. Asynchronous programming can help you make your apps more responsive to user interactions, such as mouse clicks and keystrokes, among many other uses.

Asynchronous programming in early versions of Visual C# was difficult and error prone. C#’s async and await capabilities simplify asynchronous programming by enabling the compiler to hide much of the associated complexity from the developer. In Chapter 23, we provide an introduction to asynchronous programming with async and await.

1.8.9 Other Key Programming Languages

Figure 1.6 provides brief comments on several popular programming languages.

Fig. 1.6 Some other programming languages.

Programming language Description
Ada Ada, based on Pascal, was developed under the sponsorship of the U.S. Department of Defense (DOD) during the 1970s and early 1980s. The DOD wanted a single language that would fill most of its needs. The Pascal-based language was named after Lady Ada Lovelace, daughter of the poet Lord Byron. She’s credited with writing the world’s first computer program in the early 1800s (for the Analytical Engine mechanical computing device designed by Charles Babbage). Ada also supports object-oriented programming.
Basic Basic was developed in the 1960s at Dartmouth College to familiarize novices with programming techniques. Many of its latest versions are object oriented.
C C was developed in the early 1970s by Dennis Ritchie at Bell Laboratories. It initially became widely known as the UNIX operating system’s development language. Today, most code for general-purpose operating systems is written in C or C++.
C++ C++, which is based on C, was developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories. C++ provides several features that “spruce up” the C language, but more important, it provides capabilities for object-oriented programming.
COBOL COBOL (COmmon Business Oriented Language) was developed in the late 1950s by computer manufacturers, the U.S. government and industrial computer users, based on a language developed by Grace Hopper, a career U.S. Navy officer and computer scientist. COBOL is still widely used for commercial applications that require precise and efficient manipulation of large amounts of data. Its latest version supports object-oriented programming.
Fortran Fortran (FORmula TRANslator) was developed by IBM Corporation in the mid-1950s to be used for scientific and engineering applications that require complex mathematical computations. It’s still widely used, and its latest versions support object-oriented programming.
Java Sun Microsystems in 1991 funded an internal corporate research project led by James Gosling, which resulted in the C++-based object-oriented programming language called Java. A key goal of Java is to enable developers to write programs that will run on a great variety of computer systems and computer-controlled devices. This is sometimes called “write once, run anywhere.” Java is used to develop large-scale enterprise applications, to enhance the functionality of web servers (the computers that provide the content we see in our web browsers), to provide applications for consumer devices (e.g., smartphones, tablets, television set-top boxes, appliances, automobiles and more) and for many other purposes. Java is also the key language for developing Android smartphone and tablet apps.
Objective-C Objective-C is an object-oriented language based on C. It was developed in the early 1980s and later acquired by NeXT, which in turn was acquired by Apple. It became the key programming language for the OS X operating system and all iOS-powered devices (such as iPods, iPhones and iPads).
JavaScript JavaScript is the most widely used scripting language. It’s primarily used to add programmability to web pages—for example, animations and interactivity with the user. All major web browsers support it.
Pascal Research in the 1960s resulted in structured programming—a disciplined approach to writing programs that are clearer, easier to test and debug and easier to modify than programs produced with previous techniques. The Pascal language, developed by Professor Niklaus Wirth in 1971, grew out of this research. It was popular for teaching structured programming for several decades.
PHP PHP is an object-oriented, open-source “scripting” language supported by a community of developers and used by numerous websites. PHP is platform independent—implementations exist for all major UNIX, Linux, Mac and Windows operating systems.
Python Python, another object-oriented scripting language, was released publicly in 1991. Developed by Guido van Rossum of the National Research Institute for Mathematics and Computer Science in Amsterdam (CWI), Python draws heavily from Modula-3—a systems programming language. Python is “extensible”—it can be extended through classes and programming interfaces.
Swift Swift, which was introduced in 2014, is Apple’s programming language of the future for developing iOS and OS X applications (apps). Swift is a contemporary language that includes popular programming-language features from languages such as Objective-C, Java, C#, Ruby, Python and others. In 2015, Apple released Swift 2 with new and updated features. According to the Tiobe Index, Swift has already become one of the most popular programming languages. Swift is now open source, so it can be used on non-Apple platforms as well.
Ruby on Rails Ruby—created in the mid-1990s by Yukihiro Matsumoto—is an open-source, object-oriented programming language with a simple syntax that’s similar to Python. Ruby on Rails combines the scripting language Ruby with the Rails web-application framework developed by the company 37Signals. Their book, Getting Real (free at http://gettingreal.37signals.com/toc.php), is a must-read for web developers. Many Ruby on Rails developers have reported productivity gains over other languages when developing database-intensive web applications.
Scala Scala (http://www.scala-lang.org/what-is-scala.html)—short for “scalable language”—was designed by Martin Odersky, a professor at École Polytechnique Fédérale de Lausanne (EPFL) in Switzerland. Released in 2003, Scala uses both the object-oriented programming and functional programming paradigms and is designed to integrate with Java. Programming in Scala can reduce the amount of code in your applications significantly.
Visual Basic Microsoft’s Visual Basic language was introduced in the early 1990s to simplify the development of Microsoft Windows applications. Its latest versions support object-oriented programming.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset