About patterns, UML and documentation

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

About patterns, UML and documentation

Pharo Smalltalk Users mailing list
Hello,

I don't know Smalltalk well enough to give myself an answer about the following topic:

When using design patterns, one benefit of writing interfaces and passing objects, that implement this interface, to methods is, that the reader instantly knows: okay, here the method A expects something that implements method B.

Due to the nature of being a dynamically typed language, Smalltalk does not need interfaces. An exception object is thrown when a message is passed to an object that does not implement that method. But this message send could be deep inside the code.

How do you show to the reader of your code your intention, that you are expecting, let's say for example, an iterator or an object that implements method X, Y and Z?

Just with your method comments? Do you use UML? If so, how (without interfaces that point to the required methods)?

Sorry, but I think my understanding of OOP is still to much influenced by C++ and Java based teachings...

Thanks and best regards,
Marc
Reply | Threaded
Open this post in threaded view
|

Re: About patterns, UML and documentation

tblanchard
Hi Marc.

In Smalltalk, we rely on naming conventions a lot.

The great thing is that Smalltalk selectors/symbols/method names read like English.

aDictionary at: aKey put: anObject.

aString indexOf: aCharacter  startingAt: start  ifAbsent: aBlock

Seems pretty clear, no?

We also rely on comments.  For instance this is the class comment for IceRepository - an abstraction of a git repo.

I represent an interface to a git repository. 

My main responsibilities are:
- Load/update both baselines and individual packages from the repository.
- Commit changes to the local repository and publish them to a remote repository.
- Browse other versions of the loaded packages.
- Handle branches

For the Collaborators Part: State my main collaborators and one line about how I interact with them. 

Public API and Key Messages
- loadPackage: packageName
- createBranch: newBranchName

Sample usage:

    Git new origin: '[hidden email]:npasserini/pharo-git-test.git'.
    git loadPackage: 'Pharo-Git-Test'. 


Instance Variables
- origin: A string representing the url of a remote git repository (used as origin)
- repository: An IceGitTreeGitRemoteRepository, which provides underlying git operations.
- location: <FileReference> The directory of the local repository.
- commitDictionary: <Dictionary of IceCommitInfo> Cached dictonary from commitId (hex string) to  all commits in the current branch (in the local repo).
- subdirectory: <String> The subdirectory of the local repository which is handled by the underlying GitFileTree
- versionDescriptors: <List of GitFileTreePackageEntry> cached list of all package versions saved in the (currently selected branch) of the (local) repository.
- announcer: <Announcer>
- branch: <IceBranch> currently selected branch. 
- loadedCode:  <IceLoadedCode> Contains information about the loaded code for each package in this repository. (TODO: maybe handle special cases about loading different versions loaded for different packages, see: https://github.com/npasserini/iceberg/issues/139).

I hope this helps.

-Todd Blanchard

On Jun 7, 2017, at 10:17 PM, Marc Hanisch via Pharo-users <[hidden email]> wrote:


From: Marc Hanisch <[hidden email]>
Subject: About patterns, UML and documentation
Date: June 7, 2017 at 10:17:11 PM PDT
To: Any question about pharo is welcome <[hidden email]>


Hello,

I don't know Smalltalk well enough to give myself an answer about the following topic:

When using design patterns, one benefit of writing interfaces and passing objects, that implement this interface, to methods is, that the reader instantly knows: okay, here the method A expects something that implements method B.

Due to the nature of being a dynamically typed language, Smalltalk does not need interfaces. An exception object is thrown when a message is passed to an object that does not implement that method. But this message send could be deep inside the code.

How do you show to the reader of your code your intention, that you are expecting, let's say for example, an iterator or an object that implements method X, Y and Z?

Just with your method comments? Do you use UML? If so, how (without interfaces that point to the required methods)?

Sorry, but I think my understanding of OOP is still to much influenced by C++ and Java based teachings...

Thanks and best regards,
Marc



Reply | Threaded
Open this post in threaded view
|

Re: About patterns, UML and documentation

jtuchel
In reply to this post by Pharo Smalltalk Users mailing list
I think the key to this is intention revealing names and comments. And
shipping unit tests that are the best example of "running documentation".

Take Sven's NeoCSV package as an example. Great documentation and very
good method names. and a complete set of tests.

Sounds frightening at first if you come from a static typing background,
but in my experience it works quite well.

There are UML tools. Some even allow round-trips where the UML diagrams
can be generated from code (e.g. IBM/Instantiations have the UML
Designer add-on), but to be honest, these only put you in high danger of
playing with the tool and layout and stuff rather than concentrate on
what is important. UML is fine for communicating the raw structure and
basic ideas. Generating UML from code on the fly can help understand
code, but I've seen too many projects that made the UML design documents
an art of itself, and most of the times the diagrams were out of sync
anyways...

Just my 2 cents,

Joachim


--
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          mailto:[hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1


Reply | Threaded
Open this post in threaded view
|

Re: About patterns, UML and documentation

Pharo Smalltalk Users mailing list
Thanks Todd and Joachim for your fast responses,

your examples are very interesting! I think I got the point! ...And you are so true about your experience with UML and the struggle to group / align all graphical objects so it is still understandable ;-)

Best regards,
Marc

2017-06-08 7:53 GMT+02:00 [hidden email] <[hidden email]>:
I think the key to this is intention revealing names and comments. And shipping unit tests that are the best example of "running documentation".

Take Sven's NeoCSV package as an example. Great documentation and very good method names. and a complete set of tests.

Sounds frightening at first if you come from a static typing background, but in my experience it works quite well.

There are UML tools. Some even allow round-trips where the UML diagrams can be generated from code (e.g. IBM/Instantiations have the UML Designer add-on), but to be honest, these only put you in high danger of playing with the tool and layout and stuff rather than concentrate on what is important. UML is fine for communicating the raw structure and basic ideas. Generating UML from code on the fly can help understand code, but I've seen too many projects that made the UML design documents an art of itself, and most of the times the diagrams were out of sync anyways...

Just my 2 cents,

Joachim


--
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          mailto:[hidden email]
Fliederweg 1                         http://www.objektfabrik.de
D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
Telefon: <a href="tel:%2B49%207141%2056%2010%2086%200" value="+4971415610860" target="_blank">+49 7141 56 10 86 0         Fax: <a href="tel:%2B49%207141%2056%2010%2086%201" value="+4971415610861" target="_blank">+49 7141 56 10 86 1



Reply | Threaded
Open this post in threaded view
|

Re: About patterns, UML and documentation

Peter Uhnak
> > with the tool and layout and stuff rather than concentrate on what is

Well there are tools such as PlantUML that generate it for you, you can provide some hints, but generally it tends to be good enough to not be worried about layout.

I have a Pharo -> PlantUML generator for class, object, and sequence diagrams somewhere, as I've used it to gain insight about some subsystems on several occasions, but I never published it... it's a bit of hacky code around Pharo's metaprogramming and reflecting capabilities... so you could in principle write it by hand in an hour or so... in fact doing so by hand might be beneficial for specific problem, because you can reverse-engineer only the parts that you care about instead of having everything or having a complex generator parametrization...


> > Take Sven's NeoCSV package as an example. Great documentation and very
> > good method names. and a complete set of tests.
> >
> > Sounds frightening at first if you come from a static typing background,
> > but in my experience it works quite well.

I don't think that this is a good example. From user perspective you usually interact with only two classes (reader and writer)... and I don't really see how UML could help you there. The internal architecture on the other hand, or tools with models could benefit from it much more (at least in class diagrams, the relationships between elements tends to be the most important part, so if you have one or two classes... then you won't have much connections...).

Peter

On Thu, Jun 08, 2017 at 08:40:34AM +0200, Marc Hanisch via Pharo-users wrote:

> Date: Thu, 8 Jun 2017 08:40:34 +0200
> From: Marc Hanisch <[hidden email]>
> To: Any question about pharo is welcome <[hidden email]>
> Subject: Re: [Pharo-users] About patterns, UML and documentation
>
> Thanks Todd and Joachim for your fast responses,
>
> your examples are very interesting! I think I got the point! ...And you are
> so true about your experience with UML and the struggle to group / align
> all graphical objects so it is still understandable ;-)
>
> Best regards,
> Marc
>
> 2017-06-08 7:53 GMT+02:00 [hidden email] <[hidden email]>:
>
> > I think the key to this is intention revealing names and comments. And
> > shipping unit tests that are the best example of "running documentation".
> >
> > Take Sven's NeoCSV package as an example. Great documentation and very
> > good method names. and a complete set of tests.
> >
> > Sounds frightening at first if you come from a static typing background,
> > but in my experience it works quite well.
> >
> > There are UML tools. Some even allow round-trips where the UML diagrams
> > can be generated from code (e.g. IBM/Instantiations have the UML Designer
> > add-on), but to be honest, these only put you in high danger of playing
> > with the tool and layout and stuff rather than concentrate on what is
> > important. UML is fine for communicating the raw structure and basic ideas.
> > Generating UML from code on the fly can help understand code, but I've seen
> > too many projects that made the UML design documents an art of itself, and
> > most of the times the diagrams were out of sync anyways...
> >
> > Just my 2 cents,
> >
> > Joachim
> >
> >
> > --
> > -----------------------------------------------------------------------
> > Objektfabrik Joachim Tuchel          mailto:[hidden email]
> > Fliederweg 1                         http://www.objektfabrik.de
> > D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
> > Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1
> >
> >
> >