A Coder’s Diary 2 (All About Deviations)

Alexander Weinmann
Good Audience
Published in
4 min readMar 4, 2019

--

Monday, the 4’th of March, 2019

Dear Diary

Last time I started telling you about the wizard that I dreamed of. Here is more:

Imagine you have a story to tell, and the story is somehow split into sections. A simple wizard would just allow browsing through the story forward and backward, section by section.

But this is not how my mind works! There is always something that distracts my attention, that might drive me off the main road. Let me call it a deviation.

It is not a good solution to just call any deviation “off topic” and ignore it in order to stay focused. Deviations may be interesting or amusing. They might add something new or important to my story, enrich it in an unforeseen way. So it would be very useful, if I had a software reader that could support deviations.

This is what I dreamed about last night: A wizard allowing deviations.

You would still be able to stay on the main track in my story, navigating forward and backward. But if you clicked on a special link in my story, that would lead you onto a secondary road, and you could follow that for a while. The secondary road would just correspond to a secondary thought or idea that pops up in my mind, while I am working on my story.

So this secondary road would not lead me away from the main road forever — it would do that only for a while. In the end it would always lead me back to the junction, and I could follow my initial idea once again.

This is one more reason, why reading on an electronic device will sooner or later become superior to reading a paper book. A book will always remain sequential. The only thing you can do to navigate is turning pages. But my mind works in a different way — the mind of most people works in a different way!

There should be a way to cope with different topics within the same writing, and still everything should be held together and remain cohesive.

Another example taken from the “old” world is footnotes. In an electronic text, you might want to read a footnote and easily find your way back to the main text. There are already solutions. For example in the kindle reader, you can follow a bookmark, read it and then go back. But I don’t like so much that way the problem is solved. You can get lost, if you do not pay attention. You are losing orientation — at least you are losing a good feeling of where you are.

A footnote is just a limited version of what can be done with deviations. Deviations could profit of all the advantages that a software reader has with respect to a printed book. But they would still respect the main topic and its limitation. Following deviations would not be as arbitrary as following some link in the internet. The latter can always lead you to places that have absolutely nothing to do with where you came from.

So, how could I implement such a deviation in software?

I changed some of the details since my last diary entry. Still Content is the model of a textual content displayed in a browser. The content can be shown using jquery, but there needs to be a callback to handle all the actions necessary after the content has been loaded. So we end up with something like this (I hope you did not forget that this code written in Scala will lead to JavaScript, that can be deployed on my wordpress site):

trait Content {
def show(callback:(JQuery)=>Unit)
(implicit $ : JQueryWrapper): JQuery
}

And the state of the wizard at a given point in time:

case class WizardStatus(
previous:Option[Content]=None,
current:Option[Content]=None,
next:Option[Content]=None)

A wizard not knowing about deviations could be simply implement like this:

class WizardImpl(wizardSeq: ContentSeq){[...]}

But a “deviation aware” wizard would need more knowledge:

class DeviationWizard(mainWizard: Wizard,
deviation: Seq[Content],
splitIndex: Int){[...]}

What I call splitIndex here is the index of the junction, where my mind suddenly flipped and I started to think about something different, but related to the original idea. At the junction, the reader must choose if he follows the deviation or the main road. If he presses the back button at a later time, he is lead back to the junction, and then back along the main road. On the main road, if he presses the forward button at any time, he will always stay on the main road.

Dear diary, I might tell you something about the implementation in a later entry. I am still working on the details … be patient!

--

--