paint-brush
Some Ways to Apply Some Programming Wisdom in Real Lives - Exceptionsby@doublex
237 reads

Some Ways to Apply Some Programming Wisdom in Real Lives - Exceptions

by DoubleXFebruary 10th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Exceptions in software are a lot like negative emotions in human, so negative emotions should be addressed responsibly, just like exceptions being supposed to be handled properly.
featured image - Some Ways to Apply Some Programming Wisdom in Real Lives - Exceptions
DoubleX HackerNoon profile picture

Disclaimer: While exceptions and negative emotions are essentially similar, they're still not 100% the same, so there will be minor discrepancies here and there when this article tries to apply the wisdom of handling exceptions to handling negative emotions, but I still hope that this article can make its points across to as many of you as I can :)


As programmers, we probably, at least, have basic knowledge of what exceptions do in general, so it's unlikely that I'll have to explain much about that here. However, have we thought about applying some wisdom from exceptions in real life? Since I've had time to consider that, I'm going to share what I think about them in this article. However, the main gist is- Negative human emotions are just like programming exceptions and as such, they should be handled carefully.


The following examples show the similarities between negative emotions and exceptions.


Letting Exceptions Crash The Software - Letting Negative Emotions Take Over Control

Let's use an unrealistically silly example about exceptions first.


Let's say that a program has to send some GET requests for data from some remote servers, and it's totally normal for the requests to fail, possibly because of unstable network connections, overloaded servers, or some other similar reasons, so it's just the norm to throw exceptions in such cases. However, an unbelievably sloppy programmer may just let the exceptions abruptly crash the whole program badly without even telling the users what's going on, when he/she could've just told them why those requests failed and asked whether they'd like to retry or abort those requests. Needless to say, if a so-called experienced professional frequently handles exceptions in such immature ways without even thinking about them, he/she probably won't last long in the software engineering industry, because he/she'd likely just create disaster after disaster otherwise.


Of course, there are cases where there really isn’t anything for the software engineer to do. For instance, when some methods throw some nasty exceptions, like StackOverflowException in C#, even though such exceptions shouldn't be that easy to leak out to production in the first place.


But the point remains, letting an exception crash the entire system should at least be a careful and conscious decision(and preferably as the last resort only), rather than out of laziness or misconceptions.


Now let's go on to another childish example, but this time about negative emotions.


Let's say a rookie investor just watched an online video about a seemingly legitimate(while actually unqualified) stock market expert "explaining"(when it's actually nothing but nonsense) how certain stocks will skyrocket to record highs after several days and that rookie investor trusted this kind of insanity by investing more than 80% of his/her total wealth into that stock.


Unfortunately, after several days, those stocks dropped to such lows that the underlying companies may as well be considered bankrupt. So, that rookie investor feels extremely angry and frustrated about his/her tragic loss and leaves many insulting and vulgar comments on that video without even thinking about how that fraud really caused him/her to lose so much money in such a short time.


What's worse, even that isn't enough for that rookie investor to vent all his/her anger, so he/she feels exceptionally furious whenever he/she perceives anything he/she doesn't like in his/her family and disproportionally blames his/her sons and daughters for even trivial mistakes that he/she wouldn't normally even notice nor care.


Needless to say, if he/she continues to behave this way without thinking about his/her part of the responsibility for this mess(just automatically listening to any apparent authority without critical thinking), his/her family, as well as him/herself, will just suffer more and more, while he/she will just blame other people for the unfortunate turn out.


Of course, there will be times when adversities will cause even some of the most self-aware and serene people to be completely outraged, like when a guy realizes that his girlfriend had been concealing the fact that she's pregnant for another guy for weeks.


The point remains that letting negative emotions take control over you should be a very rare and last-resort-esque occurrence (even though it's okay to fail on this sometimes as long as the damages from uncontrolled emotional outbursts are at least partially compensated) rather than out of complete lack of self-awareness nor emotional intelligence.


Silently Swallowing Exceptions - Repressing Negative Emotions

Those used to handling exceptions should know that exception swallowing is generally a very bad practice and should only be used when there are very solid reasons behind it, otherwise, the original exceptions that could be properly handled can easily become something much worse much later - severe errors that seem to come out of thin air, so it'd be very hard to find the root causes behind all this, let alone fixing it.


For instance, I still vaguely remember that when I had a full-time programming job, I've taken over a codebase from someone else and soon realized that that codebase will occasionally be out of memory without obvious causes. While it's reasonable to suspect that there are memory leaks unknown to me(and it's extremely hard to eradicate every possible memory leak anyway), I'd to spend quite some time to find out that some of those memory leaks come from silently swallowing(an empty catch that's not even logging anything) a certain exception when using an API of a library as a dependency of that codebase(I unconfidently recall something like only closing connections/streams in the try block but the exception's thrown before reaching that line of code). If that exception had been properly handled, I might have noticed those suspected improper use of resources much earlier, thus saving me tons of time when debugging the application.


In a very similar sense, those used to exercise self-awareness practices should know that repressing negative emotions(even though strictly speaking, there's no such thing as "negative" emotions as every emotion reflects unique messages about one's dominant internal states) is generally very bad practice and should only be used when there are very solid reasons behind it(like under prolonged critical emergencies constantly requiring difficult yet immediate actions with no room of errors), otherwise, the originally manageable negative emotions can easily become something much worse after several years or at most decades - total mental breakdown triggered by seemingly trivial setbacks as the last straw, and sometimes even seasoned professional therapists may fail to understand the accumulated suffering of such patients, regardless of years of attempted consultations and treatments.


For instance, while I don't claim to remember every last detail, someone I know very well had almost committed suicide more than a decade ago, with the last straw being having no hope of finishing his bachelor's degree in university(and he really didn't finish it at the end). While I don't think I've thoroughly comprehended the essence behind his depression at that time (fortunately, nowadays he's at most lightly depressed once in a while for a short time), I do know that he almost never asked for help unless absolutely necessary, and he nearly always refused to talk about his hardship to anyone else(now he'll at least try to talk a little bit about that when someone else asks him about that directly).


With the fact that he rarely expressed even his positive emotions to others at that time (but now he can genuinely smile easily), it's reasonable to think that his self-awareness and emotional intelligence were both very low at that time, so repressing negative emotions in front of the others and even himself was all he could do back then. If he didn't try to escape from external challenges as well as not ignoring his internal unhappiness, I don't think he'd have tried to prepare to commit suicide (although I'd still doubt if he could've finished his bachelor's degree even with external help), even though it's lucky that he never did it, and it was all that mattered.


Properly Handling Exceptions Thoughtfully - Observing Negative Emotions Nonjudgmentally

In short, exceptions that can be handled should be properly handled with thought because different kinds of exceptions need different kinds of care, and sometimes even the same kind of exceptions can have totally different meanings under different contexts, so it's usually better to think about how to handle a specific exception under a specific context with a case-by-case basis, even though it doesn't mean there's no need to establish exception handling facilities and policies for each software.


Mixing Different Exceptions - Lacking Emotional Granularity

If you're a Java developer, it'd be a fortune for you to have not worked with a high-level try-catch block that has just a single catch-catching Throwable for no reason (ideally, such codes should never exist, to begin with) without caring whether it's an IOException(which can still be too broad sometimes), NullPointerException(which might be effectively meaningless under some contexts), OutOfMemoryError, StackOverflowError, or some other kinds of errors and exceptions. Because, strictly speaking, it's also a kind of exception swallowing, not by negating the existence of exceptions altogether, but by erasing the specific details necessary to handle them properly. Obviously, it helps to avoid facing the problems head-on, but it won't solve them either, and in fact, it often makes them much worse, sometimes even to the point of being impossible to fix within feasible costs anymore.


Similarly, if you only know that you feel bad when you're facing negative emotions, without knowing what kind of bad feeling it's (like anger, anxiety, guilt, sadness, or shame), you can end up swallowing the details of your unmet internal needs by covering them using the generic word "bad" and nothing more(although it's still better than negating negative emotions altogether), thus pretending to be working hard on improving mindfulness while giving you excuses to evade all those limiting beliefs and psychological pains that have to be faced, in order to have meaningful spiritual advancement and mental growth required to function effectively and efficiently as a healthy being. While increasing emotional granularity demands some courage and knowledge, it's the only way to stop those stagnant negative emotions from eventually evolving into nastier and nastier mental disorders, even though one won't descend into such a hell that easily or quickly in normal cases.


Analyzing Exception Stack Trace - Identifying Negative Emotion Roots

When investigating the root causes of an exception, it's often helpful to study its stack trace, at least until to the level where some meaningful fix can be done instead of just covering its symptoms. Of course, sometimes, including rare instances where I've experienced personally, covering the symptoms reflected by an exception is indeed better than trying to fix its root causes, and this can be due to varying special reasons, like the prohibiting cost and technical barrier needed to fix it, with the reasonably assumed lack of serious consequences of just covering its symptoms, or maybe the exception is due to some native bugs of the frameworks or platform used, when it'd be infeasible to find replacement just because of those relatively minor annoyances. The key to this, again, is to really know what you're truly doing, rather than just mechanically sweeping ugly messes under the carpet without long-term thinking, and being at least this responsible and thoughtful will be one of the advantages helping us go a long way as seasoned professional software engineers.


Similarly, after giving ourselves some time to just feel those negative emotions without criticism, it's often helpful to ask what triggers those negative emotions, and I might have to use an example to illustrate this. Let's say you and colleagues A and B have the same position in the same company, while they've higher salaries than yours. While you dislike A a lot because of that, you respect B despite that, however. After some brief self-observation, you realize that you dislike A more and more whenever he/she creates even more mess(and you've to clean it up) without contributing much to anybody or anything(and the higher-ups never punished A for anything ever), and you respect B more and more whenever he/she performs even better than he/she already did without making troubles to anyone else, so having the same position with different salaries isn't the full story of your disdain towards A but not B.


Instead, it makes sense to have a hypothesis that(which needs to be further verified) you have an implicit golden rule that the rewards received by someone should be proportional to the values that someone brought to the others, and your hatred towards A stems from him/her violating your golden rule without any negative consequences, thus threatening some parts of your subjective value systems that are imbued deep within your brain and heart. With this new insight about yourself, you can choose to either accept that it's okay for your golden rule to slightly fail sometimes or continue to be angry with A but with the crystal clear awareness of him/her violating your golden rule without having to pay for it, or try to reveal your past pains causing your adoption of this golden rule by digging even deeper about where it came from(which is insanely hard without professional supports), but what's the most important is that, no matter what you choose, it'd be better to admit that it's your conscious choice, and be responsible for it, as well as every consequence on your part.


Do note that, in practice, exception stack traces are handled by our minds, meaning that it's a thinking and objective process, while negative emotion roots are handled by our hearts, meaning that it's a feeling and subjective process, so just blindly applying the methodologies of handling exception stack traces into handling negative emotion roots will only make things even worse, and emphasizing the similarities between exception stack traces and negative emotion roots is to use another way to reveal some parts of the essence behind negative emotions, especially for us programmers and former programmers :D


Throwing So Many Exceptions - Being Triggered So Easily

While it's totally fine for a method to throw a couple of exceptions, if a method can throw dozens of them, then it's most likely a code smell because that method probably does too much and/or rethrows too many exceptions coming from even lower level methods, when at least some of those exceptions should be handled by the original method instead. Either way, since exceptions are special kinds of union types(and checked exceptions are special kinds of tagged unions), methods throwing so many exceptions have the same problems of union types having so many different types included, which at least indicate the possibility of low cohesion and/or tight coupling.


Similarly, while it's totally fine for us to have a couple of negative emotions once in a while, if we frequently have so many negative emotions simultaneously, then it's most likely a sign for some needs on more personal growth because we're probably under too much stress and/or have so many past yet unhealed mental sufferings triggered by the current adversities when it'd be ideal for us to let go of at least some of those stale psychological pains. Either way, since emotions, including negative ones, are the communication media between our conscious and unconscious mind, when we frequently feel so many negative emotions simultaneously, it's natural to suspect that our conscious minds have been ignoring or twisting too many messages from our unconscious minds for far too long, and such self-defeating pattern can indicate the tendency of feeling a false need to strictly control the others rather than ourselves at all times, and being far from always solely responsible for our external behaviors(barring extreme cases like being forcibly drugged by the others).


Chaining Exceptions - Stepping Back

It seems to me, and possibly seems to you as well, that exception chaining is a best practice when it comes to handling exceptions, but whenever we've to chain exceptions, it means those exceptions can't be handled by places they're thrown, and have to be escalated to a higher level method, by wrapping those original exceptions irrelevant to that higher level method with exceptions meaningful to it, to hope that it can handle those wrapped exceptions, with the original exceptions as their causes. If it still can't handle those wrapped exceptions, the same exception chaining process will be repeated to further escalate those exceptions into an even higher level method, so the whole process will repeat until a high enough level method can handle those exceptions, or the program has to escalate them into the highest level and inform the end users about what really happened, then either ask for user inputs and continue the program safely or ask for user apologies and crash the program nicely.


Without wrapping lower-level exceptions with higher-level exceptions, the higher-level methods won't even understand what's going on, let alone do anything meaningful to it; Without preserving the original lower-level exceptions, the higher-level methods won't know what causes the exceptions they understand, and sometimes different actions are needed for different causes.

The same wisdom can be applied when we're facing some serious negative emotions that can't be just looked away from but can't be directly dealt with on the level directly triggering those negative emotions either, and this can be illustrated with the following example. When the annual contract of my previous job nearly ended, I feel anxious about both renewing and not renewing the annual contract. On one hand, I liked the workplace, and I'd slightly miss it as well as my colleagues for a while if I just choose not to renew the contract; On the other hand, as I foresee a high probability for the workplace to change from being very nice to being very nasty within months, I'd probably have to change from contributing as much to the workplace as I sustainably can to protecting myself from the workplace as much as my track records won't become too broken, so I'd likely suffer significantly for quite a while if I choose to renew the contract.


Because I already had some experience on self-awareness and mindfulness at that time, I realize that this apparent psychological conflict is more than just about the contract itself, so I took a step back and escalated this issue to a higher level. After some inner work, I revealed something noticeably deeper - I don't want to escape from difficult challenges and leave my colleagues behind(I was perceived by most of them as the most helpful colleague there), as I'd feel that doing so is a little bit like betraying at least some of them(now I still think I'm just an unforgivable deserter that deserves to be hated even though no one seems to despise me for that), but I don't want to go back to be someone defending my self-interests at the cost of the greater good either, as I'd feel that doing so is going massively backward when it comes to personal growth(and this will eventually harm my self-interests even more even though this backward approach is just temporary). Since I already know that my core principle is to avoid hurting anyone else as much as I can sustainably do so(I suspect that my whole value system's built for this), choosing either side is going to somehow violate what I care the most, I decided to choose the side that most likely hurt my colleague less - Not renewing the annual contract, in the hopes that the one replacing me will perform much better and help those colleagues much more than I did, thus causing them to at least suffer less.


Of course, that doesn't mean my decision is perfect because maybe I could've taken another step back and tried to have some insights on my past psychological pains causing me to avoid hurting anyone else even at the cost of harming myself(provided that those harms are totally reversible), or maybe I could've found ways to raise my map of conscious level to joy(540) before starting the renewed contract, so I'd feel incredibly blessed and eternally ecstatic when I know I'm going to face the toughest challenge for me ever, while still sustainably contributing even more to my colleagues and fostering my personal growth. But without taking a step back and escalating the original conflict of whether to renew the contract to a higher level, I might not have understood that the nature of the conflict is actually failing to find any way to withstand my core principle no matter what I do, so I feel hurt and sad about having no means to maintain the integrity of my identity towards myself and possibly some of the others. Therefore, if I just kept struggling on the surface issue alone, no matter what I choose, I'd just be even more guilty and remorseful about what I've done, and I'll have to do, all without fathoming why I'd be this ashamed of myself.


Summary

As seasoned professional programmers, we're good on our thinking sides; otherwise, we wouldn't have lasted that long in the software engineering industries, so we'd usually have little problems with aspects primarily using our minds. But as authentic human beings rather than objectified machines (although a little bit of systematic dehumanization is still a necessary evil to support the civilization of mankind) solely for keeping the societies running (when societies are supposed to serve their members rather than the other way around), we'd want to be good on our feeling sides as well; otherwise, we'd be more and more alienated and foreign with who we really are and what we really want, so our hearts would bleed and die more and more inside every day we try to escape from and eliminate our negative emotions. Therefore, by spotting the similarities between exceptions and negative emotions, this article tried to apply some wisdom on handling the former into handling the latter, with the goal of helping me, and perhaps at least some of you, to be good on both our thinking and feeling sides(although most of you are already this good without needing this article at all), and to have little problems on using either our minds and hearts(rather than treating them as polar opposites), thus our lives can become more complete and fulfilling to us and preferably to the others.


Even though this article is by no means exhaustive on applying wisdom on handling exceptions to handling negative emotions, at the very least, if we realize that choosing between letting our negative emotions take over control and repressing them is such a false dilemma that will only cause us to be more and more miserable, we're already on a good way to be more self-aware and mindful, just like how understanding exceptions will help us to be better and better programmers. As our emotional intelligence keeps increasing, it'd be more natural for us to handle negative emotions wisely until it'd so intuitive to us that it'd become our second nature, even though it doesn't mean that this will become a piece of cake nor we'll always do it well, just as sometimes we'll make an ugly mess out of exceptions no matter how seasoned and professional we're, and no matter how much we take exceptions seriously, hence it's still okay for us to become a little bit childish once in a while, and it's part of being human rather than machines :P


Also Published Here