Sunday 25 October 2015

A Concise Chinese-English Dictionary for Lovers, by Xiaolu Guo

Book cover - the sexy version :) What starts as a slightly humorous book about the differences in perspective between the Chinese and the Western world turns into a deep insight into the raw psyche of women. That's not a nice place, BTW.

The thing that pops up immediately is the style of the English language in which the book is written. Xiaolu Guo creates this character who is a female Chinese coming to England on a year long visa to learn the language so she can get a better job in her native country. A Concise Chinese-English Dictionary for Lovers is written as her diary and, true to character, her English is really bad, but getting better, so that at the end of the book it is rather decent. Some things that Zhuan, the protagonist, is thinking are sometimes really funny, but sometimes feel really artificial, so much so that I scoured the Goodreads reviews of Chinese people to see if there were many exaggerations and it seems that the verdict is NO! In that respect, the book shocks a European by how weird the mindset of a Chinese country woman can be, so I consider it a win to have read it.

Also, the book is rather short, so unless you really dislike something about it there is no reason to not finish it up once started. However, the starting premise of the book is immediately changed when she meets this older Englishman, who lives life by the day, dabbling into art that he doesn't really care about and making ends meet by driving a transport van, which he hates. However he is well educated and, besides boning the young Chinese girl, also doubles as her English tutor. So it turns into a love story. But wait, it's not all roses, as her perspective over life (the woman that takes care of the household and makes babies and the man who provides for the family) is completely at odds with his views on intimacy, privacy and personal goals.

In the end, I have to say that if you want to start hating the relationship you're in, you should read this book. Like the Chinese concept of Yin and Yang, the two characters in the book are complementary, but separate, archetypes of the male and the female and the great attraction between them cannot nullify the classical disparities on their value systems. I don't know about women, but as a man I started to hate the pitiful neediness that Zhuang was exhibiting and I totally understood how the distance between the two people grew. I despaired when I read her thoughts on her own actions, when she knew what she was doing was hurting him and their relationship, but she found herself unable to stop.

What's worse is that, being archetypes, none of the characters compromises in any way, so I believe the reader is then faced with their own failings, but also with their compromises, laid bare, made evident and seeding regret. In that regard, it is a brilliant book. It pits West against East, male vs female, real vs ideal. It's not for everyone though. While I do not regret reading it, I don't think I would have read it if I really knew what it was about.

Friday 23 October 2015

Performance of the NOT operator in Javascript when used to verify existence or if a value is set

I had this Javascript code that I was trying to write as tight as possible and I realized that I don't know if using "!" on an object to check if it is set to a value is slow or fast. I mean, in a strong typed language, I would compare the object with null, not use the NOT operator. So I randomly filled an array with one of five items: null, undefined, empty string, 0 and new Date(), then compared the performance of a loop checking the array items for having a value with the NOT operator versus other methods. I used Chrome 48.0.2564.109 m, Internet Explorer 11.0.9600.18163 and Firefox 44.0.2 for the tests.

Fast tally:
  • NOT operator: 1600/51480/1200ms
  • === 0 (strong type equality): 1360/47510/2180ms
  • === null : 550/45590/510ms
  • == with 0: 38700/63030/131940ms
  • == with null: 1100/48230/900ms
  • === used twice(with 0 and null): 1760/69460/3500ms
  • typeof == 'object' (which besides the Dates also catches null): 1360/382980/1380ms
  • typeof === 'object' (which besides the Dates also catches null): 1370/407000/1400ms
  • instanceof Date: 1060/69200/600ms

Thoughts: the !/NOT operator is reasonably fast. Using normal equality can really mess up your day when it tries to transform 0 into a Date or viceversa (no, using 0 == arr[i] instead of arr[i] == 0 wasn't faster). Fastest, as expected, was the strong type equality to null. Surprising was the null equality, which catches both null and undefined and is second place. typeof was also surprising, since it not only gets the type of the object, but also compares the result with a string. Funny thing: the === comparison in the case of typeof was slower than the normal == comparison for all browsers, so probably it gets treated as a special construct.

It is obvious that both Chrome and Firefox have really optimized the Javascript engine. Internet explorer has a 18 second overhead for the loops alone (so no comparison of any kind), while the other browsers optimize it to 300ms. Sure, behind the scenes they realize that nothing happens in those loops and drop them, but still, it was a drag to wait for the result from Internet Explorer. Compared with the other huge values, the ===null comparison is insignificantly smaller than all the others on Internet Explorer, but still takes first place, while typeof took forever! Take these results with a grain of salt, though. When I was at FOSDEM I watched this presentation from Firefox when they were actually advising against this type of profiling, instead recommending special browser tools that would do that. You can watch it yourselves here.

Final conclusion: if you are checking if an object exists or not, especially if you can insure that the value of a non existent object is the same (like null), === kicks ass. The NOT operator can be used to check a user provided value, since it catches all of null, undefined, empty space or 0 and it's reasonably fast.

Here is the code:
var arr=[];
for (var i=0; i<100000; i++) {
var r=parseInt(Math.random()*5);
switch(r) {
case 0: arr.push(null); break;
case 1: arr.push(undefined); break;
case 2: arr.push(''); break;
case 3: arr.push(0); break;
case 4: arr.push(new Date()); break;
}
}

var n=0;
var start=performance.now();
for (var j=0; j<1000; j++) {
for (var i=0; i<100000; i++) {
if (!arr[i]) n++;
}
}
var end=performance.now();
console.log('!value '+n+': '+(end-start));

n=0;
start=performance.now();
for (var j=0; j<1000; j++) {
for (var i=0; i<100000; i++) {
if (arr[i] === 0) n++;
}
}
end=performance.now();
console.log('value===0 '+n+': '+(end-start));

n=0;
start=performance.now();
for (var j=0; j<1000; j++) {
for (var i=0; i<100000; i++) {
if (arr[i] === null) n++;
}
}
end=performance.now();
console.log('value===null '+n+': '+(end-start));

n=0;
start=performance.now();
for (var j=0; j<1000; j++) {
for (var i=0; i<100000; i++) {
if (arr[i] == 0) n++;
}
}
end=performance.now();
console.log('value==0 '+n+': '+(end-start));

n=0;
start=performance.now();
for (var j=0; j<1000; j++) {
for (var i=0; i<100000; i++) {
if (arr[i] == null) n++;
}
}
end=performance.now();
console.log('value==null '+n+': '+(end-start));

n=0;
start=performance.now();
for (var j=0; j<1000; j++) {
for (var i=0; i<100000; i++) {
if (arr[i] === 0 || arr[i] === null) n++;
}
}
end=performance.now();
console.log('value===0 || value===null '+n+': '+(end-start));

n=0;
start=performance.now();
for (var j=0; j<1000; j++) {
for (var i=0; i<100000; i++) {
if (typeof(arr[i])=='object') n++;
}
}
end=performance.now();
console.log('typeof(value)==\'object\' '+n+': '+(end-start));

n=0;
start=performance.now();
for (var j=0; j<1000; j++) {
for (var i=0; i<100000; i++) {
if (typeof(arr[i])==='object') n++;
}
}
end=performance.now();
console.log('typeof(value)===\'object\' '+n+': '+(end-start));

n=0;
start=performance.now();
for (var j=0; j<1000; j++) {
for (var i=0; i<100000; i++) {
if (arr[i] instanceof Date) n++;
}
}
end=performance.now();
console.log('value instanceof Date '+n+': '+(end-start));

Saturday 10 October 2015

Continuum is so much better when you're drunk

some sort of poster Continuum is a strange TV series. It starts as some sort of police procedural, only set in the past from the standpoint of a future in 2077, where the corporations won and the future is stateless, corporate run business, where the police is just another private security force, etc. The crisis point is one from which a cell of anticorporate terrorists are sent back in time, together with a Protector (a cop from the future) to the near future (from our perspective). Each season from there on is more or less a different story, where the viewers much suspend their disbelief (again) to understand the new timeline story. As usual, a time travelling idea destroys, rather than rejuvenates, a story. Instead of a steady, involving plot, we get an all you can eat buffet of redefining the story. Each season we get basically a new series, but with the same characters. And it kind of works, but it loses all sense or meaning. (Meaning you would be dumb as fuck - and as me - to watch this)

I was fortunate enough to watch the last episode of the series (season 4, episode 6), when I was inebriated. I have to say that this is the only way Continuum will make sense to you: utterly drunk and on fast forward. This way, the storyline invented by cocaine driven Hollywood execs makes a little bit of sense and gives one the feel that the idea Continuum had has a sort of ... pardon my pun... continuity. Other than that, you should definitely avoid this series.

Rachel Nichols is super sexy and cute. That's the only thing going for the TV show. I am not kidding; I actually watched the series exclusively because she was hot. The story, the characters, the way everybody would get in bed (so to speak) with everybody - without having sex, mind you - was just puerile. And the last episode (read this: the last episode they had the budget to finish) was so underwhelming that it made me cringe with pain and disgust, only I was so piss drunk I didn't care. And I would definitely bone Rachel Nichols if I had the chance, so you, the more moraly advanced human beings, should ignore this series altogether.

Bottom line: everything that happens in Continuum feels natural when you are piss drunk. You should avoid it, if possible, if not inebriated.

Friday 9 October 2015

Z Nation, one of the most fun and innovative TV series out there

Main characters are killed all the time, too Update 31 December 2018: After five seasons, Z Nation was cancelled. It had its ups and downs, with inconsistent levels of quality and storytelling, but it was very nice overall and I am glad to have watched it. Personally, I loved the innovation in the sci-fi and the way the show did not take itself too seriously, but sometimes tackling serious and contemporary social issues was important, too. The last season, for example, was all about democracy and egomaniacs trying to subvert it. Perhaps it wasn't the right show to try that on, but I appreciate that the creators thought it was worth it. So, no Z Nation in 2019, but maybe SyFy will learn from this and continue with fun and intelligent storytelling. I certainly hope so.

And now for the original post:

Due to the sheer number of TV series I am watching, I've abandoned the list format, in which I would give a short review of each. I am thinking that I will periodically review shows that I think are exceptional in some way or another. Z Nation is something that sounds stupid from the get go: a low budget Walking Dead clone from SyFy, made by The Asylum. I mean, can this be good at all? The Asylum are famous for the low budget rip-offs and SyFy... well, they changed their name from SciFi Channel to reflect their utter disrespect for the genre that they were supposed to promote. And, to paraphrase Woody Allen, it involves zombies.

The answer to the question is a resolute YES. While it doesn't take itself seriously at all, it is not a comedy. It is not like Sharknado, for example. Most humor in it is ironic with some occasional and subtle references to other work in the genre. The characters are complex and wacky, the story gets more original as we go and the show is full of death and gore. Let me tell you this: Walking Dead is a boring piece of crap compared to Z Nation.

Is it also bad? Yes. Some of the non permanent actors can barely act, the pacing is all over the place, the budget is low and the things that go on in the series don't always make a lot of sense. But compare it with, say... Farscape, which was much better funded, it is more consistent and more fun.

Bottom line: I don't believe this is a show for everybody, but it certainly is not a fringe thing, either. It's like somebody said "We know TV series are mostly crap and instead of trying to pretend they are not, we accept it. But we will make fun crap!". It is a really refreshing TV series and I enjoyed every episode. Give it a go!

Wednesday 7 October 2015

Glasshouse, by Charles Stross

book cover I am going to go ahead and say that I didn't like Glasshouse. To be fair, after the amazing achievement that was Accelerando, my expectations from Charles Stross were quite high, but I believe this book was quite frankly badly written.

The story is set somewhere in the distant future, after "the Acceleration" which permits easy transport and energy generation through wormholes that instantaneously and safely connect two points in space. This permits creation of anything from pure energy that is just harvested directly from stellar coronas, for example. This further allows for people to choose their bodies at will, making them male, female, changing the shape, the functionality, the species, etc. While being 3D printed like this, one can also make modifications to one's brain and thought patterns. Software, like malicious worms, can infect "gates", the machines that record and create matter, and proliferate through the brains of victims that unwittingly went through those gates.

So far so good. The hard sci-fi background set, I was expecting something amazing. Instead, it's about some whiny person who gets into an experiment to recreate the "Dark Ages" (read "our present") in order to fill in knowledge gaps of the period and discovers he got more than he bargained for. I thought that the idea of the book was to describe the present through the eyes of an Accelerated person, revealing the ridiculousness of the rituals and hard set ideas that hold us back - and it certainly started like that - but in the end it was impossible for Stross to keep up with it and everything devolved in a silly detective story that made no sense in any period, especially the far future.

My review thus denounces this book as clumsy, both in the chaotic change of direction and pace and in the writing style. The only good thing about it: it was rather short.