Why I prefer using new/prototype/this to ‘createClass’?

Here is my thoughts on “factory” vs. “new/class”. First I agree that class is not necessary when we use prototype system in javascript. And prototype is superior than class, that’s why we love javascript.

But when we design a system, we need some tool to help use minify the side effects between your internal API calls. Making zero side effects system is possible, but that doesn’t make too much sense. Closure is a important feature in javascript, the closure is mutable, we use that commonly to reserve state in function. This is not pure functions anymore, but that’s an sweet spot in the middle of the spectrum from pure functional programming to none-pure functional programming. So the rules of thumb here is localize the side effects, and make the side effects physically close to functions. That’s one style we use to describe how Object Oriented Design marry with functional programming happily.

The previous chapter help us explain why the prototype is good. We can use the object to localize their local states (side effects), and the prototype is the functions which apply side effects on them. This style help us get rid of the dirts from classical OO’s class system. So here is a new question, do you think the class and new harmful in javascript? My answer is NO.

So the intention of the functional and localized side effects is a goodwill, and we should think about what’s the right tool/pattern for us to achieve that? And there’re 2 common patterns in javascript to achieve that.

  1. Factory:
var User = function() {
    var privateState = {}

    var setPrivateState = function(value1) {
        privateState.state1 = value1;
    }

    return {
        publicMethod: function(value1) {
            setPrivateState(value1);
            this.otherPublicMethod();
        },
        otherPublicMethod: function() {}
    }
}
var user = User();
  1. Use function, prototype and new:
var User = function constructor() {
    this.privateState = {}
}

User.prototype = Object.create({
    _setPrivateState: function(value1) {
        this.privateState.state1 = value1;
    },
    otherPublicMethod: function() {}
});

User.prototype.publicMethod = function(value1) {
    this._setPrivateState(value1);
    this.otherPublicMethod();
}

var user = new User();

The Factory use closure simulate private methods and variable, the reference of this is inexplicit reference the returned object literal itself. The magical stuff is that the Factory way don’t need the new keyword, which is the reason why someone love it.

The prototype way lost the private method/variable (you can do that by define some private method inside the constructor, but let’s put that aside). But the benefit is explicit this binding in new, and having a prototype chain in new (that’s how the prototype chain works). Although prototype chain is commonly used for simulating inherit (which is bad), but we can also doing mixin by prototype (which shares all methods on prototype; in comparison, mixing is normally done as method copy between objects in Factory way).

Because the prototype is a killer feature IMHO, so I lean towards using the new/prototype/class pattern. I don’t have strong opinion on the keyword new (because I have some friends don’t like it), but let’s review what’s new is doing?

  1. A new object is created, inheriting from foo.prototype.
  2. The constructor function foo is called with the specified arguments and this bound to the newly created object. new foo is equivalent to new foo(), i.e. if no argument list is specified, foo is called without arguments.
  3. The object returned by the constructor function becomes the result of the whole new expression. If the constructor function doesn’t explicitly return an object, the object created in step 1 is used instead. (Normally constructors don’t return a value, but they can choose to do so if they want to override the normal object creation process.)

So I think new is still quite useful 🙂

Going back to the implementation side. Using the new/prototype/class is my choice, but there’s some drawback. The prototype is very flexible, and we may misuse it. I’m especially against using that for inheritance reuse. Because most people believe composition over inheritance (for reuse).

So what I need?

  • Make clear that we need a constructor for a object factory (I don’t call it class)
  • We define a set of own methods for that object, and they should be assign into constructor’s prototype
  • We’d like to use mixin (on prototype) to reuse

And probably you know that React is hot in our community. And react have a method React.createClass, which is doing exactly that 3 thing I describe above. It’s like a factory of object factory, put some restriction to you, but showing you a schema of a object factory. I like it. But you don’t need React to use createClass, you can do it with couple of lines of code.

var _ = require(‘underscore’);

var createClass = function(options) {
    options = options || {};

    var constructor = options.hasOwnProperty(‘constructor’) ? options.constructor : (function() {});
    delete options.constructor;
    var mixins = options.mixins;
    delete options.mixins;

    options.mixin = _.mixin;
    constructor.prototype = options;

    if (mixins) {
        mixins.forEach(function(mixin) {
            _.extend(constructor.prototype, mixin);
        });
    }

    return constructor;
}

I used methods in underscore, you can copy them out and have a standalone createClass.

How about class support in coffeescript and ES6? I’m a believer of both. I use coffeescript for years, and I love it’s class implementation. The class support doesn’t give you mixin out of box, because mixin is a personal choice. So the class is just a factory of object factory, which is same as what we introduce above.

The how is not very important in this post, because you can write your own (better) implementation easily. The more important is why we doing this, the core is adopt functional and localized side effects design style.

站立办公桌

说来对工作环境和工作方式的关注是因为相信他们可以改进工作效率。但是有的时候我也觉得这无非就是无尽的物欲而已,难以自拔。站立办公桌这个东西,投入可大可小。对于我来说,我希望的是培养自己的一种仪式感(Ritual)。仪式感这个东西对我来说是很有用的一个心里工具。我一直尝试对自己进行心理暗示,很多时候它是一个有用的工具,尤其是使用在积极的场景。而具有仪式感的生活实践大都是有一个积极的初衷的。以后我还会陆续的记录我生活中的一些仪式。

站立办公桌在湾区这里非常流行,经过三藩大街上那些玻璃窗里开放的办公室你就能看到很多站着办公的潮人码农。关于站立办公优劣的文章轻易可以搜到一大把,我其实完全不在意那些文章所说。这其实也是个有趣的细节,估计大家都看到微信上面那些看似很合逻辑的科普文章吧?其实大部分时候,你应该尝试解读坐着的意图,而应该忽略他们那些逻辑。因为语言逻辑是有悖论的,完全可以用合逻辑的方式灌输一个谬误给你。在这个问题上我不相信逻辑和确定性,我相信直觉(但是你要优化自己的直觉,保持初心,而不是一味碰壁),我相信不确定性。我的直觉告诉我,站立办公应该不会让我减肥,也不会让我变得强壮或者更健康。但是站着办公应该可以帮助我进入 flow,并且减少长时间拖沓的工作(因为我会累)。长话短说,这几个月下来我的使用感受和我的预期一致。当然这也可以解释为心里暗示,我的偏见影响了我的判断。但是我不太在乎确定性 ^__^。

我的配置就是 IKEA 的那套经典穷人配置。唯一不同的是我用了加厚的桌面,我指的是作为底座的那个桌子,因为那个桌面更加厚实和沉重,质感更好。显示器我用的是 Seiki 的穷人 39 寸 4K TV,这个在 Hacker News 上讨论曾经很热。显示器就是公司配的 15 Retina MBP(公司会给你配顶配的,如果想换机器那就换个工作好了,当然公司也会毫不犹豫的满足你的需求的),用 HDMI 1.4 接到 TV 上面。因为 HDMI 1.4 的限制,在 3840 x 2160 的分辨率下只有 30Hz 刷新率。这个刷新率在使用 Logitech 的轨迹球的时候感觉不那么明显,但是使用 Apple Trackpad 的时候会比较明显。肯能是手指的移动让大脑更饥渴的看到鼠标指针的反馈吧(我试图在扭曲你的想法?)。在滚动网页的时候页面的顿挫感也很明显,解决方法就是减少页面滚动,反正显示器大了一页的内容会多很多。减少滚动对阅读来说其实是有积极影响的,这个我推荐大家尝试一下,即使没有很大的显示器,在 iPad 或者手机上也可以实践。键盘是 Apple 的蓝牙键盘,因为它的尺寸配合 Trackpad 感觉更舒适,否则 Trackpad 需要放在更远的右侧。Trackpad 属于我的个人习惯,我觉得它比鼠标和轨迹球都更舒适,对各种手势的支持也绝好。

在使用的过程中,我觉得后背和脖子会感觉舒服很多。但是腰(背部靠下的位置)还有腿部会比较紧张,时间长了它们都很疲劳。我的痛觉大概在 3 – 5 小时的站立以后会达到高峰,我一般就会停止站立。这的确有效的减少了我连续伏案工作的时间。因为腿部的肌肉酸痛和脖子不太一样,腿部的酸痛来的比较线性。也即是说腿部的紧张是慢慢加剧的,而脖子则是几个小时后或者第二天才显现出来,那个时候已经产生了明显的疲劳伤害(落枕)。肩膀和胳膊没有太多的疲劳感,但是 IKEA 这个穷人装备的手托的稳定性没有直接伏案工作好,但是这不是个严重的减分。39 寸的 4k TV 对于我来说像素密度有点太大,Apple 的操作系统目前不支持在这个廉价的 4k TV 开启 @2x (retina)模式。我倾向于把字体调大,然后可以让双眼离显示器远一些。如果你是字体或者像素癖患者一定会相当的不满意,我也的确费了一些时间适应。但是由于它渲染的并不够细腻,所以我也很少在它上面娱乐。做大部分需要进入 Flow 的工作来说,这个显示器已经足够我用了。当然,要不是在黎明前出手入了这个 4K TV 我一定会选择支持 60Hz 的 28 寸 4K monitor,那个感觉会让我更满意一些。软件上,我觉得 Divvy 是必须有的工具,因为更大的分辨率也就是更大的桌面需要很好的 layout 管理工具。Divvy 是第一个这样的工具,我习惯它也喜欢它,它很好的解决了窗口摆放问题,一个快捷键就可以把窗口布局做好。除此之外没有什么了。

周末和每晚睡前的私人时间使用这个配置的时间很短,完全不会有啥疲劳问题。在家办公的时候,完全专心的工作时间基本上可以控制在 3 小时和 5 小时这个范围内(可以早上 3 小时,下午 4 小时)。这样办公心里感觉很满足,因为思想的集中,和身体的疲劳时钟可以配合在一起。身体敏感度的提高其实可以帮助我集中精神,进入 flow,在这点上是一举多得的。我个人认为这是一个非常有趣的仪式。双脚稍微分开站立在显示器前面,脑袋平视可以到达显示器中线稍微靠上面的位置。小臂和身体可以垂直,手腕在敲打键盘和 Trackpad 的时候没有弯曲。也许这些自我描述是心里的意思满足感开始的地方,就和打坐一样帮助你联系物理感受和心理的一个状态。

Tin's Standing Desk

如果你还完全没有站立办公过,那我推荐你试试。

IT’S THE LITTLE THINGS

世界充满大事,但是那些小事也很重要。这不是个很好的翻译,但是我喜欢这样简单的翻译。这个标题其实来自 Ugmonk,是 Jeff Sheldon 的一个独立的设计品牌。我从 Offscreen Magazine 得知 UgmonkOffscreen Magazine 是一本独立杂志,他的出版人 是 Kai Brach。Kai 是一个网站设计师,而那本杂志充满了网站/设计圈的访谈和一些有趣的短文,很有趣。我有空再写文章介绍。Kai 在两个月前发起了一个 OFFSCREEN MAG + MOUNTAINS BUNDLE 的活动,$32 可以买一本 Offscreen mag 和一件 Ugmonk 的 Mountains T-shirt。Kai 在 他自己的博文 里面介绍了他与 Ugmonk 相识的过程。一开始 Kai 只是被网站和里面商品的设计吸引,但是读了 Ugmonk 的故事以后他发现原来这也是一个人全包(One man show)的品牌。这让 Kai 产生了很大的兴趣,并且定了一件 Mountains T-Shirt,他收到后很喜欢。

我看到 Kai 发布的 bundle 以后很喜欢,而且由于我贪图小便宜,所以就买下了(其实我已经有那一期的 Offscreen,但是多买一本可以送朋友嘛)。收到后我觉得那件 T-Shirt 做工挺一般,那个设计也非常简单。但是穿在身上感觉很好,这种简单设计给我一种平静的舒适感。后来我看到 Jeff Sheldon 的文章才知道他的图案是印在 American Apparel 的 T-shirt 上,这个牌子的衣服是美国制造的,号称剪裁合身材料舒适。Jeff 认为用 AA 的衣物保证了本国制造的优越感,并且 AA 的商品质量控制让他不用担心自己的产品在质量上出现问题(因为小品牌的出货量小,自己控制产业链质量不容易控制)。我觉得他这个思路很好,这样他就可以专心与品牌和设计了。做一个独立品牌是很难的,他把收入的一部分投入慈善,这对品牌价值提升很有好处。

it's the little things

上面介绍了 Ugmonk 和 Offscreen,他们吸引了我的眼球,让我消费了他们的产品。而且我在持续消费他们的产品。原因就是标题所说 “It’s the little things”这件 T-Shirt 我今天正好穿在身上。这些个人品牌在细节上非常卓越,没有扭捏的粉饰。从你听说这个品牌,到被吸引转化为消费,这个过程非常流畅。相比之下,T-mobile 这样的笨蛋品牌,一味追求低价,但是在消费者转化的过程中确忍受着巨差的用户体验,这个以后再聊。注意细节,耐心的琢磨这些小事,品牌就会很有味道。

Ugmonk by Jeff Sheldon from Ugmonk on Vimeo.

所以,记得,那些小事很重要。

本文所以链接都不是 affiliate 链接,也就是说我不会收取任何经济好处

小型的聚会

在北京的时候,我非常喜欢我和朋友们在组织的 OpenParty。那是一个 Unconference,起先的一年我记得每次活动都要准备很久,现场的环节也都是严格按照我们计划好的方式和时间进行。但是随着时间的流转,我和朋友们开始变的不那么守规矩。每次进行一些大概的计划,到了现场就跟着感觉走了。

OpenParty 的规模大概是 50 – 100 人,属于小型活动。但是如果拿来和我们日常生活中的朋友聚会比起来,它已经是很大的活动了。

来到美国以后,我就没有组织过 Unconference 了。有个在国内参加过 OpenParty 的美国同事问过我为啥在这里我不来住址一下,我只是敷衍的说这里好的活动太多了,而且我语言不够自如。其实那是借口。在国内组织一个十人规模的饭局是很容易的,但是在美国这并不怎么容易。在美国是人规模的聚餐不容易订到长桌,所以一般我们会选择在公园烧烤。但是烧烤有个缺点,就是有人烧烤、有人聊天、有人玩。但是对比更小规模的聚会,这样的烧烤 Party 缺少深入的聊天。还有,烧烤聚会不会带来内心的平静,不适合于每个周末。

最近的半年,其实有很多更小型的聚会。有的时候就是一两家人在一起,自己做一些饭,聊聊天。这种规模的聚会可以分享你所喜欢的东西,深度的讨论从人为什么要活着一直到哪里买东西便宜这样的话题。并且由于规模小,可以自己动手做一些菜,或者买一些自己喜欢吃的喝的互相分享。分享与聆听都是我们 Enjoy 的。

其实这种感觉和这本杂志有重要的关系,Kinfolk 这是一本围绕这美食和生活的杂志,没有广告,会有一些访谈,私人菜谱和美丽的图。它有一本菜谱,叫做 THE KINFOLK TABLE: RECIPES FOR SMALL GATHERINGS。我这篇文章的灵感和名字就来自这里。就像负片的摄影一样,一些胶片和他们的冲洗方法会赋予照片特殊的质感。因为那些色调和抽象的取景会联系到你对相机和照相的人的感觉,这种人为的联系给简单的主题赋予丰富的感觉。比如一个细节,在森林里聚会的时候,带上一瓶红/白的葡萄酒,请不要偷懒带塑料杯子。带上一对玻璃杯,可以是最简单的那种,就会极大的提升品味儿的质感。

记得个把月前,和 Lordhong 与他的夫人 Lily 相约带孩子去森林野餐。这是一个标准的小型聚会。我们带上了一些鸡肉沙拉,酒杯,Trader joe 买的德国产 Riesling ($4.99 每瓶),一些 Farmers Market 买的新鲜水果。开车走 CA 84 好公路去 San Mateo Memorial Park 聚会。CA 84 是一条非常崎岖的山路,很不好开。快要到那里的时候得知 Lordhong 的孩子们都晕车了,很不舒服。但是当我们到达公园的时候,空气清新,阳光被密密的树林遮住。孩子们在一起蹦蹦跳跳的玩耍,很快晕车的事情大家就忘记了。我们在公园里面散了步,然后就找了树下的木桌子坐下野餐。

Lordhong 的夫人 Lily 的厨艺非常好,她带了一些自己烤的小羊排,还有鱼糕。我们在桌子上铺好桌布,一起分享美食和美酒。孩子们更喜欢吃那些新鲜的水果,还有果汁。这次我们带的食物其实并不多,但是在落满松枝的木桌上吃饭感觉非常愉快。

我们聊天的内容我已经记不清了。但是在高高的红木下品尝自己亲手制作的食物,配上有趣的白葡萄酒和啤酒是很有意思的。这样的小型聚会就像那些用心的胶片摄影一样,留下的是精致的质感。这样的聚会一点不会累,留下的是满心的平静和满足。

选择牛奶

很少写博客,找借口没有意思。但是,心里还是有一些想法时不时想要记录下来的。最近几个喜欢的博主都在挑战一个月内每天发布一条博文,我觉得这样玩不错。

今天再说说选择牛奶。我记得我写过 Wondermilk (万得秒)牛奶的博文,但是刚才搜索了一下我其实没有写过。所以我应该说今天说说牛奶的选择。

很喜欢的 Podcast ATP 里面有两个风格不同的 Geek。 Marco Arment 非常主观。虽然他也引经据典, 但是他完全不介意主观偏见。而 John Siracusa 则是个非常客观的 Geek,论证事情经常事无巨细。我这里沿用 Marco 的风格来主观的描述牛奶的选择。

我之所以很挑剔牛奶是因为我对咖啡 Geek 式的偏爱(我比较接近 Marco Arment 描述的那种咖啡狂热,但是我和他对咖啡做法持不同观点),我希望我可以同时具有品咖啡和烹煮咖啡的能力。这是一种手艺崇拜。做个比喻,我比较像摄影爱好者圈的器材派。所以我对咖啡豆子,烹调工具和手段,杯具,牛奶这些“器材”都很重视。从此大家也就知道我的水平了,属于玩票的水平,相当的业余(自谦)。

我记得我和一些 OpenParty 的朋友分享过牛奶选择的知识。现在常见的是超高温消毒牛奶和巴氏消毒牛奶。前者保存时间长,据称只杀死了细菌和酶,不影响牛奶的营养成分。而后者因为是低温消毒,只杀死了细菌,所以保存时间短。我优先选择巴氏杀毒的牛奶,因为口味好,体现本地自豪感(因为巴氏奶不适合长途配送)。

上面那段好短,没有讲清楚为什么。但是这是我的意图,因为这种借口不同意见者都可以找来一大堆支持自己的论点,我找他们有啥意思呢?微信上还有人传喝牛奶致癌这些事情,你说我能反对的了么?我比较朴素的相信科学世界观,而且相信不确定性,所以我也不太在乎谁的理论更站得住脚这个问题。我现在更相信我的舌头和嘴,因为经过相对长期的啤酒品评的训练,我对自己品味道还是有一些自信心的。

那么我现在如何选择牛奶呢?目前我最喜欢的牛奶排名如下(美国湾区):

我不太喜欢的品牌是 Berkeley Farm 还有 Horizon,最后是 Trader Joe 的牛奶。Berkeley Farm 的牛奶带一股青草和酸的味道,而且非常稀,我受不了。Horizon 的牛奶带有很浓的香料味道(所以其实很好喝,但那不是奶的本味),而且他家是超高温消毒牛奶。但是我女儿很喜欢喝 Horizon 的调味牛奶,这也是我很讨厌它的原因之一(凡是特意迎合儿童的调味食品我都不喜欢,而且 Horizon 的儿童牛奶太甜了,非常邪恶)。而 Trader Joe 的牛奶喝起来和 Berkeley Farm 有点像。其实还有个 Costco 的 Kirkland 有机牛奶,那味道就好像有烧焦的东西放到了牛奶里一样,我的朋友没有一个喜欢的。我觉得我是个 Hater,用这么多篇幅描述我不喜欢的牛奶。

回到正题,为啥我会那样排名那些牛奶呢?我的基本思路是我很喜欢奶油味道重的牛奶,因为那是儿时玻璃瓶牛奶带的那种味道。其实这并非很自然的味道,可是我也没有喝过刚挤出来的牛奶。我不喜欢脱脂牛奶,所以可能就跳到喜欢加奶油的牛奶了。Creamtop 就是包装的时候上面附上一层奶油,这可以帮助牛奶保存相对长一点的时间(巴氏消毒以后低温保存也就是两周)。所以排名靠前的两个都属于 Creamtop。再有就是玻璃瓶优于屋型包装,屋型包装优于塑料包装。

其实上面说的这些还是扯淡,我之所以发现最上面三中牛奶是因为我发现 Blue Bottle 选择了这三种牛奶。Ferry Building 那家蓝瓶子一般选择 Clover 的有机牛奶。而 5th and Mission 那家很 fancy 的蓝瓶子 则选择了 Saint Benoit 和 Strauss 的牛奶。尤其是新奥尔良冰咖啡配 Saint Benoit 的牛奶那味道简直是完美了。

即使你的味觉不那么灵敏,尝一下我上面列的那三个最靠前的牛奶你基本上也可以尝出巨大的区别。Clover 的有机牛奶我个人觉得和万得秒 Wonder Milk 的牛奶味道很相似,那基本上是我对好牛奶划的线。这些好牛奶基本上都是没有使用人工荷尔蒙,Organic。Creamtop 的两款没有经过匀化(所以你会看到油花和沉淀,而且颜色会发黄),Clover 的则经过了匀化。他们都是巴氏消毒的牛奶,两款使用玻璃瓶(还要退瓶,挺麻烦)一款使用利乐包装。三款都是本地农场生产的。都被比较挑剔的咖啡师傅认可。在湾区这里,靠谱的咖啡店基本上都是用 Clover,但不都用 Organic 的。我觉得这写元素暗示了一些好牛奶需要具有的品质,希望它能帮助你找到适合你和你家庭的牛奶。

strauss and saint benoit milk

Good bye luke!

Hi Luke, I think that’s about 1 or 2 months after I heard your latest news. Hope you are all well in heaven! I’m sure your family miss you most, and I am just a very normal firends in your life; but I think I also miss you.

I wrote letters to you in dream, in my day dreams and when I’m drunk. I don’t know why? Maybe it’s because I used to admire you. Acctually I admire so much people, but I never let them now. I feel shy to let someone know that I’m a fan boy, say Steve Jobs. You are not as great as Steve Jobs I think, but you are great! I feel that my poor English expression limited my ability to express my feeling, but that’s what I’m trying to improve for very long time after I work with some people you know in ThoughtWorks, that’s a part of golden time in my life. OK, let me pour my feelings out now.

Back to 2007, I joined a team in ThoughtWorks studio. The guy who recruit me is Jez Humble and Hukai, you know those 2 funny guys, they are great. I was suppose to work in Cruise Control team, which was called Cruise team and later Go team. But the first job I did in TW is acctually in Mingle team, because both teams belong to Studio. I remember David Rice or Jen Marley introduce you to me. They said that you are great UX guy, and you can draw wireframe but also write html and css. That’s what I’m looking for when I join that company, being a cross-function specialist in team. And when I first talk with you I learn that there is a thing called wire-frame, which is a series of sketch shows the interation of UI. That’s great for a super junior developer, that’s the first time I learn that there is tool stimulate conmmunicate before something is deliveried. And with your wire-frame, I feel it’s quite confident to deliver a piece of UI without bother too much for a PS guy. But that’s not what blows my mind, when I see you doing a presentation in sprint planning, I was shocked. That’s the first time I see how a people showing off something before it’s implemented, that’s what we call lean nowdays. You play the magic which make us feels like watching a movie, imagine a hi-fi world with some black and white lines. OK, I shouldn’t make those moments magical, they acctually like old people told their life story, it’s quite plain and peaceful when it’s happending. I remember Jen told me that your time is precious, because you also have other things to do. You are a busy man.

It’s not far until I get a chance to see you face to face. That’s a away day of ThoughtWorks. It happens in Great Wall of China. I remember that you looks doesn’t match my imagination (I doesn’t see you picture before I see you). You are small, and soft. I remember you wear a red bennie, which is pretty special. I think I got lots of chance talking with you that day, because we talks a lot over skype. Beijing is my home town, so I want to share my knownledge of Beijing to you. And I think you like talking with me, which made me feel exciting. I remember that you mentioned that you like photography, and you did take lots of pictures on that day. My English is not very fluent at that age, and I think that’s not a barrier between us.

After we come back from Away day, you continued working for some days in Beijing office. I remember you shared that you must install a Parallel VM which running Windows, so that you can use a Powerpoint to draw wire frame. That’s the first time I feel respect about Microsoft, because you describe why Powerpoint is better to do wire-frame, and the Ribbon UI in Office 2007 is a big improvement in the industry. You show me how to do wire frame in powerpoint, and how utilize C&P which brings smooth experience for end user.

I didn’t see you after about half year after that. Then you come back to Beijing and did a cross team building. I remember Chris Stevenson also joined ThoughtWorks Studio, my impression for him is a purple monster (because he describe himeself like that after he got allergies). I rember that we have good time in Karaoke. I ordered “Can you feel the love tonight” to whole team, and you and Chris grabed Mic before me. But I got mic from you (thank you, you saw that I want to borrow your mic), so I can sing that song. Seems that’s the only English song I can sing in Karaoke, LOL. I remember you played tambourine instead, and you play very well; and you wore a red bennie with you. You did Jamming dance that day, that’s a suprise, you were fancy guy.

And after that I think I didn’t see you for another long time, I heard that you are starting a new business in Manchester. Then you become the head of Manchester businees in UK, that’s a big deal, I felt prod of you. Because I thought a UX pelple was also good at business is a miracle.

But I got another chance to see you in Beijing office. You were really busy at that trip. But you spent some time with me for Mingle project. I remember that we draw some wire frame together. That’s awesome! It’s like working with your star as a fan boy. I remember that I asked you how you make the looks and feel good in hi-fi design. You show me that you have a folder in desktop which includes lots of screen shots of different products and web-sites. You said those things inspire you when you want to create a hi-fi design. So you should find some feelings from heuristic brain storm, then you should find those elements in your design collection. Then you will find the graphic elements and colors for your new design. You mapped abstraction into details, so you have a practical plan to implement those designs. OK, that’s a big deal to me. I degist this for long time, and I think I do learn something from that.

After that, I didn’t see you face to face again. As far as I remember.

But skype and facebook notify me of your birthday. Year after year, I don’t remmber how much years is that. I thought I’m too normal a person in your life, you will forget me after some time. Because you are head of UK business then, and I already left TW. But you did remmber me, and say thank you for each greating. I remember that you poke me for my birthday too. That’s a weak relation, as a good friend looking each other across river. I enjoy that I know a good person like you. I saw you post lots of things about charity, like breast cancer run and some other thigns. And I saw you get merried and have babies. That’s great, I did that too. I feel that I know this is a serious life change, you were taking more and more responsibility.

In this year, I clearly remember that you joined a event “Live below the line“. I remember you have a tight budget to eat, and we can donate money for poor people who really live below the line. I feel proud of you. That’s a good sign when a adult play great social responsibility, some of my friends I respect also share this character. I do want to donate money at that time, but it’s a shame that I was busy working on something and I didn’t donate money. I will say that’s a lesson, I start donating money to charity a lot afterwards (In wholefoods, for children’s cancer, for lots of campaign in restaunrant and super market, and other place where I see someone need help). I feel much better then! Thank you for moved me.

But the next news I heard is absolutely sad!

When is that? I think I was 1 month or 2 months ago. I was super busy at that time. But I accidentally see Badri post something on Facebook, it says “Good bye Luke”. I think that’s not you, because you are health and at prime of your time. I see Badri’s word, it’s beautiful, I feel he is very sad. A friend of him passed away. I’m afraid, but I firmly believe that’s not you. But I leave a message said “Hope it’s not the Luke I know!”. And then I send some messages to other friend in TW circle to make sure it’s not you.

But next day, when I woke up. I sit on tolilet, I checked message. I saw Jiajun left a message, “No that’s the Luke we know, I’m afraid”, then she share a link from ThoughtWorks UK. I felt that my head is exploding. That’s super sad! I was under pressure on that days, but that message just make more even more sad. I know if TW post something that’s true.

I contacted Badri, I want to learn why you passed away, and what I can do for your family. I should say thank you to Badri, he said “Hugs!”, he said “We don’t know what we can do now. But please don’t write message on Luke’s facebook page. But you can let his family know that you feel sad about his passing away. And please don’t do anything before his family say they need help.” OK, I’m sadden in that mood for a while. I just feel it’s not fair.

And then 2 weeks later. I google your nane, I found that I even can’t type your name without google. I feel really sorry. I think no one should forget his/her friends’s name. That’s a shame. A man live in the world, and friends will always remember him/her. But I remember it now: Luke Berrett.

I didn’t leave any message on facebook which mentions you, or event not on twitter. I want to set a timeout for my memories, so that means it’s deepen in my mind. That someone cares about you even after you passed away. I know you family will miss you most, but we as normal friends in you life we also miss you.

When I google your news I learn that you was killed in traffic accident. But even more sad is that the accident is not very clear. They wanted witeness and the news. But you passed away, as a adult I know find the killer is not the most important thing. We should let you rest in peace. I feel shame that the god (sorry, but acctually I don’t have religion) chose a wrong one. But I know the human world is not fair, everyone has equal chance to be in heaven. The people who have beloved family should not have that earlier, because more living things suffer from that. But, but that’s the inifite possibility. I don’t trust logic, I just appreciate. I appreciate for friendship, for love, for every goodwill. I don’t want to say too much, becaus that’s out of my control.

I just keep living my life. But I occationally thing about you, especially I feel sad or under heavy pressure. I hope there’s karma, good people live good life. It’s just a silly hope. I know it’s not fair to you. I’m really sorry. But I do miss you as a normal friend. I have so many normal friends in my life, and I have close friends, I miss all of you. I’m just a simple emotional animal as most of human.

I was sick for a month. I have some illution that I’m dying. But I’m not, I have family, I need to live forever. Then I was very busy trasfer knownledge to my previous colleagues, since I’m moving to a new job. And then I joined a team, exciting, also was super busy. Then my wife sick, I was under pressure. I need to take care of my daughter, I worried about my wife, I won’t want to let my new teammates down. That’s not easy. But it gave me months of time to do reflection. It’s fortunate that I sill have a strong feeling that I should write those words down for you, for your family, for myself. I don’t want to express my sadness. That’s not how human live. We look up, we remember, we try hard to change the world!

So, luke, my friend, hope you have good day in heaven. Hope you family see you in their sweet dreams! Hope you blessed us, home you lessed eveyone live on the planet. But, Good bye luke! See you in heaven.

Your normal friend, Tin

Here is a picture of you, that’s the only 1 I can find (maybe more, but I’m poor on managing picture files).

SQLAlchemy gevent Mysql python drivers comparison

sqlalchemy-gevent-mysql-drivers-comparison

Compare different mysql drivers working with SQLAlchemy and gevent, see if they support cooperative multitasking using coroutines.

The main purpose of this test is to find which mysql driver has best concurrency performance when we use SQLAlchemy and gevent together.
So we won’t test umysql, which isn’t compatible with DBAPI 2.0.

Code is here. Thank you CMGS.

Result example

100 sessions, 20 concurrency, each session take 0.5 seconds (by select sleep)

mysql://root:@localhost:3306/mysql_drivers_test total 100 (20) 50.5239 seconds
mysql+pymysql://root:@localhost:3306/mysql_drivers_test total 100 (20) 2.6847 seconds
mysql+oursql://root:@localhost:3306/mysql_drivers_test total 100 (20) 50.4289 seconds
mysql+mysqlconnector://root:@localhost:3306/mysql_drivers_test total 100 (20) 2.6682 seconds

With greenify ptached MySQLdb (mysql-python).

mysql://root:@localhost:3306/mysql_drivers_test total 100 (20) 2.5790 seconds
mysql+pymysql://root:@localhost:3306/mysql_drivers_test total 100 (20) 2.6618 seconds
mysql+oursql://root:@localhost:3306/mysql_drivers_test total 100 (20) 50.4437 seconds
mysql+mysqlconnector://root:@localhost:3306/mysql_drivers_test total 100 (20) 2.6340 seconds

Pure python driver support gevent’s monkey patch, so they support cooperative multitasking using coroutines.
That means the main thread won’t be block by MySQL calls when you use PyMySQL or mysql-connector-python.

1000 sessions, 100 concurrency, each session only have 1 insert and 1 select

mysql://root:@localhost:3306/mysql_drivers_test total 1000 (100) 10.1098 seconds
mysql+pymysql://root:@localhost:3306/mysql_drivers_test total 1000 (100) 26.8285 seconds
mysql+oursql://root:@localhost:3306/mysql_drivers_test total 1000 (100) 6.4626 seconds
mysql+mysqlconnector://root:@localhost:3306/mysql_drivers_test total 1000 (100) 22.4569 seconds

Oursql is faster than MySQLdb in this case.
In pure python driver, mysql-connector-python is a bit faster than PyMySQL.
use greenify or not won’t affect the testing result in this user scenario.

Setup

mkvirtualenv mysql_drivers_test # workon mysql_drivers_test
pip install --upgrade setuptools pip cython
pip install -r requirements.txt
python mysql_drivers_comparison.py

Test with greenify MySQL-python (on OSX with homebrew).

mkvirtualenv mysql_drivers_test # workon mysql_drivers_test
pip install --upgrade setuptools pip cython
pip install -r requirements.txt
git clone https://github.com/CMGS/greenify
cd greenify
cmake -G 'Unix Makefiles' -D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV CMakeLists.txt
make & make install
cd ..
export LIBGREENIFY_PREFIX=$VIRTUAL_ENV
pip install git+git://github.com/CMGS/greenify.git#egg=greenify # if you are using zsh, use \#egg=greenify
git clone https://github.com/CMGS/mysql-connector-c
cd mysql-connector-c
export DYLD_LIBRARY_PATH=$VIRTUAL_ENV/lib
cmake -G 'Unix Makefiles' -D GREENIFY_INCLUDE_DIR=$VIRTUAL_ENV/include -D GREENIFY_LIB_DIR=$VIRTUAL_ENV/lib -D WITH_GREENIFY=1 -D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV CMakeLists.txt
make & make install
cd ..
git clone https://github.com/CMGS/MySQL-python.git
cd MySQL-python
export DYLD_LIBRARY_PATH=$VIRTUAL_ENV/lib
export LIBRARY_DIRS=$VIRTUAL_ENV/lib
export INCLUDE_DIRS=$VIRTUAL_ENV/include
unlink /usr/local/lib/libmysqlclient.18.dylib
ln -s $VIRTUAL_ENV/lib/libmysql.16.dylib /usr/local/lib/libmysqlclient.18.dylib
python setup.py install
brew switch mysql [version] # brew switch mysql 5.6.15 on my env, brew info mysql to check which version is available on your env
cd ..
python mysql_drivers_comparison.py

If the greenify doesn’t work for you, you can use otool -L _mysql.so in your $VIRTUAL_ENV/lib/python2.7/site-packages MySQL-python folder. Can’t find otool even after you installed XCode’s command line tools? Follow this link.

I need say thank you to CMGS. He guided me how to install greenify and how it works, he also help me triage the issues I met (include the otool part). Make greenify and mysql work on OSX make no sense, you shold do it on your application server which probably will be a linux, hope you will figure out how to.

ThoughtWorks 将于 2014 年 3 月 8 日举行的第十一届 B’QConf (北京软件质量大会)

本 Post 是代朋友转发。

亲爱的软件业朋友们:

第十届B’QConf(北京软件质量大会)是否还在你的脑海回旋,爆棚的场面和激烈的讨论是否始终让你记忆犹新?

由ThoughtWorks中国和阿里巴巴集团共同主办,中国软件测试经理联盟协办的第十一届 B’QConf(北京软件质量大会)将于2014年03月08日如期举行。B’QConf 邀请IT测试及质量相关人员共聚一堂,一起分享经验,探讨话题,结识业界朋友。无论你是B’QConf的老伙伴,新伙伴,还是大伙伴,小伙伴,只要你热爱测试,关注质量,期待学习,喜欢分享,都欢迎加入我们的活动。

本期精彩话题:

  • 话题一:中小型项目的web性能测试模型

中小型项目的性能测试和大型项目不同。在时间和资源都有限的情况下,我们来聊聊如何选定性能测试指标,怎样设计性能测试用例,最终出一个什么样的结果,才对项目最有价值。

演讲嘉宾:孙弘 ThoughtWorks QA

  • 话题二:Android自动化测试实践

本分享将介绍针对Android手机app测试方面的一套自动化测试框架,该框架能解决一般Android系统上的自动化问题,原理以及使用方法。同时会根据结合示例讲解。

演讲嘉宾:赵婉萍(菁菁)阿里妈妈-无线

  • 话题三:虚拟机初探

日常工作中,对于多个不同的环境有需求,拥有多个物理机也不太现实。我们尝试利用虚拟化技术来解决这一问题。在一些调研之后,决定使用KVM来定义、管理我们的虚拟机,本话题会分享一些KVM上对于虚拟机的定义、配置和性能方面的一些经验。

演讲嘉宾:杨锐 ThoughtWorks QA

  • 话题四:大数据的质量监控和保障

分享将介绍大数据时代下分布式系统的监控和数据仓库,数据挖掘的测试方法和原理。

演讲嘉宾:李春元(春元)阿里妈妈-CNZZ

  • 报名:我要报名第十一届B’QConf
  • 时间:2014年 3 月 8 日 13:30 – 17:30 (现场提供茶点,水果,软饮。)
  • 地点:北京市东城区东直门南大街3号国华投资大厦11层1105室 (ThoughtWorks 北京办公室)

地铁路线: 2号线东直门站D口出,来福士商场旁边国华投资大厦

公交路线: 106,107,117,24,612,635等20多条公交车到东直门内/东直门外/东直门枢纽总站下车都可
自驾路线: 东直门桥西南角来福士商场旁边国华投资大厦

更多消息请大家关注 B’QConf的微博

Places to find essential new things

Had a discussion with friends this morning, about how to explore new things, learn new staff. Then I got a list for myself:

  • new.me digest email (daily)
  • zhihu.com and quora.com weekly digest email
  • HN (Hacker news), best realtime tech world aggregation
  • Github trends, place to find intresting ideas, or high quality projects
  • twitter geek list (not twitter timeline, you need pick your own geek list)
  • Techmeme, technology industry headlines
  • Theverge, for high quality reviews and news post with good quality of pictures
  • Reader (digg reader, feedly, or what-ever), baseline is you need to follow intresting people here

Some of my best coworkers and friends contribute those:

  • Lifehacker, for interesting howtos
  • ScienceDaily, Latest Science News
  • reddit, everything fun
  • google plus, depends on your circle quality and time you spend
  • Engadget

Recommendation for my coworker Stan

I wrote a recommendation for my previous coworker Stan on Linkedin, but another coworker said it’s not proper and too funny for this serious site. So I guess I should rewrite it, but I will leave it here 😀

To be honest, Stan makes me cry, I can’t catch up with him. But it’s a honor to work with his brilliant mind. He is kind, he didn’t call us dummy. He has great abstraction ability, which IMHO is the most precious skill a software craftsman should have. He has good sense on new technology, and he build his own sharp toolsets and leverage other folks in his team. One thing I think he may improve is, he doesn’t drink beer with us, so he will always be sober when we are drunk.