{C++ etc.}

Latest Posts
Home | C++ Posts | Linux Posts | Programming Posts | Issue Tracking Posts

Tuesday, October 27, 2009

How Software Companies Die by Orson Scott Card

A friend of mine sent this to me and it immediately captured my attention because of its synonymous nature with some of the present day software organizations.

Software: How Software Companies Die  ====================================  by Orson Scott Card  -------------------  The environment that nurtures creative programmers kills management and marketing types - and vice versa.  Programming is the Great Game.  It consumes you, body and soul.  When you're caught up in it, nothing else matters.  When you emerge into daylight, you might well discover that you're a hundred pounds overweight, your underwear is older than the average first grader, and judging from the number of pizza boxes lying around, it must be spring already.  But you don't care, because your program runs, and the code is fast and clever and tight.  You won. You're aware that some people think you're a nerd.  So what? They're not players.  They've never jousted with Windows or gone hand to hand with DOS.  To them C++ is a decent grade, almost a B- not a language. They barely exist.  Like soldiers or artists, you don't care about the opinions of civilians.  You're building something intricate and fine. They'll never understand it.  Beekeeping  ----------  Here's the secret that every successful software company is based on: You can domesticate programmers the way beekeepers tame bees.  You can't exactly communicate with them, but you can get them to swarm in one place and when they're not looking, you can carry off the honey.  You keep these bees from stinging by paying them money.  More money than they know what to do with.  But that's less than you might think.  You see, all these programmers keep hearing their parents' voices in their heads saying "when are you going to join the real world?"  All you have to pay them is enough money that they can answer (also in their heads)  "Geez, Dad, I'm making more than you."  On average, this is cheap.  And you get them to stay in the hive by giving them other coders to swarm with.  The only person whose praise matters is another programmer. Less-talented programmers will idolize them; evenly matched one will challenge and goad one another; and if you want to get a good swarm, you make sure that you have at least one certified genius coder that they can all look up to, even if he glances at other people's code only long enough to sneer at it.  He's a Player, thinks the junior programmer.  He looked at my code.  That is enough. If a software company provides such a hive, the coders will give up sleep, love, health, and clean laundry, while the company keeps the bulk of the money.  Out of Control  --------------  Here's the program that ends up killing company after company.  All successful software companies had, as their dominant personality, a leader who nurtured programmers.  But no company can keep such a leader forever.  Either he cashes out, or he brings in management types who end up driving him out, or he changes and becomes a management type himself.   One way or another, marketers get control.  But...control of what?  Instead of finding assembly lines of productive workers, they quickly discover that their product is produced by utterly unpredictable, uncooperative, disobedient, and worst of all, unattractive people who resist all attempts at management.  Put them on a time clock, dress them in suits, and they become sullen and start sabotaging the product.  Worst of all, you can sense that they are making fun of you with every word they say.  Smoked Out  ----------  The shock is greater for the coder, though.  He suddenly finds that alien creatures control his life.  Meetings, Schedules, Reports.  And now someone demands that he PLAN all his programming and then stick to the plan, never improving, never tweaking, and never, never touching some other team's code. The lousy young programmer who once worshipped him is now his tyrannical boss, a position he got because he played golf with some sphincter in a suit.  The hive has been ruined.  The best coders leave.  And the marketers, comfortable now because they`re surrounded by power neckties and they have things under control, are baffled that each new iteration of their software loses market share as the code bloats and the bugs proliferate.  Got to get some better packaging.  Yeah, that's it...working toward a better product line...  

Sunday, October 11, 2009

Functions that take length of strings as parameters

Lately, I've been working on a component which had HUGE issue with string lengths. The problem was that all the strings were initialized with an integer instead of defined lengths. When these were used in various places in the source, the programmer has used various lengths to alter the same string. And now I find myself faced with the nightmare of cleaning up the mess.

The code used to look like this:
pCursor->Define(3, z_User, 30); // wrong. would only copy 29 chars off a database column
pMsg->Get(5, z_User, 30); // wrong. would only copy 29 chars off a message
ToUpperCase(z_User, 30); // correct. expects user to pass the length to convert and then appends '\0'

The problem is, functions which take string length as an argument would treat this length differently. For example, strcpy requires you to give one less than the actual length of the string in order to have space to print the NULL termination character. Another problem is the situation one would find ones self in if the size of the string were to be changed (e.g. change the size of User to 50).
When writing a function which uses char buffs, it would always be prudent to implement it in a safe way so that users would not have to worry about the actual implementation and wonder how it would behave if you pass the full length of the string to it. The above code would ideally be written as (keeping the same structure):

const int LEN_USER = 51;
pCursor->Define(3, z_User, LEN_USER);
pMsg->Get(5, z_User, LEN_USER);
ToUpperCase(z_User, LEN_USER); // Function changed to accept the full length of the string

The real fun begins when you have to do these changes in multiple code paths. :)