Monday, April 22, 2013

Children's books

Now that we have two little kids in the house we're reading a lot of kids books.  I am absolutely shocked by how many kids books have typographical errors in them.

First off, kids books don't have A) lots of words or B) very long words.  [BTW, when I say "kids" I'm referring to 1 - 2 years old.]  So errors should be very easy to catch.  I'm an engineer and I'll be the first to admit my spelling and grammar are not the best.  So the fact that I'm catching all these errors just means there are most likely more errors that I'm missing.

Secondly, the whole idea behind a kids book is to help teach kids how to read and write.  How can kids be expected to grow up and speak proper English when the authors of their books can't even read or write.

So what are some of these errors you ask?  By far the biggest error is using the word till when they mean 'til. 'Til with an apostrophe is short for until, but so frequently the author uses till, as in "to till the soil."

Probably the second most common mistake is using round instead 'round (again short for around).  So the popular kids song goes, "the wheels on the bus go 'round and 'round."

Both of these errors are similar in that A) it involves contractions and B) both forms are legitimate English words which means you can't rely on a computer spell-check to correct the mistake.

And there are tons of other errors such as improper punctuation.  When listing 3 or more items use commas to separate them (or depending on the situation even semi-colons, but again we're talking about kids books so the list should never be so complicated as to require semi-colors to separate the items).

Most of the books we have were given to us as gifts or hand-me-downs.  There is no way I would ever spend money on a book like this in the store, I don't want to support authors who can't proof read something as simple as a kids book, or be bothered to have someone else check their work.

Wednesday, April 10, 2013

STL String Class

So it's kind of funny, I chose the name for my blog because I'm a software developer, and yet very few posts deal with computer programming.  But today's post is very much about computer programming.

My preferred programming language is C++.  When working in C++ you pretty much need a good string class to help out.  One of my favorite string classes is the MFC class CString.  The downside is it's only available to MFC apps and sometimes you're developing non-MFC apps, or writing for other platforms.  Another common string class is the Standard Template Library (STL) string classes; std::string and std::wstring.  However, I've found the STL string classes to have some major drawbacks.  I have two main problems with these classes.

1)  They implement few useful functions compared to other string classes.  The STL string classes do not offer the ability to A) perform case-insensitive searches and compare, B) format a string like printf, C) lowercase/uppercase a string, or D) tokenize a string using delimiter characters just to name a few.  These are all very common tasks and the STL string class doesn't implement them.

2)  The second problem is a crash bug that shouldn't be.  Take the following code for example
char *sz = NULL;
std::string str(sz);

This code will result in a crash 100% of the time.  If you pass NULL into the constructor of an STL string it will crash.  This shouldn't be.  A string class that accepts pointers should check them for NULL before dereferencing them.

The STL string class has a few benefits.  First, it's pretty much ubiquitous these days.  Every C++ compiler includes a version of the STL library so you can always count on it being there.  Also, whereas it doesn't offer many advanced functions it does offer memory management and the most basic of functions.  So it's better than nothing.

I think what shocks me the most about the STL string classes is how poor they are compared to the rest of the STL.  The STL container classes like vector, list, and queue are extremely well written and I use them a lot.  So I would have expected the string classes to be better than they are.

Even though CString is my preferred class, I actually use a different string class in most of my projects.  Years ago I wrote my own string class, which I've continued to improve over the years.  It is pretty much the best of all the string classes I've come across.  The function names very closely follows that of CString.  I've also profiled the class for performance against both CString and STL.  The STL (because of it's simplicity) is faster than CString.  My class is as fast or faster than the STL.  Plus I've added additional functions I've felt CString was missing such as constructors that perform printf style formats.  So it's the best of both worlds; the speed and performance of the STL string classes, with all of the functions in CString and then some.  I guess the only downside to the class is it calls some Windows APIs and therefore is not cross platform.  But other than that it's a really nice, fast, and stable string class.  I truly wish I could upload this class for everyone to use, but alas I developed it at work which makes it the property of my employer.

Monday, April 8, 2013

Helium

Recently we had a birthday party for our 2 year old.  As with many parties for kids we had Helium-filled balloons.  But part of me feels like this was a horrible waste of a useful resource.  I know, that sounds a little odd to regret buying Helium-filled balloons, but let me explain.

As anyone who's taken chemistry knows, there are only two gases lighter than the average density of air; Hydrogen and Helium.  Because Hydrogen is highly inflammable (think Hindenburg), balloons and dirigibles are now filled with Helium.  But people don't realize Helium is a precious commodity that, depending on how you look at it, is NOT renewable.  When Helium is present in the atmosphere, because it is lighter than air, it rises.  It continually rises higher and higher in the atmosphere until eventually it bleeds off into space.  The same is true of Hydrogen, but Helium (unlike Hydrogen) is chemically inert so it can't react with anything making it heavier and thus keeping it in the atmosphere.  What this means is once Helium becomes airborn, it's only a matter of time until it's gone.  Helium is the second most abundant element in the universe, but it's extremely rare on Earth.  Only 5 parts per million of the atmosphere is Helium, and most of that is in the extreme upper atmosphere where we currently don't have the ability to extract it.

You might be asking yourself, if Helium is so rare in the atmosphere how or where does the Helium we use come from?  It may shock you to learn Helium is extracted from the ground, in the exact same way as natural gas.  There is Helium trapped in layers of rocks underground which is extracted and separated from other gases.  I believe up to 10% of raw natural gas underground is Helium.  If you're wondering how the Helium got in the ground in the first place, it turns out Helium is the by product of radioactive decay of several large elements such as Uranium.  That's why, to some degree, Helium could be considered a "renewable" resource because even though we take Helium out of the ground, there's always elements decaying creating more Helium.  That said, I highly suspect man is extracting Helium and using Helium at a greater rate than it's being created.  And that's why I feel like the Helium-filled balloons were such a waste.  We used Helium strictly for decoration when Helium has so many other uses such as cryogenics, dirigibles, inert gas environments, etc.  So in the future if I need MRI medical scan but the MRI machine isn't operational because there is no Helium to cool the super-conductive magnets, I'm sure going to wish I didn't waste the Helium on balloons.