Code formatting patterns (was: [squeak-dev] The Trunk: Compiler-cmm.275.mcz)

Chris Muller asqueaker at gmail.com
Fri Oct 4 15:45:33 UTC 2013


>> Compare
>>
>>         [ undeclared at: sym put: nil ]
>>                 on: AttemptToWriteReadOnlyGlobal
>>                 do: [ :noti | noti resume: true ]
>>
>> to:
>>
>>         [ undeclared
>>                 at: sym
>>                 put: nil ]
>>                 on: AttemptToWriteReadOnlyGlobal
>>                 do: [ :noti | noti resume: true ]
>>
>> Isn't the first one much more "rectangular" and easier to read? I find the
>> indentation in the second one irritating.

Yes, I agree with you for that one case.  RB, Indented Control Flow,
etc. do not specify how to handle keywords sent to Blocks.  One
suggestion is to add a blank line, as in:

         [ undeclared
                 at: sym
                 put: nil ]

                 on: AttemptToWriteReadOnlyGlobal
                 do: [ :noti | noti resume: true ]

Or, an extra indention:

         [ undeclared
                 at: sym
                 put: nil ]
                      on: AttemptToWriteReadOnlyGlobal
                      do: [ :noti | noti resume: true ]

The important thing to handle the _general_ case, so the computer can
do at least 97% of the formatting.  If we had a larger keyword
message, your rule would look like this:

           [ mySoundRecorder copyTo: resultBuf from: j to: (j + n - 1)
from: buf startingAt: firstInBuf normalize: nFactor dcOffset: dcOffset
]
                   on: AttemptToWriteReadOnlyGlobal
                   do: [ :noti | noti resume: true ]

which, clearly, is a mess compared to:

           [ mySoundRecorder
                 copyTo: resultBuf
                 from: j
                 to: (j + n - 1)
                 from: buf
                 startingAt: firstInBuf
                 normalize: nFactor
                 dcOffset: dcOffset ]
                      on: AttemptToWriteReadOnlyGlobal
                      do: [ :noti | noti resume: true ]

I would LOVE to make pretty print use RB formatting in a way that's
acceptable to the wider community, so we can be developers and not
formatting slaves.


More information about the Squeak-dev mailing list