Skip to Content
Personal Insights

I Have A Dream: Code Visualization

There are some things I find absolutely addicting. Besides of code beauty and clean code and education, which I find interesting, I am also a great fan of gamification and visualization.

I wanted to find out how gamification might work in the ABAP programming environment and therefor started the GLADIUS project where you could kind of code-fight ABAP problems.

Visualization in the SAPGUI is not very easy because the graphical conditions are quite limited. There are UI5 components which can be used better for visualizing data and figures, like this UI5 demo. Some visualizations are also possible in SAPGUI but often very complicated.

There is a very interesting aspect of visualization and some special data: source code. Some people also tried to visualize source code dependencies or specials aspects of code like lines of codes, number of methods or attributes of a class and many more.

I will try to give an overview on existing projects and ideas that I have… Sorry for this long article. I figured out to split into mutliple posts but decided that one larger article might be better. Have fun reading!

Metrics

Before you can visualize source code, you need to have some metrics that you can apply on the displayed objects. Because there are limitations on the amount of different metrics and displayable data for one object, you will have to define some views depending on your intent.

One of the most metrics used might be LOC – Lines of Code. This metric is very simple and yet useful in similar cases. Other metrics might be

  • Number of comments per lines of code
  • Number of methods of a class
  • Number of attributes of a class
  • Number of dependencies (where-used list)
  • Code coverage
  • Number of changes
  • age
  • Number of contributors

These metrics can be more or less easily be found out. There are other metrics that are harder to determine and sometimes are not directly stored with the code, like:

  • performance
  • security issues
  • number of issues
  • number of short dumps caused by this function
  • number of transactions

You might also consider to add beauty metrics:

  • pretty printer executed?
  • indented code
  • number of spare lines

I know that clean code and beauty depends on personal views but some might be quite countable if you run abapOpenChecks by Lars Hvam on it…

There is a good overview of code metrics by ndepend.

Using Metrics for Visualization

If you want to visualize code you have limited options because you can only use a few of the existing metrics to build an object. If you use three metrics for the width and length, the height and the color then you are done. Other metrics can only be displayed by tags or additional tags but not really visualized. Of course you can have something like a dashboard to display all the metrics but that is not what I understand by visualization.

At the end of this post I will try to tell about some ideas of how to display more metrics at once.

Code Visualization Projects

Here are the projects and examples that I found on my search for code visualization. There are many projects that seem to be quite active although the demo sites are down. Some projects are some years old and do not seem to be maintained any more.

Moose

The first time I got in contact with code visualizations was with Moose and the contributions of Rainer Winkler to it. Moose provides a some very nice pictures of code like the one on the main page of Moosetechnology.org:

Visualized%20code%20with%20Moose

Visualized code with Moose

Moose can be used to view the source code parts, get an overview on the number of objects and its dependencies. The more lines of code an object has the bigger it is. Private methods are red and protected are blue (or vice versa). Black dots are attributes. Or something like that. Sorry, I don’t remember exactly. Dependencies are shown by lines.

Rainer Winkler wrote some blog posts about it and uses it for his daily work to understand and document legacy code.

Code City

Another great but maybe discontinued project is Code City by Richard Wettel. Code City visualizes source code in form of a city. Each class is a block and each method a building. The more lines a method has the higher the building is.

A%20Code%20City

A Code City

Code City also uses Moose as platform.

Promising: there is a Codecity Eclipse-Plugin in the Eclipse marketplace. I assume that it will not work with ABAP…

Codecity%20Eclipse%20plugin

Codecity Eclipse plugin

Further Links:

Quantified Code

The Code is Beautiful project of Quantified Code provides some very promising screenshots:

Code%20Is%20Beautiful

Code Is Beautiful

Some source code is on github but the demos are not reachable.

5 Tips to help you visualize Code

On this web page some code visualization tools are named and provides some further links.

Code Radar

Code Radar is a project to visualize code similar to Code City and also provides a functionality to compare two different versions of a code base which you can explore in the demo.

Code%20Radar

Code Radar

Softvis3d by sonarcube

Also very interesting is the project Softvis3d. Also looks very promising but same here: unluckily the some demos are not running althouhg the github project seems to be quite active. Try out this demo.

Softvis3d

Softvis3d

ndepend

The company ndepend offers a complete suite for code metrics, code visualization and more.

ndepend%20code%20visualization%20dashboard

ndepend code visualization dashboard

The Future

The above projects are great and can be really helpful to understand and document code. But after my son got an Oculus Quest 2 VR headset on Christmas day, I have the dream to explore code in virtual reality. The Headset and the experience within this virtual reality is so amazing that I can think of many things and options to do there. One thing is to walk through classes and into the code. And at least I am not the only one who was thinking of it…

ISUE Lab

The ICE or ISUE Lab in Orlando, Florida, already did some researches on this topic.

They built a world where code is displayed as a 3D world that can be explored by walking from class to class.

Code%20Park%3A%20class%20building

Code Park: class building

Inside each class you can see the code of it:

Code%20Park%3A%20inside%20a%20class

Code Park: inside a class

Again there is very little information about this project. The website shows that there are a lot of things going on, but nothing about the Code Park project. There is a video where I took the screenshots from.

Code 3D-Fylthrough

There is one abstract I found by the Aalen University where the idea of 3D-code visualization and virtual interaction has been described very detailed. The screenshots I see here come quite close to the main idea that I had and that I will describe in the next chapter. The parts of the code are displayed as real buildings with structure and windows.

3D%20world%20of%20Code

3D world of Code

3D%20world%20buildings

3D world buildings

VR Code City

I wrote a lot about existing projects, metrics and I hope you got an idea of what could be.

Now I would like to give you some idea of how code visualization, virtual reality and gamification might come together…

Up to now we learned, that buildings are a good idea to visualize code. The last chapter comes quite near to my idea of how a I imagine a real cool 3D source code world. The buildings are not only blocks but buildings that look like buildings with windows and some architecture. At least they have only four dimensions:

  • width
  • length
  • height
  • colour

If you walk through this city then there could be code of arms or emblems of all contributors of this class. The person that last changed the object could be highlighted by a fire ring or purple glowing mist.

building types and attributes

Objects that someone is working on can have a scaffold around it.

Building%20someone%20is%20working%20on

Building someone is working on

Classes that haven’t been changed for years and do not have clean code might look like this:

old%20building%20with%20unclean%20code

old building with unclean code

If there are a lot of changes and abapOpenChecks has no “errors” then the building could look like this:

beautiful%20code%20object

beautiful code object

The programs behind the most or common used transaction could be placed in the middle of the city or directly at the harbour so it can be accessed easily:

often%20used%20objects

often used objects

Special Metrics

Buildings can have attributes that clearly show some metrics:

  • A test coverage of 100% is sourrounded by green mist while objects w/o unit test are on fire.
  • Open issues for an object can be visualized by a shiny red laser beam pointing to the sky.
  • The more often an object has been changed the wider and better the way to it. If the object hasn’t been changed for years then you might need a machete to get into the house.

System visualization

If you can visualize separate programs, transactions and classes, then it might also be useful to display other objects like dictionary tables or maintenance views. Tables could be displayed as tanks or storage houses. The more data in it the bigger the storage.

storage

storages (big and small)

Periodic jobs could be buses, trains or horse carts driving through the streets. Also processes could be visualized by moving objects. Although I have no idea of how to retrieve the data for it…Modules might be districts of the city.

Pictures taken from game Anno 1404 with help of http://annowelt.eu/

VR code fights

As mentioned in the beginning, the GLADIUS project wants to make the programmer fight for better coding. What, if you could fight the Code Inspector monster by changing as many CI findings in a given amount of time. You could challenge your colleagues at the end of the day to find the worst problem or the most important issue. In half an hour you will have to fight as many issues or findings as possible. At the end of the day you made a building better, more beautiful then it was before.

The code inspector findings of a class could be a monster with as many arms as there were findings. And if I talk about monsters, there is one ABAP programmer who is specialized in monster who might have fun to build them in 3D: Paul Hardy your turn… ๐Ÿ˜‰

code%20insepctor%20monster

code insepctor monsters

Conclusion

At first glance all of this might be too much effort for having fun at work. But I am convinced, that some good visualizations, metrics and game rules can provide much better and stable code. This 3D Fylthrought might be a big overload but, hey, this is a dream. ๐Ÿ˜‰ And modelling and interaction is not that complicated using the unreal engine or unity. The art will be to build houses dynamically and nevertheless beautiful. Plus showing relevant information and visualize changes when code was improved. VR and coding should also be possible as there are at least three different virtual desktop apps which make it possible to view the PC desktops in a virtual environment.

Of course no one would spend so much effort to design and build such a fantasy landscape of an ERP code base… Or maybe some day?

Damir Majer had this dream already some years ago. Let’s see if this dream will come true someday…

14 Comments
You must be Logged on to comment or reply to a post.
  • /
  • Very nice ideas! I’ve been working on a dependency map for ABAP (perhaps one day to be open sourced). Soย I have had a little insight on the complex interdependencies of SAP objects.

    But classes, methods and tables are really just the tip of the iceberg, there are so many other object types in the ABAP universe, it gets really messy – and fun – the deeper you dig.

    • Thanks Mike Pokraka for your comment! Yes, source code is only a part of a lot of other objects, but in my opinion the objects that are changed most. A database table is at it is, there is no need of optimization or beautyfying. It’s good to know that it’s there but no need to have a gamified view.

      • Ah but depending on point of view they are very relevant. If two programs share a data element then they share a dependency. I often find connections via tables and structures.

        Or consider the question of where a Z-Structures is used? In a SAP Standard transaction perhaps? Easy to spot if your visualization shows a dependency chain Transaction > BAdI > Implementation > Class > Method > Structure.

        Or consider something as benign as a method calling a function module. If the FM is self contained then good, but if it uses global data of the function group then there is a dependency to the function group and all other FMs in it. And then you get the mess that internally it has a dual nature of being both Function Group/Module objects, but they also consist of a bunch of includes.

        All fun and games ๐Ÿ™‚

        • Depending on the point of view is the relevant phrase… ๐Ÿ˜‰

          I was more source code triggered. But yes, it would be cool to directly see the dependencies from within the “building”. Maybe by entering the utility room or looking into the garden? ๐Ÿ™‚

          • There are many metaphors to choose from.ย To debug a program we have to follow a little robot as he visits all the houses (classes) and goes into each room (method), carrying bits of data around.

  • In my opinion, code visualization is absolutely necessary in the future. Probably more source code is created every day than there are developers maintaining it. At least if the source code has been in use for years. Everything that helps with maintenance will be necessary!

    • Hey Michael Keller, Code Visualization is only one part for maintenance. If you want to really work with it, then there is a lot more to do. Rainer Winkler can tell about it… There must be an out-of-the-box solution for the developer. If it is hard and complicated to setup, then it will not be used. For example with Moose, the following steps are needed (as far as I remember):

      • install FAMIX export report in SAP system
      • Export selected packages to file
      • install Pharo Smalltalk environment with moose
      • Get used to a completely new GUI/ environment
      • Import file in moose
      • Define views for selected objects

      It would be far better if there was an eclipse-plugin…

      • I agree with you. The mere existence of a possible solution doesn’t mean that it is easily accessible. But that is precisely what makes up part of the value in everyday work!

  • I think FORM routines and old DYNPRO programs should come out as medieval buildings. They can be beautiful, but most are not. I shudder to think what SAPMV45A would come out looking like. Gormenghast falling to bits and on fire I suppose.

    OO Classes should come out as science fiction thingies like starships.

    Monsters of course don’t care either way. They can crop up in the old fashioned buildings and in an ultra-modern starships. In fact the analogy is good because a monster can do a lot more damage in a spaceship than in a thatched wooden hut i.e. poorly designed OO code can be a lot worse than poorly designed procedural code.

    Looking at the “Moose” picture which yields a sort of circular image as a result it seems that a really bad program would come out looking like the Coronavirus.

     

    • Looks interesting, Klaus Haeuptle! Thanks for this input.

      One part is to gather the data, however this data might look like: objects, source code, dependencies, beauty or as you mentioned Hotspots.

      The second part is the visualization itself. as described, you will need to have different views to visualize the data. A hotspot might be an additional attribute (color, badge, height, …) of a building.Or maybe a filter. The hotter the spot the more the building will be on fire or the more money will fly out of the windows when walking through the city with the “technical dept” glasses on.