Down the rabbit hole
Again, the devslopes course. More than a year after I started the course I managed to start the final task of week 4. My background is, that I am currently a bit oerwhelmed by all the stuff going on that I need to take care for. I am constantly bordering on the edge of a burnout.
I work fulltime as a freelancer and the project is quite challenging, since it requires some in depth technical skills that you cannot learn by anything but inventing.
Then there is our house. We decided to remodel it at the end of 2020. The top floor with the roof had to be completely removed and replaced by a new roof, allowing the top floor to be fully usable as, well, a place to life in. With that came the idea to add solar panels, which required a certain amount of electrical rewiring of the house. Then during a nasty storm our chimney broke and we decided due to the climate changes that we no longer wanted to do the heating by burning fossil fuels. Therefore we installed a heatpump for the water and infrared heaters for the heating.
And I decided to get my oldest son into my company so he could start learning how to code. He finished his midlevel school (in germany its called Realschule). Since he had a certain affinity for everything computer this seemed like a good idea. But there is still a huge difference between an affinitiy for computers and the willingness to learn how to code. We’ll see how this turns out.
And between all of this and some health issues and a pandemic floating around I somehow lost the energy to pursue the course full steam.
In july I decided to start the final task of weak four which is to program a calculator app for iOS. And I really fancied doing so. At heart I still am a hardcore programmer, despite the fact that my programming profession started some 35 years ago when I was around 15. I really love coding. So doing the intrinsics of a calculator seemed as a nice idea and a welcome change.
The task at hand was pretty straight forward. Take the usual calculator app. Make buttons for the 10 digits, some basic operators, and a button to execute a calculation. And then print the result.
And while thinking about this little app ideas started to float into my mind how to enhance this calculator. As usual I started to dig my own rabbit hole. Actually I don’t know in which order these additional ideas appeared, but appearing they did.
It might be nice to be able to write full terms before letting the calculator calculate them. So not only “1+2” but “1+2–3*4”.
This requires a calculator engine that is capable of taking an input string which contains the term and returning the result of the term. Seems pretty simple. Look, I am not really that deep in the rabbit hole yet.
In addition it might be nice to be able to add subterms via paranthesis. Like “1+(2–3) * 4”. Doesn’t really add that much complexity to the app. Just a little bit. Maybe some recursive magic. And heck, I can still see the entrance of the rabbit hole, where I came in. But was it always so small?
And then, it might be nice to have nested paranthesis. Like “1 + 2 — (3*(4–5))”. Since at this point the calculation engine must already be pretty advanced this surely won’t be much of a problem.
And an ability to calculate just the next step of a calculation. So only the current innermost term is executed and not the full term. Meaning that “1 + 2 — (3*(4–5))” results in “1 + 2 — (3*-1)”
Hmm, this hole feels cozy. Was there really ever an entrance? Anyway, going back is never an option, at least not for someone as thick headed as me. Kicking in walls with my head was always my specialty. Therefore the more important question is: Will there be ever an exit, or will this rabbit hole consume me.
Doing the calculator engine for all this proved rather challenging:
- Operator prevalence needs to be considered
- is a ‘-’ a minus or does it start a negative number?
- How do you traverse back and forth through a string in swift, with all these somewhat strange range expressions?
A great help for a thing like this are unit tests. Testing all the possible combinations types of calculations that can occur. And then, when you think you have tested them all and have thought of every strange calculation you play around with the calculator only to find out that you have forgotten that one really relevant type of calculation. And to fix it you have to rewrite the hole engine.
This is actually part of the love-hate relationship between me and coding. And this love-hate-relationship is maybe the one thing I really love about coding. Standing before a problem that seems to be unsolvable, and then solving it. Overcoming again and again the urge to _not_ solve a problem. To leave it for the people after me. For once taking the big wide road, which everyone travels on. And then deciding that this wide road is not for me. To realize that I am not the person that takes this wide road, the easy way. No. To take the road where it is stony, uneven, and uncrowded. On my own. Not using some fancy library, but inventing new ideas on the fly. It is challenging, time consuming, sometimes painful and exhausting and requires a certain amount of energy. But then the rabbit hole ends. The barely noticeable small road turns into a clearing, surrounded by a nice forest, and a really nice lake in the middle. Warm. Relaxing. Finished. The app works. Does, what I want.
And arriving at these places filled with beauty, calmness and peace is truly the one reward I strive for. And there is no place like code where I can find these places.
In the end I could have continued to enhance and perfect this app more and more. Give it a nice shell, wrap up the design. But in this stage, at the end of week 4, it is not meant to be appstore-ready.
Therefore I decided to submit the app in a state where it works and performs all the expected calculations with nested subterms, stepping functionality, a calculation history.
But it could be polished even more. Doubletapping the history could bring the element back into the calculation line. Editing a calculation not only at the end but in the midst would be nice. And some more tweakings to the ui. Taking care of line overflows.
I have exited the rabbit hole. And it was a very nice experience. But what did I learn?
- I am still very bad at giving estimates. This will probably never really work.
- Sticking to an initial plan might be a worthy idea. While it is good to enhance a program on the fly, I should learn to stick more closely at what the real task is. A calculator where you can enter some digits, followed by an operator, followed by some other digits, followed by an ‘=’ to receive the result is something different than a calculator which can handle nested subterms, provides a history and stuff.
- When I invest myself into code it can really become good. Even when I overreach and try to do way more than expected.
- Finding an end is useful and sometimes the hardest part.
- What is important to me is okay to be important to me. So I will stick more to these things important to me.