[squeak-dev] Note sharing inside Squeak?

St├ęphane Rollandin lecteur at zogotounga.net
Tue Jun 28 09:17:46 UTC 2022


> One issue I have with lots of inline comments like here is that it makes 
> it really painful if you want to comment out a section of the code for 
> debugging, testing etc.
> A way of skipping whole lines like C style // single line comment could 
> maybe help with that.
What I sometimes do is just enclose a chunk of code within a block. It 
has the nice effect that comments inside the block are not a problem.

With Chris example:


      | minElement minValue |
      "enumerate my elements"
      self do: [:each | | val |
           "has a current minimum already been established?"
           minValue
                ifNotNil: [ "yes, does the current element compute less?"
                     (val := aBlock value: each) < minValue
                          ifTrue: [ "yes, assign the new minimum"
                               minElement := each.
                               minValue := val ] ]
                ifNil: [ "no.  Establish current as the minimum"
                     minElement := each.
                     minValue := aBlock value: each ] ].
      "Answer the element that computed the minimum value."
      ^ minElement

I would do for example something like


      | minElement minValue |
      "enumerate my elements"
      self do: [:each | | val |
           "has a current minimum already been established?"
           minValue
                ifNotNil: [ "yes, does the current element compute less?"
                     [ (val := aBlock value: each) < minValue
                          ifTrue: [ "yes, assign the new minimum"
                               minElement := each.
                               minValue := val ]	].

			val := 0 "for testing"]	

                ifNil: [ "no.  Establish current as the minimum"
                     minElement := each.
                     minValue := aBlock value: each ] ].
      "Answer the element that computed the minimum value."
      ^ minElement

Stef


More information about the Squeak-dev mailing list