// Instead of this:
return 4/step; // step always > 0
// Use this:
assert(step>0);
return 4/step;
It's the specification, documented and enforced-- the mental model of how this code is supposed to work. Bim: Here's that book I borrowed. Thanks, I enjoyed it.
Reader: Did you.. write in my book?
Bim: Only a little.
const doub rad = sqrt(x*x + y*y); // "rad" not changing.
Combined with short functions it is a powerful element of self documenting code.void make(); // not const, changes state.
void load(); // not const, changes state.
bool valid() const;
int size() const;
void save() const;
void dump() const;
class Threaded {
public:
static void Run(ThreadCB, int N, void*v=0);
static int numCPUs();
private:
static void* _Run(void*);
static int find_free(vector<int>&, vector<pthread_t>&);
struct ARGS {
ThreadCB CB;
int i, N, channel;
void *v;
vector<int>*log;
};
};
Placing ARGS inside the class tells the reader (and requires) that it can only be used in a restricted context.class layoutUI: public layoutui_, public plug {
public: layoutUI();
PCOPY(layoutUI); // plugin copy.
GFUNC(layoutUI); // declare geom CB.
OFUNC(layoutUI); // declare origin CB.
// ...more implementation.
};
nedwaves.com 2017 [171108]