摘要: GCD is a C APIThe basic idea is that you have queues of operationsThe operations are specified using blocks.Most queues run their operations serially (a true “queue”).We’re only going to talk about serial queues today.The system runs operations from queues in separate threadsThough there is no guara 阅读全文
posted @ 2012-01-31 18:00 rickxu 阅读(1499) 评论(0) 推荐(0) 编辑
摘要: Creating a “type” for a variable that can hold a blockBlocks are kind of like “objects” with an unusual syntax for declaring variables that hold them.Usually if we are going to store a block in a variable, we typedef a type for that variable, e.g.,typedef double (^unary_operation_t)(double op);This 阅读全文
posted @ 2012-01-31 14:22 rickxu 阅读(629) 评论(0) 推荐(0) 编辑
摘要: 我总感觉一个方法返回null值有问题。当读了Misko Hevery关于how to think about OO的博客文章后,又让我想起这个问题。我感觉返回null值是有问题的,它大量的被使用在一个方法有不同的返回类型时。简单的用谷歌搜索一下“returning null”,你就会发现有建议把返回类型做成一个null对象。返回一个Null对象在某些情况下是合适的,但并不适合当你需要向客户端传送两种不同的东 西的情形。用Misko重构的一段代码来说明这个问题。他重构的是一段登录代码(我非常喜欢他的过程),这段代码大概是这个样子: Cookie login(Ldap ldap) { if... 阅读全文
posted @ 2012-01-31 09:37 rickxu 阅读(523) 评论(0) 推荐(0) 编辑