\\\nWhen I was a junior developer, I starved for knowledge about the ways software engineers work. In my stories, I want to depict closely how this happens during tangible actions. Even more, I want to describe the ways that give better results than the most evident ones.\n\n\\\nThe approaches I describe do not have to be challenging to implement. The ongoing debugging process is almost apparent. Nevertheless, it adds more structure and boosts your debugging power.\n\n\\\nAs in my previous stories, we go through a practical example to demonstrate the subject in action. I like the combination of succinct description and practical examples for two reasons:\n\n1. A lonely theoretical presentation of a scheme leaves you with a need to apply it to reality. Doing so gives too much room for interpretation. You might translate it in a way that doesn't provide the required results. Also, when trying to clean the core from the details, always exists a risk to remove something necessary and leave a reader puzzled in the end.\n2. The only practical description, by contrast, dumps too many details. You need to reverse-engineer it and then come up with an approach suitable for different cases yourself. What is my role in the story then?!🙂\n\n\\\nI plan to be even more helpful to the software engineering community in this story. I'll find a bug in one of the open-source GitHub repositories and try to fix it. I never did any significant open-source software fix before except for the documentation update. I hope my first experience won't break anything important.\n\n\\\nI also didn't know how to find a repository where my help would be valuable. So I decided to navigate to the [Explore](https://github.com/explore) and then to [trending Clojure repositories](https://github.com/trending/clojure?since=daily). I like Clojure, but it is not the language I write on my job. From time to time, I try to find additional practice out of it. I wander through a few repositories and then decide to find something in the [Metabase](https://github.com/metabase/metabase) project. I like how they document things, and it's easy to discover bugs here.\n\n## What Are These Sharpest Instruments?\n\nWe've already gone a little too far into the action. Let's step back to discuss the instruments I want to propose. They are:\n\n* Paper,\n* Pen,\n* Your brain.\n\n\\\nHmm, why are these instruments the sharpest ones? This question is easy to answer. I guess you once experienced paper cuts or even pen pricks. Regarding the brain, there is a "sharp-minded" word.\n\n\\\nThe paragraph of humor came to an end. Let's discuss more intriguing questions. Why do we want physical paper and pen? Aren't they inefficient?\n\n## Why Do We Want the Physical Instruments?\n\nSoftware engineers love automation and optimization. The shiny golden dream is to relax in the pool with a glass of refreshing drink. At the same time, your computer does all the necessary things to earn you money for a relaxed life. I'm happy for you if you are already there. Usually, we are somewhere on the road to this place.\n\n\\\nSome engineers also love purity: excellent testability and predictability, no side effects.\n\n\\\nLet's see where these beautiful ideas work against us.\n\n\\\n**First, let's discuss optimization**. Who doesn't like when something perfectly fits? Imagine you have jeans, and they are optimized for your size. No single superfluous pinch of fabric is present — no space between you and your jeans; it’s ***a beautiful mathematical balance***. The problems start when you try to put them on. If there is no extra space and fabric, you cannot move your foot through the place prepared for the upper part of your ankle. It is usually thinner.\n\n\\\nSeveral years ago, I read another example about optimization flaws in the book called "[Hard and soft mathematical models](https://www.goodreads.com/book/show/40118180)" (Russian). Vladimir Arnold, the famous Russian mathematician, is the author of it. The case about fishery demonstrated the situation where there was just enough fish left to support the population but no more. In this case, a minor casualty can bring the fish population to extinction. The optimum is too fragile.\n\n\\\n**Second, let's discuss automation**. You take something imperfect or even dull and let the computer do it. Sounds cool! But what if we do not need to do this at all? What if we can drop these activities and win? At the beginning of this year, I listened to [the "Lean Thinking" book](https://www.goodreads.com/book/show/289467.Lean_Thinking) by James Womack and Daniel Jones. It describes the lean methodology applied to manufacturing. The idea of lean is that you find imperfections on the path of value creation and eliminate them. Imagine that you wrote a program that sets these imperfections in the concrete. Sounds not that cool. What astounded me was removing complex manufacturing management software after cleaning much Muda (waste) from the process. You don't need complex solutions when you manage to mitigate complexity.\n\n\\\n**Third, and last, let's discuss side effects**. We don't like them in our functions. We want to give them extra emphasis to prevent mistakes. In contrast with refined abstractions, life is not pure. We do have side effects, and some of them are even positive ones.\n\n\\\nWriting by hand is not that fast as writing using a keyboard. I tried to write the "speed of writing" phrase on paper, which took me 8 seconds. I am not a native speaker and might be slow in it. The same exercise with the keyboard took me 3 seconds. When I write a sentence, I usually know at least a part of it that I want to put into words. When being slow and writing by hand, I can free my active usage of the left brain hemisphere and relax. This condition is not a pure relaxation with no action taken. It's the time of our right hemisphere performance.\n\n\\\nLet's see what [Andy Hunt](https://twitter.com/PragmaticAndy) writes about the competition between our hemispheres called CPUs in this paragraph:\n\n> Notice that both CPUs share the bus to the memory core; only one CPU can access the memory banks at a time. That means if CPU #1 is hogging the bus, CPU #2 can't get at memory to perform searches. Similarly, if CPU #2 is cranking away on a high-priority search, CPU #1 cannot get at memory either. They interfere with each other.\n\n\\\nThe quotations above and below are from [the "Pragmatic Thinking and Learning" book](https://www.goodreads.com/book/show/3063393-pragmatic-thinking-and-learning).\n\n\\\nDo you remember the new music you listen to when actively being involved in detailed programming activities? I don't, and we now can understand why.\n\n\\\nAnd why do we want to give the ruling to our right part of the brain? See the answer in the following quote:\n\n> You need both: R-mode is critical for intuition, problem-solving, and creativity. L-mode gives you the power to work through the details and make it happen. Each mode contributes to your mental engine, and for best performance, you need these two modes to work together.\n\n\\\nIt's great that you are concentrated and disciplined to implement your hypotheses. Don't forget to allow your brain to prepare them for you. Gather the details carefully researching, and let them synthesize while seemingly relaxed.\n\n\\\nWhat a great power we get from almost invisible natural obstacles! What an unwanted side of efficiency we've just seen.\n\n\\\n## The Structure of Problem-Solving Paper\n\nAfter such an extensive introduction, let's finally look at the structure of the problem-solving paper.\n\n```\nProblem You Are Trying to Solve\n\nFirst hypothesis\n First subhypothesis\n Notes\n Subhypothesis testing results\n Notes\n Second subhypothesis\n Subhypothesis testing results\nSecond hypothesis\n Hypothesis testing results\n ...\n```\n\n\\\nDo not treat this structure as a rigid one. Think of it as gentle guidance. What you need is to see the destination — it's in the header. Also, you need to observe the path you decided to take. You can return to it if you've accidentally left. Or you can explicitly state that you are on a new one.\n\n\\\nAs before, let's discuss why do we need it? Aren't we smart enough to know where we go?\n\n\\\nWe are smart for sure. What we also are is that we can become stuck. Do you remember waking up from your chair without results after several hours of debugging? Do you also remember that you couldn't state what you were doing? We are going to handle this. But first, let's look at some alarming evidence of human nature from [the "On Trails" book](https://www.goodreads.com/book/show/27276431-on-trails) by Robert Moor:\n\n> ...on average, people who are lost, without external navigational cues, will typically not travel farther than one hundred meters from their starting point, regardless of how long they walk.\n> A horrifying thought: On a cloudy day, in tall woods, with no other cues and no compass, a person will not travel more than the length of a football field in any one direction.\n\n\\\nIn the quotation above, the one who's lost has its eyes to analyze what's around. When debugging, much of sightseeing happens in our heads. And your eyes look in the opposite direction. So you are both lost and blind.\n\n\\\n## Some Praise for the Approach Before Applying It\n\nI think that the worst problem I solved with this method is worth mentioning here. I once faced the problem of non-working legacy front-end microservices in any browser except Google Chrome. My objective was to make it run in Firefox. The complexity of the situation was spiraling because of the following factors:\n\n* We had a hard deadline. It didn't give me any speed, just inflamed the overall stress.\n* Legacy front-end microservices were the result of the work of the already not existing team.\n* People from this team were 8 hours from our timezone. They also never thought that somebody would ever use their code. Its style could characterize by the "After me, the flood" expression.\n* Part of the code inside files was missing because of the inaccurate grep command work. Our fearless DevOps team leader solved this crazy problem by either reverse engineering or getting the necessary code. I don't know.🙂\n* The front-end microservices were not running locally: they required some unusual Lua setup. And our DevOps team leader already left at that time.\n* Thankfully, we had a pipeline deploying and running them on the Staging environment! It took "just" 30 minutes to run a single deployment.\n* Firefox debugging tool crashed when I tried to set a debugger.\n* It took 40 minutes for Chrome to pause on the debugger.\n\n\\\nI made it, in the end, using the problem-solving paper described above. I think it took me about 3 or 4 days of debugging, making hypotheses, and verifying them.\n\n\\\nThe problem was the insensibility of Gulp to duplicating transitive links to the moment.js library and its plugin: moment-timezone. The legacy application used the deprecated HTML modules functionality: there were around 20 imports in total. There also were two versions of both library and plugin. In Chrome, the correct version was in use, and in Firefox happened the version mismatch. Adding few extra build steps brought the application in Firefox to the working state.\n\n\\\n## Discovering the Metabase Bug\n\nAt the beginning of this article, I mentioned that I like Clojure. I was brave enough to find the project which uses this language for the back-end. However, I decided not to leave my comfort zone too far and chose the front-end problems. I decided to take the one which is not that important to become overtaken by someone else. On the other hand, it shouldn't be too old to become irrelevant. I've chosen [the "Saved Questions search input is super jumpy" Github issue](https://github.com/metabase/metabase/issues/14782).\n\nThe list of items becomes filtered on typing, and the filtering input is in the same scrolling block. For every character entered, the scroll moves to an unexpected place, thus disorienting a user.\n\nI am for the first time in this codebase, and everything is unknown to me. I would quickly find the place requiring the fix and then begin applying the method I describe. At least I thought that.\n\nAfter half an hour of wandering, I found myself stuck. The application is not that big, but where is the component I am trying to find? It looks like I need to take my paper and pen and start the guided investigation.\n\nAfter \\~6 hours of searching, I discovered what I needed. It turned out to be the `AccordionList` component requiring a fix.\n\n\n:::tip\nBy the way, a good bud description could save me hours here. Because of this, I am a great fan of [the Definition of Ready](https://www.agilealliance.org/glossary/definition-of-ready).\n\n:::\n\n\\\nI even thought of a better way to structure the notes, and I'll present it later. Here are the raw records I've taken during the investigation.\n\n ![First hypothesis](https://cdn.hackernoon.com/images/Mxatcr8t3EN0D24z6YR3DrWlIoX2-vjok29zx.jpeg)\n\n ![Second hypothesis](https://cdn.hackernoon.com/images/Mxatcr8t3EN0D24z6YR3DrWlIoX2-noow29ij.jpeg)\n\n ![Third and fourth hypotheses](https://cdn.hackernoon.com/images/Mxatcr8t3EN0D24z6YR3DrWlIoX2-mxp429nh.jpeg)\n\n ![Returning back to the first and the discovery!](https://cdn.hackernoon.com/images/Mxatcr8t3EN0D24z6YR3DrWlIoX2-s4pg29vx.jpeg)\n\nI've come through the following hypotheses during the discovery.\n\n\\\n***I need to find the input or the "Saved Search" list item to discover the place where the problem arises.***\n\nIt turned out that there exist both the dedicated component and several ad hoc search inputs implementations. None of the places containing the "Saved Questions" text were convincing enough, or not they were discoverable through the UI.\n\n\\\n***Did someone remove this list at some point in the application development?***\n\nI discovered no deletion of an item containing the "Saved Questions" text after creating the GitHub issue. Furthermore, someone has added a new component containing this line.\n\n\\\n***There is something about Stats in the bug description, but I can't see something similar. Maybe these words are about Metrics, and the component is there?***\n\nI've investigated the Metrics part of the application and didn't find anything close.\n\n\\\n***I have a feeling of seeing this list somewhere, but where? Maybe in the administrative part of the application?***\n\nNo, I don't see anything familiar here.\n\n\\\n***Maybe I should look once again at the search inputs in code?***\n\nHmm, I see some conditional logic for adding the search input to the `AccordionListCell` component. The "accordion" word makes me think that it's something collapsable, like the component I can see on the GIF in the issue description.\nAnd after few more thoughts... Got it!\n\n\\\nThe `AccordionList` component is the place I was searching. When I discovered it, I'm perplexed that it took so long — you meet this component one attracting click away from the main page.\n\n\\\nIf you sometimes feel puzzled after solving a complicated problem, please look at this quote from ["The Psychology of Computer Programming" book](https://www.goodreads.com/book/show/1660754.The_Psychology_of_Computer_Programming) by Gerald Weinberg:\n\n> Similarly, it will always be difficult to appreciate a really good job of problem solving. Once the problem solution has been shown, it is easy to forget the puzzlement that existed before it was solved. For one thing, one of the most common reasons for problem difficulty is overlooking some factor. Once we have discovered or been told that this factor is significant, working out the solution is trivial. If we present the problem to someone else, we will usually present him with that factor, which immediately solves nine-tenths of the problem for him. He cannot imagine why we had such trouble, and soon we begin to wonder ourselves.\n\n\\\nDuring the investigation, I found that sometimes I want to jump back to the previous hypothesis and try something I didn't notice. The format of the writing I'd chosen forced me to rewrite the ideas I had before. We can do better — we can have a dedicated paper for every single thing we plan to investigate. Here's how this could look:\n\n ![This way, we could jump back and forth easier](https://cdn.hackernoon.com/images/Mxatcr8t3EN0D24z6YR3DrWlIoX2-q9q029bm.jpeg)\n\nAfter finally discovering where we need to apply the fix, let's go and do this!\n\n## Fixing the Metabase Bug. Or Not?\n\nMy first story on Hackernoon is "[The Meticulous Approach to Coding](https://hackernoon.com/the-meticulous-approach-to-coding-8g9353n)". It's helpful, and I will apply it here and reflect the flow in a separate article so this one doesn't become overcomplicated with excess details.\n\n\\\nThe first thing I need to do is to reproduce the problem. I've found the component where it occurs and now need to prepare the case displaying it. The way of setting a necessary state is rather challenging as well. And when I managed to do this in the end, the bug didn't reproduce.\n\n\\\nThere is a scheduling algorithm called round-robin. It executes processes in a cycle without priority. My brain and, possibly, yours has an association-based-robin which makes me jump forwards and backward when I see something inspiring me to switch the theme.\n\n\\\nWhen I originated my first research by looking for all the `"Saved Questions"` string, I looked through the PRs to find out where the issue could be. I noticed that one with the desired text arrived in [PR #16808](https://github.com/metabase/metabase/pull/16808).\n\n\\\nThe burden of trying to set the proper state of the `AccordionList` component and the fightback made me think that the bug might be no longer present. The jumping list might have gained the replacement when [the "Add saved questions picker" PR](https://github.com/metabase/metabase/pull/16808) made its way to the `master` branch.\n\n\\\nOn Saturday, I [asked](https://github.com/metabase/metabase/issues/14782#issuecomment-881941480) if my suspicion is valid and received [the confirmation](https://github.com/metabase/metabase/issues/14782#issuecomment-882069011) on Sunday. The issue went to the closed ones and didn't require any fixes.\n\n\\\n## Are We Satisfied With Where We Are?\n\nAt this point, you and I might be unsatisfied that no PR made its way to the Metabase code. Thus we can feel unsuccessful here. If we try to see a broader perspective, our goal was to apply the method of bugs discovery, and we succeed in doing so. One can also add that the best code is no code at all.🙂\n\n\\\nThe essential thought to add here is that I used many debugging tools along the way: my IDE and its code discovery tools, React Developer Tools browser plugin, etc. I couldn't replace them with paper and pen effectively. The story's core idea is that you need a guiding light to help you unstuck in the very sticky process of debugging.\n\n\\\nThank you for reading! Please reach out [on Twitter](https://twitter.com/turbobureaucrat?ref=hackernoon.com) if you want to discuss the ideas I describe.