measuring namespace imports

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

measuring namespace imports

Reinout Heeck-2
The more I write Smalltalk in VW the more I'm bothered with my domain
vocabulary being 'taken' by the Smalltalk namespace.
Such simple things as modeling a Message or a Model too often gives me
the jarring experience of the name being 'taken'.

So what imports do we actually use in code?
I started to play in new namespaces _without_ any imports and started to
import only specific names instead of using 'Smalltalk.*'.
This led to the surprising result that domain models often need less
than 5  specific imports from outside the Soops namespace hierarchy.

Here is a little analysis script that measures uses of non-Soops names
from methods inside Soops namespaces.
I only measure references from methods because references for the
purpose of subclassing do not use the import mechanisms.


---------------------
ns := Soops.
refsByNamespace := Dictionary new.
refsByPackage := Dictionary new.
ns enumerateMethods:
         [:class :sel :compiled |
         compiled literals do:
                 [:lit |
                 (lit isVariableBinding
                     ifTrue: [lit binding environment notNil]
                     ifFalse: [lit isBindingReference and: [lit isDefined]])
                         ifTrue:
                             [(lit binding absoluteName
asQualifiedReference path
                                 startsWith: ns absoluteReference path)
                                     ifFalse:
                                         [(refsByNamespace at: class
environment ifAbsentPut: [Set new])
                                             add: lit binding.
                                         (refsByPackage at: class
package ifAbsentPut: [Set new]) add: lit binding]]]].
refsByNamespace inspect.
refsByPackage inspect
---------------------

It turns out that in our code there are many packages that only use a
handful of names from the libraries.

We already have the option to set a 'default namespace' on a package (to
allow resolutions unrelated to the imports of a class we might be
extending).
My experiments suggest that we do not need a default namespace on
packages but rather that we need to go one level deeper and have a
'default imports' section so I can declare the handfull of names the
package references instead of all-of-cincom-smalltalk.



Thoughts?

R
-



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: measuring namespace imports

Michael Lucas-Smith-2
I haven't imported Smalltalk in to my own namespaces in years now. I often import Core, Graphics, sometimes Net but never Smalltalk. I recommend others do the same, so that they find out what they really do and do not depend on. I like your script.

Michael


On 24 January 2014 03:22, Reinout Heeck <[hidden email]> wrote:
The more I write Smalltalk in VW the more I'm bothered with my domain vocabulary being 'taken' by the Smalltalk namespace.
Such simple things as modeling a Message or a Model too often gives me the jarring experience of the name being 'taken'.

So what imports do we actually use in code?
I started to play in new namespaces _without_ any imports and started to import only specific names instead of using 'Smalltalk.*'.
This led to the surprising result that domain models often need less than 5  specific imports from outside the Soops namespace hierarchy.

Here is a little analysis script that measures uses of non-Soops names from methods inside Soops namespaces.
I only measure references from methods because references for the purpose of subclassing do not use the import mechanisms.


---------------------
ns := Soops.
refsByNamespace := Dictionary new.
refsByPackage := Dictionary new.
ns enumerateMethods:
        [:class :sel :compiled |
        compiled literals do:
                [:lit |
                (lit isVariableBinding
                    ifTrue: [lit binding environment notNil]
                    ifFalse: [lit isBindingReference and: [lit isDefined]])
                        ifTrue:
                            [(lit binding absoluteName asQualifiedReference path
                                startsWith: ns absoluteReference path)
                                    ifFalse:
                                        [(refsByNamespace at: class environment ifAbsentPut: [Set new])
                                            add: lit binding.
                                        (refsByPackage at: class package ifAbsentPut: [Set new]) add: lit binding]]]].
refsByNamespace inspect.
refsByPackage inspect
---------------------

It turns out that in our code there are many packages that only use a handful of names from the libraries.

We already have the option to set a 'default namespace' on a package (to allow resolutions unrelated to the imports of a class we might be extending).
My experiments suggest that we do not need a default namespace on packages but rather that we need to go one level deeper and have a 'default imports' section so I can declare the handfull of names the package references instead of all-of-cincom-smalltalk.



Thoughts?

R
-



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc