Before we jump into the fray with gusto and abandon (and aplomb, of course), I was recently chatting with my chum Steve Manley who features so prominently in my main Cool Beans column. I'm not sure how we got into this particular topic, but Steve taught me a very cunning coding trick as follows... It very often happens in my programs that I have an integer variable that I use as a pointer (or index) to a number of elements in an array or some such entity. For example, let's say we have ten elements of something or other numbered from 0 to 9. For clarity in our code and to make it easy to modify in the future, we might define NUM_E ('number of elements') as being 10 and MAX_E ('maximum element') as being 9. (We could also define MIN_E as being 0, but we typically just use 0.)
展开▼
机译:在我们用Gusto跳进磨损之前(当然,当然),我最近和我的Chum Steve Manley聊天,他们在我的主要酷豆柱中突出了。 我不确定我们如何进入这个特殊的话题,但史蒂夫教我一个非常狡猾的编码技巧如下......它经常发生在我的程序中我有一个我用作指针(或索引)的整数变量 在数组中或某些此类实体中的许多元素。 例如,让我们说我们有十个或其他数量的东西,从0到9.在我们的代码中清楚起见,并使将来很容易修改,我们可能会将num_e('元素'数量')定义为10和 max_e('最大元素')为9.(我们也可以将min_e定义为0,但我们通常只是使用0.)
展开▼