Myself, I see only one issue in your code, and that is the pointless
use of sqrt.
scoreX: anInteger y: anInteger2
    | radiusSquared |
    radiusSquared := anInteger squared + anInteger2 squared.
    radiusSquared > 100
        ifTrue: [ ^ 0 ].
    radiusSquared > 25
        ifTrue: [ ^ 1 ].
    radiusSquared > 1
        ifTrue: [ ^ 5 ].
    ^ 10

Make that two issues.  The names anInteger and anInteger2.
How about
scoreHorizontal: horizontal vertical: vertical
  ...

The OO dogma about "if' that you refer to is about not using
"if" to make decisions based on TYPE.  Making decisions based
on NUMERIC RANGES is perfectly OK.

You could introduce a 'HalfOpenRangeDictionary" class
[K1,K2) -> V1
[K2,K3) -> V2
...
[Kn,infinity) -> Vn
But "You Ain't Gonna Need It", so don't.

On Sat, 28 Dec 2019 at 08:18, Roelof Wobben via Pharo-users
<pharo-users@lists.pharo.org> wrote:
>
> Hello,
>
> Im trying to solve a challenge from exercism where  I have to calculate the 
> points somehow gets on a very simple darts board.
>
> I solved it like this :
>
>
> scoreX: anInteger y: anInteger2
>     | distance |
>     distance := (anInteger squared + anInteger2 squared) sqrt.
>     distance > 10
>         ifTrue: [ ^ 0 ].
>     distance > 5
>         ifTrue: [ ^ 1 ].
>     distance > 1
>         ifTrue: [ ^ 5 ].
>     ^ 10
>
>
> but now I use three if then and I think it's ugly code.
>
> Is there a way I can make it more the smalltalk way ?
>
>
> Regards,
>
> Roelof
>

Reply via email to