Dec. 9th, 2009

jack: (Default)
When someone invented petrol pumps that accepted credit cards, they must have been really pleased. "We can save everyone time!" they might have said. But judging by the "safe, secure, fast" stickers all over them, they must also have worried that people might not be eager to take them up.

Thus, in an effort to make paying at the pump seem easy and attractive to people stuck in their ways, there are two sorts of pumps: those that cheerily proclaim "Pay at pump" and those that cheerily proclaim "Pay at pump only".

However, there seemed to be one aspect of this stragegy which was woefully ill-thought out: what on earth if it _succeeds_. If your customers see paying by card as normal, and going into a quaint little hut full of chocolate bars and newspapers as touchingly retro, then "pay at pump" no longer carries the connotation of helpfully, this pump also offers the shiny futuristic pay-at-pump option, naturally contrasted with "can't pay at pump". It starts to look more like it ought to contrast with "pay at kiosk". But it can't, because if "pay at pump" means "pay at pump only", then what would "pay at pump" mean?
jack: (Default)
In many "introduction to C-style programming language" books, you see two variables being set to the same value with syntax like:

 x = y = 0


In fact, I almost never write that in real life. Normally I find:

* The variables are being declared and initialised, and you can't write "int a = int b = 0"
* It's possible the variables may be set to different values under some circumstances, in which case I find assigning them in separate statements clearer.
* It's being done to squeeze an extra statement into a conditional expression, like "while (p=getcharacter()) { dosomething(p) }", and it's actually clearer to move the assignment to a separate line

All the same, if I've ever declared any assignment operators on any user defined classes, I've always scrupulously declared them to return the value used*.

But for the first time in about five years, I actually *did* try to write "if (newval>obj.max) obj.val = obj.max = newval".

And it failed. Because obj was from the .NET framework, which has getters and setters, and setters apparently do NOT return a value. I'm not sure if they _should_. But maybe this piece of advice is dead now, if I never needed it before?

* Aside

In the C++ books I've seen, in fact they return a non-const reference from their assignment operators, allowing you to write:

(obj=1)=2


I assume no-one ever WOULD want to write that, because either (a) the assignment has no side effects, and it's pointless or (b) "obj=1" does something interesting, when it should have its own line. Why is the reference non-const, is it so it so that you can write "a = (obj=1)" or "f( obj=1 )" even if a.operator= or f take non-const parameters?

Active Recent Entries