The Release of Start Here! Learn Microsoft Visual C# 2010 Programming

It’s always exciting to see a new book released. I had previously told you about my new book, “Start Here! Learn Microsoft Visual C# 2010 Programming” in my post entitled, “New Book Announcement: Start Here! Learn Microsoft Visual C# 2010 Programming.” That post provides some basic information about the book, including a list of the chapters and what you should expect as content. Today this book is finally in print, so you can see it for yourself. Interestingly enough, I’ve already received a few queries about this book. I’ll answer the most commonly asked question in this post, which is what prompted me to write it.

Every time I receive an e-mail, see a review of one of my books online, or obtain information about a book in some other way, I try to see if I can use the feedback to improve later editions or to write a better book. In fact, I maintain statistics about each of my books because I really value your input and want to make the best use of it. The statistics I obtain from all of these forms of input help me understand how you use books better.

One of the comments I receive fairly often is that most books feel like college courses. They’re highly structured and seem most interested in teaching how to write applications using a stilted, old fashioned approach that doesn’t fit the reader’s needs very well. At least one reader has associated this approach with learning how to play piano using textbooks—you spend hours performing boring exercises to learn how to play something relatively simple. In the reader’s words, “Such an approach sucks every bit of joy out of the process of learning to play piano.” Yes, many people do learn to play piano using textbooks, but others learn to “play by ear” (simply by doing it without learning any basics first). These readers wonder why computer books can’t be written in a way that let’s you learn how to program using the “play by ear” approach.

I agree that not everyone learns in the same way. All other things being equal, one person may require a completely different book from someone else in order to get anything out of it because the two people learn differently. So, even if I wrote the most error free and comprehensive book ever written about C# application development, some people would love it and others would hate it simply because of the approach I took. Trying to solve this problem of writing a book that uses the “play by ear” approach has proven difficult.

To solve this problem, I needed to come up with a technique that would allow the reader to write code and then “hear” what the code does by running it. However, simply seeing the output isn’t sufficient in this case. In order to understand the code, the reader has to trace through itessentially “hearing” the individual tasks performed by each line of code. I tried a tracing technique for the first time in LINQ for Dummies and received quite a few positive responses about it. Now, LINQ for Dummies does use the college approach for the most part, but some sections use this new “play by ear” approach and it seems to work well for readers who require that approach.

It was with great excitement then, that I took on a book that would approach C# development from a completely different perspective after Russell Jones asked me about it. Start Here! Learn Microsoft Visual C# 2010 Programming is the result of my efforts. This book uses the tracing technique I started to develop in LINQ for Dummies extensively. Instead of spending hours learning about basic programming constructs and then writing tiny programs to put the theory into practice, you begin writing code immediately.

The main plus I see in using this approach is that nearly anyone should be able to learn to write useful (but basic) applications in a fraction of the time normally required and without devoting nearly as much time to the activity. The learning process should also be significantly less boring because you’re always doing something that has real world results. Of course, I’m extremely interested in seeing how this approach works for you, the reader. The only way I’ll get that information is if you write me at John@JohnMuellerBooks.com and tell me what you think of the book.

New Book Announcement: Start Here! Learn Microsoft Visual C# 2010 Programming

Have you ever attended a college course and found that you just didn’t understand what the teacher was trying to say? Worse yet, you found yourself dosing during a lecture? Many people require a hands-on approach to learning—they just don’t learn well using the college approach. Start Here! Learn Microsoft Visual C# 2010 Programming is designed to answer needs of anyone who has quickly become disenchanted with the way that colleges teach programming. You’ll start coding in Chapter 1 and won’t stop coding until you’ve completed the book!

Start Here! Learn Microsoft Visual C# 2010 Programming takes an entirely new approach to learning how to write code. You begin by writing some codeimagine that! Then, you use a special tracing technique to see how the code workswhat it does and how it does it. Instead of mind numbing sessions involving the discussion of keywords from a purely theoretical view, you jump right into using those keywords to do something useful.

You also don’t waste your time with silly Hello World applications. You get right into techniques that will prove useful later when you’re creating applications on your own. Chapter 1 starts things off right by showing you how to display an image from a Web site on the local desktop. Instead of spending hours trying to figure out looping mechanisms, you use the modern techniques provided by Language INtegrated Query (LINQ) to achieve your goals. You’ll do things like access a Web service and request weather information from it. There are even Silverlight and Windows Presentation Foundation (WPF) examples. Here is a quick overview of the book’s content:

  • Chapter 1: Getting to Know C#
  • Chapter 2: Developing a Web Project
  • Chapter 3: Using Simple Data Manipulation Techniques
  • Chapter 4: Using Collections to Store Data
  • Chapter 5: Working with XML
  • Chapter 6: Accessing a Web Service
  • Chapter 7: Using the Windows Presentation Foundation
  • Chapter 8: Working with Libraries
  • Chapter 9: Creating Utility Applications
  • Chapter 10: Using LINQ in Web Applications
  • Chapter 11: Working with Silverlight Applications
  • Chapter 12: Debugging Applications


You’ll also gain knowledge that many people spend years learning. For example, the tracing technique you use throughout the book naturally leads into the debugging information in Chapter 12. Debugging won’t be a mystery to youit’ll actually be a natural part of your work process so you’ll find it much easier to locate the bugs in your applications.

There is even a chapter on writing command line utilities. More and more administrators are returning to the command line because the GUI is simply too slow in today’s competitive world. Unfortunately, many developers don’t know how to write a really good command line utility, but you’ll gain this skill at the outset.

This book (my 88th) is truly designed for the complete novice. You do need to know how to work with Windows and perform basic tasks such as installing applications. However, you don’t need to know anything about coding to start using this book. In fact, people who already have a good starting knowledge of programming may find that some of the material is a little too simple. If you have any questions at all about my new book, please let me know at John@JohnMuellerBooks.com.

Using the PTVS for a WPF Project

As with Silverlight, there is no mention of theWindows Presentation Foundation (WPF) in my book, “Professional IronPython.” The WPF is supposed to help solve some display problems for application developers and allow better use of modern graphics processors. Microsoft has provided a significant amount of information about the WPF that I won’t be discussing in this post. Whether you find WPF helpful or not depends on the kind of applications you create. I’m sure that WPF will find use in game applications, widgets of various sorts, mini-applications, and a host of other uses, but I’m not sure just what it adds to the common business application, such as a data entry application. Still, WPF is an exciting new technology that you should investigate.

As with the Silverlight project in my previous post, you need to have the PTVS installed on your system to work through this example. To begin this example,
you start Visual Studio as normal and choose File | New to create a new
project. The New Project dialog box should contain an entry for a Wpf Application template as shown here. If you don’t see
this template, then you probably don’t have IronPython 2.7 installed on
your system and can use the instructions found in the IronPython 2.7 and PTVS blog entry to install it.

WPF01

The example will accept the default name for the project. Of course, you can use any name that you’d like. Click OK. You’ll see a new WPF application. However, for some odd reason, the eXtensible Application Markup Language (XAML) (pronounced zammel) file doesn’t always open, so you’ll have to open it manually. At this point, you’ll see a project similar to the one shown here.

WPF02

The top half of the designer shows what the page will look like, while the bottom half shows the associated XML. As you add controls to the form and configure them, you’ll see the changes in the XML, making it easy to code changes to the controls when necessary. Of course, you can choose to display just the Design window or just the XAML window if desired. Depending on the amount of screen real estate at your disposal, collapsing one of the panes by clicking Collapse Pane at the right side of the window, may be a good idea.

One of the advantages of using WPF is that you have immediate access to the Ribbon without having to employ any odd programming techniques. You just drag and drop the Ribbon controls from the Toolbox as you would any other control. Here’s a subset of the default set of WPF controls you can access from IronPython.

WPF03
As you can see, the set of controls is rich and you do have access to others, so WPF may be the way to go for IronPython developers who need maximum control access.

The example isn’t going to do anything fancy. I’ve added two Button controls to the form. Here is how I set the various properties using XAML:

<Window
   Title="WpfApplication1" Height="300" Width="300">
   <Grid>
      <Button Content="Click Me"
              Height="23"
              HorizontalAlignment="Left"
              Margin="191,12,0,0"
              VerticalAlignment="Top"
              Width="75"
              Uid="btnDisplay"
              Click="btnMessage_Click" />
      <Button Content="Cancel"
              Height="23"
              HorizontalAlignment="Left"
              Margin="191,41,0,0"
              VerticalAlignment="Top"
              Width="75"
              Uid="btnCancel"
              Click="btnCancel_Click" />
   </Grid>
</Window>

The first button displays a simple message box, while the second ends the application. Each Button control is assigned basic visual properties, a name, and an event handler for its Click() event. One thing I dislike about working with WPF is that the Properties window doesn’t display any quick help for the various properties. You need to know what each property does or look it up, which is really inconvenient.

The code behind for this example relatively simple. As previously mentioned, the first control displays a message, while the second closes the application as shown here:

import wpf
 
from System.Windows import Application, Window, MessageBox
 
class MyWindow(Window):
    def __init__(self):
        wpf.LoadComponent(self, 'WpfApplication1.xaml')
     
    def btnCancel_Click(self, sender, e):
         
        # End the application.
        MyWindow.Close(self)
     
    def btnMessage_Click(self, sender, e):
         
        # Display the message on screen.
        MessageBox.Show("Hello")
     
if __name__ == '__main__':
    Application().Run(MyWindow())

Much of this code is automatically generated for you. In order to use the MessageBox class, you must add it to the import statement as shown in the code. The code begins with the initialization, which simply loads the components from WpfApplication1.xaml.

The btnCancel_Click() event handler relies on the MyWindow object’s Close() method. Make sure you pass a copy of self as part of the call.

The btnMessage_Click() event handler makes a call to the MessageBox.Show() method with a simple text message. You’ll see the dialog box appear as expected.

From what I can see, the WPF support for IronPython in PTVS is on par with WPF support for any other .NET language. It has the same limitations and benefits as any WPF application will have. So, what do you think of the new WPF project support provided by PTVS? Let me know at John@JohnMuellerBooks.com.