Monday, January 28, 2019

编译链接错 - 程序员逃不掉的梦魇


编译链接错 - 程序员逃不掉的梦魇
- 记一次调试经历


"Error: Undefined reference to xxxx"
       相信每一个程序员对于这样的错误并不陌生,多少次,接二连三的错误提示如同死亡缠绕一般挥之不去,如影随形。
    
       近期遇到了一个比较坑的链接错,记录下来解决的过程。作为经验的累积,也为在同一条路上苦苦挣扎的程序提供一些参考。

       问题描述:编译程序A,其中用到了grpc以及protobuf,编译时需要链接相应的库。具体来说,需要如下链接如下几个库:-lgrpc++ -lgrpc++_error_details -lprotobuf
      但是在Linux平台下,链接时总是报错未定义引用,比如: undefined reference to `gpr_log'. 可是grpc明明我已经安装了,系统目录下确实存在并且囊括了几乎所有的grpc静态以及动态链接库文件。LD_LIBRARY_PATH中也包含了系统库文件目录路径。

       调整链接库的顺序会产生不一样的连接错误,一开始以为grpc的库和其他库之间存在循环依赖,所以思路一致放在调整库链接的顺序上,以期能解决循环依赖的问题,但无果。百思不得其解。诡异的是,同样的程序在mac下可以编译成功。
        但是诡异的事情往往暗藏玄机。既然编译选项相差无几,mac下可以编译,而linux下不能编译,是不是意味着在Linux下链接的库有问题。用nm神器看下Linux下生成的静态链接库文件,果然找不到提示错误中的符号;但是在mac下却可以找到。所以印证了之前的想法,意味着Linux下的库文件编译有问题。

       可是我下载的grpc的源代码都是一样的啊,等等,唯一不一样的好像是:官方文档里,编译grpc是在grpc源码根目录下直接make,而在Linux平台下,我之前是通过cmake去配置然后make编译的。会不会是这个引发的问题?于是按照官方文档的方法重新make并且更新了Linux平台系统目录下的库文件。这一次,我用nm能找到符号了。重新编译软件A,一切如“丝般润滑”。

       至此,问题解决了。可是回想一下这个问题的解决过程,一开始如果能够早点在mac做一些简单验证,就可以排除循环依赖这个因素而省去很多时间和精力在无谓的事情上。在此之后,通过对比mac和Linux下库文件符号差异,直观感觉可能是grpc链接库本身的问题,才找到了解决方法,但是如果没有mac平台作对比,能不能想到是grpc的问题呢?恐怕没那么容易。

      所以,经验和教训就是:
      1. 快速定位问题。用简单易行的方法快速验证,用排除法,尽快排查掉无关因素;
      2. 抽丝剥茧,顺藤摸瓜,思维不要局限在问题发生的范围内。事出必有因,有时候也需要从源头上找原因。

以上。


Thursday, June 7, 2018

My Dear Angel

亲爱的Aimee, 我们的女儿:

这是我(你的老爸)还有你妈妈一起写给你的一封信,说是一封信,其实就是对你成长的点滴记录。

这是在距离你出生之后刚刚一月个的时候,我才开始想到写这封信的。在你出生之前就一直有想法写一个类似于这样的备忘录,但是因为你老爸总是很忙,你出生的时候适逢老爸在创业公司工作,工作任务很繁重,加上照顾你和妈妈(其实主要是你妈妈照顾我),所以总是拖延。然而,有一天晚上,你爸爸突然想开了,工作永远是做不完的,但是陪伴家人的时间却是有限的。虽然抚养你的时间看似很长,但是仔细想一想能够陪伴你一起成长的时间也就十来年而已,等到你成年了,或是求学,或是工作,你就会以各种各样的原因离开爸爸妈妈的呵护。所以爸爸决定再忙也要及时记录下你成长的点点滴滴。

1. 备孕篇
你知道么,一开始爸爸妈妈对怀你并没有具体的计划。妈妈有宫寒,从生理角度来说,怀你并不容易。所以爸爸妈妈也是怀着试试看的心情准备怀孕。为了备孕,爸爸每周都会去健身房,妈妈更是严格监督爸爸,不准喝啤酒,控制脾气。


         



因为妈妈每年是两个月的探亲假,所以爸爸妈妈尝试着在有限的时间内想怀上你,前面几次似乎不太顺利,在妈妈回国过年之前,我们又尝试了一次,但是没有抱有太大的期望。几天之后,妈妈要回国了,记得当时回国的飞机是在LA起飞,我们驱车从SD赶到LA,但是因为爸爸当时对机场停车的路线不太熟悉,停车的地方离出发的航站楼比较远,走的距离比较长,加之机场CheckIn的时间比较紧迫,妈妈也是大包小包的拎了好多东西。爸爸妈妈自机场匆匆离别之后,过了大概两周,妈妈神秘的跟爸爸说要跟我说个事儿(通常在这种时候,一般妈妈会说又在某个购物网站上买了多少钱的东西)。我问你妈妈是不是怀孕了,她很惊讶地问我是怎么知道的,其实我哪里知道,只是直觉告诉我应该是怀孕了。然后,我们俩唏嘘不已,首先没想到的是最后一次尝试居然成功了,然后就是各种后悔,你妈妈后悔当时不应该提那么多重物,而且回国之后还喝了山楂水(对胎儿不好),然后就是感叹你是一个多么皮实的宝宝。

2. 怀孕篇
怀上你之后,妈妈就是各种小心谨慎了,被外婆照顾得无微不至,本来妈妈在家里就是大小姐,现在更是了,谁都不敢得罪她(主要是看你的面子)。遗憾的是,爸爸要在美国这边上班,不能照顾妈妈,只能每天问一问近况。大概在五六个月的时候,妈妈就能感受你在肚子里的移动了。你是一个很活跃的宝宝,当时我们不知道你到底每天在妈妈肚子里干嘛,怎么动的。但是后来我们大概明白了,你应该就是在伸懒腰,因为你是我们听说过的,见过的最喜欢伸懒腰的宝宝了。



大概在怀你六个月的时候,妈妈也请假来美国待产了,爸爸妈妈终于团聚了。来了美国之后,妈妈没有怎么享受到爸爸的照顾,反而要照顾爸爸,主要是爸爸的饮食。在妈妈过来之前,一直在中国的医院里也就是妈妈所在单位指定的医院渤海医院做检查,来到美国之后,我们也必须有医生帮忙检查。因为爸爸当时的工作单位是UIUC,远在伊利诺伊州,与加州相隔大半个美国,我无法享受到那边的医疗保险福利,所以我们只能通过付现金的方式来支付生产你的费用。最开始我们联系了Scripps,和UCSD,他们的要价偏高,大概在7~8k美元,包括医生和医院的费用,这个已经有点超过了我们的预算了。后来在爸爸同事的介绍下,我们找到了一个华裔医生Dr. Michael Wong,一个挺慈祥的老爷爷,他祖籍香港,在美国从医已经几十年了,他给我们的报价比前面两家大概低2k美元左右,而且经验丰富,所以再三权衡下,我们选择了这个王医生。联系好王医生之后,我们每隔两周都会去拜访一下他,然后他给妈妈做做检查。最开始去的两次,医生给做了B超,看得到你在妈妈肚子里的状态。来美国之前,在中国医院检查的时候,发现你有脐带绕颈的现象,很神奇的是,来美国之后居然没有了。唯一的问题是,你的妈妈肚子的上部,而理想状态下,你应该倒立着在妈妈肚子里。但是没有关系,这些都是可以解决的,回家之后,妈妈每天撅着屁股来帮你调整体位,以帮助你的头移动到下面。幸运的是,大概过了两周,也就是第二次去看王医生的时候,居然发现你已经头冲下了,看来妈妈每天的努力起了效果。



随着妈妈的肚子一天天变大,爸爸妈妈也考虑得搬到一个宽敞一点的地方,因为我们当时住的是一个town house,跟房东还有其他住户一起住,厨房和厕所都是共享的,妈妈非常的不方便,做饭还好,但是上厕所有时候还得排队,等你出生之后会更加不方便。所以从七月份开始,爸爸妈妈就开始在网上找各种房源,我们也出去看了不少的房子,因为是租房的旺季,要找到性价比高的房子确实很难。经历过一番波折之后,我们最终在SD的UTC(University Town Center)附近的一个小区找到了一个公寓,一个月的租金在$1300左右,而且小区环境感觉也不错。说起来搬到这个公寓很是费了爸爸妈妈一番周折,首先是找,爸爸一开始就联系了这个小区的物业部门,因为申请的人太多,所以她们把我们加到了waiting list中,然后等了差不多一个月也没有动静,基本上当时就没有抱希望了。之后再过了一段时间,爸爸某天心血来潮,还想打电话问一问,结果物业部门告诉爸爸说有房子了,让我赶紧交押金如果想申请的话,然后我们就很快进入申请流程了,之后选房等房又花了一段时间,但是总体都还比较顺利。其次是等,房子在八月中旬其实就已经可以住进来了,但是因为房子要重新粉刷,爸爸妈妈怕有味道影响你,所以我们推迟了大半个月在9月1号的时候才搬进来。在搬进来之前,爸爸和妈妈隔三差五会过来除除味道,妈妈准备了各种招法来除味,比如防菠萝仔柜子里,放一大盆盐水/醋水在房间里,在冰箱里放柠檬等等。最后是搬家,这是最为费事的环节了,而且也是因为这次搬家,直接或者间接导致了你,我们的宝贝提前来到了这个世界。在八月底之前,妈妈和我就想蚂蚁搬家一样,每天从mira mesa挪几个箱子或者几样东西到新家。九月初的时候完全搬完,临离开mira mesa福建房东奶奶家之前,爸爸还手欠地弄坏了窗帘,不过好在房东奶奶没有要我们赔钱。搬家的时候,妈妈很要强,而且总怕爸爸累着,大包小包的帮忙拎东西,宝贝你要知道当时妈妈大着个肚子,行动已经很不方便了,还要拎着大包爬楼。后来你比预产期提前三周出生了,爸爸妈妈事后总是在说,估计是因为搬家拿了重物导致的。


世间的际遇总是很奇妙,在搬家之前,某次爸爸带妈妈去UTC附近一个诊所抽血打针的时候,我们遇到了从国内上海来San Diego生产的阿姨和她的妈妈,还有她的女儿。认识之后,妈妈和这个阿姨互相留了微信方便交流。阿姨的孩子在七月份出生了,在我们搬进新家之后,阿姨一家也要回国了,于是他们把一些家具也转让给了我们,最有用的是一张queen size的床,这也是在你出生之后爸爸睡觉的地方,以及你和爸爸妈妈嬉闹的乐园。当然,搬家过程中,还要感谢同事叔叔送的一个大床,还有桌子。宝贝不要介意家里的家具是二手的,爸爸妈妈也去Ikea看了新的家具,但是味道都比较重,出于安全考虑,最稳妥的还是用二手的。


3 生产篇
搬进新家之后一周左右,9月7号凌晨,妈妈感觉到肚子很疼,我们预感是不是要生了。但是时间上比预产期提前了三周,理论上似乎有些早,于是我们打电话给Sharp医院,护士告诉我们肚子疼是因为宫缩,意味着小宝宝想出来了。护士同时告诉爸爸妈妈注意观察宫缩的时间和频率,如果达到一定的频率而且疼痛感越来越剧烈的时候,那才能去医院。于是妈妈就在家躺着休息,爸爸也请了假陪妈妈。期间,妈妈的疼痛感越来越强烈,头上都开始冒虚汗了,爸爸不断给医院打电话,问护士什么时候能去医院,然后护士就不断问有多疼,多频繁,但是就是不建议马上去医院。下午四五点的时候,妈妈觉得太疼了,然后我们就去了医院,护士检查了下,感觉还没到生的时候,让我们先在外边走几圈再看看。走了很多圈之后,再去检查,护士还是坚持说没到时候,不能留在医院,于是我们打道回府。回家之后疼痛还在频繁地的持续,看着妈妈痛苦的样子,爸爸很心疼,但是爱莫能助,只能安慰。

8号晚上,妈妈看到有流血的迹象,我们怕破水,就赶紧驱车去医院。这一次护士检查的结果是留院观察,当时我记得是开了四指的时候,妈妈进了产房,但是要等到十指的时候才能顺产。助产士阿姨很nice,一边检查并且准备接生的用具,一边和爸爸妈妈聊天,帮助我们放松心情。看得出,妈妈有些忐忑,爸爸于是安慰妈妈,其实爸爸心里那时候完全没谱,因为这是破天荒生平头一次看自己孩子出生。后来医生给妈妈打了麻药,慢慢地,妈妈的左右腿开始失去了知觉,因为频繁宫缩引起的疼痛也不大能感觉到了。凌晨三点左右的时候,负责接生的医生终于出现了,但是不是之前一直为妈妈做检查的Dr. Wong, 而是另外一位白人大妈。因为9月7日当天是美国的labor day,Dr. Wong休假了。不过临时“上任”的白人大妈医生很负责,也很温和。医生进来之后,就开始生产过程了,抱歉,爸爸不愿过多去描述当时的细节。妈妈留了不少血,因为身体有撕裂,而且混合了你的羊水,一大张床单都红了。幸亏当时妈妈打了麻药,不然那种疼痛真得很难承受。记得最先看到的是一撮黝黑的头发,然后是你的小脑袋,真的是很mini。嘴唇乌青,身上也有大片大片的乌青,皮肤因为羊水的浸泡变得皱皱巴巴的,活脱脱一个小老头似的。

                                       




伴随着初为人父母的喜悦,我们从产房转移到了另外一个陪护病房。根据医院的规定,顺产的妈妈可以在医院休息24小时。在这24小时里,妈妈和宝宝的护理工作就被一个叫做Julie的护士阿姨全程安排监督。Julie告诉妈妈要多和宝贝肌肤接触,培养母女感情。因为宝宝你刚出生,周围的一切都是陌生的,包括爸爸妈妈,所以多接触妈妈,熟悉妈妈的味道很重要,在你成长过程中,妈妈的味道是你获取安全感的源泉。Julie自己生育和培养了三个子女,而且基本上都是自己带,据她说,她老公基本上不会帮忙带孩子。她的经验毋庸置疑,但是她也很严格。产后才过了几个小时,她就鼓励妈妈自己下床去卫生间上厕所。虽说卫生间近在咫尺,但是对于一个刚生完宝宝才几个小时,身上的麻药劲儿还没全过,疼痛感也没有完全消失,且处于兴奋和紧张状态的新晋妈妈来说,这无疑是个挑战。但是妈妈很棒,居然完成了。所以,爸爸妈妈回头事后聊起这个时,总是感叹中国人坐月子太娇气了。

在这24小时里,宝宝我的小可怜被各种护士打着抽血检查的旗号打了不下四针,其中最为让爸爸揪心的是抽血,两个胖胖的白人护士阿姨一人一个捏着你娇嫩瘦小的胳膊四处找血管抽血,一管血钻了三个针眼,抽了十分钟才弄完。可怜刚生下来才几个小时,肚子饿的呱呱叫(爸爸后来才知道宝贝有多饿)还要被人抽血。在这24小时里,也有护士过来帮宝贝洗了澡,身上的羊水和其他杂物被洗掉之后的宝宝变得漂亮了,恬静地躺在妈妈怀里像个小天使。在医院休息的这段时间还不错,每个几个小时就有护士来关心下,医院的饭菜也还不错,而且可以根据个人的口味定制,当然必须是菜单里available的了。天下无不散的宴席,休息期一过,我们就要回到自己家了,临行前,Julie阿姨叮嘱了很多注意事项,譬如哺乳、睡觉、洗澡等等。 



4. 坐月子篇
回到家,妈妈就开始了坐月子。虽然美国人没有坐月子这一说,但是这在中国是极为重要的。月子里的妈妈不能接触水,不能接触凉的东西,也不能吹风。基本上就是卧床休息为主了。没有其他人帮忙,爸爸必须担负起照顾妈妈的责任,于是厨艺不佳的爸爸开始学着做月子餐了。爸爸依然记得月子里第一个礼拜的饭菜必须是清淡,不含油的,因为油脂分子可能会堵塞妈妈正在准备泌乳的乳房,这样一来的话,宝宝就吃不到饭得饿肚子了。


从出生到回家第二天,宝贝你总是时不时的哭。一哭,妈妈就让你嘬乳头来安抚,但其实那个时候,妈妈还没开始泌乳。换言之,前两天我们的宝贝一直饿着肚子。好在回来第二天要到儿科医生那儿去检查。爸爸还记得在儿科诊所,宝贝一个劲儿的哭,爸爸很无奈的把手指头伸到你嘴里让你嘬,但是还是止不住哭。在医生检查完后,我问医生为什么一直哭,医生跟爸爸说了简单的一个词:hungry。医生准备了六十毫升的奶粉加水,然后把宝贝放在他的腿上,扶着你的背开始喂奶。爸爸神奇地看着那么小的宝贝开始吧嗒吧嗒的吸奶,心里一阵酸楚,嘬不出母乳的宝贝你是有多饿啊,而蠢笨的爸爸尽然没有想到给你喂奶粉。从医院回来之后,爸爸妈妈就开始在母乳喂养的同时,也给宝贝喂奶粉,以确保在母乳暂时不足的情况下,我们的宝贝不会饿肚子。 


5. 暂别篇
今天宝贝和妈妈回国了,回去看看姥姥姥爷了。一大早,六点爸爸就起床了,妈妈也被吵醒了。一晚上妈妈也就零星睡了两三个小时。自己洗漱完,给宝贝喂完奶,八点钟,我们出发去LA机场。因为离别,爸爸哭了,妈妈也哭了。天真可爱的宝贝不知分别的滋味,依然乐呵呵的。

爸爸回到家,空空荡荡,冷冷清清,好不习惯。在一刹那,情绪有些失控。在空落落的家里找寻你和妈妈的气息,可那必然是徒劳的努力。接下来的几个月,爸爸要独自面对。但是,晚上依然难以入睡,爸爸心里总是担心着你和妈妈。妈妈第一次独自一个人带着你回国,十九个小时的行程,还要在长沙转机,爸爸很担心妈妈能不能应付得过来。

所辛的是,妈妈很厉害,一直把小宝贝安全地带回了家,虽然在长沙经过了一番折腾。姥姥姥爷也终于正式和小宝贝见面了。 



6. 重逢篇
北京飞三番,然后转机到San Diego。“无所不能”的妈妈把我的小可爱带回我的身边了。一年之后,再次见面在机场,宝宝害怕地不敢投入爸爸的怀抱。一年时间,在姥姥姥爷的精心照料下,我的宝贝已经长高了很多,完全不同于之前的小婴儿形象了。
虽然几乎每天都可以视频,但是真正面对面的时候,宝宝还是一时无法马上和爸爸亲近起来。但对于我而言,看看宝宝的喜悦自是无以言表,很后悔为什么要跟她分开这么久。

2017-06-13,生病了
宝宝一晚上没睡好,很早就醒来了。醒来喂完奶之后,一摸身上发烫,额头也是一样,发烧了。但是好像不是很严重,所以没有太多留意。等我上班之后,妈妈突然给我打电话,说宝宝不省人事了,口吐白沫,眼睛发直,浑身发烫。于是赶紧回家,一生中从来没有这样焦虑过,那一刻感觉我好像要失去我的孩子了。路上打911,对方说已经有人打过了,急救车已经过去了。

驱车直奔医院emergency room,看到妈妈在带着宝宝,已经好很多了。小脚丫上夹着心率监测装置,只穿着尿布湿躺在妈妈怀里,感觉很虚弱,完全已无平常的那份“淘气”。 物理降温退烧之后,回到家继续观察。好在第二天早上已经基本退烧了,但是身上开始起了很多疱疹,没什么食欲,不喝水,不怎么吃东西。急得我很后悔来美国,在国内,这种情况已经在打点滴了。和妈妈想尽各种办法让宝宝喝水吃东西,但是收效甚微,好在楼下邻居也是我的同乡,很好心的帮宝宝做了红枣馒头,宝宝勉强吃了些。不然我真的很担心,宝宝怎么撑下去。

之后去医院看了儿科医生,确诊了“手足口病”。回想起来,应该是我们平常没有注意给宝宝的奶瓶,水瓶消毒,才导致病菌滋生。很对不起宝宝,由于我们的粗心导致她受那么大罪,常常在想,如果疼痛能够转移就好了,我来替我的崽受所有的痛。经过这件事之后,和妈妈约定,每个礼拜我们都要给宝宝的奶瓶水瓶消毒。 


未完待续 ...

回国流水账

纠结了很久很久,最后还是决定回国了。所以,仅以此文记录下回国的整个过程,也许会给其他想回国的同学提供一点参考建议。

因为我在美国这边是有工作的。在这里,我就不赘述如何辞职并交接工作,同时如何在国内找到新工作的过程了,毕竟每个人的经历不一样,所以写出来其实并没有什么参考意义。

那么我们从鸡毛蒜皮开始把。

1. 房子、家具等:待在美国的第五个年头,正式工作的第三个年头,当时也有了买房的打算。但是无奈当时南加州不断攀升的房价和并不多的房源,导致房子相当抢手。前前后后下了三个Offer,其中两个中心区的Condom还有一个非学区single house,最后都被人beat了。悲催,不过也因为没有买房,回国的时候,在房子方面就不需要操心那么多了,特别在我回国的日程非常紧的情况下。在这里多说一句,如果在美国买了房,也可以一直放在那儿,也许将来还会升值,美国政府对购房者并没有任何身份的要求。话说回来,我是租的房,而且lease term是按月的,所以相对比较灵活,主要是在离开之前,提前通知leasing office,并且打扫好房间就ok了。
       至于家具和其他物件,除非特别值钱而且有必要带回国,我们都该卖的卖,该扔的扔。很多朋友在回国之前买了很多很多的保健品,衣服鞋子等,大包小包很繁琐。个人觉得没有这个必要,现在海淘这么方便,想买什么基本上随时都可以买到,只不过可能邮寄回国内的钱稍微多点,但是相对于剩下的时间还有麻烦,我觉得是海淘是更好的选择。

2. 汽车:既然说到了房子,那么也说一下车子。在美国这么多年,就换了一次车。之前是买的车,后来是lease的车,两年的term。但是term还没到期就要回国了。我采取的策略是先把车从dealer那边买回来,然后再卖掉。之所以这样是因为,我的leasing term里suppose我每年开一万mile,但其实我车入手了大半年,才开了三千多点,所以转手卖车比较划算一点。买之前先去car max估了下值,价格不太划算,所以后来就打算自己卖了。因为回国之前还要用车,所以跟买家提前说好,省得到时候产生误会。

3. 银行卡:在美国生活,基本上每个人手里会有至少一张debit card,加上几张或者一把credit card。因为考虑到将来还存在一些不确定因素,而且我的工作可能会经常出入美国,所以我保留了我boa的debit card,跟银行确认过了,只要保证balance大于$1500,就不需要交任何费用。此外还保留我仅有的两张credit card,discover和amex,Amex有$95的年费。这两张卡都不需要交年费,而且也不需要我定时消费之类的。这个我是跟客服确认了的。

4. 其他服务:其他服务包括家里网络,手机网络,还有家里的水电等。家里的网络,我打电话给 time warner跟他们说在我走之后自动取消我的账户。至于手机网络,就更简单,因为我是和朋友一起share的plan,跟朋友说好,到时把我从plan里删除就好了。水电类似,通知service provider什么时候取消账号就ok了。

前前后后整理了一个月,终于要离开生活了五年之久的SD了。虽然在这里的时候,不时的抱怨,比如吃的没有国内的丰富,特别是小吃。没有亲戚朋友之类的。可是心里也清楚,每个地方都有其优势和劣势。当飞机起飞的那一刹那,心里突然有一种落寞,也许此生不会再回来生活了,即使回来也应该是在若干年之后了。

别了,SD。人生路漫漫,且行且珍惜。

以上。



Saturday, February 3, 2018

Outsourcing for Startup: Cons and Pros

We’ve heard of outsourcing, and there are many platforms for outsourcing, for example, www.elance.com, www.upwork.com, www.peopleperhour.com. On each of those platforms, you can easily post your job/task, and find the freelancers to help you get the job done. A very good thing of outsourcing your job on those platforms is that you can pick up the best expertises world widely to deliver the job, and thus, it’s naturally good for startup companies, especially in their early stage. Fig 1 shows a typical workflow of outsourcing your job.



Fig 1. Outsourcing Flow on Upwork
However, everything is a double-edged sword, and today, we will talk about the cons and pros of outsourcing for startup.


1. Why outsourcing is good for startup
Well, it looks too obvious. As we have mentioned before, as a startup, especially in its early stage, it usually has a tiny team, really short of people. Outsourcing the project and find good freelancers to work for you, will definitely bring significant benefits:


First of all, it saves a lot of your time. If things go well, I mean you can find the good freelancer who can help you deliver the job on time, it saves time for sure. You do not need to spend a lot time find the good one to join your team to finish the job, and we all know recruiting is actually not that easy.


Second, it’s also cost efficient. We all know the cost of hiring and keeping an onsite developer, not just his/her salary, but also the insurance, people management and communication cost, etc. Comparing with how much you pay for freelancer, usually you pay more for onsite developer.


The third benefit is: more flexibility. When you post your job on those platforms, you are looking for good freelancer all over the world: US, Europe, India, China, etc. You have more flexibility and have high chance to find the good ones. And this, actually, also help reduce the cost, since you can pick those good freelancers from developing countries, usually their hourly rate is relatively lower. Flexibility also comes from another side, because in most of the cases, you work with freelancer based on the project, if you find out the one working with you is not good, for your next project, you can easily switch to another freelancer. While, for onsite developers, if they are not good, pretty much you have no one else to switch, it’s also troublesome to fire the people and start to look for new developers.

2. So, what’s the downside
Nothing is perfect, as I’m working in Whova as a founding engineer, I have been working with some freelancers. According to my personal experience, there are several cons you may need to pay attention to.


As a client, when working with the freelancer, you are actually playing the role of project manager, because:


Firstly, recruiting cost. It’s not easy to find the right person work for you. If you are willing to pay with high hourly rate, definitely it will be helpful to find good freelancers, but don’t forget the cost. Meanwhile, it’s not easy to recruit the good freelancers at the very beginning. We tried two ways: we invited those “super good” ones to apply for our job, some of them were not free, some of them asked for high payment which is beyond our budget. We also tried to interview and find good ones, we even assigned a paid trial project to each candidate, and eventually we found several good freelancers to work with.


Secondly, the management efforts. You need to constantly check the progress: whether the freelancer can catch up with the timeline of each milestone. Although the job or each milestone has a deadline, but according to my experience, the deadline is not rigorously followed usually. There could be many reasons for that, for example, the deadline itself is not set properly, or occasionally, the freelancer may be off for several days. At this point, you may wanna remind me that we have contract with the freelancer, yes, you are right, contact can be a weapon for us to push the freelancer. However and unfortunately, we cannot fully rely on that. The freelancer took 3 weeks to finish your job, he delayed for several days when finishing the last milestone and thus, missed the deadline. Will you cancel the job and fire the freelancer? It’s a dilemma for each side, a better solution is compromise. You may not want to work this freelancer anymore, but that’s another story.


Thirdly, the communication cost. You need to check the quality of the work. Since you cannot assume your job requirement is written perfectly and the freelancer will 100% understand exactly what you want, you need to closely check the quality of his/her work, correct the freelancer and guide him/her to the right direction whenever you find that something do not meet your requirement.
According to my experience, you may need to spend at least 20% of your time communicating with the freelancer, and actually, I even spent more on this when I started to work with the freelancer, mainly because I was lack of experience and did not truly realize the importance of communication.


The last thing, integration. Much efforts are also required when you do integration after the freelancer delivered the job. While this is actually optional, depending on what kind of job you assigned to the freelancer. We asked the freelancer to implement one functionality in the app and we can integrate it into our product afterwards.

3. Conclusion?
I have shown the pros and cons, so what’s conclusion, do we do outsourcing or not. Well, I think it depends: depends on the job, depends on your company’s status and vision. Let me make this more clear:

  • If you are in the very early stage, you only have a tiny team, and do not even have your product prototype yet, then I think outsourcing your job will be a good choice. It helps you quickly come out with the prototype, even it may not be exactly what you want.
  • However, if you already have your product, and you just need freelancers’ help to make it better. Then I think you should think more before outsourcing your job. The reason is you already have a relative mature product, you already entered the market, and more or less, you’re in a race with your competitors. Then, think about the recruiting cost, management efforts, communication cost and integration issues, you need to make your own decision whether it’s worthwhile to go for outsourcing.



Tuesday, December 27, 2016

[Movie Review] When a Peking family meets Au pair



*A movie (with Chinese name: 洋妞到我家) directed by Gang Chen, main actors include: Fan Xu,  Jianbing Chen and young actor from Columbia: Gianina Arana Terranova, the Chinese stars Honglei Sun and Liya Tong also shown up in the movie. 



A Chinese housewife (Fan Xu) was preparing for migrating to another country, mainly for her daughter (Pipi)'s education. She and her husband decided to hire an Au pair (Giannia) to teach Pipi English. Giannia is from Columbia, and she's an incurable optimist even though she had an unpleasant childhood since her mum died very early and she was raised up by her step mom who was really harsh to her. 

Overall speaking, the story is about the conflicts between Fan Xu and the au pair Giannia since they have totally different opinions on children's education, especially they were growing up in two different countries/cultures. Pipi's mom (Fan Xu) always over-protected her child: do not allow her child contact any "dirty" things, even prepared her own dishware when eating in restaurants. Do not allow her child get in touch with strangers, etc. While, Giannia wants Pipi to be independent, so she took Pipi outside, playing with her friends, took her to the subway where is full of strangers. After several rounds of conflicts, Fan Xu realized that Giannia is right, it's better to child to be independent. 

I thought about my daughter when I was watching the movie. Certainly I do not want my daughter to be over-protected, like the flower in a greenhouse, I want her to be independent as well. But how I can teach her to be independent, and what's the best way for her to grow up, this is for sure, as her father, I need to think more on this and to be prepared. 

  

Thursday, February 18, 2016

[Android UI]GridView and GridLayout

[Android UI]GridView and GridLayout

I was a bit confused about GridView and GridLayout at the very beginning when I was trying to use grid layout (not GridLayout, I had no idea what GridLayout is at that moment). What I want is the layout like this:


I want to know which one fits my need best. Here's what I have found:

1. GridView:
GridView is a ViewGroup that displays items in a two-dimensional, scrollable grid. The grid items are automatically inserted to the layout using a ListAdapter.

A typical grid view definition in XML is like this:
<?xml version="1.0" encoding="utf-8"?><GridView xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/gridview"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:columnWidth="80dp"    android:numColumns="auto_fit"    android:verticalSpacing="16dp"    android:horizontalSpacing="16dp"    android:padding="16dp"    android:stretchMode="columnWidth"    android:gravity="center"/>
You can specify number of columns, rows, and also the column width etc. But seems the cells cannot be spanned which is actually what I wanted.

2. GridLayout:
Child views are aligned as cells in GridLayout, and you can scroll vertically or horizontally. 

A typical GridLayout definition in XML is like this:
<GridLayout    android:id="@+id/glfeature"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:rowCount="2"    android:columnCount="3"    android:alignmentMode="alignBounds"    android:layout_margin="6dp">
    <ImageView        android:id="@+id/button1"        android:layout_rowSpan="2"        android:layout_gravity="fill_vertical"
        android:layout_width="120dp"        android:layout_height="60dp"        android:layout_margin="10dp"        android:text="Button" />
    <ImageView        android:id="@+id/button1"        android:layout_gravity="fill_vertical"
        android:layout_margin="10dp"        android:text="Button" />
    <ImageView        android:id="@+id/button1"        android:layout_gravity="fill_vertical"
        android:layout_margin="10dp"        android:text="Button" />
    <ImageView        android:id="@+id/button1"        android:layout_gravity="fill_vertical"
        android:layout_margin="10dp"        android:text="Button" />
    <ImageView        android:id="@+id/button1"        android:layout_gravity="fill_vertical"
        android:layout_margin="10dp"        android:text="Button" />
</GridLayout>
You can specify column/row count for GridLayout, just like LinearLayout or RelativeLayout, you can specify the child views directly in XML file.

Okay, in a word. The major differences between these two can be summarized as below:
a). GridView is a ViewGroup, similar to ListView/RecyclerView. While GridLayout is a layout for holding views, similar to LinearLayout/RelativeLayout
b). You can set up adapter for GridView while you cannot do that for GridLayout
c). You cannot span cells in GridView, while GridLayout support spanning cells.

And I got my layout implemented with GridLayout finally.



Saturday, April 11, 2015

[Android Studio] How to add an external jar into project


How to Add an External Jar in Android Studio

Any beginners of Android Studio may encounter this problem: how to add an external jar into current project. It's pretty easy, just follow these steps:

-1. download the jar file and create sub dir "libs" in the "app"dir if there's no such subdir, then put the jar file into this dir

-2. Right click current project, and select "Open Module Settings"

-3. Click "+" at the left-top corner to "Import .JAR or .AAR package"

-4. Then find and select the jar file which is now located in the "libs" sub dir. You can choose to "Remove original file" to keep the project clean.

-5. After that, android studio will automatically start to sync the whole project.

That's it, you will find out the new jar was added in your project, and also a new "build.gradle" file was also created, the new jar was added into current project's "build.gradle" file as well.