[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-smalltalk] Community sprint
From: |
Paolo Bonzini |
Subject: |
Re: [Help-smalltalk] Community sprint |
Date: |
Fri, 29 Sep 2006 16:21:00 +0200 |
User-agent: |
Thunderbird 1.5.0.7 (Macintosh/20060909) |
Hmm, having got over my initial wave of nausea, you may have a point
about Class >> #name:extend: (why not #name:extends: though?).
Just because it's been a while since I touched Java. :-P
It might as well be
String subclass: #MyString [
Method for: 'category' [
body
]
]
I'm not so sure about Method being stuck in there, though.
I should point this out again: if I get to implement this, it will be
completely optional to use it. More on this later.
I do think that #subclass: should remain the preferred way to create
classes, though. It's standard Smalltalk (in so far as such a thing
exists), and it illustrates a few fundamental Smalltalk concepts very
nicely, specifically: everything is an object, including classes, and
everything is done by sending messages to objects. Realizing that
classes were created by sending a message to another class was one of my
"Wow!" moments when learning Smalltalk.
String >> #asThingumy [
^self shouldNotImplement
]
I was warming to the first one. It looks like you're sending a block as
a message, which is odd, but not too odd. To think of a method body as a
block is very natural. Unfortunately, I've realized that it gives you no
opportunity to name the parameters.
Uuuhm, yes, I missed that.
To continue with my Java-ish example, class extension would be declared,
if we pick #name:extends:, as
Class name: String [
"This has set the scope of the method declarations."
Method for: 'extensions' [
join: aCollectionOfStrings
"Join the elements of aCollectionOfStrings, in order, with
myself."
^self inject: aCollectionOfStrings into: [ :a : b | a, b ]
]
]
Or maybe, if we pick #subclass:, as
String extensions [
Method for: 'extensions' [
join: aCollectionOfStrings
"Join the elements of aCollectionOfStrings, in order, with
myself."
^self inject: aCollectionOfStrings into: [ :a : b | a, b ]
]
]
or also
Method on: String for: 'extensions' [
join: aCollectionOfStrings
"Join the elements of aCollectionOfStrings, in order, with myself."
^self inject: aCollectionOfStrings into: [ :a : b | a, b ]
]
I don't think that the #methodsFor: case works so well. There's less
justification for having a special-case block:
The justification is just to provide a familiar syntax to people that
have prejudice. :-) If the mountain does not go to Mohammed, ...
Personally, I wouldn't mind declaring the category for each method:
String methodFor: 'examples' body: [ join: aCollectionOfStrings
"Join the elements of aCollectionOfStrings, in order, with myself."
]
Yes, and that's about the same as the above "Method" syntax. I don't
have a "body:" because anyway this has to be special cased in the parser
-- it's not a block anyway, it's just reusing the [ ] tokens, the same
as { } are used for scoping many different things in C/C++/Java.
Paolo
- [Help-smalltalk] Community sprint, Luca Bruno, 2006/09/29
- Re: [Help-smalltalk] Community sprint, Paolo Bonzini, 2006/09/29
- Re: [Help-smalltalk] Community sprint, Luca Bruno, 2006/09/29
- Re: [Help-smalltalk] Community sprint, Paolo Bonzini, 2006/09/29
- Re: [Help-smalltalk] Community sprint, Luca Bruno, 2006/09/29
- Re: [Help-smalltalk] Community sprint, Mike Anderson, 2006/09/29
- Re: [Help-smalltalk] Community sprint, Paolo Bonzini, 2006/09/29
- Re: [Help-smalltalk] Community sprint, Bram Neijt, 2006/09/29
- Re: [Help-smalltalk] Community sprint, Mike Anderson, 2006/09/29
- Re: [Help-smalltalk] Community sprint,
Paolo Bonzini <=
- Re: [Help-smalltalk] Community sprint, Mike Anderson, 2006/09/29
- Re: [Help-smalltalk] Community sprint, David Given, 2006/09/29
- Re: [Help-smalltalk] Community sprint, Paolo Bonzini, 2006/09/30
- Re: [Help-smalltalk] Community sprint, David Given, 2006/09/30
- Re: [Help-smalltalk] Community sprint, Mike Anderson, 2006/09/30
- Re: [Help-smalltalk] Community sprint, Paolo Bonzini, 2006/09/30
- Re: [Help-smalltalk] Community sprint, Bram Neijt, 2006/09/29
Re: [Help-smalltalk] Community sprint, Bram Neijt, 2006/09/29