Code formatting patterns (was: [squeak-dev] The Trunk:
Compiler-cmm.275.mcz)
Bert Freudenberg
bert at freudenbergs.de
Fri Oct 4 15:07:09 UTC 2013
On 2013-10-04, at 16:58, Chris Muller <asqueaker at gmail.com> wrote:
> Well, the new is taller and slimmer, with a consistent application of
> Rectangular Block, a "best practice" formatting pattern. I've never
> found short and squat (and inconsistent!) to be easier to read than
> tall & slim, but I guess we all have our visual acuity developed the
> way it is developed.
> method.
>
> That's why I'd suggest to simply use pretty print when coming across a
> method you find hard-to-read.
>
> Also, if I make a small, one-line change to a method, I won't reformat
> it out of respect for the prior author's format. But if changes are
> significant, it becomes "my" code and time is too scarce anyway to
> spend time manually formatting code. A Shift+Command+S just prior to
> saving converts it to RB for me, which is easiest for most people to
> read because, according to the pattern, people see things in
> rectangles.
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.
- Bert -
>
> On Fri, Oct 4, 2013 at 6:06 AM, Bert Freudenberg <bert at freudenbergs.de> wrote:
>> On 2013-10-03, at 23:02, Chris Muller <asqueaker at gmail.com> wrote:
>>
>>> The reformatting caused almost all lines to be dif'd. The only change
>>> is handling AttemptToWriteReadOnlyGlobal on the at:put:.
>>
>> I find the compact form the code had before a lot more readable.
>>
>> - Bert -
>>
>>>
>>> On Thu, Oct 3, 2013 at 2:35 PM, <commits at source.squeak.org> wrote:
>>>> Chris Muller uploaded a new version of Compiler to project The Trunk:
>>>> http://source.squeak.org/trunk/Compiler-cmm.275.mcz
>>>>
>>>> ==================== Summary ====================
>>>>
>>>> Name: Compiler-cmm.275
>>>> Author: cmm
>>>> Time: 3 October 2013, 2:34:56.409 pm
>>>> UUID: 9d002330-e75e-436f-8699-b29413e98e81
>>>> Ancestors: Compiler-nice.274
>>>>
>>>> When loading code, don't blow up just because of an undeclared ref.
>>>>
>>>> =============== Diff against Compiler-nice.274 ===============
>>>>
>>>> Item was changed:
>>>> ----- Method: Encoder>>undeclared: (in category 'encoding') -----
>>>> + undeclared: name
>>>> - undeclared: name
>>>> | sym |
>>>> requestor interactive ifTrue:
>>>> + [ requestor requestor == #error: ifTrue: [ requestor error: 'Undeclared' ].
>>>> + ^ self notify: 'Undeclared' ].
>>>> - [requestor requestor == #error: ifTrue:
>>>> - [requestor error: 'Undeclared'].
>>>> - ^self notify: 'Undeclared'].
>>>> "Allow knowlegeable clients to squash the undeclared warning if they want (e.g.
>>>> Diffing pretty printers that are simply formatting text). As this breaks
>>>> compilation it should only be used by clients that want to discard the result
>>>> of the compilation. To squash the warning use e.g.
>>>> [Compiler format: code in: class notifying: nil decorated: false]
>>>> on: UndeclaredVariableWarning
>>>> do: [:ex| ex resume: false]"
>>>> sym := name asSymbol.
>>>> + ^ (UndeclaredVariableWarning new
>>>> + name: name
>>>> + selector: selector
>>>> + class: cue getClass) signal
>>>> - ^(UndeclaredVariableWarning new name: name selector: selector class: cue getClass) signal
>>>> ifTrue:
>>>> + [ | undeclared |
>>>> - [| undeclared |
>>>> undeclared := cue environment undeclared.
>>>> + [ undeclared
>>>> + at: sym
>>>> + put: nil ]
>>>> + on: AttemptToWriteReadOnlyGlobal
>>>> + do: [ : noti | noti resume: true ].
>>>> + self
>>>> + global: (undeclared associationAt: sym)
>>>> + name: sym ]
>>>> - undeclared at: sym put: nil.
>>>> - self global: (undeclared associationAt: sym) name: sym]
>>>> ifFalse:
>>>> + [ self
>>>> + global: (Association key: sym)
>>>> + name: sym ]!
>>>> - [self global: (Association key: sym) name: sym]!
>>>>
>>>>
>>>
>>
>>
>>
>>
More information about the Squeak-dev
mailing list
|