Head First C# Fifth Edition
by Andrew Stellman & Jennifer Greene
Earlier this month I was lucky enough to get my hands on a complimentary copy of Head First C# Fifth Edition. There were things I expected and things that surprised me, here are my thoughts...
About the Review
This review will be an opinion piece from the perspective of a learner. I'm not a beginner in programming but I am new to C#. That puts me in the target audience for this book. I went into this primarily interested in GUI development. The scope of this review will be limited to the learning experience, for a more technical review you will need to look elsewhere.
Style
It's impossible to write about my experience with a Head First book without discussing the general Head First style. Books in this series tend to employ a lot of visual aids, a conversational tone, a wide variety of exercises and deliberate repetition. For a more detailed explanation you may check this page on the O'Reilly site.
Since this is a review from my perspective I will give my personal opinion. There are aspects to this teaching style that I prefer over others. For example, the conversational tone suits me fine. Do I feel I need it to remain attentive? Not really, I'm quite happy to read books written in a formal tone as well.
The redundancy is a factor I consider to be a major strength, sure it's repetition but it's explanation of the same idea in different ways. Having said that, I didn't find it helpful every time and in fact on one or two occasions I found myself skipping an (already explained) point in order not to break my train of thought.
I like the use of images to break up text. As you can see from the example page linked there is a clear structure to the page working its way from top to bottom, at the same time the reader's eye is drawn between locations. This page is a clear demonstration of the cognitive friendly approach this book aims for.
On the topic of presentation, the one thing I noticed immediately upon opening the book was the use of hand-drawn characters. Historically, the Head First series always used photographed images of people, for an example of what I'm talking about:
This is a huge improvement in my opinion and makes the pages look cleaner, less distracting and more relatable. It's worth pointing out that this update appears to be series wide as I've noticed the same in other latest edition Head First books.
Topics Covered
The book has 12 main chapters and then intertwined with them six Unity Labs. Topics covered in this book, in no particular order, include but are not limited to:
- Good code style, ie sensible variable, method naming.
- Refactoring.
- Basic types and flow control constructs.
- General OOP concepts: inheritance, composition, polymorphism, encapsulation, cohesion, separation of concerns, DRY etc.
- Abstract and Concrete classes.
- Using the Visual Studio debugger.
- The encouragement and use of paper prototypes.
- XAML and C# code behind in .NET MAUI apps.
- Data binding.
- Automatic properties with backing fields.
- Interfaces (with and without default implementations), how to use them and why they are important.
- Upcasting and downcasting.
- Sorting techniques with
IComparable
andIComparer
interfaces. - Collections, specifically covered: List, Dictionary, Queues, Stacks.
- LINQ queries, LINQ methods and deferred evaluation.
- File and memory streams. Network and Gzip streams are briefly mentioned but not explored.
IDisposable
interface for handling the cleanup of unmanaged resources.- Object serialization.
- The garbage collector.
- Exception handling.
- Nullable value types and the null-coalescing operator.
- Extending sealed classes.
- Unit testing with MSTest, writing for edge cases and unpredictable input.
- Logging with Serilog
- The encouragement and use of AI assisted learning and an introduction to prompt engineering.
- Feedback loops, emergence and how they affect dynamics both in games and other areas of programming.
As a learner, the parts I particularly liked
The book opens with a clear and detailed walkthrough with screenshots guiding the reader on setting up their development environment. This is important because perhaps the reader has never used Visual Studio. I've read other books before that lacked detailed setup instructions, this can lead to great confusion and leave a bad initial impression.
The first project you're tasked with is an Animal Matching game.
This is a great introduction to the book because it gives a fast demonstration of the power and flexibility of C# and XAML with just a few lines of code.
The .NET MAUI project Random Cards walks you through a structured process. The discussion around Ana's game also covers point one.
- Plan in advance how you intend to model your ideas into classes, possibly with the aid of a paper prototype.
- Write a working command line application.
- Complete the project by using those same classes in a GUI application. All the while reinforcing the importance of accessibility.
I very much like this methodology, first of all because it encourages the learner to really think about what they are doing. As a beginner, it's way too easy to want to rush in and start writing code, then later regret some of the choices that a better design would have avoided. By putting careful thought and planning into how you organise your classes and which methods you will make public you can separate the internal design of a class from its consuming code. Second, the process is incremental. It gives the learner the opportunity to start with the basics and build up as they go along. Last of all, having personally spent time working with users with accessibility needs, I am intimately familiar with the frustrations that can arise from inaccessible GUI design. Computers are used by all kinds of users around the world and it's important that beginners are encouraged to follow best practices concerning accessibility.
Each chapter ends with a Q&A style section. As the authors state, some of these questions are actual questions they've been asked by readers of past editions of the book. This is a great format for a few reasons:
- It gives the opportunity for readers to process topics covered in a back and forth manner
- It encourages the reader to ask questions themselves
- It may well answer a specific question they already had. The example that comes to mind personally, the IDisposable interface had been covered in chapter 10 but only in the context of files and streams. I found myself asking, is this an interface appropriately used with other types of classes? The Q&A in chapter 12 asks and answers this question almost verbatim.
Criticisms
As I mentioned in the introduction of this review, my primary interest is in GUI development and there was plenty of that present. I am less interested in game development and there was a lot of that too. Now I have to be fair in my assessment, the authors go to a lot of effort to explain their reasoning behind the game-centred focus. The lessons taught throughout the book while building the game projects are broadly applicable across programming. Nevertheless, my question is simple, would it have been possible to teach some of those same programming concepts while focusing on a wider variety of non game-centred projects?
Possible improvements
The lumberjack exercise in chapter eight has you build a console app to demonstrate the Stack and Queue ADTs. It does a sufficient job but I have to wonder whether this was a great opportunity to demonstrate the nature of the stack and queue in a more visual, .NET MAUI GUI app.
Overall thoughts
I believe Head First C# Fifth Edition is a very strong effort. It's clear to me that a lot of care and attention went into producing a complete and thorough learning experience for the reader. The emphasis on good programming practices, GUI accessibility and self learning techniques especially impressed me.
The first several chapters are gently paced and introduce fundamental concepts in C# but also programming in general. If you prefer a fast paced introduction to a language you should bear this in mind.
I've talked about the general style of Head First books and given my personal opinion but each person's experience will vary. I will say this much, if you've never tried reading a Head First book and C# piques your interest then I encourage you to give this book a go.
Further Notes:
- The authors have made available on their Github repository Blazor versions of all the .NET MAUI apps.
- They have a YouTube channel where they post guides related to the book.
Subscribe to this blog's RSS feed