Pointer arithmetic and dynamic HTML generation FTW–at 2 AM
I just finished writing the following code, the time is 2 AM local time, and I am chasing a conceptual issue deep in the guts of Voron (RavenDB’s internal storage system).
By any measure of the word, this code should frighten anyone who reads it. For what I think can we can all safely assume are self evident reasons.
So why am I so very happy about this kind of code? Because the output of this code is this:
This is pretty trivial tree view for internal data structures inside of Voron.
But the point here isn’t that this code is probably going to be a no-go zone by tomorrow morning. This is code explicitly designed for that. In fact, the calling method for this is:
So this is a piece of code that we are trying very hard to ensure that will never be called unless we are actively requesting it in a debug session. In other words, this isn’t production code. It is scaffolding code. The code that you’ll call when you lost your way, and can no longer figure out what is going on using the standard tools.
This kind of visualization is cheap & dirty trick, but it means that instead of having to reason about this kind of thing, I can immediately see what is going on.
For that matter, if you look closely at the visualization, you might be able to see the bug in question. It is pretty obvious, once we are able to look at the entire data set in one go. The more complex the algorithm, the harder it is to conceptualize it. But in most cases, if we could but look at the data in a way that would make sense to us, we will be able to immediately see what we did wrong.
Comments
Debugger visualizers would be more helpful I think. You could even ship it as nuget package for optin
Daniel, Debugger visualizer require a couple of orders of magnitude more effort. And it only works in the debugger, and doesn't give you something that you can hang on to afterward
Hello, What is the point of writing if (bool == false)? Is it a sort of convention in Hibernating Rhinos?
EQR, That is a convention I use, yes. It make the negative much more obvious
I have to salute to you that you are able to make this mess somehow work ;O
Been a while since I looked at any code, trying to get back into it but could this sort of thing be done with an IOC container? Or did it go out of fashion?
Dirk, Generally, IoC are not the hot thing now.
"For that matter, if you look closely at the visualization, you might be able to see the bug in question. It is pretty obvious, once we are able to look at the entire data set in one go."
Nope still can't see it, what's the answer ;-)
Nice technique BTW, the HTML visualisation seems a lot easier to understand than the old text-based one that Voron had before.
Matt, This is a B+Tree, but there are wide differences in sides in the tree, so it means it is unbalanced.
ah makes sense, thanks
Comment preview