我还活着

这年头确实没有心情更新文字 blog 了。

但是得统一说件事儿,
感谢不少同学觉得这个域名牛逼,我自己也很后悔没多弄几个牛逼的域名。
但是,请不要再来问我卖不卖了,我的域名你们买不起的。谢谢了。

Dose LG on Macbook Pro with Retina Display really that bad?

I and my company had bought & exchanged about 11 rMBPs, 9 of them have LG displays, 2 of them have Samsung displays.

So, dose the LG display really have IR problem? (This is also referred to as “image persistence,” “image retention”, “burn-in”, or “ghosting.”)

The answer is YES.

The 9 rMBPs with LG display all have IR problem. Some of them will show in only 3~5 minuets, the others happen in 10+ minuets, and the best LG I have which happen after an image stay still for about 20+ minuets. So for me, I can say 100% rMBP with LG display have IR problem.

But, dose the LG really so bad?

My opinion would be: NO. In some cases, LG AH-IPS is better than Samsung Super PLS.

Here are two MBPRs, The Left one is a Samsung Display, and the right one is a LG display. Both of them are set to max brightness.

 

As you can see, the Samsung one is a little bit warmer(yellow) than the LG one. Also, the LG has better contrast. But the Samsung has better brightness.

And about the response time, I think the AH-IPS is better than the Super PLS, too.

Here is the test result for LG:

 

Here is the Samsung’s result:

I am not making any calculation, but it looks like LG’s response time is little bit faster.

Additionally, here is an user comparing his/her Samsung and LG display viewing angle on Facebook:

However, I can’t help but notice that its no where near as good as the LG when it comes to the viewing angle. I noticed that immediately when I first saw my new Samsung display as I walked across the room. I’m not sure about color shift, but the perceived screen brightness seems to noticeably change outside of about 20 degrees (10 degrees left + 10 degrees right). That may be the reason why Apple prefers the LG (IPS) over the Samsung (PLS), because although they didn’t advertise the “feature” of image retention, they did claim the wide viewing angle.

So, What do you think? Do you still want to exchange your LG display?

既然给空指针发送消息不会崩溃,那么我们是否还有必要在发消息前判断一下指针是否为空?

在知乎上有人问到说,斯坦福课程里推荐不用判断 nil。但是有时候不判断 nil 又会导致程序崩溃,例如往 NSArray 里插入一个 nil 的情况。

以下是我的回答:

不管斯坦福怎么说,我的建议是如果这个指针可能为空,那么用之前都做一下判断。

为什么这么建议呢?

首先,最实际的理由是,给空指针发消息是非常慢的,而做一下 if 判断是否为空是非常快的操作。
这个速度上的差别是百倍这个单位的。

为什么呢?因为给 nil 发消息这件事情是在运行时判断的,而系统也并非简单的丢掉这个消息,系统还需要判断这个消息是否需要返回值,如果需要,还要判断返回值的类型:如果返回指针、数字、真伪等,则返回 0,如果返回的是 OS 定义过的数据结构,那么会返回一个被填充上 0 的结构回来,如果返回的是其它类型,则系统会返回一个未定义的类型回来。而一个 if,则能够直接跳过这些运行时的处理。

我做过一个实验:

分别是两个100万次的循环,其中一个给 nil 对象发送了 100万次消息,另外一个循环在发消息前,会判断一下该对象是否为空。

实验的结果是两个循环的执行时间相差了200多倍。这还是消息中没有传任何参数的情况。

这就好像我们不建议用 try cache 来做本可以用 if else 判断掉的错误处理一样,因为开销太大。

另外,“给空指针发消息不会崩溃”是语言特性,是为了防止人为失误导致程序崩溃的“保险”机制。我们写代码时应该尽量避免依赖语言特性的写法,因为这不利于代码(逻辑)移植,语言特性本身也是会变化的(哪怕变化的可能性为零)。

最后,这能养成一个好习惯,培养出一个好的思维方式。上述的这种遇到“错误”也让程序继续跑下去的语言特性本身就是有争议的,虽然给 nil 发消息不会崩溃,但也正是由于程序不会崩溃,当你的代码写错时你也无法察觉到,你的程序有可能会进入一个你完全没有预期到的状态,看似一切正常,但返回的结果却是完全错误的。而写代码时花1秒钟加一个简单的 if 判断,就能够清楚地看出哪个指针是可能为空的,这些信息在分析代码问题的时候是非常宝贵的。

MacBook Pro 应当电池用完后充电,还是用到 20% 时充电?

该用就用,想充就充。不要总是在同一个位置开始充电,甚至不需要每次都等到电池被充满了才拔掉电源。

因为锂电池更喜欢没有规律的充放电,总是让电池保持在充满或者完全空掉的状态,是让号称没有记忆现象的锂电池出现记忆现象的最好办法。

如果你把笔记本当台式机用,那么至少每个月做一次充放电(也不需要每次都完全放完)。

另外为何不去看看苹果的网站,人家有权威的官方建议,甚至还能给你的 iCal 加上一个充放电提醒的 event。

http://www.apple.com/batteries/notebooks.html