Monday, December 29, 2008

CNN headlines

This is what CNN front page looks like today.

And this is the article to which it links.

Funny how the wording of the title changed enroute, huh?


"The tale of Israel can be very much compared to someone who was beaten, tortured, molested and raped as a boy by his family members. You don't expect someone like that to grow up to be "normal". The founding of the state of Israel right after the holocaust was a big mistake. The boy grew up, learned martial arts, amassed weapons and became extremely aggressive towards his surroundings, seeing the ghosts of his tormentors in every face that he sees around him. Now he is channeling his childhood pain towards inflicting the same pain upon others. Desensitized to human sufferings, he is now capable of enormous acts of cruelty." response to...

I kid you not...

"Sometimes these dollars go to projects that have little or nothing to do with the public good. Things like fruit fly research in Paris, France. I kid you not," Ms Palin said.

Biology is clearly not on the list of graduation requirements on whatever "school" this woman went to... I am just wondering - who ARE these people in Alaska? This whole thing starts looking very much like Russia in 1920.

The reason to learn math...

I am so using it on my kids!

Sunday, December 28, 2008

SQL nullable data items and LINQ

While working on Malevich - my new code review program, - I was hit by a runtime error when doing LINQ operation on a table that contained null datetime items. In C#, DateTime is a structure - not a class - and therefore can not be null.

Classes in C# are always allocated in the heap, and the variable that holds class object is really a pointer, whereas structures can be allocated on stack (just like classes and structures in C++), and variable that references a structure is really the memory representing this structure.

If C# had a sizeof operator, the sizeof of a variable containing class instance would always be a sizeof of a pointer - 4 or 8 bytes, - whereas a sizeof of a variable containing a structure would be the number of bytes that it takes to store this structure in memory.

Which is why string x = null is valid, but DateTime x = null is not. You can, however, explicitly create a "pointer" to DateTime (or any structure or primitive data type) by using the question mark after the type, for example, DateTime? x = null. This is called a "nullable" data type.

It turns out that the logic in Visual Studio that imports the database model (dbml) does not properly recognize nullable data in SQL - it generates not nullable prototypes for it.

For most common data items it is not an issue. Strings are class instances, and so they can be null in C#. It is not usual I suppose to store nullable numeric types - it would likely be more expensive to store the fact that it is or is not null rather than ignore the value when it is not needed.

DateTime is the only important type that really has a problem - it is common for it to be null in the database, and if you have a row that has null value for the date column, and try to instantiate it using VisualStudio-generated database interop class, you will get a runtime exception saying that DateTime field cannot be assigned a null value.


CREATE TABLE [dbo].[DateTimeTest] (

INSERT INTO [dbo].[DateTimeTest] (TimeStamp) VALUES(NULL)

In C#:

// Watch this crash!
DateTimeTest[] x = (from dt in context.DateTimeTests select dt).ToArray();

I've done a few searches, and there are quite a few cases of people reporting the problem, but no good solutions for it - most people tend to rebuild their classes by hand when they need nullability, or fudge the database.

The solution does exist, however, and it is quite simple - in the graphical representation of database dbml, right-click on the offending field, select properties, and change Nullable field to true.

This is all it takes! After that, the date field is modeled as DateTime?, and everything works just fine.

Thursday, December 25, 2008

A year of blogging

So I've been at it for slightly more than a year. I started this blog for three reasons.

First, I wanted to learn to write. In the very beginning, I had to correct or rewrite almost every sentence before making a post. There were typos, awkward sentence construction, and every stylistic problem known to humanity. Some amount of it is still there - after all, English is not my native language - but I think I am a lot better now than I used to be.

Second, I needed to have a place where I could jot things down for future reference. Some of them were simple facts that I would needed to recall periodically. Some were convenient shortcuts in coding. Some where points of view that it was convenient to have written down, for future reference.

Third, I wanted to write down a few lessons that I've learned in my career in computer industry. I was lucky to have been part of a whole bunch of interesting projects, the rise and the fall of the dot com boom, the emergence of broadband, the mobile phone revolution. It felt like a bad thing to have it go to waste: fools learn from their own experience, smart people learn from that of others. Hopefully, smart people everywhere will learn from my experiences. We need more smart people!

Attracting a lot of readers was never a goal. Yet over one hundred thousands people visited it since January 2008. Many left insightful comments from which I learned a lot. Quite a few served as a motivation for further blog entries.

The most controversial was the blog entry where I duscuss the reasons I went back to Microsoft after a year at Google ( Alone, it accounted for 85000 page views out of 150000 site total. It elicited 180 comments on this site, spawned a small copycat industry of cross-posters, and was ultimately misquoted from ZDNet to NY Times.

The most visited technical article is the one on STL vector performance ( It was viewed 6500 times, and is currently #1 entry on Google searches on "C++ vector performance", "STL vector performance", and just "vector performance" at Google.

A far less interesting article ( where I gripe about poor design of atoi API was read 3000 times, despite the fact that it is buried on the second page of Google search results on atoi.

The two articles on memory management that I consider my best technical entries - "Guerilla guide to native memory management" ( and "Memory is not free (more on Vista performance) ( - have been read only ~1000 times each, despite prominent position on Google search.

I also used the blog to share a few bits of code I was toying with. About a year ago I got my hands on Sony Reader, and made a web proxy for Project Gutenberg that adds SONY LRF format to the list of available download options ( This post solicited the largest percentage of positive feedback :-). The site is still up, it has served hundreds of people who downloaded thousands of books through it.

Finally, the least popular post? This one: It's only been read 6 times :-)...

Non Piu Andrai

Wednesday, December 24, 2008

Why we should not let iPhone win...

Two articles that I spotted recently about iPhone apps, one rejected by Apple (, another (actually, a bunch of others) accepted (

While one might observe that the classiness of the Apple crowd appears to be long gone, the important thing is not that.

The ONLY way for a developer to release an app for iPhone is through the Apple store (contrast it to any other smartphone where any piece of software can be installed from any location, be it a PC, or the Internet, and anybody can build and release applications).

And for Apple to distribute an application, someone at Apple must bless the morality of its contents. In this specific instance, Apple decided that farting is OK, while boobs (even the covered ones) are not.

And this is why we cannot let Apple win in this game. Because if we do, we will be putting one company as a judge of what is appropriate, and what is not. And I don't think there's an entity in the world which is qualified to do this.

GM is us....

"To top it off, we’ve fallen into a trend of diverting and rewarding the best of our collective I.Q. to people doing financial engineering rather than real engineering. These rocket scientists and engineers were designing complex financial instruments to make money out of money — rather than designing cars, phones, computers, teaching tools, Internet programs and medical equipment that could improve the lives and productivity of millions.

For all these reasons, our present crisis is not just a financial meltdown crying out for a cash injection. We are in much deeper trouble. In fact, we as a country have become General Motors — as a result of our national drift. Look in the mirror: G.M. is us."

Incidentally, a whole lot of smart engineers that we have still left in computer science works on stuff that is very much akin to the financial engineering Friendman is writing about - chasing eyeballs, not users, producing Facebook apps that help people waste time rather than being productive...

Sunday, December 21, 2008

The one Google thing I miss the most

This week turns out to be exactly six months since I left Google to return to Microsoft. The year at Google was fun, and I learned a lot of new stuff. I am glad that I took this detour from my Microsoft career - it gave me a lot of new perspectives.

Six months later, what aspects of "The Google Way (TM)" do I miss the most?

Surprisingly, the free food is not it - not even close: luckily, most software engineers are paid enough so that the food costs are not really visible in our budgets.

Google's focus on engineering, where a developer owns everything about the product, including testing and the feature set, is nice at first, until you realize that it comes at a heavy price.

The products that can be built within this model tend to be smallish and not very well integrated. Every project that I've done at Microsoft was bigger in scope, more interesting as an engineering challenge, and all but two made far more money than anything I created at Google. And I am glad to be working on something really big again.

I miss the peer review system. But it is easy to replicate, and Microsoft already gives me all the necessary tools, and we are going to be trying it in my team, although I will implement it slightly differently.

At Google one needs to get positive feedback from people who are one's senior in order to be promoted. Feedback from peers and junior people does not matter very much. The problem is that at some point there are just not enough senior people around you - there are only a handful of technical fellows at Google, and less than 10 distinguished engineers, if I remember correctly.

As a result I have seen mediocre engineers grow very quickly just because they happened to work on a project that had a DE, and much better engineers stuck at lower levels because they were not so lucky.

So in my team we're going to value peer feedback much more uniformly, and assign a bigger weight to the manager feedback than the 10-15% that is customary at Google.

I don't miss my Google managers at all. They were nice people, but they didn't have much impact on my life. After a year at Google, I still do not quite understand what the role of a manager there is. Whatever they do, they certainly do not have the tools to succeed, and their impact on teams seems to start and end with allocating resources.

I worked with a bunch of very smart, talented, and passionate developers at Google. I even had the privilege of meeting Craig Silverstein through my work on the readability team and exchanging a couple of change lists with him. The amount of energy and brain power collected there is staggering.

But I also worked with a few people who were the weakest developers I'd seen in my entire career. They would show up at work around noon, eat the free lunch, browse the web, attend a few meetings, and generally be gone by 6-ish. In the 4 months I worked with them, they had each written a couple of hundred lines of code, and copied and pasted a few hundred lines more. I don't miss that project at all.

I don't miss Linux very much either - especially the C/C++ development tools. I now understand why so many smart people that I met at Google said that they are never going back to C++ after Java. I do not miss debugging with printfs.

The fact that Google had either reimplemented or wrapped every OS API - from thread and process creation to HTTP protocol handlers and RPC - did not help me appreciate the beauty of this extremely lean operating system :-). Yes, the OS was small, fast, (insert your own epithet describing efficiency here)...

But the applications that compensated for this leanness ended up being massive lumbering beasts, requiring hundreds of megabytes of RAM and a minute or more to start. And it was not because these apps were written by idiots - no, the people who created them were actually quite good. It was because they had to do a lot of things that the "bloated" Windows OS does for you.

I miss Python somewhat. It is a nice, effective script language that I learned to love. Python is a corenerstone in Google's infrastructure - everything, from the check-in tool to makefiles, is written in Python. The best thing about Python is its consistency - you can clearly see that the language had one designer, who actually DESIGNED it, rather than just stuffing random unrelated features in a la C++ (or Perl).

I think Linux people should just adopt Python as "the one script engine," and dispense with the proliferation of *sh interpreters with their horrible, horrible scripting support that leaves no doubt that it was simply bandaged on top of something that was never designed to do scripting. And after 25 years, the bandage is wearing off and the puss is seeping all around it.

But on the other hand, there is nothing - at least on Windows - that is doable with Python and cannot be done with C# in an equivalent amount of time, or faster. So while I like the language a lot, I found myself mostly using C# anyway because of it's "built-in" status on Windows and really nice Visual Studio support.

There is one thing at Google that I miss a lot, without any qualifications, with no "if"s or "but"s. It's Mondrian, the Google code review system.

It was written by Guido van Rossum, the creator of Python. It was his starter project, and it demonstrates another admirable thing that Google does, which is investing very heavily in development productivity. I would say that by creating Mondrian, Guido single-handedly improved the quality of Google code by at least 20%.

Guido describes it here: in great detail.

To summarize this presentation in just a few sentences: you create a change list in perforce. It automatically shows on the Mondrian web site. You go to this web and request code reviews by typing people's aliases. The mail gets sent with the link to the change list representation on this web site.

The web site shows - for every file in the change list - what it was before and what it is now, side by side. To comment, you click anywhere and start typing. The comment gets attached to the line of source on which you clicked. When you're done, submit the result, and the reviewee as well as the other reviewers are notified, and can see your comments on the same web site, right inside the files that are reviewed.

The reason Mondrian works so well is because the cost of making a comment is nearly zero - which is not true for over-the-shoulder code reviews, or trading files - where someone needs to take a note, fix the code, and then the reviewer has no easy way of verifying that the suggestion has actually been followed on. The point, click, and type UI paradigm that has been successfully driving the computer industry for so many years, has proven itself indispensable once again.

Unfortunately, Mondrian is an internal Google tool, not accessible from the outside. And even if it were, it is built on internal Google infrastructure, so it will be a cold day in hell before software organizations begin sending all of their code through Google servers. Obviously, this is not likely to happen at Microsoft :-).

So now that we've reached the end of M0 and a vast majority of my team is on their well-deserved vacations, I have a bunch of free time that I can spend on toying around. I have started playing with building my own Mondrian-like system that you can actually deploy on stock software such as IIS and SQL Server - stuff that is easily available to developers worldwide.

I have several objectives.

First, I want to learn ASP.NET and SQL. For the most part of my career, I was a very low-level developer - I know a lot about operating systems, implementation of compilers, low-level network protocols and file systems. I don't know very much about high-level abstractions - I have never written anything serious in C#, my experience building web services is confined to Google's infrastructure (and as such is not very useful outside Google), and I had never used a database until about a month ago.

Second, I want my team to have a nice code review system. We've had a few attempts at reusing tools that had already existed at Microsoft, but they all proved to be either very inconvenient, or very unstable. A good functioning code review system is a boon to developer productivity. This much I learned at Google.

Third, I think the world will benefit from a nice local, retargetable code review system that can be built on top of widely available software components. So when I am almost finished, I will be releasing it on Codeplex - Microsoft's shared code repository (

Meanwhile, you can read about my progress here. :-)

Update: It's up and running. We've used it for a month and a half, for more than 200 code reviews, 2000 files, and 3000 comments. Get it here:

Interview with a Chinese banker

"Individually, everyone needs to be compensated. But collectively, this directs the resources of the country. It distorts the talents of the country. The best and brightest minds go to lawyering, go to M.B.A.s. And that affects our country, too! Many of the brightest youngsters come to me and say, “Okay, I want to go to the U.S. and get into business school, or law school.” I say, “Why? Why not science and engineering?” They say, “Look at some of my primary-school classmates. Their IQ is half of mine, but they’re in finance and now they’re making all this money.” So you have all these clever people going into financial engineering, where they come up with all these complicated products to sell to people."

Friday, December 19, 2008

Stuck in the Middle Ages

No wonder we're still debating whether evolution is real or not.

We're using the British Imperial measurement system that results in pearls like the following:

"To examine innovation in steam technology, we need a measure of how good a steam engine is. One important measure is the amount of work delivered by a given amount of fuel. This can be measured by the duty of a steam engine: the number of pounds of water that can be lifted one foot for each 94 pounds of coal consumed."

Let's try it again: duty of a steam engine is the number of pounds of water that can be lifted one foot for each 94 pounds of coal consumed.

Think how hard physics - no, any science! - in these units...

Thursday, December 18, 2008

Conservative moral compass, part 3

"Conservative legal experts like David Rifkin (who served in the Reagan and first Bush administrations) argue that no accounting is necessary, since the worst interrogation techniques, like waterboarding, have already been abandoned and Obama is expected to make further changes."

So if someone puts a bullet through the head of this bastard and promoses to never ever do it again - we wouldn't need to prosecute him. It would be so nice to make conservatives live by their own principles!

Operator overloading

What does the following program output?

#include <iostream>

int main(int argc, char **argv)
volatile char *p = "hello";
std::cout << p << '\n';
return 0;

Wednesday, December 17, 2008

Linus on C++

Reading this was pure joy!

"C++ leads to really really bad design choices. You invariably start using the "nice" library features of the language like STL and Boost and other total and utter crap, that may "help" you program, but causes:

- infinite amounts of pain when they don't work (and anybody who tells me that STL and especially Boost are stable and portable is just so full of BS that it's not even funny)

- inefficient abstracted programming models where two years down the road you notice that some abstraction wasn't very efficient, but now all your code depends on all the nice object models around it, and you cannot fix it without rewriting your app."

Yes... Yes. Yes!!! Finally. Somebody said it. Linus is now my hero!

Seriously, if you use C++ to its full extent - and look at inane amount of crap they put in C++0x ( - lambdas! concepts! alternative function syntax (yes, check THAT one out!), built-in iterators! - why not use C# or Java instead? Equally slow (*), at least they are well designed.

What used to be a very much WYSIWYG language with a very well defined purpose (speed and closeness to hardware) is now becoming a random subset of everything from JavaScript to Haskell, whether it makes sense to pack it in one place or not.

(*) STL semantics encourages runaway number of memory allocations which is very similar to C# and Java. The difference is that both Java and C# have memory systems that are designed for this purpose - the cost of object creation is very, very low - whereas in C++ it is anything but. (

Monday, December 8, 2008

Conserative moral compass, part 2

So suppose you shoot up a bunch of innocent civilians in Iraq. Where do you get the most sympathetic jury for your trial? Why, in Utah of course!

And they don't even hide it!

"Mark Hulkower, a lawyer for one of the defendants, said the men surrendered in Utah, a relatively conservative, pro-military area, because they hoped to find a jury pool where “people are more sympathetic to the experiences of coming under enemy fire.”"

Sunday, December 7, 2008

Cartoon characters are finally given protection they deserve in Australia!,27574,24767202-2,00.html

Without rendering any opinion on "morality" of drawing naked pictures of the Simpsons kids, it appears to me that the child pornography laws are passed with the intent of protecting the children from sexual exploitation.

In the case referenced above, the judge in Australia has just extended this protection to the Simpsons family...

Clearly, he must be spending way too much time in front of an idiot box!

Saturday, December 6, 2008

Monday, December 1, 2008

It's in the genes...,0,1009632.story

Conservative moral compass

Bill Kristol of Weekly Standard urges Bush to pardon the war criminals...

"The CIA agents who waterboarded Khalid Sheikh Mohammed, and the NSA officials who listened in on phone calls from Pakistan, should not have to worry about legal bills or public defamation. In fact, Bush might want to give some of these public servants the Medal of Freedom at the same time he bestows the honor on Generals Petraeus and Odierno. They deserve it."

I suppose it was too bad Hitler didn't have time to pardon his henchmen...