Wednesday, May 30, 2007

Conditional statements in C++ Template meta-programming

C++ Template meta-programming is a black-frackin-art -- one of which I am totally in awe of -- that consists entirely of exploiting the corner cases of the specifications type deduction rules.

For your edutaining pleasure, the implementation of is_const <T> in GCC:

  /// @brief  helper classes [4.3].   
template
<typename T, T v>
struct integral_constant {
static const T value = v;
typedef T value_type;
typedef integral_constant type;
};
typedef integral_constant true_type;
typedef integral_constant false_type;

   /// @brief  type properties [4.5.3].    
template
<typename>
struct is_const : public false_type { };

template<typename T>
struct is_const
: public true_type { };

How it works depends entirely on the template (partial) specialization features of C++. When you have:

template <typename T>
void fun (T val, const true_type&) { do_foo(); }

template <typename T>
void fun (T val, const false_type&) { do_bar(); }

int main() {
typename const int a_type;
typename int b_type;
a_type a = 5;
b_type b = 3;

fun (a, is_const<a_type>);
fun (b, is_const<b_type>);
}

Temporary objects of types is_const<a_type> and is_const<b_type>, respectively, are made. C++ will try to pick the best match for each parameter type from the list of available classes for is_const<T>. In the case of b_type, the only suitable match is the non-specialized definition, for a_type, the specialization is_const<const> is a better match. That way the overloaded function fun is sent, in the case of a an is_const type that derives from true_type, and in the case of b an is_const type that derives from false_type, and thus is able to dispatch to different routines based on the overload.

New research showing that altruism is a biological function of the brain.

I wonder what this means for all the people on my daily commute who pretend to be asleep when they should be offering their seat up to an old lady clutching on to her walking cane?

Sunday, May 27, 2007

Addendum to my post about sexual discrimination: stereotypes R baad m'kay.

Saturday, May 26, 2007

The only places I've found for english language computer books in Tokyo/Kanto is Junkudo in Ikebukuro, and Yurindo in Landmark Plaza (Sakuragi cho). If you don't live near either place, your best bet is Amazon.com.

Thursday, May 24, 2007

In one who exaggerates self
there is always adherence to "I".
Through that adherence there is attachment to pleasure.

Through attachment disadvantages are obscured
and advantages seen, whereby there is strong attachment,
and objects that are "mine" are taken up as means of acheiveing pleasure.

Hence, as long as there is attraction to self,
so long do you revolve in cyclic existence.
--

There is no Frigate like a Book
To take us Lands away
Nor any Coursers like a Page
Of prancing Poetry --
This Traverse may the poorest take
Without oppress of Toll --
How frugal is the Chariot
That bears the Human soul.

--

Wednesday, May 23, 2007

In response to Jono Bacon's post on (sexual) discrimination in open source and technology in general, I'd like to add some more concrete points.

So what puts women off technology?
A partial list:

  1. Aggressiveness
  2. Being viewed as a sex object
  3. Not being taken seriously
Aggressiveness

The technology field has a rather individualistic and meritocratic culture, which is necessary and good. But whether males are born or socialized with a desire to revert to chest-thumping behaviour during conflicts, such behaviours seem to often carry over into our technical discussions (totally unrelated to hunting for the tribe's dinner).

Perhaps its a sub-conscious matter of establishing an geeky alpha-male status -- I don't know. What I do know is that women have no such need or desire to be the subject of that aggression, and such displays are most likely to give offense and nothing more.

We all have a professional and personal duty to ensure only the best technology gets selected, so no one is going to tell you you cannot argue your point based on your unbiased evidence. What we should do however, is take a good hard look at how we argue our points.

Before you write your next flame, consider how it will be interpreted: as the reasoning of a well balanced adult, or the testosterone fueled temper-tantrum of an under-socialised adolescent?


Being viewed as a sex object

This one should be easy, but I guess it isn't.

How would you feel if you arrived for the latest symposium with a head full of new ideas you're burning to share with all your intellectual peers, but when you arrive you find everyone only wants to talk about your clothes and stare at your crotch?

Women are human beings first, talented professionals next, and females somewhere down the line -- wherever they want to put that designation according to their way. And if anyone dares beat me over the head with the tired line about "why do they wear skirts if they don't want to be looked at", I may become cross.

They do want to be look at as a woman, but long before that they want to be looked at as a complete human and peer first. If you do well enough treating them as respected peers to start with, you'll find they are far more receptive to being treated as a women later -- but thats a priviledge you earn, they're not objects.

That means its only ok to ask women professionals for their address or pictures if thats the same way you treat your male colleagues.

Not being taken seriously

Read the above for one reason why. The rest comes from the belief that women somehow don't do the same amount of work to get where they are.

Its just not true, any more than its true for men. I went completed my computer science degree with my now wife, and there was not one single advantage she had that any other student didn't. Period.

Monday, May 21, 2007

I just got the new HP C5180 all-in-one printer I needed to apply for my passport. It works perfectly in Linux -- I just plugged it into the network via ethernet, set up CUPS, and got a perfect result.
very recommended.

Smoking a pipe is a bit of an art form. When you can have a good smoke, its one of life's sublime, meditative pleasures. When you have a bad smoke, its an exercise in masochism that puts you off your pipe for months.

Recently, due to lack of a place where I could buy pipe-cleaners, my pipe had become clogged with tar, which was totally ruining the whole proposition -- but recently Ive found a method to clean it decently, and tonight I had a wonderful half-bowl that really elevated the evening.

1. Wait until the pipe is cool and disassemble it, wiping out the remains with a tissue.
2. Draw a thimble of dark rum (I hear scotch will also do), and grab a couple q-tips.
3. Dip the clean cotton end in the rum and swab the inside of the bowl and stem. The alcohol should act as a solvent to clean out the tar, but leave the desirable layer of carbon (cake) intact.
4. When the pipe is clean (about 3 q-tips), turn the pipe upside down an let the flame of your match dry the inside out. This should also carbonize the sugars in the rum to add to the clean layer of cake.
5. Rinse out your mouth with the remaining rum. After all, those same tars are left in your mouth as well.

Sunday, May 20, 2007

Leonardo DiCaprio has apparently made a new environmental film in the spirit of Al Gore's Inconvenient Truth, and as in the case of the latter, it seems some people have taken to dismissing the entire content of the film based on perceived hypocrisy of the film maker.

How did this happen in western thought, that if a person who makes a point is not a spotless example of that point, then it must naturally follow that his message is worthless? I see it used in arguments all the time. Maybe someone can explain it to me.

Because DiCaprio flew to Cannes in a gas-guzzling aeroplane (as opposed to the trans-atlantic train), he is a hypocrite and his message can be comfortably ignored as we all make our way home from the movie theatre speeding down the highway in our SUVs, content in the knowledge that the existence of hypocrisy must naturally cause the laws of physics to alter itself in such a way that the burning of fossil fuels no longer causes pollutants to rise into the air and threaten the very existence of our civilization -- perhaps even our species.

Or maybe its because if DiCaprio doesn't care about our world enough to find a non-aero based method of transport across the Atlantic, we are all relieved of our own duty to care about our world, and we can face the destruction of human society with the true solidarity of the apathetic?

Saturday, May 19, 2007

If you are a programmer spending any time at all working on gnu/linux -- beginner or intermediate, this book is highly recommended. Even if you think you know it all already from skimming the table of contents, there are enough gems in this book to make it worth while to anyone short of master.

For me, pinfo libc was worth the price of admission.

Friday, May 18, 2007

I seem to have left my thinking-cap at home.

Thursday, May 17, 2007


Now if only I could find a way to make my cat stop peeing on the toilet.


What do you see when you look out your window?

Frist psot!