Moldable Development Story - SessionManager

Moldable development is a way of programming through which you construct custom tools for each problem.

This story is about SessionManager Object subclass: #SessionManager instanceVariableNames: 'currentSession categories guiCategory toolsCategory networkCategory systemCategory userCategory' classVariableNames: 'Default' package: 'System-SessionManager-Base' , an object responsible for managing how sessions work in Pharo. A session begins when the system is started and stops when it is closed. Projects can register handlers with the session manager that get notified when the image is opened or closed. We often rely on this in Glamorous Toolkit to remove resources, or initialize the graphical user interface.

Asking a specific question

When debugging a part of Glamorous Toolkit that was using the session manager we asked this question: "Which handlers with a priority of 100 are currently registered in the Tools category?". To answer this question we inspected the default session manager object, and started navigating through its state.

This ended up being a complex navigation involving four objects and requiring knowledge about how the session manager object is implemented.

Answering our question through specific views

To make sure next time we can answer this and similar questions faster, we took five minutes and added two custom views. We added the first one to the session manager to show the list of categories.

        
SessionManager>>#gtViewSessionCategoriesFor: aView
	<gtView>
	
	^ aView columnedList 
		title: 'Categories';
		priority: 10;
		items: [ categories ];
		column: 'Category' text: [ :each | each name ];
		column: 'Handlers Count' 
			text: [ :each | each prioritizedList size ] 
			width: 200
        
      

The second one we added to the category object to show the list of handlers from that category based on their priority.

        
SessionCategory>>#gtViewPriorityListsFor: aView
	<gtView>
	
	^ aView forward 
		title: 'Priority Lists';
		object: [ (priorityLists associations 
			sorted: [ :assoc |
				assoc key ] ascending) asOrderedDictionary ];
		priority: 20;
		view: #gtTreeFor:context:
        
      

Using these two custom views we can now get a direct answer to our question. We also do not need to deal with implementation details regarding the SessionManager object.

Formulating and answering more questions

At this point we created a small tool to answer our initial question.

However, while working on our task we kept asking one more question regarding the session manager: What are the startup and shutdown lists of handlers?

We further created two more views to directly show these two lists.

Reusing views for creating documentation

Views are small units of composition capturing interesting aspects about objects. Their scope is not limited to the object inspector, and can be freely embedded within Lepiter pages.

To end our tool-building session, we decided to create a documentation page "How to view the Startup and Shutdown lists" in the Glamorous Toolkit Book, showing the two lists.

In that page we directly embedded the two views that we created above.

Wrap-up

Software development is an activity where we constantly formulate and answer specific questions about our software systems.

With Moldable development every specific question that we ask is an opportunity to create a custom tool!