Chapter1. How to learn bioinformatics
看起来是琐碎的小技巧,甚至是关于信仰的东西,可能要真正投入进去,才能慢慢体会,看得不太认真,许多略过的东西,以后可以再回头看。
Test Code, or Better Yet, Let Code Test Code
学到了用Code test code:
EPS = 0.00001 # a small number to use when comparing floating-point values
def add(x, y):
"""Add two things together."""
return x + y
def test_add():
"""Test that the add() function works for a variety of numeric types."""
assert(add(2, 3) == 5)
assert(add(-2, 3) == 1)
assert(add(-1, -1) == -2)
assert(abs(add(2.4, 0.1) - 2.5) < EPS)
尽管有时用于test 的code本身也可能成为bug,但是确实,当写得多了之后可以起到事半功倍的效果。
多用短小可重复的代码块,这样可以避免总是写相同作用的代码。
记得写README files