Tag: book

cover

这是讲软件设计的一本相对较短的一本小书。 购买地址: https://leanpub.com/4rulesofsimpledesign

4个原则是:

  • Tests pass
  • Expresses intent
  • DRY
  • Small

测试是基础;命名要表达明晰贴切;拒绝重复;保持代码短小。解释了4个原则之后,使用实现生命游戏为例来说明这些原则。

另外一些吸引我的点:

快速判断是否有 Duplication 的方法

一段代码的实现,考虑如果发生变化的话,其他地方是否也需要修改,需要修改的地方可能就是有重复代码的地方。因为没有很好地隐藏实现。

Tell, Don't Ask

其中提到了 “Tell, Don't Ask” 原则。

去命令对象做什么,而不要依赖一个对象的状态去决定下一步做什么。将这个判断隐藏到对象的实现中。否则就是“leaky abstraction”。

Bad:

def street_name(user):
    if user.address:
        return user.address().street_name()
    else:
        return ‘no street name’

Good:

def street_name(user):
    return user.address().street_name()

class Address(object):
    def street_name(self):
    return self._street_name or 'no street name'

class User(object):
    def address(self):
        return self._address or Address()

遵循这个原则的好处明显,减少逻辑,代码更简单,对象的实现更凝聚。

Unwrapping 方法

Bad:

class Num(object):
    val = None

    def greater_than(self, other_num):
        return True if self.val > other_num.val else False

Good:

class Num(object):
    val = None

    def greater_than(self, other_num):
        num1, num2 = self, other_num
        return self.compare(num1, num2)

    @classmethod
    def compare(cls, num1, num2):
        return True if num1 > num2 else False

第二种实现的好处是:在做 greater_than 时,不必再去接触Num对象的内部。

《Think Smart》 摘录

2012-11-17 15:42:32

Think Smart

Page 41, Care and Feeding of the Brain

So what practical conclusions can one draw about diet and the brain? Here's a summary of the most commonly accepted dietary formula for maintaining optimum brain health: maintain low weight, cut way down on saturated fats, eat fish and other foods contain high amounts of omega-3 fatty acids, decrease your intake of red meats, take in more fruits and vegetables, drink red wine in moderation, and sensibly supplement your diet with vitamins and antioxidants.

Page 128, Enhancing Your Brain's Performance

这个方法将来真的可以实践一下。

As part of your efforts to improve brain function, learn a new word each day. Keep a record of the new words you learn by entering them in a dedicated word journal. I started this exercise at twelve years of age in response to an intriguing and appealing proposal by my father. He told me that on certain days he would place a dollar inside the front flap of the dictionary. Since I couldn't be certain which days he would do this, he suggested that I check the dictionary every day and, dollar or no dollar, learn a new word each day. "Every day a new word will be your reward and on some days you will be doubly rewarded," he told me. Thus began a habit that has gone on now for almost a century (sadly, minus the excitement of finding my father's dollar bribe).

Page 211, Impediments to Optimal Brain Function

KEY WORKPLACE TRAITS of each generation

Mature.Silent
  • Long tenure with organizations
  • Respect hierachies and authority figure
  • Like structure and rules
  • Demonstrate strong work ethic
  • Pay attention to quality of work
  • Less mobile
Baby Boomers
  • Skeptically "accept" authority figures
  • Are results-driven and ambitious
  • Have long-term aspirations with organizations
  • Retain what they learn
  • Are idealistic and competitive
  • Are people-focus
  • Optimistic overall
Generation X
  • Comfortable with diversity
  • Value freedom and informality
  • Have short-term loyalty
  • Work well in networks and teams
  • Embrace techology
  • Seek work/life balance
  • Learn quickly
  • Skeptical overall
Generation Y
  • Comfortable with diversity
  • Value informality
  • Have short-term loyalty
  • Learn quickly
  • Embrace technology
  • Need supervision

Page 231, Impediments to Optimal Brain Function

一个简单有益的方法。

The simplest imaging technique involves nothing more complicated than looking at your immediate surreoundings and taking a mental snapshot of them. Then close your eyes and "see" in your mind's eye as many details as you can. Finally, open your eyes and compare your internal snapshot record with the scene in front of you. Note what you failed to missed. Repeat the process until your mental image contains all of the relevant components.

Anothor way of practicing this exercise that I personally favor is to use a camera. First, I select a particularly appealing scene that I will enjoy conjuring at a later time when I'm under stress. Then I take a picture of it with the small digital camera I always carry with me. Later, When I'm feeling stressed. I envision (without looking at the picture) the scene in my mind with as much detail as I can muster. When I've done my best mentally recalling the scene. I then look at the picture and compare my remembered image with photograph.

豆瓣读书链接

荒诞的一本书:地铁

2012-08-12 11:19:11

地铁封面

地铁,非常荒诞的几个故事,都是围绕地铁发生。

地铁是一个封闭的空间,有起点,有终点。要是突然有一天地铁开起来停不下来会怎样?如果停下来了,所有人都在昏睡并被奇怪的生物泡进装满液体的大玻璃瓶子里抬走会怎样?载着你亲人的地铁开走就没再回来会怎样?

我最喜欢第一个故事,这本书的几个故事一个比一个荒诞和科幻,我更喜欢现实的其中夹杂科幻,亦真亦幻的,这个故事我边看边就在脑子里拍成了电影,每一幕都挺有意思。