A little namespace "proposal"
Michael van der Gulik
squeakml at gulik.co.nz
Wed Apr 7 02:21:43 UTC 2004
Hello everybody.
Wow.. that became a big thread quickly.
goran.krampe at bluefish.se wrote:
>
> Primary values I have sought to fulfill:
>
> - Simplicity (for example, there are no "imports")
Are "imports" not simple?
> - Making it work "optimistically"
> - Somewhat backwards compatible in the meaning that most things will
> "work just like now".
You mean that it's also disposable and intended as a temporary measure,
for when somebody else comes along with a more thorough proposal?
> - When creating a class in a class category the template would look
> like:
>
> Object subclass: #NameOfSubclass
> instanceVariableNames: ''
> classVariableNames: ''
> poolDictionaries: ''
> category: 'Kernel-Processes'
> namespace: 'Kernel'
I like the namespace: part. But we already have a "category" - why can't
we re-use that instead?
>
> ...thus autopicking the PI-first part of the category, or perhaps like
> this:
>
> Object subclass: #Kernel::NameOfSubclass
> instanceVariableNames: ''
> classVariableNames: ''
> poolDictionaries: ''
> category: 'Kernel-Processes'
>
> ...whichever we like the best.
Umm...
Something subclass: #Namespace
instanceVariableNames: 'myClasses importedNamespaces '
classVariableNames: ''
poolDictionaries: ''
category: 'Kernel(?)'
importedNamespaces: 'Kernel Collections Morphic Globals'
" myClasses are a list of classes in this Namespace.
importedNamespaces is a list of other namespaces imported into this
one. "
and
Object>>namespace
^ self class getNamespace.
So then you can do:
self namespace importNamespace: #AnotherNamespace
at runtime, or put them in the importedNamespaces list at.. er..
compile-time.
Instead of saying ANamespace::AClass in code, you could do the (uglier):
c := self namespace getClass: #ClassName fromNamespace: #ANamespace.
bob := c new.
or is that too ugly? It's wordy, but it "feels" right. All the existing
classes could be put into a "Smalltalk" namespace until they've been
sorted into their own namespaces. If a class name is not present in the
importedNamespaces list, then IMO that class shouldn't be accessable.
Smalltalk is a nice simple language. Please don't change it's syntax if
you don't need to!
I also think that modifications made to an external Namespace from a
"current" Namespace (e.g. adding yet another obscure method to String
that's only used by you) should be visible only from the Namespace from
which it was made. I.e. the "MikesStuff" namespace might add a
"asChewingGum" method on String, but it can only be seen and used from
the "MikesStuff" Namespace and no other. Don't ask me how though...
perhaps ClassBoxes do this?
Mikevdg.
More information about the Squeak-dev
mailing list
|