我看的这一节是1.5, 主题是Magic Numbers, 大致意思是尽量不要在代码中使用含义不明的数字, 应该要给他们取个名字; define numbers as constants, not macros;
那么问题来了:
Exercise 1-10. How would you rewrite these definitions to minimize opotential errors?
#define FT2METER 0.3048
#define MI2FT 5280.0
...
在C++中可以用const定义, 在Java中可以用final float定义, 在C中, enum只能用于整数,define又是不被推荐的, 那么有别的方法吗?
ps: 1.5节中有一句话我没看懂, 不知道大家可以给我讲讲么:(白乔 注解版Page 27, 中间一段)It may not be worth inventing a name for the size of a local array, but it is definitely worth writing code that does not have to change if the size or type changes.