AddThis Social Bookmark Button

Listen Print

An Interview with Jesse Liberty

by Bruce Stewart
07/10/2001

Related Reading

Programming C#
By Jesse Liberty

Table of Contents
Index
Sample Chapter

Read Online--Safari Search this book on Safari:
 

Code Fragments only

Stewart: It's hard to talk about C# without discussing .NET. Before we get into some specifics about the language and your new book, let's take a look at the big picture. What is the .NET Framework?

Liberty: The .NET platform is almost a new operating system layered on top of the existing operating systems. It is, at a minimum, a new development framework. .NET brings together a number of technologies and architectural approaches Microsoft has been developing over the past few years. These include COM+ component services, a significantly upgraded ASP Web development framework, a commitment to XML and object-oriented design, support for new Web services protocols such as SOAP, and a focus on the Internet--all integrated within the DNA architecture.

Microsoft says it is devoting 80 percent of its research and development budget to .NET and its associated technologies--that is a few billion dollars of R&D every year. The results of this commitment are impressive, to say the least. .NET is huge.

The entire platform consists of four separate product groups:

Group one is a set of languages, such as C# and VB.NET; a set of tools, such as Visual Studio.NET; a comprehensive class library for building Web services and Web and Windows applications; and the Common Language Runtime to execute objects built within this framework. My book, Programming C#, focuses on this part of .NET.


Check out O'Reilly's new .NET Resource Center for the latest articles and books covering Microsoft's .NET technology.

Group two is a set of .NET Enterprise Servers, formerly known as SQL Server 2000, Exchange 2000, BizTalk 2000, and so on, that provide specialized functionality for relational data storage, email, B2B commerce, etc.

The third group consists of commercial Web services, recently announced as project Hailstorm. For a fee, developers can use these services in building applications that require knowledge of user identity, etc.

Finally, group four may include new .NET enabled non-PC devices, from cell phones to game boxes.

Stewart: Do you think .NET represents a shift in Microsoft's focus from creating desktop applications to creating network services?

Liberty: .NET represents a growing realization that the distinction we currently make between desktop applications on the one hand, and Web applications on the other, will soon be made meaningless. Web access is being integrated into desktop applications, and desktop applications are being distributed across the Web.

Here's an example: the Microsoft Streets & Tips program provides maps and directions. You put in where you want to start and where you want to go, and they provide a route. They have now integrated Web access so that they can update the maps with current information about roadwork and detours. Is this a desktop application or a Web application?

At the same time, more applications are integrating modules or Web services running on remote computers. The concept of a desktop application is simply becoming obsolete. It is like the idea of "made in America." I was in a car dealership recently and a customer said to the salesman "I want an American car." "Great," said the salesman, "do you want this Chevy built in Canada, or this Toyota built in Ohio?" So, do you want this desktop application running on the Web, or this Web application running on your desktop?

Stewart: .NET sounds a lot like what Sun has tried to achieve with its Java technology. What advantages does .NET have over the Java platform?

Liberty: .NET runs on Windows and it is built by Microsoft. Next question?

In all seriousness, for the vast majority of business consumers, that is more than enough. While developers may think that Java is superior in some ways (where have I heard this before, Mr. Jobs?), Microsoft won the desktop wars long ago. Win2K is a stable and rapidly improving platform for Web development, and a lot of developers will want to build their apps on Windows.

As to whether head-to-head, from a technical standpoint, .NET is better than Java is a matter of priorities and aesthetics. I won't even begin to try to defend that proposition. To be perfectly frank, I don't spend a lot of time on the question of which is superior. I know that Microsoft will continue to represent a good solution and I focus my energies building my skills, rather than wringing my hands over which platform to use.

Stewart: Fair enough, let's move on to the language. How does C# fit into the .NET Framework?

Liberty: Microsoft did a radical thing with .NET; it takes a while to get used to the idea. Rather than starting with a language, they started with a Common Language Specification (CLS). Any language that complies with the CLS is able to run on the .NET platform. What is more, if you comply with the CLS and you use only types defined by the Common Type System (CTS) then your objects can interoperate with (and derive from and be derived from) any other CLS language. That means that you can create a class in VB.NET, derive from it in C#, and then derive from that C# class back in VB.NET!

To accomplish this, they created a whole new language, and then implemented that language with two syntaxes. One syntax is C# and it looks a lot like C++ and Java. The other syntax is VB.NET and it looks a lot like VB. In essence, both C# and VB.NET are the same language with different syntactic sugar.


For in-depth coverage of Microsoft's .NET Framework, visit the O'Reilly Network's .NET DevCenter.

C# has some minor advantages over VB.NET, but only at the margin, and mostly as a matter of perception. That said, I suspect a lot of VB 6 programmers will jump to C#, reasoning that they have a lot to learn anyway, and why should they continue defending their perfectly good language to the market, when they can simply acquire a language with a C in its name. Historically C-language programmers earn more than VB language programmers, so why not take this opportunity to jump on the wagon? Of course, the market may wise up and pay VB.NET programmers as much as C# programmers, but I personally wouldn't bet on it happening overnight.

Stewart: What are the main strengths of C#? Do you have any favorite features?

Liberty: I love garbage collection, what a luxury. Properties and foreach loops are pretty nice. Oh, and you don't need a semicolon at the end of class declarations. I mean, is that cool, or what?

The truth is, the language features are not the story. The story is the framework itself. The support for metadata (attributes & reflection), overlapped I/O, streams, networking and so forth mean that you can focus on the task at hand and not rebuild the plumbing. Probably the best thing about .NET is WebForms and Windows Forms. These bring Rapid Application Development to industrial-strength programming.

Stewart: How do WebForms and Windows Forms work?

Liberty: Well, this is a very big topic, of course. In my book I spend an entire chapter on Windows Forms and another chapter just on Web Forms.

The short answer, however, is that .NET brings the Rapid Application Development (RAD) tools from VB6 to C#, and allows you to create both Windows applications and Web applications by dragging and dropping controls (list boxes, radio buttons and so forth) onto a form. The assumption is that most Web and Windows applications are centered around data gathering and display, and that a form is the right metaphor.

While Web Forms and Windows Forms use different sets of controls, they have a great deal in common and the programming model is very similar. Essentially, you drag controls onto the form and then write event handlers to implement the events that each control can raise. Controls raise events in response to user action. For example, if the user clicks on a button the button raises the click event, and your event handler code takes whatever action you wish to take in response to a button click.

Web Forms are built on ASP technology, and it is possible to write the event handling code and all the other supporting code right in the aspx page along with the HTML, but this is not encouraged. Instead, Web Forms now provide "code behind" pages which are associated with the aspx page, but which allow you to separate the display code (html) from the implementing code (C# or another .NET language).

The very best news about Web Forms and ASP.NET is that the implementing code is no longer script: it is fully compiled C#, with all the supporting technology of C# such as exception handling, attributes, reflection and so forth.

In version 1 of .NET there is little difference between writing Windows applications and writing Web applications, and the boundary between the two can be expected to blur even more over time.

Stewart: So what's the difference between Web Forms and Windows Forms?

Liberty: The principal difference between writing Web Forms and Windows Forms is that when writing Web applications the event handling happens at the server. Because it takes time to send the event to the server and to respond to it by sending a new HTML page back to the browser, Web Form controls respond to fewer events; only those events that the user might legitimately expect will update the page. While a control on a Windows form might raise events when the mouse enters the area of the control, another when it hovers over the control and yet one more when the mouse exits; none of these events is raised by Web Form controls. Web forms typically respond to click events and, if the programmer chooses, to other events which change the state of the control (such as changing the selection in a list). You have a great deal of control over which events will cause the page to post back to the server.

Stewart: How does C# compare to C++?

Liberty: Perhaps the nicest feature of C# that we didn't have in C++ is properties. Essentially, a property looks to the class owner like a method, but to the class' client like a member variable. They are a way to make accessor methods first class elements of the language and thus encourage and facilitate data hiding.

I've written an article for MSDN magazine on the transition from C++ to C# in which I try to make the point that the real change from C++ to C# is not syntactic, it is that C# was designed for the .NET managed environment. In C++ you have control over the creation and the layout of your objects, in C# you yield that control to the platform. You no longer explicitly control the lifetime of your objects; you leave that to the non-deterministic finalization of the garbage collector.

The differences in syntax are almost trivial. I'm creating a collection of the syntactic differences in the FAQ for Programming C# on my Web site, Liberty Associates. There are a few "gotcha's" along the way for C++ programmers, most notably the change to the meaning of the keyword struct, but nothing that you can't learn quickly. The transition from C++ to C# is painless at worst, and a real pleasure if you embrace the advantages of .NET. Personally, I won't go back, and you can't make me.

Stewart: How about Visual Basic? Joshua Trupin wrote in MSDN Magazine that C# is "a little like taking all the good stuff in Visual Basic and adding it to C++, while trimming off some of the more arcane C and C++ traditions." Is it a fair assessment that C# combines the ease of VB with the power of C++?

Liberty: I never argue with Josh. C# took a lot of the Rapid Application Development features from VB6 and that is a great thing. I'm not sure what the language itself borrowed from VB except foreach loops and properties, both of which are a big win. I must say, however, that they trimmed more than just arcane features of C++. For example, they greatly diminished the role of pointers, which are right in the heart of the language. You can make a good case for deprecating pointers, but you can't say that pointers are arcane.

C# does not offer multiple inheritance, but that is not terribly burdensome, as Java programmers know well. Most of the rest of what was eliminated was of marginal importance or utility.

I spent the past few years splitting my time between C++ and VB. I like both languages, but C# is superior to both, in my opinion.

Stewart: Microsoft claims that the modern design of C# eliminates the most common C++ programming errors. In what ways is C# less prone to programmer errors?

Liberty: The biggest change is garbage collection. Yielding memory management to the framework will eliminate some of the most difficult errors. In addition, because of garbage collection, managing heap-based variables in the presence of exceptions becomes much easier. With C++, if you created an object on the heap and then you threw an exception it was possible that you would unwind the stack and never delete the object, which would cause an instant memory leak. There were ways around this with smart pointers, but they were cumbersome and error-prone. With C# all that goes away.

There are lots of other little error avoidance features. For example, "if" statements require a Boolean value, and integer values no longer implicitly promote to Boolean. Thus, a classic error of writing if (foo=bar) when you mean to write if (foo == bar) is entirely eliminated; the former won't compile.

Stewart: What makes your book, Programming C#, more valuable than other sources of information, like the extensive online documentation that Microsoft has provided?

Liberty: Microsoft provides a tremendous amount of information. I don't try to compete with that; my book is not a reference. My book is a tutorial. I have a story to tell; I will take you through the material and help you distinguish the most important aspects of the language and of developing software with the language. Their material is encyclopedic; my goal was to provide a guided tour. As for why my book rather than any other book, I can only tell you that after months of multiple revisions and edits, I now know why O'Reilly books are as good as they are: the editors are incredible (and relentless!).

Stewart: What skill-level does Programming C# presume?

Liberty: Programming C# assumes you have programmed in some language previously. The truth is that if you are a very bright person who has never programmed before, you probably will have little trouble reading the book, but the assumption is that this is not your very first programming experience. Clearly the majority of our first readers will be coming to C# from C++ or Java or VB, and the book caters to that audience, but I had beta testers who had no experience with these languages and I know the book can be approached without that background.

Stewart: What specific knowledge and programming techniques should a reader come away from Programming C# with?

Liberty: The book is divided into three parts. The first part teaches the language and object oriented programming. The second part focuses on building applications with the language, and the final part teaches some of the core facilities of the .NET Framework.

When you are done reading Programming C# you should feel very comfortable with the details of C#. You will understand not only the syntax of the language itself, but also how to design and build object oriented programs, and how to implement encapsulation, inheritance, and polymorphism in your programs.

You should also understand the fundamentals of how to build Windows Applications, Web applications and Web services with C#. In addition, you should be comfortable with attributes and reflection, marshaling and serialization, threading, overlapped i/o, and creating and writing to and from files and across the network using streams. Finally, you will have a good understanding of Assemblies, App domains and context and how to create and deploy applications.

Stewart: C# is the first language to incorporate XML comment tags that can be used by the compiler to generate readable documentation directly from source code. Have you played around with that feature at all, and how important do you think XML will be for developers creating Web services?

Liberty: XML documentation is very nice, and I introduce it in the book. XML itself is simultaneously critical and irrelevant to most C# developers. It is critical because so much of the infrastructure is built around XML. The SOAP protocol used for most remoting and Web services is based on XML, as is the documentation and many other tools. On the other hand, Visual Studio.NET hides most of the details of XML, and most C# developers will never need to understand the intricacies of XML if they don't want to.

Stewart: How well do you think C# is being accepted by the developer community? Do you think this language will appeal to programmers who have not previously been developing Windows applications?

Liberty: That is a great question. My unscientific survey (I asked some buddies) says that many C++ programmers are planning on making the jump within the next 12 months. There is an argument that in two years C++ will be obsolete. Windows development will be done in C#, and Unix development either in C# or in Java. That may be too strong a statement, but it is hard to imagine many C++ programmers ignoring C# for long.

As for Java programmers; my guess is that they will cleave into two groups. One will not touch C# simply because it comes from Redmond. The other will explore the relative merits of the two platforms, and I'd guess that many of these developers will come to C# when their clients begin to ask for a Windows-based solution.

Stewart: Thanks for your time Jesse, it's been very interesting. Clearly there are a lot of good reasons for developers to take a look at C#.

Liberty: It's been my pleasure. I hope your readers find Programming C# a valuable addition to their bookshelf.


Jesse Liberty is a computer consultant, trainer, and best-selling book author who specializes in .NET and Web development. His company, Liberty Associates, designs and builds Web and Windows applications and delivers intensive on-site seminars on C#, ASP.NET, and related technologies. He has been a distinguished software engineer at AT&T, vice president for technology development at CitiBank, and software architect at Xerox and PBS. Jesse provides support for his books at www.LibertyAssociates.com.

O'Reilly & Associates will soon release (July, 2001) Programmng C#.