Misleading Stats Bother Me

I saw an interesting video today. This post isn’t about its political ramifications. In fact, I have no freaking clue what they’re trying to say. But the part that caught my eye was this:

It’s an agenda that – so far – has resulted in an increase in U.S. corporate profits of 45%, while wages of America workers has risen only 3% in the last five years.

That sensationalist quote makes it sound like corporations are eating up profits at the expense of their workers. The problem with their implied conclusion is that if profits went up 45%, so should wages. Unfortunately, that’s not realistic.

Let’s say a service-oriented corporation had $10,000 in employee wages (its only cost) and made a profit of $1,000. In other words, they had total revenue of $11,000.

But then they had an awesome year and sold $12,000 worth of services. Let’s say we funnel that 50/50 between “profits” and “wages”. Notice that wages increases to $10,500 (5%) while profits increase to $1,500 (50%).

For every $10 in wage costs, you might get $1 in profit. Wages are the single biggest cost of running a company. Unlike revenue, profits are a fraction of wages.

That little figure they threw out means nothing. Even if revenue jumped 45%, it would still be misleading since most companies would spend it to increase HR, not increase wages by 45%.

Why Apple Chose iPhone Despite Cisco Owning the Trademark

In moments, there will be blog comments all over the Internet about the new iPhone that Apple just released. But I pondered, “Why iPhone? Isn’t that taken by Cisco?”

I’m not a lawyer, but I offer an explanation. I may be wrong, but give my explanation some thought.

The Wikipedia article on trademarks has this clause:

Unlike patents and copyrights, which in theory are granted for one-off fixed terms, trademarks remain valid as long as the owner actively uses and defends them and maintains their registrations with the applicable jurisdiction’s trademarks office.

The key is “defends.” Now do a news search for iPhone. You’ll see a freakishly lame press release about Cisco’s new lame phone, a trademark they’ve owned for a decade. But it’s buried in articles about Apple. People have been speculating for years about Apple’s coming iPhone. Even in 2002.

And yet no word of Cisco ever telling anybody to quit referring to the product as iPhone. None.

Perhaps Apple’s logic is simple: The entire world already thinks of Apple when someone says iPhone and it’s largely due to the fact that nobody ever contested this public perception. Perhaps they intend to argue that the trademark was invalidated years ago.

P.S. For the record, my prediction wasn’t too far off.

Why is Software Development So Hard?

Why is software development so hard? That was the topic of a Slashdot article that was featured today. In short, the article was asking why, after all of the collective experience in software development, is it still notoriously difficult to get quality software out on time, without bugs, and under budget.

On one hand, it’s obvious that software development is still a relatively young “science,” as it has not been around for even half a century. Despite this, the article had an interesting point. Why is it that no matter how many times companies produce new software, they inevitably fall victim to delays. Just look at Vista, the next version of Windows that has been delayed over three years and shed large portions of its original specifications. Less features, more money thrown at the problem, and yet still late by three years? How, you ask?

I am not linking you to the actual article because it isn’t nearly as interesting as this comment I read in response to the question. A clever reader wrote in response:

Why is conducting an orchestra so hard?

Some might read that and think it was a joke. But the next reply put it into context.

It isn’t. Haven’t you seen them, all they do it wave their hands around and look silly. That’s the point. Everyone thinks it’s a breeze when it isn’t, so everyone underestimates everything.

Of course, my sharper readers would notice that these answers don’t actually answer the question. In fact, all they do is dismiss the question by saying, “because it is harder than it looks.” This brings up a very important lesson that seems to elude many companies (thankfully not mine) when it comes to IT project managing. You can’t expect a masterpiece without the talent, knowledge, and experience. Another reader wrote:

A good orchestra conductor who is in front of a bunch of rank beginner inexperienced musicians will not be able to make very good sounding music. You get what you pay for.

Amen.

PHP Array Keys and Floats

Wow! I found another obscure “feature” of PHP! Array keys were silently round off into integers when I tried to index by floating point numbers!

We’ve all heard PHP is “smart.” It converts stuff for you. If you try to add “4” and ” 2 ” together, it will make 6, even though the two is really a part of a word that happens to contain the number two in it. You see, PHP is very forgiving about mixing variable types. It just converts integers into floats, floats into strings, and strings into doubles without hesitation.

So imagine my surprise when I was creating an array using floating point numbers as keys. Why floating points? Coincidence.

A little “trick” I use is to create an array using some unique value as the key so that I can ensure there are no duplicates. For example, when I am working with result sets for a user, I might use the user’s user ID as the key so that if the result set contained that user again, I can ensure they show up only once in my final array. Other times, I might use the username, since PHP accepts strings as keys. And here was my problem.

It just so happened that the “ID” in this particular case was a float, which is very unusual, but hey, it happened. You see, sometimes my application grouped stuff by strings. Other times numbers. It just so happened this time was a float because that’s just what I was given. Here’s some demo code.

$totals = array();
// grouping results by subtotal
foreach($result as $record) {
    $unique = $record[‘subtotal’];
    $totals[$unique] = $record;
}

Examine that code. Now some people might say, “but why not just format your SQL so that the results are already grouped!” Well, that’s beyond the scope of this discussion, but I’ll entertain the notion. For me, changing a 2 page long SQL query that examined, on average, 2 – 4 million rows was not an option. I’m sure you can sympathize. That’s not the point anyway.

The point is that when you run the above code and “subtotal” happens to be a floating point number, weird shit happens. The unique values looked something like:

0, 0.1, 1, 1.95, 2, 5, 9.95, 35.50, 35.90, 35.99, etc.

The grouped results looked like this…

0, 1, 2, 5, 10, 36, etc

So it was very surprising when the actual result had about half as many uniques as it should have. What happened? Things were getting rounded off! So since most of the values had decimals in them, they were getting lumped together with their nearby counterparts, silently screwing up my results!

The lesson here is that array keys *can not* be floating numbers. And if you assign floating numbers (numbers with decimals), you must convert (cast) them into strings. So to fix the original code snippet…

$totals = array();
foreach($result as $record) {
    $unique = $record[‘subtotal’];
    $totals[(string) $unique] = $record;
}

That makes the number 0.1 into the string “0.1”. Thus, PHP is able to tell “1.1” apart from “1”. Remember, this only applies to array keys since PHP will normally distinguish the two numbers correctly.

And this is one of the many reasons how PHP trains programmers (including me) to be sloppy about their data types. Oh well.

MySQL Timestamp and NULL – ANNOYING Part 2

Today I discovered a new bug/feature in MySQL that is very annoying and ALSO involves NULL (see previous post). In short, a NULL-enabled column can’t be set to NULL if it is of the type timestamp.

So here’s the run down.

If you create a timestamp column that is…

  • NULL enabled and has a default value to NULL, things work exactly as you imagine. You can set it to NULL, you can set it to other time values, and then set it back to NULL. No problem.
  • NULL enabled and has a default value of “0000-00-00 00:00:00” or CURRENT_TIMESTAMP, it can NOT be set to NULL. Ever. If you try to set it to NULL, it will instead *DANGER DANGER* set it to CURRENT_TIMESTAMP!

Did you catch that? NULL is converted to CURRENT_TIMESTAMP in a NULL enabled table without NULL set as the default value. Can you say insanely stupid bug? Well, supposedly this is a legacy feature, but you know how I feel about that.

To fix this, make sure your NULL enabled timestamp columns are correctly defaulted to NULL.

I confirmed this DOES NOT apply to datetime columns. Great.

Isset and NULL, Array Keys and NULL – ANNOYING Part 1

I have two VERY annoying bugs to share with you in PHP. After this, I’ll make a post about an annoying thing I found in MySQL regarding NULL values too.

This is a relatively known “bug” to some people, but often forgotten. In fact, I learned about this over a year ago, but completely forgot until now when I came across impossible bugs caused by it. The function isset() returns FALSE for variables equal to NULL, despite the fact they are set!!

The PHP function isset() returns whether a variable “is set” or “does exist.” UNFORTUNATELY, that’s only half true. Take the two following code samples. One will act as you think, and the other will not.

$myName = ‘Michi’;
isset($myName); // TRUE

$myName = NULL;
isset($myName); // FALSE. @$!%#*?

For those of you screaming bloody murder, it gets worse. Consider the following:

$names = array();
$names[‘a’] = ‘Michi’;
$names[‘b’] = ‘Kono’;
$names[‘c’] = NULL;

Now observe the results of the following applied to that array.

isset($names); // TRUE
isset($names[‘a’]); // TRUE!
isset($names[‘b’]); // TRUE…
isset($names[‘c’]); // FALSE, %@#*^!

That’s right, the function ALSO ignores NULL array keys!!!

 Anyway, I’m sure this will introduce more than its fair share of bugs in code without people ever even realizing it. Ever. Since this throws up no warnings and will very, very rarely be a factor. But trust me, sooner or later, it will cause bugs, whether or not you’ve noticed.

Here are the fixes to this insanely stupid bug. Well, some people call it a “feature,” but it’s a bug in my book. That or the function should be renamed to not_null().

array_key_exists(‘myName’ ,get_defined_vars()); // TRUE
array_key_exists(‘c’, $names); // TRUE

The first line checks to see if the variable is set by comparing it to an array that contains all variables in the current scope. The second line checks to see if the specific key is set (obviously).

Isset() is only good for variables you know will never be NULL, and for cases where you are not doing type-sensitive checks (triple equals sign). Luckily, that’s 99% of the time in PHP.

6 Predictions of 2007 – More Spam, Less Paper, Bigger Google

I thought it would be cool to look back on this post in 2008 and see how I did. These are 6 predictions I believe may come true by the end of this year.

Google will grow 20% to $600 a share.

I’ve already explained this in depth. In short, Google Checkout, the radio ad agency they purchased, YouTube, and an entry into the CPA ad market will fuel this growth. Of course, this growth won’t be until the end of the year when they report their Q3 and Q4 earnings. Q1 earnings may disappoint due to the new costs of running YouTube. But these costs will be offset with the sponsorship of YouTube by various content owners in the remaining quarters.

The single biggest stock spike will come when Google formally begins public CPA ad network trials.

Ruby remains the new Python and does not surpass either ASP, VB, C, C++, C#, or PHP, and does not enter the enterprise market in any significant way.

Sure, a few startups such as Digg may start out on Ruby and make it, but I predict now that no major entrenched corporation that goes online, nor one that is already online, will switch to Ruby. The only enterprise Ruby applications that will exist will be small startups that grew large. Ruby will replace Python as PHP replaced Perl (in the mind share sense).

Ruby on Rails made headway while there was no competition, but now there is plenty in .NET, Java, and PHP. When the Rails hype dies down, people will have to compare Apples to Apples again — Ruby as a language compared to others. While many have discussed its beauty and elegance, comments like that certainly didn’t help Python much either.

Dell rebounds, Apple grows more, Microsoft grows for once, and Vista makes it to laptops.

Now that there is a new operating system out, we will see some renewed spending on computers. Pay particular attention to Q4 where Dell should report large earnings on its laptops, right around when Microsoft gets out its first service pack. Microsoft’s Zune will continue to flounder while its operating system will make major inroads — on laptops. Luckily for them, the Xbox division will do finally turn in some profits, offsetting the cost of the Zune. The corporate desktop scene will hardly change at all this year for Microsoft as nobody can justify the huge costs of getting top of the line hardware for a new operating system when you can buy great XP machines from Dell for $300.

Meanwhile, Apple will release a major new product in the next three months. One will be “iTV”, and the other will be a new top of the line iPod. This may be the “iPhone” or just a new video iPod. Either way, this will continue to boost Apple’s stellar iPod sales, keeping its revenue strong and the halo effect stronger. We should see continued growth in the Apple market share as new people decide to give Apple a try.

Electronic paper will see its first true mainstream applications in the US, but it won’t catch on for another year.

Why a prediction about electronic paper? Because I think it will become hugely prevalent within the decade, creeping into virtually everything that touches electricity.

There is one product that could appear this year that will make e-paper big (and invalidate half my prediction): e-photo frames. Right now, there are those annoying “plug-in” photo frames. An e-paper version would mean the photo could sit without a power source, only requiring it during uploading. Since so many photos are digital these days, this would be a huge plus for people looking for an easy way to frame their photos themselves.

Otherwise, e-paper made an appearance in India late last year on a cell phone, and I think we’ll see production here in the US. But, it probably won’t sell very well due to an over-emphasis of the feature. I further predict that it will NOT appear in the old-media publishing industry (newspapers) because of its new-technology-averse nature and large trial cost (distributing readers). I give it a 50/50 chance that the credit industry picks this technology up this year in select trial markets. There is a small chance that a portable music player maker picks this technology up – but it won’t be Apple.

I think there is a very high likelihood that we will see a product that will allow someone to copy pages into a digital “handout” used in presentations (with a next button). Again, this product will probably languish in obscurity because photocopying just isn’t that inconvenient. E-paper’s real power will come when they have large scale production in swing, allowing for e-billboards and e-whiteboards (with pressure sensitive e-writing). That, and, of course, reading tablets. But these won’t hit the mainstream market for another year or two.

IE will still be #1, but monopoly abuse, no more.

That’s right, Internet Explorer 7 will continue to dominate. However, the share will soon look the iPod’s market share: 75% internationally (including IE6, that is). The prediction I am making here is that the downward spiral of IE will slow and even stop in some markets. Part of why is because Microsoft will try to make a new IE-only client-side application framework. IE7 just isn’t that bad, and Firefox’s growth is slowing down now that all willing early-adopters (and their friends) are tapped. That said, 2007 will still see a continued decline for IE.

Overall, IE will be weakest in Europe while Firefox will continue to gain share until Firefox averages about 25% there (IE gets 70%). In the US, Firefox will rise to 20% while IE will lose another 5% to end up at 75%, thanks to the continuing security leaks being reported. But don’t be mistaken — Microsoft is not going to be losing the browser war anytime soon. They just won’t be given a free ride anymore.

Microsoft will try to re-exert its monopoly power to make client-side IE-only web applications. This means the first IE-only Microsoft desktop web applications will show up late this year – complete with a new .NET libraries – and they will do well because they will center around Office. Most other software development businesses will not follow Microsoft and ignore 20% of the market, although some will. Firefox and friends won’t have a formal answer to the new technology until 2008, although portions of it will be emulated in Flash based implementations such as Flex.

IP technology will hit our homes, but not our living rooms.

While IP phones are making real progress in replacing conventional lines, IP TV will not replace the television set. While YouTube will grow in prominence, it will remain “just” a website until 2008 when mobile broadband technology (in the US) is mature enough to allow handheld streaming. While major content producers will sign up for YouTube, they won’t get on board with their arms wide open for at least a year due to the potential disruptive effect the medium will have on the traditional cash cow: prime time TV ad spots.

None of this will ever become main stream until regular TV viewing takes a dip, which won’t happen until a vast portion of the population becomes more comfortable with streaming videos online over watching commercial breaks on the TV sets. TiVo will have its day too, just not until near the end of the year when cable providers and networks realize they will be screwed out of the TV pie if they don’t react quickly. TV may eventually become a second monitor used only for media viewing, but if this does happen in a big way this year, it will either happen with Apple’s “iTV,” or not at all.

At the very least, I predict that YouTube will host a big event, such as the Super Bowl, a live news broadcast, or anything else that is live (or very close to live) and thus can be streamed with commercials and be *just like regular TV* in that it will be shown in a parallel time slot with the TV counterpart. I know they did a New Years thing this year (just online), but I’m thinking bigger and less anti-social sounding.

    And those are my predictions for 2007.

    Resolutions 2007

    The following are my resolutions for the year: #3 was edited for wording.

    1. Work harder than ever in securing my career. This means maintaining my work ethic and making sure my company succeeds.
    2. Save more money. I currently spend too much money going out or buying random things I only half need. My first step will be to hire a financial planner. The second step will be to stop spending like I have no budget.
    3. Make sure I devote more time to a personal life. See point #1 to understand why this is on the list at all.