Hidden Overhead – how small things really add up

If you have ever spent some time in the corporate world you may have heard of the word ‘overhead’, and it is generally used to refer to the costs associated with the ‘headquarters’ staff in a large organization. See, you may be the worker on the front lines at the clients’ site, but your hourly rate goes towards your pay, the overhead, and profits for the company. Obviously, the greater the overhead expense the less flexible the company can be in setting rates and still making a decent profit. Now let’s take the concept of overhead to the network world, the two main transport protocols in use in the web are UDP and TCP/IP, one of them comes with more overhead as far as packet size is concerned. So what, why does this matter, it’s just a small bit of data right?

Consider this: What’s a stamp worth? 

Let’s illustrate the fact that small inefficiencies can lead to a large cost to an organization given the frequency of the inefficient action.  Imagine you are in charge of the post office and you need to identify cost savings.

Using the facts below you devise a plan that eliminates an inefficiency that exists with stamps.

  • 1 Pound – 453.592 grams
  • Mail pieces processed in 2010 – 171,000,000,000 [1]
  • Assume every piece of mail (packet) requires one stamp
  • Stamps are printed on paper that weighs 56 g/m(sq) [2]
  • Current stamps have the following dimensions 22.10 x 24.89 mm [3]
  • Assume that we are using first class letters which cost $0.45 cent for the first ounce and $0.20 for each additional ounce. The post office works like airport parking garage, they charge for the full ounce (even if you’re over by .20 grams!).

Now we all know that weight affects postage prices[4], I mean why else would we have those cool airmail envelopes and sheets of paper with the little striped edges, right.

First let’s translate the paper weight so that we have the grams per square millimeter, since we are dealing with the metric system we know that 1m² = 1,000,000 mm², next we divide the weight by the square millimeters to get a weight per millimeter. 453.592 / 1000000 = 0.000453592 grams / sq mm.

The postage stamp is 22.10 x 24.89mm so the area is 550.069 sq mm. The weight per postage stamp is 0.249506897848 grams.

Now we can calculate the straight cost of the stamp in weight added to the letter, we know that 0.249506897848 =  0.0088010968208481997 ounces and that it costs $0.20 cents per ounce, so it costs $0.00044005484 cent to mail the stamp on your letter. Barely noticeable, right? Now let’s multiply that by 171 billion ( 171,000,000,000 ), which is the yearly mail volume; the result, we would be paying $75,249,377.64 just to cover the weight of the stamps on the envelopes. If it was this simple we could use triangular stamps and save 37million dollars!

That’s great but we know that the post office rounds up to the nearest ounce and slaps a $0.20 cent charge on those that go over. Lets test the assumption on varying percentages of letters that could theoretically be put over the ounce limit by the weight of a stamp.

1% of letters are over = 1,710,000,000 * .20 = $342,000,000

This brings me to the last point: quantifiable things matter. You may disagree and many do, however, when you start presenting solutions to problems in the work world there is only one measure that really matters and it comes down to quantifiable outcomes.

To ensure your idea makes it you have to translate these outcomes into dollars, especially when dealing with network speeds, and security issues. Why? For far too long the IT department has sat back and used the ‘security’ argument, which seems to work without any thought to cost (be it in time or money, and more often both) . Your challenge is to sit down and translate your IT related issues into dollars and cents, and come up with quantifiable savings. Remember you can save money by saving time, which is what automation strives to accomplish.

Sources

[1] http://pe.usps.com/businessmail101/rates/weight.htm

[2] http://www.google.com/patents/US5503436?dq=us+post+office+adhesive+stamps&hl=en&sa=X&ei=_AliUKy-GZKo9gSRrYHgCA&ved=0CDoQ6AEwAw

[3] http://about.usps.com/postal-bulletin/2012/pb22330/html/info_006.htm

[4] http://pe.usps.com/businessmail101/rates/weight.htm

Random thoughts on code errors after teaching two different languages in one semester

When I was a bit younger we used to play a game called Pitfall where you would guide your player across various obstacles, including chomping alligators, deadly quicksand, and rushing rivers. In programming there are also pitfalls, and they may not be as bad as an alligator pit, but they will consume your time and leave you drained at the end of the day.

Software errors will always happen, it comes down to how quickly you can identify them and correct them that make all the difference. Those that argue that code should be written error free the first time have obviously not written much code. We can all agree that production code should be error free, but to achieve error free code means you will have to identify and eliminate errors.

I wanted to share a few thoughts on how to cut down on errors in your code.

Use proper indentation, and formatting. This is almost never taught in class, and most of the books that I have seen even contain code that runs and is compact but is not really easy to read.  It’s important to write all your code as if you are going to spend the rest of your career maintaining it.

This sounds great but how can I implement it? Let’s take a look at some code.

I like to use a tab for each block of code. Look at the difference between block a and block b.

A

Ext.override(Ext.form.Radio, {
        setValue : function(v) {
            if (typeof v == 'boolean') {
                Ext.form.Radio.superclass.setValue.call(this, v);
            } else if (this.rendered) {
                var els = this.getCheckEl().select('input[name=' + this.el.dom.name + ']');
                els.each(function(el){
                    if (el.dom.value == v) {
                        Ext.getCmp(el.dom.id).setValue(true);
                    } else {
                        Ext.getCmp(el.dom.id).setValue(false);
                    }
                }, this);
            }
            return this;
        }
    });

B

Ext.override(Ext.form.Radio, { setValue : function(v) {
if (typeof v == 'boolean') {
Ext.form.Radio.superclass.setValue.call(this, v);
} else if (this.rendered) {
var els = this.getCheckEl().select('input[name=' + this.el.dom.name + ']');
els.each(function(el){
if (el.dom.value == v) {Ext.getCmp(el.dom.id).setValue(true);
 } else {Ext.getCmp(el.dom.id).setValue(false);
}}, this);}
return this;
} });

Hard to believe that’s the same code right? Now imagine this throughout a file containing a thousand, ten thousand, hundreds of thousands of lines of code.

Use curly braces even when you don’t have to. Wait won’t that bloat my code? I’ve been taught that I should keep things as compact as possible what’s up with this. Let me explain in code:

A

if (condition1)
{
    if (condition2)
    {
        statement1;
    } else {
        statement2;
    }
}

B

if (condition1)
if (condition2)
statement1;
else statement2;

To the compiler, both pieces of code above will achieve the same result; however, the top block is far easier to read for us humans. Which code would you like to maintain.

Don’t use variable names that have no meaning – remember comments in the code should not be used to explain what your variables are, let their names tell all. This rule needs no code explanation, just stay away from one letter variables like a, b, or c and try to spell them out like

A

        double    a;
        double    b;
a = (b - 32) * 0.555555556

 

B

 

        double    celsius;
        double    fahrenheit;
celsius = (fahrenheit - 32) * 0.555555556

Bet you didn’t know that example A did until you got a look at B, right.

Test often and test early. How many lines do you write before you stop and see if what you have compiles. Do you write test cases for all your functions when you code them and actually test them before connecting them to the user interface? This helps you tackle bugs close to the source without wading through hundreds of lines of code.

If your IDE does not have a nice auto save feature like Jet Brain’s WebStorm, then please remember to save early and save often. There is nothing more frustrating than losing hours of good code.

Nobody ever wanted an app that ran slower, keep that in mind and optimize, optimize, optimize. You can use tools like Page Speed, or Chrome’s Developer Tools to get your JavaScript on track. In addition Google and Yahoo have written detailed articles that are essentially a lessons learned document

Some advice on IT management from a marketing pro

I noticed that Seth Godin posted a piece on the tendency to take star programmers and transform them into mediocre managers, it’s a mistake that cuts you twice, once with the loss of the key performer, and twice with the fact that you now have a management problem to deal with that may impede more key performers from joining the team. I asked and received permission to post the piece here in its entirety. The original can be found at this link, and a lot of other stuff on management and marketing that may be of intrest.

The extraordinary software development manager

Being good at programming is insufficient qualification for becoming a world class software project manager/leader. Too often, we take our best coders and turn them into incompetent managers because it seems like a logical next step, and because we don’t pay adequate attention to what we really want from these critical executives. (Hint, this is about many fields, not merely software).

1. Clients want useful visibility into the future in terms of costs, timing and deliverables

in fact, it’s almost impossible to be too clear, to benchmark enough and most of all, to overdo the work of identifying forks in the road when it comes to decision making. When a client hires a developer or a company embarks on a software project, they are lost. Even something as complex as building a house is dwarfed by the rapid change, shifting priorities and most of all, the requirement for the new, that’s involved in even a simple software project.

The indispensable software development manager is aware of this and lays it all out for us.

2. Code is going to be used, reviewed, updated and inspected by people other than the person writing it

At some point in the next [insert time frame], a dozen people we have never met will either be updating or using this code, whether they are people we hire or people we partner with. It’s tempting to question the value of an organized architecture and clear code commenting, but again, it’s almost impossible for an organization to overdo this. We don’t have time to do it over so we have to spend the time to do it right. In software programming only the amateur’s approach rewards speed over long-term usability.

3. A great programmer is worth thirty times as much as a good one.

Which means that hiring a good programmer in a competitive field is a killer error. It also means that managing a programmer in a way that accepts ‘good’ will lead to a fail as well.

4. Programming at scale is more like building a skyscraper than putting together a dinner party

Architecture in the acquisition of infrastructure and tools is one of the highest leverage pieces of work a tech company can do. Smart architecture decisions will save  hundreds of thousands of dollars and earn millions. We’ll only make those decisions if we can clearly understand our options.

Or, you can have some newbies hack something together real quick. Up to you.

Forget you identity, what about your pacemaker

The video below highlights a serious problem with medical devices that are as sophisticated as a large computer was just a decade ago. Dr. Rubin of Johns Hopkins outlines the hacks that the academic community have taken against implanted medical devices. Six years ago implanted devices were outfitted with wireless capabilities so that the devices can be updated without surgeons having to open you up.

Some of the devices include defibrillators, pacemakers, embedded insulin pumps.

What’s the difference between UNION and UNION ALL

I recently ran into a situation where I had to provide a summary of items ordered in a table and needed to union the products table in order to get all of the lines that also contained a zero as I had a requirement to show a summary of all the quantities ordered as well as line for each product on the products table that did not have any orders in the orders table yet.

Let’s try to solve this using the tables below, and in turn learn a little about the differences between UNION and UNION ALL:

Products

id product description
1 ajax clean anything
2 glo-brite mopping solution
3 steel wool scrub anything
4 soap plain and good

Orders

fk_product_id total
1 200
2 300
1 200
1 50

Query

The query below

Select orders.total AS ordered,products.product
FROM orders INNER JOIN products ON orders.fk_product_id = products.ID
UNION
SELECT        '0' AS ordered, product
FROM            products AS products_1

Returns

ordered product
0 ajax
0 glo-brite
0 soap
0 steel wool
200 ajax
300 glo-brite
50 ajax

 

Notice that all of the orders for ajax did not get returned in the query. Since we used union it discarded the duplicates in this instance. Now let’s see what happens when we replace UNION with UNION ALL in the query.

ordered product
200 ajax
300 glo-brite
200 ajax
50 ajax
0 ajax
0 glo-brite
0 steel wool
0 soap

When using all we tell the query to get every record from both queries without removing the duplicates as you can see in the results displayed above. This is important because if we were to finish the query to the specifications in the requirement in the first paragraph we would expand the query to get the totals using the SQL below, which would result in a missing order count of 200 for ajax when using UNION inside our inner query.

SELECT SUM(ordered) as orders, product
FROM(
Select orders.total AS ordered,products.product
FROM orders INNER JOIN products ON orders.fk_product_id = products.ID
UNION ALL
SELECT        '0' AS ordered, product
FROM            products AS products_1) as source_table
Group by product
orders product
450 ajax
300 glo-brite
0 soap
0 steel wool