Tuesday, March 1, 2011

M&Ms

Brilliant phrase from one of the latest TEDs: one of the reasons behind low productivity of people at work is M&Ms — managers & meetings.

Saturday, December 25, 2010

On min and max

Today I'm gonna tell you about a trap I've been falling into once a two years or something, and I believe many other C/C++ programmers have.

This will be about XXX_MIN and XXX_MAX macros from <limits.h>. As it clearly stands from their names, these macros are a minimum and a maximum numerical values which can be stored in a variable of some numerical type. That is, INT_MAX is a maximum value representable by a variable of type of int, and is precisely equal to 2^31–1 on most 32-bit systems; and INT_MIN equals –(2^31–1), or –INT_MAX. For unsigned types, XXX_MAX equals to 2^bits_per_type–1 and XXX_MIN is expected to be zero.

This is all good, and using these macros is strictly advised for writing fine cross-platform code, but, believe me, you'll find yourself in trouble as soon as you're using it with floating point types, because FLT_MIN, DBL_MIN and LDBL_MIN really ruin your party. For some diabolic reason they don't stand for what their integral type counterparts do; in fact these are a representation of the least positive number that can be encoded with the type. That's right, FLT_MIN is actually 1/FLT_MAX, DBL_MIN is 1/DBL_MAX, and so on.

The things turn even worse when you're in the C++ boat and using std::numeric_limits<>. This generic behaves badly, too, and on my opinion compromises the very idea of being a template.

Have a look at the minimalistic proof code below.

#include <iostream>
#include <limits>

template <typename T>
std::string check()
{
    T def = T(),  // initialized with 0
      min = std::numeric_limits<T>::min(),
      max = std::numeric_limits<T>::max();
    return min < def && def < max ? "true" : "false";
}

int main()
{
    std::cout 
        << "int: " << check<int>() 
        << ", double: " << check<double>() 
        << std::endl;
    return 0;
}

It for sure outputs


int: true, double: false

What can I say? Thank you Kernighan, and thank you Ritchie! See you in hell guys, for the biggest evil on Earth being an inconsistent design.

Monday, November 29, 2010

Good architects draw good

One fine generalization I would make from my experience of working with programmers of different talent, from newbies to gurus: good software architects draw good

It's always a pleasure to look at diagrams or charts drawn by these people: the lines are straight, the corners are sharp, the text is beautiful, always. Of course I mean, on whiteboard or paper. And, do you know how many crappy diagrams drawn in special diagram editors I've seen? 

I beleive, that any diagram consists of three important things. They're: design, drawing, and demonstration. While editor can make the drawing for you, you first have to come up with a good design, obviously. And, still you have to teach yourself how to do comprehensible layouts and present your stuff.

P.S. by no means if you draw precisely you can make up a good architect, but you'd better be a top-notch draftsman to apply for senior developer's position on my team.

Linkedin distance

It seems now everybody on the planet uses Linkedin. Not only IT specialists do, but normal people as well. And Linkedin has nice little feature that is if you're viewing a person's profile, and s/he is in your network (you are connected to them via somebody of your shared connections), Linkedin is showing the distance between this person and yourself. 

For one, say, you know Bob and Bob knows Alice, but you don't. Then the distance between you and Alice would be 2 hops, while Bob-you and Bob-Alice makes simply 1.

Not fun yet? Well then, substitute Alice with some celebrity and see how many persons you're away from them. I took Barack Obama and know what - it appears that the distance between mr. President and me is just 3 hops. 



Well, it's no wonder, taking into account that Obama has 500+ connections (I believe, people behind Obama's profile on the Linkedin timidly accept any invitation).

Next I picked Bjarne Stroustrup and Linus Torvalds and was kind of surprised of the same distance of 3 hops, despite both Bjarne and Linus seem picky about whom they're connected to: 128 (nice, heh) and 181 direct connections, respectively. 

Then I took Andrei Alexandrescu and Erich Gamma who appeared not connected to me. I made it to 500+ connections of Grady Booch, but missed lucky five of Bill Gates'.

Finally, I checked dozen more persons, and now am ready to postulate the rule of Linkedin distance: for any given person on Linkedin, either you're not connected to them or distance between you two is less or equal than 3.

Go check it for yourself, really.

Sunday, November 28, 2010

Disclaimer

Ok, hi there.

Well, what would it be about? I don't know yet.

People behind software and software behind people? Yes.
Success stories? Maybe.
Fuckups? Definitely.

Make yourself comfortable and enjoy!