On 16 April 2011 13:32, Ted F.A. van Gaalen <[email protected]> wrote: > Hi there. > > I am probably not the first, and will not be > the last person to come up > with this suggestion, neverTheLess: > > To increment a numeric value I would like to write: > > aNum := 1. > aNum ++. to increment it > aNum --. to decrement it > this is wrong smalltalk syntax. ++ and -- are binary messages, which means you should pass an argument to message, i.e:
num ++ x num -- y. If you want unary messages, use word: num increment num decrement unless of course you want to extend the number of special operators, which are only: ':=' for assignment and '^' for return. So, you wanna increase the number of syntax rules to either introduce new operators (++/--) or add reserved words (increment/decrement). But if we follow that road, then next day one would argue why we don't have operators like +=, *=, -= and so on.. And then smalltalk will slowly turn into C dialect, where all language semantics available through syntax, instead through implementation & message sends. Smalltalk having very small number of syntax rules comparing to other high level languages. And this is one of its best characteristics , among the rest. So i prefer it to be staying this way. > instead of: > aNum := aNum + 1. > > For reasons of efficiency and readability. > > Why? > Most, if not all, of today's computer processors > ( they used to be called microprocessors :o) > have INCrement en DECrement instructions, > which are much more efficient than addition > and subtraction instructions. > (less clock cycles, perhaps even just one) > > Of course, the work should to be done by primitives, > which directly utilizes the processor's INC, DEC instructions. > > So, wouldn't it be convenient to implement these ++ and --- > methods in Pharo? and VM. I am not sure, but I suspect also a number > of system classes e.g. in do: [:i|...] would perform better, > wenn this method/ instruction is supported? > > ? > > Kind Regards > Ted > Currently making/learning Pharo/Seaside app. > > -- Best regards, Igor Stasenko AKA sig.
