Reading just the source code to understand a class is inefficient. The sheer amount of information, implementation details, and non-linear nature of source code require an alternative representation to grasp effectively. The interactive edge bundling graph in Eureka is the most successful alternative representation of source code we've experimented with in the past few years.
If you look at the source code of an object-oriented class, it is fundamentally a graph representing state and behavior. And ultimately, we end up connecting them in such a way it solves a specific problem for us. Therefore, to gain a quick understanding, we need to focus on the fields, methods, and how they are related to one another. Eureka's goal is to surface and highlight this information while limiting the amount of information developers need in order to comprehend a class. It is essential to remember that Eureka is a complementary solution and not a replacement for reading source code. It works best when you combine the two.
Inspecting a class
Running Eureka on any class creates an interactive edge bundling graph with two groups—fields and methods. These groups are spatially separated, and the tool draws relationships between them. The direction of the dependency relationship is color-coded, using red for outgoing dependencies and blue for incoming dependencies.
Hovering over a class member (field or method) on the graph will highlight relationships between members and can help you,
- Gain insights about the class
- Ask interesting questions about the relationships between class members
These are two primary ways to quickly and incrementally build a mental model about the problem and the solution space the class addresses.
The diagram above has two groups and is annotated in blue to help you see the grouping.
Experimental Android Support
With Eureka, we're constantly experimenting and figuring out ways to help developers become productive when working with classes. As a next step, one of the experimentations revealed it helps to group fields and methods related to the Android framework, thereby bringing in more structure when studying a class.
With experimental support for the Android framework, Eureka can now groups class members into 4 categories:
- Fields
- Methods
- Android Fields
- Android Methods
This grouping can now help you see how framework methods and APIs relate to your domain.
The framework grouping unlocks the following use cases:
- Quickly understand how lifecycle methods interact with your business logic.
- What framework APIs are your domain logic dependent upon?
- What framework dependencies should you break to get a function under test?
Activity
and Fragment
classes are not the only ones supported by this feature. You can find
the list of all supported classes
here. Please let us know if you need support for additional classes by raising a GitHub issue.
How to try it?
If you don't have Eureka installed, install it via Homebrew using the following command.
brew install legacycodehq/tap/eureka
To try the new experimental Android support, use the following Eureka command.
eureka watch -x android PassphrasePromptActivity
You will see an Android icon in the top bar when running in the experimental Android mode. Try it out on one of your
Activity
or Fragment
classes, and let us know what you think! We're sure you'll have an eureka moment or more!