Werner ... It's not a bad technique at all. Look at Collection>>detect:ifNone: which is doing exactly what you are doing ... in fact you could use #detect: in your case:
^aCollection detect: [:each | each satisfiesTest ] and you'll get a 'not found' error if none of the elements answers true... Dale ----- Original Message ----- | From: "Werner Kassens" <[email protected]> | To: "A friendly place where any question about pharo is welcome" <[email protected]> | Sent: Friday, May 18, 2012 5:05:40 AM | Subject: [Pharo-users] dirty hack question | | Hi, | i looked at a method in a package i downloaded that goes essentially | like this: | | method:aCollection | aCollection do:[:i| i satisfiesTest ifTrue[^someNumberDependingOnI] | ]. | ^someOtherNumberDependingOnACollection | | now theoretically some 'i' should always satisfy test, the | ^someOtherNumber was obviously added because there is a bug in | satisfiesTest and this way the bug is hardly noticable any more (its | not | important for my question, but someOtherNumber is perfectly logical | in | the general setting, if one does not understand the bug itself). i | changed satisfiesTest so that there should be no more bugs in it. of | course i cant be sure, hence i changed the ^someOtherNumber line to: | self error:'should never be reached'. | now i wonder whether that last error line would be considered a dirty | hack by the usual smalltalk programmer, and if yes, what would be the | usual procedure in such a case? | werner | |
