<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alan Potter</title>
    <description>The latest articles on DEV Community by Alan Potter (@apotterri).</description>
    <link>https://dev.to/apotterri</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F556106%2Fd1b60671-0b35-46cb-8f87-aa36e7124216.jpeg</url>
      <title>DEV Community: Alan Potter</title>
      <link>https://dev.to/apotterri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/apotterri"/>
    <language>en</language>
    <item>
      <title>Using a Graph Database for Better Understanding of Unfamiliar Code</title>
      <dc:creator>Alan Potter</dc:creator>
      <pubDate>Wed, 13 Jan 2021 15:21:10 +0000</pubDate>
      <link>https://dev.to/apotterri/using-a-graph-database-for-better-appmaps-593</link>
      <guid>https://dev.to/apotterri/using-a-graph-database-for-better-appmaps-593</guid>
      <description>&lt;p&gt;Like &lt;a href="https://dev.to/dustinbyrne/uncovering-critical-data-access-using-appmaps-3fn3"&gt;Dustin&lt;/a&gt;, I worked on a project for the AppLand Hackathon. I was particularly interested in understanding how to make the visualizations generated from recordings in &lt;a href="https://github.com/applandinc/appmap"&gt;AppMaps&lt;/a&gt; easier to understand. &lt;/p&gt;

&lt;p&gt;The basic structure of code can be somewhat hidden by its use of trivial helper classes. Theses are classes with simple functions (getters, setters, predicates, etc) that don't use other classes. I wanted to see if there was a way to use a graph database to help identify such classes in an unfamiliar code base.&lt;/p&gt;

&lt;p&gt;I put together a simple JavaScript &lt;a href="https://gist.github.com/apotterri/5d4014f47e3dbd4c000ec4920835280a#file-load-js"&gt;program&lt;/a&gt; that uses the &lt;a href="https://github.com/applandinc/models-js/tree/master/src/callTree"&gt;CallTree&lt;/a&gt; class from the &lt;a href="https://www.npmjs.com/package/@applandinc/appmap-models"&gt;AppMap model code&lt;/a&gt; to a graph in a &lt;a href="https://neo4j.com/"&gt;Neo4j&lt;/a&gt; database. For each function in the call tree, it creates a node for the class that contains the function. It creates an edge from that class to the classes containing each of the functions called.&lt;/p&gt;

&lt;p&gt;Once that's in place, a &lt;a href="https://neo4j.com/docs/cypher-manual/current/"&gt;cypher&lt;/a&gt; query shows all the "leaf" classes, i.e. those that don't call methods in other classes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MATCH(n)
WHERE NOT (n)-[:CALLS]-&amp;gt;()
RETURN n 
ORDER BY n.defined_class 
LIMIT 10;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This query returns 10 classes that don't have a &lt;code&gt;CALLS&lt;/code&gt; relationship with any other classes. &lt;/p&gt;

&lt;p&gt;These are the simple classes I was looking for, and excluding them from AppMaps definitely improved the visualizations.&lt;/p&gt;

&lt;p&gt;You can read more about my Hackathon project &lt;a href="https://appland.org/code-gallery/querying-appmap-data/"&gt;here&lt;/a&gt;, and check out the &lt;a href="https://gist.github.com/apotterri/5d4014f47e3dbd4c000ec4920835280a"&gt;code&lt;/a&gt;, too.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
