# SMA Discussion points # Instructions for participating in lectures Due to Covid-19, this class will largely be held remotely. Lectures will generally be pre-recorded, with a live Q&A session on Zoom during the regular lecture hour. (Some lectures may instead be held live via Zoom.) For this to work, you must watch the lecture podcast beforehand, and prepare your questions for the live zoom session. To help with the organization, you are encouraged to post your question on a shared Google doc in advance. Of course you may also ask questions spontaneously during the Q&A session. The Zoom link and the Google doc will be announced weekly on Piazza in advance of the lecture hour. --- Podcast: https://tube.switch.ch/channels/45e44e12 Zoom Q&A: https://unibe-ch.zoom.us/j/94222614072?pwd=SXBoSEFraTNyNzk1VG1FRTJJRHlIUT09 Meeting ID: 942 2261 4072 Passcode: 329196 Google Doc for questions: https://docs.google.com/document/d/1gKzODHe48QCnthr_m6qHASPBdEsyLw9USwvXmFXYiQg/edit?usp=sharing ## General Intro - Course will be online until further notice - Mostly pre-recorded lectures (podcasts) + interactive Q&A (zoom) - Some interactive lectures (zoom), especially guest lectures - Please view podcasts before the lecture hour and post questions on Google doc - NB: Please register in Piazza -- all notifications will be posted there - All resources are on the course web site (schedule, podcasts, PDF slides, piazza) --- ## 1. Introduction - Who has experience extending an existing software system? - What issues did you encounter? - What is a (software) model? Give some examples? - What are these models useful for? - Do they describe existing software or software to be created? - What are the metamodels for these models? - How are reflection and metaprogramming useful for software analysis? - What software metrics do you know? What are they used for? How useful are they? --- ## 2. Smalltalk - step through downloading and running Gt - show the tools - do a kata: Implement ComplexNumbers --- ## 3. Understanding Classes and Metaclasses i) Classes and Metaclasses Inspect Class, Class class etc Show how x class class class = Metaclass for any object x If x is a class, then it’s Metaclass class ii) self == super (GtPlayground newWithSnippets: { 'SelfSuper new selfIsSuper'. 'SelfSuper new superIsSelf '}) openInPager What happens if we try to implement SelfSuper>>#== ? iii) why is super static? superman puzzle PharoLightTheme beCurrent. Metacello new baseline: 'SMAForGt'; repository: 'github://onierstrasz/sma-examples/src'; load. (GtPlayground newWithSnippets: { 'man := Man new. superman := Superman new.'. 'man self' . 'superman self' . 'man super' . 'superman super'}) openInPager --- ## 4. Reflection Check all Google Q&A questions See HDTestCoverage for example of run:with:in: Have a look at Behavior and Class Check out accessing methods and testing methods. Especially is* and has* methods. Also all* class* Interesting: methods allMethods subclasses allSubclasses isAbstract Question: which classes have abstract methods but are not themselves flagged as abstract? Build query incrementally. ((SystemNavigation default allMethods select: [:m | m isAbstract and: [ m methodClass isAbstract not ] ]) collect: #methodClass) asSet asOrderedCollection sort: [:a : b| a name < b name] --- ## 9. Static Analysis ## SMA Dead Code analysis "Load the project with the example models" PharoLightTheme beCurrent. Metacello new baseline: 'SMAForGt'; repository: 'github://onierstrasz/sma-examples/src'; load. Smalltalk saveAs: 'SMA.1'. model := MooseModelExamples argoUML. model := MooseModelExamples weka. DeadCodeSlideShow new openInSpace. "to clear the models" MooseModel resetRoot. ## TO DO Script Load the argoUML model. What constitutes dead code? Analogy to garbage collection: mark and sweep. Start with reachable methods Need to find "main" methods. Look at allModelMethods and see "name" attribute Find the two main methods. Need to find reachable methods. Recurse over invokedMethods While there are methods to check, find invokedMethods If they are new (!) add them to methods to check and to reachableMethods Now we need the reachable classes. All classes of the methods : get parentType Need also all classes of attributes accessed by reachableMethods: accesses Make sure they are actually attributes and not parameters: collect variable and select isAttribute Then get parentType Need all superclasses: withSuperclassHierarchy What about subclasses? (leave them out for now) Also need all classes referenced from reachable methods: providerTypes Finally we need to recursively get all the classes referenced from reachableClasses: allproviderTypes Find all provider types for reachable classes, and see which are new (not already in reachableClasses). While we have new ones, add them and recurse The unreachable classes are all model classes minus the reachable classes. This will give us a bunch of inner classes, so we should ignore those! What happens if we consider subclasses to be reachable? Next -- look at weka ---