Sunday, April 15, 2012

Patents - Necessary Evil

The deal with patents is fairly simple. Innovate, file patent, get exclusive rights for some period of time on your invention and make money from your invention. Now the problems.

  • Too many patents being filed
  • Too many generic patents 
  • Patent Troll
  • Defensive patents 
In simple terms the problem is uncertainty. I have developed this cool technology and I have no clue if someone already has a patent on it. File stupid patents, because if you don't someone else will and that is a threat. Oops someone sued me, how much do I need to pay to settle this apart from the lawyer fees. Patents add huge variance to predicting costs/profits in business. 

The fix is simple enough - bring certainty and sanity to the patent ecosystem. 

Time is money

The exclusive rights to use your invention is nothing but a way to make money. And the simplest way to fix this is to base exclusiveness on money and not on time. What this means is that at the time of filing patents, you need to put a monetary value on it which tells the worth of the patent. The cost of filing patent would be based on this monetary value (call it patent tax).  This has two important repercussions.
  • Patent Troll is controlled because a finite value is attached to patent. Irrespective of how patents are "sold" to others for use, total payout cannot exceed the declared value of the patent. 
  • Stupid patents are avoided because you need to attach monetary value which will be taxed. Unless you are sure that patent is worth that value, you probably don't want to waste money on it.
I guess what I am talking about is making patents a market where patents can be purchased/used to  make life  better on planet by figuring out a way to attach monetary value to patents instead of finding it out through expensive court battles. This makes the process efficient and reduces uncertainty and provide value to both the inventor and the user of the technology. The idea as I understood was always to reward the inventor and never to prevent others from using it. Preventing other from using it is just a way to reward the inventor, but not the only way.  If we can find alternative ways for ensuring the same, we can perhaps bring some sanity to the system so that both the inventor and society as a whole can benefit from the invention at reasonable costs, predictably. 

Friday, April 13, 2012

Ford Mantra

I have been driving Ford for eight years now. I like the car, but spare parts are stupidly expensive. I wanted to get the windscreen changed, but thought against it when I was told the price. Rs 9000. Compare that to windscreen cost of Skoda Rapid - Rs 3600. Now that is hell lot of difference.

What does that tells us about Ford Business Model? Sell cheap cars. Make money on spare parts and services. Which again brings me to the old dilemma of choice in capitalism - namely you don't have a choice after you make a choice.

I think some rule like cost of all parts put together in the car cannot be more than the price of car would probably help bringing some sanity to the system. If everyone needs to go through this experience to learn it then Ford surely has a very bright future. I think the statement, "You can fool some of the people some of the time, all people some of the time, some people all the time but not all people all the time" is missing a crucial component. The component is people have finite life times. Then the game starts all over again. If new generations don't listen to the old generation, the cycling of fooling can run indefinitely because people continue to be replaced by new people.  

Fundamentally this is all about frequency of choice.

Sunday, April 08, 2012

Two Favorite Patterns in C

The first one is for error handling.

#define IfTrue(x, level, format, ... )          \
if (!(x)) {                                    \
   LOG(level, format, ##__VA_ARGS__)          \
     goto OnError;                              \

This is the simplest way of simulating try/catch in c. Yeah it uses goto and is a bad programming practice and what not, but it makes c code beautiful and understandable. Take a look at the code below for creating a server connection below. These code samples are from cacheismo.

connection_t  connectionServerCreate(u_int16_t port, char* ipAddress, connectionHandler_t* handler) {
connectionImpl_t* pC = ALLOCATE_1(connectionImpl_t);
IfTrue(pC, ERR, "Error allocating memory");
pC->fd = socket(AF_INET, SOCK_STREAM, 0);
IfTrue(pC->fd > 0, ERR, "Error creating new socket");
         int flags = fcntl(pC->fd, F_GETFL, 0);
         IfTrue(fcntl(pC->fd, F_SETFL, flags | O_NONBLOCK) == 0,
    ERR, "Error setting non blocking");
memset((char*) &pC->address, 0, sizeof(pC->address));
pC->address.sin_family        = AF_INET;
pC->address.sin_addr.s_addr   = INADDR_ANY;
pC->address.sin_port          = htons(port);
if (ipAddress) {
pC->address.sin_addr.s_addr  = inet_addr(ipAddress);
IfTrue(bind(pC->fd, (struct sockaddr *) &pC->address,sizeof(pC->address)) == 0,  ERR, "Error binding");
IfTrue(listen(pC->fd, DEFAULT_BACKLOG) == 0,  ERR, "Error listening");
pC->isServer = 1;
pC->CH = handler;
goto OnSuccess;
if (pC) {
pC = 0;
return pC;

It is a linear code. This avoids multiple exist points and repetitive error handling code. Less nesting of "if" blocks makes it easy to follow the code. Error handling/cleanup happens in the end and is common for all possible errors in the function, which also means less code.

The second pattern I use often is opaque objects.

typedef void* chunkpool_t;

chunkpool_t  chunkpoolCreate(u_int32_t maxSizeInPages);
void         chunkpoolDelete(chunkpool_t chunkpool);
void*        chunkpoolMalloc(chunkpool_t chunkpool, u_int32_t size);
void         chunkpoolFree(chunkpool_t  chunkpool, void* pointer);

Almost every type is opaque. What does it accomplishes? Freedom. Freedom to change the implementation of the objects because rest of the code only uses functions to access the object and doesn't knows how object is actually implemented.  This also forces me to think hard about what should be the minimal interface for accessing this object because it is painful to keep writing new methods.  I use this for almost all objects except objects whose only job is to be containers of data and no functionality.

I do use function pointers when they make sense, but that would be a topic for another post. Writing high performance software is fun, but making sure it is easy to code and easy to change makes the journey pleasant.

Friday, April 06, 2012

The Debt Of Humanity

We are all in debt. I don't mean the financial debt, your home loan and stuff like that. I mean the debt of humanity.  What were our chances of surviving if we were born million years ago. Death during labor, infections, lack of food, shelter. Instead of fighting with each other, we choose to live together and developed a language to talk. Rest is history. We have taken the concept of being together from few families to villages, towns, cities, nations and now we are almost at the edge of time when all of humanity is considered one big family. And the reason is simple - nations also fight and don't know how to live together.
No matter how much we feel for our country, the truth is that vaccines that saved us were invented by someone else, the languages that we speak and which runs multi billion dollar BPO industry is not ours. Bangalore is silicon valley of India but computers and programming languages and the OS we use etc were not invented here.
We are so much deeply connected today than we were yesterday but our ability to see these connections has diminished over time. I am not talking about facebook friends, but those who work at facebook to make it possible. Those who work at google to make search simpler, democratize the mobile OS. I am talking about the people who make our cars and those who make sure you get the petrol/diesel at the station. The ones who run the refineries and the ones who dig oil out of wells and the ones who build the pipelines. The ones who build the roads and those who build the equipment to build the roads. The ones who invest their lifetimes researching life saving drugs, the ones who ensure we have electricity at our homes. The list is endless.
Everyone on the planet is in some ways making life easier for the rest of us. They realize it or not is debatable. We realize it or not is also debatable. But I do feel that we would have never been here without the rest of us. 

The Best

We know what is the best (product/service/decision/policy/whatever). Actually we knew the best all our lives. Sony makes best TV's. Ferrari is the fastest car, iphone is the best phone, land and gold are the best investments, and so on.

At some point in the past, the best TV was theater, their was no fastest car,  but fastest horses, their was no phone. People with more gold were probably robbed and people with more land ended by killing each other to get more land.

Beware of the future. Best is yet to come.