Automating Your Configuration with a Daily Batch

Batch files are still an important part of your system, especially if you find that you need to perform certain configuration tasks every day. Both Administering Windows Server 2008 Server Core and Windows Command-Line Administration Instant Reference discuss batch files, but this post is about a practical example of a batch file in daily use.

My system has a daily batch file. It runs every morning when I start the system up. (To save electricity, I do turn off my system every night and find that things also run better because I do.) The main reason for using a daily batch file is to configure my system so I don’t end up performing the same repetitive tasks every day. I tell the computer what to do and it performs the required configuration for me. After I get my cup of coffee, my system is ready to go—fully configured for my use.

The daily batch file appears as an entry in the Startup folder on my system. Placing the file in the Startup folder means that it runs automatically, but that I can also easily disable the batch file should I wish to do so. Use these instructions to add a daily batch file to your Startup folder:

 

  1. Choose Start > All Programs. You see a list of entries including Startup.
  2. Right click Startup and choose Open from the context menu. (Unless you want everyone to use the same automatic batch file, you don’t want to choose Open All Users.) You see a copy of Windows Explorer open for the Startup folder.
  3. Right click anywhere in the right Windows Explorer pane and choose New > Text Document from the context menu. Windows will create a new text document named New Text Document.txthowever, only the New Text Document part of the filename is highlighted.
  4. Highlight the entire filename and type Daily Tasks.bat. Make absolutely certain that you also overwrite the .txt part of the filenameDaily Tasks.bat.txt won’t do anything for you.
  5. Press Enter. You see a Rename dialog box that asks whether you’re sure that you want to change the extension of the file.
  6. Click Yes. Windows renames the file.

Of course, the file is empty at this point. Right click Daily Tasks.bat and choose Edit from the context menu. Windows will open a copy of Notepad with the empty batch file loaded. At this point, you can start typing commands for Windows to execute automatically when you start up in the morning. It’s possible to execute many commands directlyespecially those that are meant to execute at the command line, such as W32Tm /Resync, which forces an update of the system clock. Other commands require that you use the Start command to execute them. For example, you might want to tell Firefox to automatically open the Astronomy Picture of the Day site using this command:

 

Start “C:\Program Files\Mozilla Firefox\Firefox” http://antwrp.gsfc.nasa.gov/apod/

<font<> <font<>The Start command starts Firefox in this case. It passes the URL you provide to Firefox as a command line parameter. Obviously, the application must support command line parameters for this technique to work. More applications than you might think do support command line parameters (many undocumented), so a little research can provide a lot in automation.

Any command that you can execute in any other batch file is also available when you’re starting Windows. There is one special consideration. You’ll likely find that executing one command immediately after another causes timing problems when Windows is initially starting. For example, if you try to open several Web sites, you’ll find that Windows actually misses opening a few unless you provide some sort of wait period between commands. Fortunately, the Choice command fulfills this task perfectly. For example, the following command provides a 15 second delay that you can insert between commands:

 

@CHOICE /C:N /N /T:15 /D:N


Using this command the user won’t even be aware of the delay. The @ symbol makes the Choice command invisible. The /C command line switch provides the available choices (which consists solely of N in this case). The /N command line switch hides the list of choices from view. You create the actual timeout value using the /T command line switch, which is set for 15 seconds in this example. However, the /D command line switch actuates the delay by automatically choosing N after the 15 seconds. In short, this entire command line is a wait statement.

If you want your batch to run more or less invisibly, make sure you start it with an @Echo Off command. Otherwise, every command appears in the window. It’s helpful to check for errors when you first put the batch file together and when you make changes. Adding an @Pause at the end of the batch file keeps the command window visible so you can check for errors.

After you finish the batch file, you can execute it as you would any other batch file. The only difference in this situation is that this batch file executes automatically each day because it resides in the Startup folder. When you need to make changes to this file you can choose Start > All Programs > Startup, then right click Daily Tasks.bat, and choose Edit from the context menu. The file will open in Notepad for you.

This is one of the more interesting and useful ways to employ batch files. What are your favorite batch processing techniques? Let me know at John@JohnMuellerBooks.com.

 

Source Code Download Issues

Most of my books include source code. The source code is made available on the publisher’s Web site and you download it from there. I always recommend downloading the source code to reduce the potential for errors. Typos are the number one source of problems for readers who work with the source code in my books. A single mistyped word will cause the application to fail in some way. If the reader is lucky, the compiler will catch the error and provide a clear message saying what’s wrong (such as the fact that the .ResX file is missing), but often that isn’t the case and then the reader becomes frustrated with the unworkable code. Sometimes the error isn’t even the reader’s fault—errors do creep into books (see my Errors in Writing post for details). The point is to use the fully tested downloadable source code whenever possible to save yourself time and effort.

 

There is another good incentive to download the source code. The reason to work through the source code in your debugger is to discover how it works through actual tracing. To help accomplish this task, the source code examples are carefully crafted to provide an optimal learning experience and they include features such as additional comments to help enhance the learning experience (see my Handling Source Code in Books post for details).


However, what happens when the downloaded source doesn’t appear to work either? Some readers have complained that the downloaded example won’t compile. Normally, the problem is one of a missing file. Firewalls and other network security features can strip out files and some organizations are proactive about stripping out anything that even looks binary. Consequently, the downloaded ZIP containing the source code is missing solution (.SLN), project (.CSProj or .VBProj), resource (.ResX), or other files. The project won’t compile with missing files. The best course of action is to try to download the source code from another systemone that isn’t inhibited by the network security features that stripped out the files.

 

Missing .DLL files aren’t normally an indication of a failed download. In most cases, missing .DLL files are part of a library or third party product you must install. The book will always include instructions on where to obtain these required add-ons and how to install them. Make sure you install any required additions as part of your system setup.


Sometimes a reader doesn’t have another way to download the file. Asking me to send the source code to you won’t help because the same features that strip out the files from the publisher site will also strip them out of the e-mail I send containing the files. In most cases, the firewall still downloads the actual source code. Create the project using the instructions from the book, and then copy and paste the source from the downloaded files into this new project. It’s not a perfect solution, but it should still work better (and faster) than typing all of the source code by hand.

A few readers have asked that I create a disk containing the source code and mail it to them. I’m not set up to perform this kind of support and the costs would be prohibitive. Unfortunately, if all else fails, you may have to try typing the source in by hand, but it should be your last option because typos really can ruin the learning experience. I’m always open to suggestions for making your reading experience better. If someone has a magic bullet solution that will help others get the downloaded source code in one piece, please let me know at John@JohnMuellerBooks.com.

 

Review of Creative Close-Ups

You may have noticed that I use quite a few photographs in my blog entries. Some of these photographs look nice (they aren’t art by any means) and some of themwell, they didn’t quite work out as I hoped they would. Over the years I’ve grappled with unwanted shadows and close-ups that aren’t quite close enough. Focus is also a problem and fuzzy pictures never convey what you want when it comes to factual posts of the sort I create. I was recently talking with Harold Davis about my photographic ventures and he graciously offered me a copy of Creative Close-Ups. As expected, this is a self-help book for people who want to create better close-up photography, which is the sort found most often in my blog posts.

The one thing that will strike you immediately about this book is that Harold is quite talented and is possibly wasting him time writing books, but I’m extremely happy that he did. The book contains page-after-page of striking images. Some of them have been Photoshopped, something that Harold readily admits and even recommends to an extent. Because I’m looking more for better real world shots and not necessarily art, I’ll very likely not Photoshop anything on my blog from an artistic perspective (I could very well use Photoshop to enhance images to make them better convey the information I want), but the book also pointed out the usefulness of creative croppinga technique I intend to employ from now on.

 

I’ll always tell you if I’ve modified a picture in some way. Otherwise, you can be sure that the picture you’re seeing on the blog is the picture as it came from the camera. I know that there is a certain amount of discussion about this topic and plan to be up front about any modifications or twiddling I perform.

Harold has convinced me that using a tripod isn’t quite the waste of time I thought it might be. The discussion starting on page 64 will probably change your mind too. There are few sections of the book that provide a purely artistic view of a topic, but you won’t find many. Instead, Harold tries to provide good solid reasons for doing things a certain way and then backs them up with stunning pictures. In fact, there isn’t a single photograph in the book where Harold has kept the technique secrethe exposes every technique for your learning pleasure. Where there are multiple ways to accomplish the task, you’ll find them listed, along with any pros or cons of that particular technique.

I found the discussion of equipment helpful in many cases. For example, in page 60 you’ll find a tip about the Lensebaby 0.42X Super Wide Angle accessory lens. However, the text isn’t formatted differently (as a Tip or a Note found in other books), so finding the information later isn’t as easy as it could be. In addition, there isn’t any picture of the lens taken apart so that I can see what he’s talking about. The information is probably quite helpful, but it’s less useful than it could be due to a lack of pictorial backup.

Overall, the book is more focused on technique, than on how to apply the techniquethe discussions of equipment left me scratching my head and I ended up researching the information on my own online. (Harold also kindly answered my e-mail queries.) Admittedly, there is a short list of URLs on page 234, but you won’t find a resource for every piece of equipment listed in the book. Creative Close-Ups lacks pictures of any of the equipment, so someone like me has no idea of what these devices look like. If I were to go to a store, I’d be completely lost. It would also be nice to know if there are places online to buy equipment where I won’t be cheated since the nearest camera shop is in Milwaukee (170 miles away). So, this book will tell you how to do something, but not provide you much in the way of describing the means to accomplish the task.

That said, there are many sections that make the book worth the purchase price (if the amazing photography and associated setup instructions isn’t reason enough). The section on focusing on page 68 is especially insightful. In fact, the tips on page 70 are precisely what I need to do a better job with my own photography.

This book provides me with plenty of room to grow. The discussion of focus stacking starting on page 124 will require plenty of work on my part and I may never master the technique in the same way that Harold obviously has. Still, the discussion gives me some ideas and I hope that I’ll be able to use the technique in my blog.

Creative Close-Ups provides inspiration, food for creative thought, and lots of technique. I don’t think that a complete novice will be able to use the book because Harold doesn’t explain many terms such as ISO and what an f-stop is, making notations such as ISO 100 and f/40 useless. (There is a short description of these terms on page 72, but hardly enough for the novice and not early enough in the book to make the initial discussions helpful.) However, for someone who is truly serious about taking better photographs, this book provides a lot of informationmore than most people will be able to absorb in a single reading. I personally plan to read through some sections multiple times and use the book as a reference in the future. Whether this book makes me a better photographer remains to be seen. (As Harold says on page 46, “Cameras don’t take pictures; people do.”) I wish that there was more about the mechanics of performing these amazing tasks and better descriptions of the equipment the author used, but that may be asking too much out of a single book on a complex topic. Overall, I think the author has achieved his goals admirably and that anyone reading this book will truly be dazzled by what is possible.

Creating a CodeBlocks Project with Multiple Existing Files

Most real world C++ projects include multiple source files. Book I Chapter 5 of C++ All-In-One Desk Reference For Dummies shows how to create a project that has multiple source files. The first example, found in \Author\BookI\Chapter05\MultipleSourceFiles, discusses two .CPP files. The second example starts on page 115 and you find it in \Author\BookI\Chapter05\MultipleSourceFiles2. This example includes two .CPP files and a single .H file. I’ll use the files from the second example for this post. The example works the same as the one in the book, but in this case, we’ll start with the three files and create a project around them.

You need to start with a CodeBlocks project. It’s possible to use either an existing project or create a new project to hold the files. In either case, once you have a project to use, you simply add the files you want to it, set the build options for those files, and then create your application. The following steps create a new project, add the files from MultipleSourceFiles2 to it, set the build options, compile the resulting project, and show you the results.

  1. Choose File > New > Project. You’ll see the New From Template dialog box.
  2. Highlight the Empty Project template as shown here:MultipleSourceFiles01
  3. Click Go. You’ll see the Empty Project wizard. If you’re seeing the Welcome screen, click Next to get past it.
  4. Type the name of the project (the example uses MultipleSourceFiles3) in the Project Title field and choose a location for the project (the example uses \Author\BookI\Chapter05) in the Location field. If you’re following the example, your wizard should look like the one shown here:
    MultipleSourceFiles02
  5. Click Next. Look in the Compiler field and ensure that the GNU GCC Compiler option is selected.
  6. Click Finish. The wizard creates a blank project for you.

At this point, you have an empty project without any files in it. However, you can add files to any existing project. The following steps add the files from the MultipleSourceFiles2 project to this project.

  1. Right click the project entry (MultipleSourceFiles3) in the Projects tab of the Management window and choose Add Source Files from the context menu. You see the Add Files to Project dialog box shown here.

MultipleSourceFiles03

  • Locate the \Author\BookI\Chapter05\MultipleSourceFiles2 folder on your system.
  • Click on main.cpp. Ctrl+Click on safestuff.cpp and safestuff.h. You’ll see all three files added to the File Name field.
  • Click Open. You’ll see the Multiple Selection dialog box. This dialog box contains entries for each of the builds that you specified when creating the project. The default is to use the files you’re adding in all of the builds as shown here. (The example uses all of the files in all of the builds.)
    MultipleSourceFiles04
  • Configure the files you’ve selected by choosing the build the file should appear part of and click OK. You’ll see all three files added below the MultipleSourceFiles3 entry in the Projects tab of the Management window as shown here:
    MultipleSourceFiles05

 

This technique adds existing files to a different project. Notice that the files are still referenced in the original project. If you make a change to these files, the changes will also appear in the original project. Of course, that’s not always what you want to do. So, you need an alternative for those situations where you want a copy of the file in a new project. In this case, use Windows Explorer to copy the files from the MultipleSourceFiles2 folder to the MultipleSourceFiles3 folder. You then use Steps 1 through 5, with the MultipleSourceFiles3 folder as the source, to add the files to the project.

Many developers find the need to use existing files in a project. It’s something you’ll do quite often, especially with header files. Of course, when working with header files you also have the option of using the #include directive. Please let me know if you have any questions about this process at John@JohnMuellerBooks.com.

Fun is Where You Find It! (Part 2)

One of my more popular previous posts is Fun is Where You Find It! In this post, I suggested that family crafting can provide a source of cheap entertainment. Finding crafting activities that the entire family can enjoy is productive from a number of perspectives, not the least of which is promoting communication between family members. Of course, not every activity has to be craft related. Every year Rebecca and I put together a number of jigsaw puzzles. They’re inexpensive, require a few hours to complete as a minimum, and also promote communication. We discuss all sorts of things while putting our puzzles together.

Some of the jigsaw puzzles we’ve done are quite exotic. We put one together that glows in the dark and some are works of art that we’ve displayed for weeks on the dining room table before begrudgingly packing it away. A few have been oddly shaped or had other special features. In a few cases, we’ve even discussed using Mod Podge to preserve our treasure for all time, but have never quite made it to that point. Should we ever decide to do so, we could easily frame our treasure for everyone to see. Given the number of puzzles we do though, it’s unlikely that any particular puzzle will prove so spectacular that we’ll actually go this extra step.

One of the complaints about jigsaw puzzles is that they’re boring. In order to make the jigsaw puzzle interesting, it has to have a twist. The glow in the dark puzzle offered such a twist, but it was probably more complex than the average family would want to do and the subject matter was along the lines of a Gothic image that many people would dislike (it was of several women walking through a medieval forest at night to a party of some sort). Families will also want to avoid the double-sided and 3D puzzles because they can prove difficult to complete. However, a puzzle we just completed could prove interesting to quite a few people, Murder at Bedford Manor. You put the puzzle together, read an associated booklet that contains the basic story, and then look at the completed puzzle for clues as to who committed the murder.

The puzzle took about 22 hours for two people to complete and solving the murder required another 3 hours, for a total of 25 hours of fun for the low cost of $26.00. Where else can you entertain two people for 25 hours at a little over $1.00 an hour? We actually worked on a 1,000 piece version of the puzzle, but the 500 piece version will probably work better with a family that has younger children with shorter attention spans. The point is that you need not spend vast sums to have funa good time can be had for just a few dollars, which is perfect for the self-sufficient family on a budget. What is your favorite jigsaw puzzle? Let me know at John@JohnMuellerBooks.com.

 

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.

 

Making Brussels Sprouts Palatable

Rebecca and I grow a large assortment of vegetables. There are many reasons to grow a variety of vegetables, but you can distill them down into several important areas:

 

  • A balanced diet requires diversity because each vegetable has something different to offer.
  • Each grown year comes with different challenges and you can’t be assured that a particular vegetable will grow well in a given year.
  • Local nurseries will offer different choices in a given year, so unless you start absolutely every vegetable in your own greenhouse, you’re reliant on what the greenhouses have to offer.
  • Biodiversity ensures that your garden’s soil won’t be able to concentrate any particular pathogen.
  • Crop rotation is known to help garden soil by keeping any particular element from becoming depleted.

There are likely other reasons for growing a large variety of vegetables, but this list will suffice for the purpose of this post. I eat every vegetable we grow. In fact, I’ve never had a problem eating vegetables, having had insistent parents when I grew up who ensured I developed a taste for everythingeverything thing that is except Brussels sprouts. No matter how hard I tried, I just couldn’t convince myself that the little cabbages were good tasting. As a child, I’d swallow them whole to avoid tasting them at all (since eating them wasn’t an option).

Imagine my surprise then, when I got married and found that the one vegetable that my wife loved best was Brussels sprouts. Given a chance, she probably would have eaten them at every meal, leaving me wondering what to do next. So, I embarked on a quest to make the Brussels sprout more palatable while begging my wife’s indulgence in eating them only occasionally until I found a solution.

A good part of overcoming any vegetable dislike is to find a way to prepare them. Simply boiling Brussels sprouts in water and serving them with a bit of butter preserved the bitter taste all too well. My first discovery was that boiling Brussels sprouts (or any other vegetable for that matter) is simply a bad idea. Simmering tends to reduce the bitterness. I also discovered that lemon juice and garlic salt make the bitterness of many vegetables appear considerably less. So, here is my first Brussels sprouts recipe that made the vegetable at least sort of palatable.


Plain Brussels Sprouts

 

3 tsp

Garlic Salt

1/2 cup

Lemon Juice

3 tsp

Butter

2 cups

Brussels Sprouts

1/2 cup

Parmesan Cheese


Just
barely cover Brussels sprouts with water. Add lemon juice, garlic salt, and
butter. Simmer Brussels sprouts slowly until tender (don’t boil them). Remove
from heat and dish out into a bowl. Let cool for about 5 minutes. Coat top with
parmesan cheese. Serves 4.

Later I discovered that the method used to grow Brussels sprouts makes a huge difference. Most people pick them during the hot summer months. We found that by letting the Brussels sprouts continue to grow until late fall and only picking them after the second frost, that the Brussels sprouts were not only much larger, but also considerably sweeter. Since that time, we’ve found a few other vegetables that benefit (or at least survive) a light frost, including broccoli. (Most vegetables don’t like frost, so this technique does come with risks.) The combination of the new growing technique and my recipe made Brussels sprouts a somewhat regular visitor to the table, much to the happiness of my wife (who had waited patiently for many years for the day to arrive).

Recently I experimented with a new Brussels sprouts recipe that makes them taste even better. In fact, I’ll go so far as to say, I like them enough to eat them more often now. Here’s the fancier Brussels sprouts recipe.


Fancy Brussels Sprouts

 

1/2 tsp

Lemon Peel

3/4 tsp

Corriander

2 tsp

Garlic Salt

1/2 cup

Pomegranate Balsamic Vinegar

1/2 cup

Water

2 tsp

Butter

1/4 cup

Parmesan Cheese

2 cups

Brussels Spouts


Mix
the water, lemon peel, coriander, garlic salt, pomegranate balsamic vinegar,
and butter together in a pot. Bring the mixture near a boil, but not a full
boil. Add Brussels sprouts. Reduce heat to a simmer. Simmer Brussels sprouts
until tender. Remove from heat and dish out into a bowl. Let cool for about 5
minutes. Coat top with parmesan cheese. Serves 4.

Now you know my secret methods for dealing with Brussels sprouts. However, there are some important lessons here for the self-sufficient grower. First, make sure you pick your vegetables at the optimal time because timing is everything when it comes to taste. Second, the manner in which you choose to cook a vegetable is important. Taking time to make your vegetables taste good is an essential part of learning to like them. Let me know about your vegetables eating experiences at John@JohnMuellerBooks.com.

Getting the Most from Your Technical Reading Experience

There are many ways to work with books. However, in all cases, there is some work involved. No book, no matter how well researched and written, will simply spit out answers without any effort on the reader’s part. It’s true that the author can employ techniques to make the reading experience more pleasurable, productive, or efficient, but in the end, it’s the reader who decides just how much information a book conveys with regard to a specific need.

Of course, the first step is to ensure you get the right book. I’ve already discussed this issue in the Techniques for Choosing a Technical Book post. So, let’s assume that you have possession of a book that’s the best possible match to your needs. It may not be a perfect match, but it offers more than any other book you’ve checked.

Now you have to decide on how to interact with the book. That may seem simple, but many readers fail to discover what they need from a book, even when the book contains the required information in several places. Let’s face it, books are relatively large and it’s easy to lose track of a required bit of information. Without some guideline, the mind wanders and tends not to work very hard.

To obtain the most from a book you need a goal. The goal determines how you approach the book. Someone who is trying to learn a new skill will probably begin at the front of the book and work toward the end. Skipping chapters is akin to skipping classes in collegeyou can’t expect good results if you don’t obtain all of the information. As a contrast, someone who is trying to fix a specific problem under the watchful eye of a boss, probably doesn’t want to waste any more time than necessary finding the required information. This sort of reader will want to locate the section of the book containing the answer quickly. There are some readers though, who really don’t know what they want to dothey lack a goal and are thwarted when the author can’t guess what the reader wants. So, ask yourself why you’re reading the book and create a goal for that particular session. In some cases, you may very well want to wander through the book randomly looking for something interesting, but few people have the time or need to perform this sort of reading with a technical book.

Depending on your goal, you’ll want to determine where to start. Someone who is learning a skill will start in the Introductionnot in Chapter 1. If you don’t read the Introduction, you’ll discover that your educational experience is going to be less helpful. The Introduction is where the author conveys book goals, knowledge requirements, and required training aids. For example, you might not be able to use the educational version of the product you have to learn a new skill with this particular bookit may be necessary to get the released version of the product instead. Researchers and those who simply need the book for reference would do well to check both the Table of Contents and the Index. A book intended solely for reference may include tables in an appendix that provide additional ways to locate information, so you’ll want to find these tables as well.

You’ve likely heard all of the advice for creating a good study environment before, such as turning off the radio. A good study environment also requires focus on your part and the availability of the required equipment. Simply reading about how to perform a task isn’t nearly as good as actually performing the task. Reinforcing the information by putting it into your own words is helpful as well. Everyone learns differently, so it’s important that you take time to discover how you learn. Whatever it takes for you to create a good study environment, you won’t get much out of a book until you create it.

Everyone seems to be in a hurry today, but being in a hurry won’t help with technical information. Hurrying only creates errors. Take time to actually read and understand the materialread it several times if necessary. Work through the material before you act. Yes, I realize that the boss is ready to pound little knots all over your head, but he’s simply going to have to wait. A good solid answer that produces results often requires a little more time up front to create. The book probably has the information you need, but you have to take time to find it.

One of the most important things to remember is that the author isn’t clairvoyant. You won’t find a precise answer to any given question in any book. It’s possible to find an answer that’s close, but in most cases you’ll have to create a solution based on the information the book providesquick answers are rare.

I wish it were possible to create some form of instant mental transfer of precise data. Perhaps someday it will become the norm to do so, but I hope I’m not around. Part of the joy of technical reading is obtaining the author’s point of view and then creating your own permutations of that information. Working through problems creatively is a challengeone that I hope people working in technical areas continue to enjoy. If you have any pointers to getting more from a technical reading experience, let me know at John@JohnMuellerBooks.com.

 

Using CodeBlocks 10.05 – Part 5

This post begins with the code found in Book IV Chapter 3 (found in \Author\BookIV\Chapter03) of my book,  C++ All-In-One Desk Reference For Dummies. I’ve been testing my code for use with CodeBlocks 10.05 continues. I introduced this new version in Using CodeBlocks 10.05 – Part 1, where I discussed the general look of the new version.

The example on page 456 (example Constructor04) is supposed to fail. It’s an example of what happens when you add a specific constructor to a class without also defining a default constructor. CodeBlocks 10.05 fails in the same way that its predecessor does. However, the order of the candidates may differthe Simple::Simple(int) version may appear first. I’ve pointed out a few other error message changes in other posts (you can see the entire list of posts for this book in the Category Archive for C++ All-in-One for Dummies).

Otherwise, all of the other examples in Book IV Chapter 3 should work as described in the book. Since there was little to talk about in Book IV Chapter 3, let’s also discuss Book IV Chapter 4.

The example that begins on page 482 (example OverridingDerived, found in \Author\BookIV\Chapter04) of the book compiles with three warning messages in CodeBlocks 10.05 as shown here:

 

C:\Author\BookIV\Chapter04\OverridingDerived\main.cpp: In constructor ‘Printer::Printer(std::string, Printer::PrinterType, int, int)’:

C:\Author\BookIV\Chapter04\OverridingDerived\main.cpp:19: warning: ‘Printer::Type’ will be initialized after

C:\Author\BookIV\Chapter04\OverridingDerived\main.cpp:22: warning:   base ‘Peripheral’

C:\Author\BookIV\Chapter04\OverridingDerived\main.cpp:20: warning:   when initialized here

Linking console executable: bin\Debug\OverridingDerived.exe
Output size is 1000.61 KB
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 3 warnings

CodeBlocks 10.05 performs some additional checks that CodeBlocks 8.02 didn’t, so it will catch problems like the one shown in this listing. The example still works as described in the book. To get rid of the warning messages, you need to change the order of inheritance for the Printer class as shown here:

class Printer : public Peripheral {
public:
    enum PrinterType {laser, inkjet};
    PrinterType Type;
    Printer(string aname, PrinterType atype, int aprice,
        int aserial) :
        Peripheral(aname, aprice, aserial), Type(atype) {}
};

The idea is to ensure initialization takes place in the correct order. Even though the initialization order doesn’t make a difference in this example, it could in code you write. Notice that Type(atype) now appears after Peripheral(aname, aprice, aserial), which provides the correct initialization order.

In the next post I’ll start with Book IV Chapter 5. In the meantime, let me know if you have any questions about the CodeBlocks 10.05 updates for this book at John@JohnMuellerBooks.com.

 

Squash and Pesticides

Rebecca and I avoid pesticide/insecticide use whenever we can. Pesticides cost money, are costly to apply, and tend to ruin our health. They also kill pollinators, which are already in short supply. In fact, we’re able to use other solutions for every pest in the garden other than the squash bug. There is a host of bugs that will attack your squash, but the squash bugs seem to be the worst in this area.

Most other bugs are easily picked off (such as the tent caterpillars we squash by hand in the spring), drown in standard dish washing soap, killed using an environmentally safe method, or otherwise controlled. Mulching (see my Mulching Your Garden post) can help control bugs, as will keeping your garden weeded. One of the few good reasons to mow your lawn is to keep pests under control by reducing the places they can hide. (I’m a strong advocate of mowing the lawn less often to reduce mower emissions and to make the grass a length usable for purposes other than filling the landfill.)

The squash bug will infest a squash or cucumber patch quickly in spring and will continue infesting it until every plant is completely destroyed. Adult squash bugs are incredibly difficult to kill. The pictures I’ve seen online don’t quite depict the monsters that we have in our area:

SquashBug01

I happen to catch this picture of one of our squash bugs. A single counting on one plant turned up 42 of themall breeding. As you can see, the picture here shows a bug considerably bigger than the bugs you’ll find on most sites online. I’m not sure why ours grow so large, but they are quite vigorous.

The eggs also aren’t limited to the underside of the leaf. The bugs seem quite happy to put them on both sides of the leaf and in large clusters. Here is just one cluster:

SquashBug02

As you can see, this cluster is on the top of the leaf and it isn’t in the V pattern discussed in online sources. The point is to examine the plant thoroughly for squash bugs because they’re determined to destroy your plants.

To keep pesticide use at a minimum, check the leaves regularly for these clusters. Trying to pick the eggs off won’t workyou’ll end up damaging the leaf and it’ll die. The eggs hatch in one to two weeks and get darker as they get nearer to hatching. These eggs are just about ready to hatch, so yesterday I applied Seven (Carbaryl) to the affected plants. I’ve been looking into some of the more environmentally friendly solutions, but so far Seven is the solution that works best. If you have a bug infestation, try some of these other solutions first, before you use Seven.

You can’t apply Seven three days before harvest (more if you want to be careful). In fact, once the plants start blossoming robustly, you don’t really want to use any sort of pesticide (it’s essential to look after pollinator health). The best idea is to look for the squash bugs early in the season and attack them vigorously so that you start with a strong vine. If you see eggs after the blooms start, try drowning them using a limited application of neem oil. Insecticidal soap is completely ineffective on hard bodied squash bugs. Smash adult bugs using your fingers if there aren’t too many of them.

There is a point each season where we lose the bug battle. The squash bugs simply overwhelm every defense we can mount. However, by that time our squash have grown quite large and produced well for us. The vines die too early, but not before they produce usable output for us. To ensure we get enough squash, we simply plant more plants knowing that they will die too early from the invading plague. Yes, we could keep them completely under control using Seven, but only at the cost of our own health and the health of our pollinators, so this approach represents a good compromise that ensures an adequate harvest. Let me know if you have any questions at John@JohnMuellerBooks.com.