[squeak-dev] The Inbox: Compiler-ct.418.mcz

Marcel Taeumel marcel.taeumel at hpi.de
Mon Feb 17 09:09:29 UTC 2020


Hi Christoph.

> actually, I love the Dictionary API with the #ifPresent:ifAbsent: arguments as it is very convenient for describing the code paths

The terms "at" or "at if present" are quite generic while "class named" reads domain specific. So, #classNamed: can improve code readability. And once you are in that domain, as Levente mentioned, you can then support things such as metaclass lookup using the same interface. :-) That would be awkward (or at least unexpected and surprising) through #at:ifPresent: ...

> If you think it is important to distinguish between classes and globals

Classes are a special kind of global variable. Yes, this domain knowledge should be represented in the interface.

>  maybe we should also introduce #classNamed:[ifPresent:][ifAbsent:] (three variants) to SmalltalkImage? But this would be a lot of "forwarding noise"

I don't think that we need that change. Programmers can write quite readable code using #hasClassNamed: and #classNamed:.

Best,
Marcel


Am 17.02.2020 00:17:02 schrieb Thiede, Christoph <christoph.thiede at student.hpi.uni-potsdam.de>:
Hi Levente,

actually, I love the Dictionary API with the #ifPresent:ifAbsent: arguments as it is very convenient for describing the code paths (IMHO). As you may have seen, I am trying to establish it for more domains (see Collections-ct.873, Collections-ct.872, Collections-ct.875).

If you think it is important to distinguish between classes and globals, maybe we should also introduce #classNamed:[ifPresent:][ifAbsent:] (three variants) to SmalltalkImage? But this would be a lot of "forwarding noise".

Best,
Christoph
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Levente Uzonyi <leves at caesar.elte.hu>
Gesendet: Sonntag, 16. Februar 2020 22:39:13
An: squeak-dev at lists.squeakfoundation.org
Betreff: Re: [squeak-dev] The Inbox: Compiler-ct.418.mcz
 
Hi Christoph,

The idea with Environments was to move away from the SystemDictionary API.
It obviously didn't happen, but there's #classNamed: for class lookup by
name. Actually #classNamed: was there with SystemDictionary too, but it
was and still is underused.

Levente

On Sun, 16 Feb 2020, commits at source.squeak.org wrote:

> Christoph Thiede uploaded a new version of Compiler to project The Inbox:
> http://source.squeak.org/inbox/Compiler-ct.418.mcz [http://source.squeak.org/inbox/Compiler-ct.418.mcz]
>
> ==================== Summary ====================
>
> Name: Compiler-ct.418
> Author: ct
> Time: 16 February 2020, 3:49:08.315 pm
> UUID: 3ca7ba74-6e8b-f64d-bc62-701ebc5df3e0
> Ancestors: Compiler-eem.416
>
> Small refactoring: Use SmalltalkImage >> #at:ifPresent:ifAbsent:.
>
> =============== Diff against Compiler-eem.416 ===============
>
> Item was changed:
>  ----- Method: Compiler>>evaluateCue:ifFail: (in category 'private') -----
>  evaluateCue: aCue ifFail: failBlock
>        "Compiles the cue source into a parse tree, then generates code into
>        a method. Finally, the compiled method is invoked from here via  withArgs:executeMethod:, hence the system no longer creates Doit method
>        litter on errors."
>
>        | methodNode method value |
>        methodNode := self compileCue: aCue noPattern: true ifFail: [^failBlock value].
>
>        method := self interactive
>                                ifTrue: [methodNode generateWithTempNames]
>                                ifFalse: [methodNode generate].
>
>        value := cue receiver
>                                withArgs: (cue context ifNil: [#()] ifNotNil: [{cue context}])
>                                executeMethod: method.
> +      ^ value!
> -      ^ value
> - !
>
> Item was changed:
>  ----- Method: MethodNode>>asColorizedSmalltalk80Text (in category 'converting') -----
>  asColorizedSmalltalk80Text
>        "Answer a colorized Smalltalk-80-syntax string description of the parse tree whose root is the receiver."
>
>        | printText |
>        printText := self printString asText.
> +      ^ Smalltalk
> +              at: #SHTextStylerST80
> +              ifPresent: [:stylerClass | stylerClass new styledTextFor: printText]
> +              ifAbsent: [printText]!
> -      ^(Smalltalk at: #SHTextStylerST80 ifAbsent: [nil])
> -              ifNotNil: [:stylerClass| stylerClass new styledTextFor: printText]
> -              ifNil: [printText]!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200217/8197d1ff/attachment.html>


More information about the Squeak-dev mailing list