Working with Code in e-Books

Most of my technical readers now use e-books instead of paper books. Of course, there is a convenience factor to storing your entire library on a Kindle, even if it’s a software version of the Kindle. Of course, there are all sorts of e-book formats for your desktop system as well. The point is that electronic format makes a lot of sense when dealing with technical books.

However, e-books can cause some interesting problems and I’ve encountered a few with a number of readers now. The most important consideration is that you can’t cut and paste code from an e-book directly into your IDE and expect it to work. There are all sorts of reasons for this exclusion. For example, cutting and pasting may insert special characters into the output stream or the resulting paste may not have white space in the right places. A common problem is that publishers often convert regular single and double quotes into curly quote equivalents. The two kinds of quotes (both single and double) are completely different and the second type definitely won’t compile.

The best option when working with an e-book is to view the code in the e-book, but still get the downloadable source code for the book from the publishers website. I always provide a blog post detailing where to obtain the downloadable source for a book, when you need source code to use the book. If you can’t find the downloadable source, always feel free to contact me at John@JohnMuellerBooks.com. I want to be sure you have a great reading experience, which means having source code that actually runs in your development environment.

Another potential problem with e-books is that you may see unfortunate code breaks (despite the efforts of the publisher and myself). When you need to understand how white space works with a programming language, always review the downloadable source. The fact that the downloadable source compiles and runs tells you that all the of white space is in the right place and of the correct type. Typing the source code directly out of your e-book could result in added carriage returns or other white space errors that will cause the code to fail, even though the commands, variables, and other parts of the code are all correct.

As always, I’m open to your questions about my books. If you don’t understand how things work, please contact me—that’s why I’m here.

 

Using the Correct Product with MATLAB for Dummies

A reader recently wrote in with a problem with the example on pages 311 and 312 of MATLAB for Dummies. In this case, the reader was using the R2015b academic license edition. What the reader saw was this error:

>> A = magic(4)

A =

    16     2     3    13
    5    11    10     8
    9     7     6    12
    4    14    15     1

>> factor(sym(A))
Error using sym/factor (line 50)
The first argument must be a scalar.

It turns out that the newer version of MATLAB doesn’t provide the same support as the R2013b release used for the book. As a result, the example code doesn’t work as expected because the newer version requires different code that looks like this:

A=magic(4)
for i=1:4
    for j=1:4
        B{i,j}=factor(A(i,j));
    end
end

To get all factors double click on B in the workspace window. This workaround is needed because the newer version no longer supports the old method of performing the task.

The point is that the book is written to use a specific version of MATLAB, R2013b, so you must have that version in order to get good results. Fortunately, you can still get the R2013b release. All you need to do is go to the Mathworks site at: http://www.mathworks.com/downloads/select_release. Simply choose the R2013b release from the Download Earlier Release list after you have logged in. Please let me know if you have any questions or concerns at John@JohnMuellerBooks.com.

 

Entity Framework Examples – Visual Studio 2013 Update

Microsoft has a habit of making updates between versions of Visual Studio applications difficult. For example, the simple act of opening a solution (.SLN) file using a different version of Visual Studio than the one used to create it can be difficult or impossible. Most technology updates contain breaking changes that mean older code requires tweaks in order to continue working. Even the Visual Studio IDE interface changes, which means step-by-step instructions no longer work properly. Unfortunately, all of these sorts of changes have affected the examples in Microsoft ADO.NET Entity Framework Step by Step. This book is written to support:

 

  • Visual Studio 2012 Professional (or above)
  • Entity Framework 5.x

It doesn’t surprise me that Visual Studio 2013 developers are encountering problems with the book. Changes to the IDE mean that the step-by-step instructions won’t work as stated and there isn’t an easy method of fixing this problem short of rewriting the book. Likewise, changes to the Entity Framework mean that some assemblies such as System.Data.Entity don’t even exist any longer, so some book explanations won’t make sense.

However, it’s still possible to open the examples and see how they work. Instead of opening the .SLN file associated with an example, open the C# Project (.CSProj) file. For example, when looking at the example in Chapter 1, you open the SimpleEF.csproj file found in the \Microsoft Press\Entity Framework Development Step by Step\Chapter 01\SimpleEF\SimpleEF folder instead of the SimpleEF.sln file found in the \Microsoft Press\Entity Framework Development Step by Step\Chapter 01\SimpleEF folder when using Visual Studio 2013.

Much of the theoretical, usage, and general functionality information in the book (about half of the book) is still useful to the Visual Studio 2013 developer as well. So, there is still a lot of value to obtain by reading my book, but readers are right to point out that not every feature will work as written. Please accept my apologies in advance if you purchased the book and were disappointed with it. I did provide clear instructions about the products to use with the book in the book’s Introduction, but such information can be easy to miss.

As always, I try to provide every reader with a great reading experience. Should the publisher decide to update this book, you’ll learn about the update here when I start looking for beta readers. Please let me know about your other book-specific questions at John@JohnMuellerBooks.com.

 

Choosing an Example Type

It can be difficult to choose just the right kind of source code examples to include in my books. In fact, readers often write to ask why I didn’t choose a different kind of example for a book. For example, a lot of readers tend to prefer console applications because they’re:

 

  • Straightforward
  • Easy to understand
  • Easy to write
  • Demonstrate the code clearly
  • Don’t rely on any automation


Given these reasons, it would seem as if I’d use console applications for all of my examples in all of my books. In fact, these benefits (and others) are the reason I used console applications in C++ All-In-One Desk Reference For Dummies. In fact, to this list, you can add the benefit of the same example code running on multiple platforms to the list. The same example code runs on Mac, Linux, and Windows platforms with the GCC compiler. Even with this book, however, I’ve had readers write to ask why I didn’t use a different compiler or IDE and why I didn’t include examples that demonstrate the ability to use C++ to create user interfaces in anything but Visual Studio (the new edition of the book won’t include the Visual Studio examples).

Some books don’t lend themselves to console applications. For example, one of the purposes of Microsoft ADO.NET Entity Framework Step by Step is to show how you can use the automation provided by Visual Studio to write your applications with less code and in significantly less time. Not everyone likes the automation and I’ve actually had a few readers ask why I couldn’t write the examples using a console application format. The problem is that few people use the Entity Framework with console applications and the automation is there to simplify things. I understand that other books may provide console application examples, but I chose to provide the examples in a form that the majority of my readers would use in a real world setting.

Trying to come up with a book that pleases everyone is simply impossible because everyone has different needs. It all comes down to people wanting the best deal possible in a book, which means seeing an example that uses their environment on their platform and demonstrating precisely the kind of code they need to write. It’s an unrealistic expectation for any book. My Getting the Most from Your Technical Reading Experience post explains how you can optimize the purchasing experience to obtain the best book for your needs. The caveat is that no matter how good the purchase is, the book will never answer all of your questions and most definitely won’t answer them in precisely the way you need them answered for fulfill an application development requirement.

Of course, I’m always open to your input. It’s the reason I run this blog and ask for your input in nearly every post. My purpose in writing is to answer as many questions as I can for as many readers as I can in the best way possible. Sometimes that means I need to take a step back and rethink a particular process I’m using, technique I’m applying, or perspective I’m pursuing. I encourage you to continue contacting me at John@JohnMuellerBooks.com with your book-related queries. I always use your input to help create better books in the future.

 

LINQ for Dummies Examples and Older Versions of C# Express

A number of people have written me about the examples in LINQ for Dummies not working with older versions of Visual C# Express. I’ve tried to become more proactive about telling people precisely which version of language products I use to write a book so there are fewer surprises, but this isn’t one of those books. In this case, I used Visual Studio 2008 Professional edition and Visual Studio Team System 2008 edition for testing purposesI definitely didn’t test it using Visual C# 2008 Express edition. In every case that I know of, when the reader upgraded to at least Visual Studio 2008 Standard edition and read through Chapter 1 to understand the LINQ usage requirements, the examples began to work.

Of course, many people don’t have the funds to buy Visual Studio 2008 (or any other version of Visual Studio for that matter). So, I’ve decided to check whether the problem example that most people write me about (Listing 2-1 on page 30) will work with Visual C# 2010 Express edition, which is a free download. Before you begin then, download and install Visual C# 2010 Express edition on your system using Microsoft’s directions. I’m assuming that you’re performing a default installationaccepting all of the default settings and not installing SQL Server.

Once you have Visual C# 2010 Express edition installed, download the source code (if necessary) and locate the \Chapter 02\SimpleFromQuery\SimpleFromQuery folder. In this folder you’ll find a file named SimpleFromQuery.csproj. Right click this file and choose Open With > Microsoft Visual C# 2010 Express from the context menu. You’ll see the Visual Studio Conversion Wizard start up as shown here.

VisualCSharp01

Follow the steps to convert the example to Visual Studio 2010 format. Use all of the default answers, including creating a backup of the original example, just in case you need it later. After you complete the conversion, press F5 or click Start Debugging. The example should compile and run. Click Test and you’ll see the results shown here.

VisualCSharp02

In short, if you’re having trouble getting the examples to run using an older version of Visual C# Express, try the latest version. It does appear to work fine. I’ll check the remaining book examples just to be certain. If you do encounter problems with any of the examples working with Visual C# Express 2010, please let me know at John@JohnMuellerBooks.com.