<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Karthikkeyan Bala Sundaram on Medium]]></title>
        <description><![CDATA[Stories by Karthikkeyan Bala Sundaram on Medium]]></description>
        <link>https://medium.com/@karthikkeyan?source=rss-2beda720c2c1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rPAxXJ0wD8deXDwPLRgAXA@2x.jpeg</url>
            <title>Stories by Karthikkeyan Bala Sundaram on Medium</title>
            <link>https://medium.com/@karthikkeyan?source=rss-2beda720c2c1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 07:57:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karthikkeyan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Thoughts on Test Driven Development]]></title>
            <link>https://karthikkeyan.medium.com/thoughts-about-test-driven-development-3faae7502d3a?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3faae7502d3a</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Fri, 17 Dec 2021 08:27:13 GMT</pubDate>
            <atom:updated>2021-12-17T10:08:56.399Z</atom:updated>
            <content:encoded><![CDATA[<p>One of the thing I really like about test driven development is that it allows a good architecture emerge out of your code organically.</p><p>I have been told the above statement when I was introduced to test-driven development. When I heard that, I said to myself “this guy is over-romanticizing this idea”. Back then I didn’t know he means that literally. A few months later, I started realising that how good of a development strategy it is.</p><p>It has been a year since I started building software using TTD, it has been a satisfying year so far(in terms of writing code). Prior to TTD, I used to spend hours and hours, some times weeks build prototypes, to come up with an optimal architecture for a feature or a library I was asked to work. Since TTD I stopped worrying about the architecture so much as I learned and knew that a good architecture will emerge out of my code as long as I let the test drive my implementation.</p><p>Now a days when a task is given to me, my workflow goes like this,</p><ol><li>Prepare the business use cases</li><li>Pick a use case and write a test which is obviously going fail(or it would not compile as there is no production code yet)</li><li>Now, write production code to pass the test.</li><li>Stop writing code as soon as the use case is satisfied.</li></ol><p>Since I am writing a production code to pass a test, I have to make use of all the useful design patterns and design principles to write the production code that is testable. There are overwhelming amount of design patterns and design principles out there, but usually all we need to know is that how to hide your concrete class under a abstract interface and inject any dependency through another abstract interface. It is not limited to these two but this is where you will end up spending majority of your time.</p><p>Since you will stop writing code as soon as you are done with your test, your production code will have no dead code.</p><p>As your tests are written to implement a use case, at the end of passing a test you will be producing a working code. With TTD as your development strategy, your will be <strong>continuously producing a working code</strong>.</p><p>To learn more about TTD with practical examples, watch some of the videos from my Youtube channel. There I am doing a live coding exercise using test driven development.</p><p><a href="https://youtube.com/c/KarthikKeyanBalan">Software Engineering</a></p><p>Hopefully, you will find this useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3faae7502d3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The greatest task of a man in his life is to expand his conscious mind.]]></title>
            <link>https://karthikkeyan.medium.com/the-greatest-task-of-a-man-in-his-life-is-to-expand-his-conscious-mind-db01cebeee71?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/db01cebeee71</guid>
            <category><![CDATA[self-improvement]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Sat, 06 Jul 2019 18:24:22 GMT</pubDate>
            <atom:updated>2019-07-06T18:24:22.400Z</atom:updated>
            <content:encoded><![CDATA[<p>The greatest task of a man in his life is to expand his conscious mind. Unfortunately, only through pain, suffering and chaos he can expand his conscious mind; thereby pain, suffering and chaos became an acute and innate part of the structure of his existence itself. He cannot escape from it, cannot postponed for a later time, cannot cheat it, cannot delegate it; what is decisive will always happens to him. The only thing he can do is, accept it.</p><p>Say yes to the pain and suffering that which is a potential mnemonic.</p><p>Say yes to the chaos that which pushes you into the abyss of unknown.</p><p>Then comes the chance and transformation he truly seeks. The change and transformation that synchronize with the expansion of conscious mind.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db01cebeee71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chaos and Order]]></title>
            <link>https://karthikkeyan.medium.com/chaos-and-order-addfce51b6d3?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/addfce51b6d3</guid>
            <category><![CDATA[carl-jung]]></category>
            <category><![CDATA[jordan-peterson]]></category>
            <category><![CDATA[life]]></category>
            <category><![CDATA[being]]></category>
            <category><![CDATA[chaos-and-order]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 19:08:40 GMT</pubDate>
            <atom:updated>2021-06-08T04:32:38.628Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gswWecQy1ZZn80tt1EthQ.png" /><figcaption>Chaos and Order</figcaption></figure><p>A modern individual has an incalculable proclivity, and profound intimidation, to follow the postmodern era’s socio-culture, like a cult, to feel a part of belonging in today’s society. In an effort to <em>belong</em>, everyone wears a persona to act themselves out so that the person feels socially acceptable. So then the persona becomes his real identity to his Ego-Conscious mind. He who erroneously identify oneself with his persona, become of it; a lie. What left of him is irrational views of himself and society.</p><blockquote>Note: Before preceding, please forgive me for my poor English, as it is not my first language. I have tried my level best to articulate my thought process as clear as possible.</blockquote><blockquote>Also, I must warn the readers, this is a very long article.</blockquote><p>I can undoubtedly proclaim myself, I have a fair bit of an experience living in such a society of individuals filled with personas and irrational views. It would be a terrible mistake from my side if I portray myself as an intellect that I am not. I must admit, I did live through the insanity plaguing the society; I identified myself with the persona I wear every day. I would strongly encourage one to withdraw from the practice of wearing the persona, at the very least conscious of it, for I have understood it is the first step forward towards <em>Self</em>-realization. If one stays in this state of mind for a considerable amount of period in his life, it could potentially cause irreversible damage to his psyche. He will find his unconscious mind consistently engaged a conflict with his ego-conscious mind, so he will see a dual personality inside himself. On the one hand, there are tremendous urges to manifest his unconscious instinct, on the other hand, he has to repressed those instincts to protect the persona he wears. This dual personality in his psyche will inescapably cost him dearly. This internal conflict within oneself undoubtedly paves the path to neurotic behaviours and views. As these views of an individual influence every aspect of his life, so it does to his family, tribe, nation and up to his ethnic group.</p><h3>Spiritual Poverty of Modern Man</h3><p>I have heard repeatedly, people talk about this one precious little idea, “<em>Life is all about happiness</em>.”. Without giving a considerable amount of thought I did buy into such views, for I was desperate to hang on to some sort of belief. After reading <em>Carl Jung</em>, my inner world completely turned upside down; all the thick walls I built around my ego started to crumble down in the face of their psychological insights of the unconscious mind. Once again I have revisited my previous supposition, which I bought into without enough thought process, that, “<em>Life is all about happiness</em>”. This time though, this very precious little idea strikes me as vague; a false statement for some reason everyone follows blindly. This beg the question, why on earth people believe in such a vague idea? I want to quote Carl Jung’s words here,</p><blockquote>“Now religious ideas, as history shows, are charged with an extremely suggestive, emotional power. Among them I naturally reckon all représentations collectives, everything that we learn from the history of religion, and anything that has an “-ism” attached to it. The latter is only a modern variant of the denominational religions. A man may be convinced in all good faith that he has no religious ideas, but no one can fall so far away from humanity that he no longer has any dominating représentation collective. His very materialism, atheism, communism, socialism, liberalism, intellectualism, existentialism, or what not, testifies against his innocence. Somewhere or other, overtly or covertly, he is possessed by a supraordinate idea.”<br><br>- Collected Works of C. G. Jung, Volume 9 (Part 1) Aion: Archetypes and the Collective Unconscious.</blockquote><p>It appears a man cannot go on living without <em>faith</em> in some <em>-ism</em>. It is for the reason that the belief system is built right into his collective unconscious as an archetypal motif, <em>an innate form without representation</em>, a man cannot simply abandon his beliefs, he can only give a representation for that form. When a man speaks of, truth, morality, teach his kids to be kind and respectful, gets emotional against unjust, stood up for the people who cannot stand for themselves, sets his different a sided for the benefit of collective good, trust his friend, vow to the women to stand beside her in sickness and in health, he speaks through the moral guidelines of his society. These moral guidelines are an evolution of a religious belief. These beliefs are not sudden enlightenment of modern man, for these are his inherent tendencies peculiar to the human species. He has only given them a form either through his parental imago or his culture. These guidelines are endless repetitions of experiences throughout the process of human psyche’s evolution; so it earns its place right into the collective unconscious. Repressing or abandoning energies produced by an archetype is an impossible task for a man.</p><p>A modern man forsaken his religious faith in pursuit of <em>reasoning</em>, so he does lose the connection to his roots. These beliefs once provided meaning for the suffering of life in chaotic times for our forefathers. We have lost that connection and wandering in the forest like a blind man envying for spiritual enlightenment. This spiritual poverty of a modern man, especially in the west, perhaps, led him to gaze upon the east, the lands of spirituality.</p><p>A man has cut out his connection to his roots and became mechanical in this post-modern times, he can only satisfy his ego-conscious mind by seeking happiness outwards by possessing materials and social validation from “likes” he gets for his photograph from fellow man. The fact that these ego satisfactions are ephemeral, for he has outsourced his happiness to an entity which he does not possess any control. For a medium to long term happiness, he needs something profoundly meaningful in his life to transgress the limits of his Ego-Conscious mind. Even when our conscious presuppositions are far more advanced than any other primates, a man is still primitive when it comes to his unconscious instincts. For a primitive man faith and religious practices are inseparable in his world he lives in. A modern man constantly looking for meaning in his life will be disappointed, since he lacks faith and belief, he will only regress back to outsourcing his happiness to the outside entity. The process of finding happiness in life remains unfathomable. As he is not finding happiness in his life, the envy for happiness became the baseline for his life. As this emptiness and envying get stronger every day, it attracts vague ideas like “<em>Life is all about happiness”</em>.</p><p>I do not have a high opinion on those who preach others to find happiness in their life, as I have learned life’s baseline is not happiness; and that is not the structure of being. I do truly believe, those who preach such ideas are doing deeply disservice to humanity.</p><h3>Chaos</h3><p>Happiness is one emotional state of mind we experience as the life events unfold in accordance with our expectations and plans. If that is so, what about the time something unexpected happened? As we continue to exist in time and <em>space</em>, a life of a man is prone to experience sadness, disappointment, failure, betrayal, malevolence, unjust, death of closest one, and so forth. If Being is not predicated upon happiness, then what is the baseline upon which we can build our life.</p><p>I had read book called 12 Rules for Life, also I have been watching. Among all, one particular statement caught my attention and struck me to the core. “<em>Life is suffering, what you going to do about it?</em>”. When I heard that statement, I did not perceive it as a brand new idea, instead, it felt like someone slapped my back head in order to remind me of a forgotten doctrine. There is a truth to that sentence. The reason it is true is that all the religions, of east and west, begin with the idea of suffering. In order to grasp the underlying conception of the religious scripts, we must leave our religious prejudice at the bay. I am obligated here to announce that I am not a theologian, I am merely trying my level best, within my limited knowledge, to provide the readers with my thought process. I would want to quote these paragraphs from the Bible,</p><blockquote>3:15 And I will put enmity between thee and the woman, and between thy seed and her seed; it shall bruise thy head, and thou shalt bruise his heel.<br>3:16 Unto the woman he said, I will greatly multiply thy sorrow and thy conception; in sorrow thou shalt bring forth children; and thy desire shall be to thy husband, and he shall rule over thee.<br>3:17 And unto Adam he said, Because thou hast hearkened unto the voice of thy wife, and hast eaten of the tree, of which I commanded thee, saying, Thou shalt not eat of it: cursed is the ground for thy sake; in sorrow shalt thou eat of it all the days of thy life;<br>3:18 Thorns also and thistles shall it bring forth to thee; and thou shalt eat the herb of the field;<br>3:19 In the sweat of thy face shalt thou eat bread, till thou return unto the ground; for out of it wast thou taken: for dust thou art, and unto dust shalt thou return.<br> <br>Genesis — The King James Bible.</blockquote><p>When God banished Adam and Eve from the garden of Eden, he cursed them to suffer to multiply and eat until the day they die. These words mark the beginning and set the stage for the origin of Being itself, which is why it took place in Genesis. The entire western culture is predicated on this concept to a great degree. This same reflects on the eastern religions as well, Life is suffering(<em>dukkha</em>: suffering, pain, unsatisfactoriness or stress), is the first of the Four Noble Truths by which Buddhism is predicated on. It is by no means a superstitious idea.</p><blockquote>Note: I would not want people to perceive the above theologically, instead try to understand the meta-truth.</blockquote><p>As this suffering prolong it causes internal disturbance to the framework in which we perceive the events of the world as it manifest. It demands an update to the framework he built around his Ego-Conscious mind. The process of updating the framework so far as I know contains two different tasks,</p><p>1. Regress back to the life experiences that formed all the perceptions; analyze the experiences once again and recalibrate the perceptions, with the help of the present state of conscious mind i.e. the subjective-knowledge acquired in the process of maturity.</p><p>2. Expand your conscious mind, incrementally, by voluntarily facing the events that are causing the internal disturbance.</p><p>The former is an internal work which, in my experience, one can work by himself. However, the latter requires dealing with an external entity, either a person who provoke fear, a betrayal, a hostile situation, a place that provokes anxiety, dealing with lies, uncertain times that stake your security, disturbance to the ordinary occurrence, helplessness, when you run out of options; when your words are ignored; when truth is denied; when you are exposed to malevolence, tragedy, difficulty, death, trauma, and so forth. I hope the few examples from the last sentence are sufficient to understand the motif of what I am trying to convey. These motifs are inescapable situations for a man in his lifetime. Events of such forces a man to expanding his conscious mind. In this process, a man has to deal with the unexplored part of life which he had ignored to deal with or never found an opportunity to deal with. This process of learning with the unknown in order to update his framework while he is sinking into the dynamics of internal disturbance is called <strong>Chaos</strong>. This is the time, as a modern man says, “People hit <em>rock bottom</em>”.</p><p>As a man acquainted with the new chaotic situation, he realizes the boundary of his conscious mind. If only he had prior experiences of such a situation, he would have portended it and would have done something to avoid it. These times ARE, without a doubt, tremendously painful, but he has to bear it. How long does he have to bear this suffering and chaos? As long as it takes to find a way to set things in order. This is the very reason why life is NOT happiness; life is not supposed to be happy. It is his destiny to find Order to all his chaos.</p><p>When a man fell into the darkest valley of chaos and spend significant time there, he learns how deep he fell down. It is the time he realizes how little he knew about the world around him; it is the time he realizes all his perceptions and presuppositions are incorrect; it is the time he realizes the incalculable suffering he had to endure in order to embark the journey toward Order, for he has to kill his own ego’s identification willfully; it is the time he realizes he is paying his dues for the lies and the ignorance he has been telling himself. it is the time he realizes how much he relied on others; it is the time he realizes the cowardly act of people around you; it is the time he realizes his inadequacy. It is not a fun ride to Disney Land.</p><h3>Order</h3><p>This realization of his shortcomings and limitations is the first step towards psychological transformation, for he has to learn what he is fighting against. After all these realizations, thenceforth, he begins the journey toward Order. Forgive me for a man of pessimistic here, this journey of transformation is, undeniably, as painful and laborious as it can be, for I have experienced walking down that path.</p><p>The more he learns the unknown side of himself, the more he gains control over his personality. The more he deals with the fearful, the more he gains control over the situation/object that provokes the fear. There is no other way around, he has to voluntarily participate in the process of mastering unknown and fear. It is through this process, a man reincarnates as a mature man by transcending his prior consciousness, so does he obtain control over his environment and himself; this very state is called <strong>Order</strong>. It is the time he realizes he is finally made peace with his own guilt; it is the time all his archetypes functions in accordances to his motivation; it is the time he realizes HE is the only man he can go for a trusted advisory; it is the time he realizes the state of oneness in his mind.</p><h3>Structure of Being</h3><p>A man has to confront chaos multiple occasions in his life, for he cannot expand his conscious without it. It is for that matter chaos is perceived as a potential; an opportunity for growth; an unknown land seeking for an occupant; a book of knowledge seeking its reader. Chaos, undoubtedly, has the tendency to morph a man to degenerate. Perseverance of morality is vital in order to reprehend the degeneration. As a man exposed to chaos and learn to bring order, he matures psychologically, so every confrontation of chaos should be perceived as a recurring knowledge awaited for a student to learn from it. This routine of Chaos-to-Order and Order-to-Chaos is a never-ending cycle in life, thorough which his whole Being is architected upon. This is the Structure of Being. Understanding this structure along gives one a clear hypothesis to deal with difficult situations in life.</p><h3>End</h3><p>I would be deeply humbled if even a single person finds this article helpful, to put his life together. I would strongly encourage people to read the following books,<br>- Aion I: Archetypes of Collective Unconscious — by Carl Jung<br>- Aion II: Research into the phenomenology of Self — by Carl Jung<br>- Two Essays on Analytical Psychology — by Carl Jung</p><p>Most of my thought processes are influenced by Carl Jung. My morality would obliterate if I have failed to mention him here. I am forever grateful to him for his insightful work on the human psyche.</p><p>Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=addfce51b6d3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Software Design Thinking]]></title>
            <link>https://karthikkeyan.medium.com/software-design-thinking-5769ea31df84?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5769ea31df84</guid>
            <category><![CDATA[object-oriented-design]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[design-principles]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Mon, 27 Aug 2018 23:39:50 GMT</pubDate>
            <atom:updated>2018-09-16T02:24:38.104Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, Im gonna share the approach that I took to solve a complex problem by composing individually working classes.</p><blockquote>Warning: This is a lengthy article to read.</blockquote><p>I been working in an iOS project for almost an year. It is <em>almost</em> production ready. The architecture of the project was finalized way back. We built each layers, from Network Layer to Presentation Layer, and the communication between each layers well defined. Below is the high level architecture of the project,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tXqECxONGyDF1pAvU8VPBA.png" /><figcaption>Base Architecture</figcaption></figure><blockquote>Please refer <a href="https://medium.com/@karthikkeyan/ios-app-architecture-3f1d1400862f">iOS App Architecture</a> for the detailed explanation of the above architecture.</blockquote><h3>New Requirement</h3><p>Right when we thought every class and layer are working perfectly, there comes an another requirement.</p><p>In a screen, if/when an API fails because of timeout error,</p><ul><li>Cancel all the existing network calls on that screen</li><li>Display an alert with a generic message and asking the user to Retry</li><li>Upon user’s decision to Retry, call all the API related to that screen and refresh the data in the screen.</li><li>Importantly, the logic/component should be generic or flexible enough, so that it can be used through out the project.</li></ul><p>This seems simple to implement, but after a year it became complex to mess around with the underlying network layers. So I decided not to directly make code changes in the existing classes.</p><h3>Approaches</h3><p>I have tried two approaches before finalizing one,</p><h4>Notifications</h4><p>NSNotificationCenter is the first thing that popped out of my head and it was encouraged by fellow engineers. The approach is to post a notification when ANY request timeout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*qN6eof5eceoWCgxie4Yljw.png" /><figcaption>Notification Approach</figcaption></figure><p>This looks simple, but there are couple of fundamental issues with this approach,</p><ol><li>Any objects can register for this notification, even the classes those are not relevant to the API can register to get notified. I wanted to set the boundaries of each classes.</li><li>One of the requirement is to cancel all the network calls triggered from the screen. With this approach there is no way for the view controller to know which network calls are currently running, so it cannot cancel them.</li><li>Even if the view controller some how managed to obtain that information, view controllers are not allowed to interface with network layers. If it does then it a violating in my architecture.</li></ol><p>Given the above, notification approach doesn’t seems feasible, so I have to look for other approaches.</p><blockquote>One notable takeaway here is, Observer Pattern(NotificationCenter-Notification), pattern by passes all the middle layers in between network and presentation layers. All the middle layers code remain unchanged.</blockquote><h4>View Models</h4><p>Since the view models are the data-backing layer for view controllers in the architecture, the second approach I was thinking was to handle the timeout error of each API calls in view models.</p><ul><li>When API fails/succeeded the network operation is gonna call the completion block in view model.</li><li>If the error code is of timeout, then the view model will notify view controller to present retry alert message to the user.</li><li>View model cancels all the network calls it initiated.</li></ul><p>Something like this,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/44849b057e6416c8e2f17d65776e723c/href">https://medium.com/media/44849b057e6416c8e2f17d65776e723c/href</a></iframe><p>This approach seems pretty simple. This is not violating the architecture. All the layers are communicating with one layer above and one below. I could make it work. However, there are some major issues with this approach.</p><ul><li><strong>Lots of Code Change</strong>: Note that the above example is just for one API call. A view model could be working with multiple API calls, so I will have to update all the completion blocks of the view model. If I have to implement the retry logic in another view controller, I will have to update all the completion blocks in one more view models. We are talking about updating all the completion blocks in most of the view models.</li><li><strong>Bugs</strong>: More modification in existing code, more prune to bugs.</li><li><strong>Open/Close Design Principle: </strong>What if I want to handle one more error type in the future. I will have to update all the ViewModels once again. With this approach we are going against Open-Close Design principle.</li><li>This is a brute force approach.</li></ul><h3>What I need</h3><ul><li>I want to extend my existing code, but don’t want to modify.</li><li>I can leverage Observer Patterns.</li><li>I want to the new component completely modular.</li><li>With or without connecting the new component into the existing architecture, the existing code should work.</li><li>The new component should not be limited handling Timeout error.</li></ul><h3>Components</h3><p>Lets dig deeper into implementation details. Lets list out what are all the classes required,</p><h4>Response Proxy</h4><p>First thing first, it all starts with an API response. I need a entity that checks <strong>any</strong> API response for error. If the response is error, then that entity should some how send that message to the presentation layer.</p><p>Most importantly, the network layer’s functionality shouldn’t be dependent on this new entity. Basically the new entity should be of optional type.</p><p>Since this entity is acting as an agent, that handles the response on behalf of Network Layer, we call that entity ResponseProxy.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9df71794fd44fbcc1f67b36be03d657a/href">https://medium.com/media/9df71794fd44fbcc1f67b36be03d657a/href</a></iframe><p>We have our proxy class ready. Now the questions are,</p><ul><li>Who creates &amp; keep the proxy object alive.</li><li>Who sets the proxy object to network operations.</li></ul><p>The answer is the whoever manages the network operation. In my case, I have an NetworkOperationQueue which lives as long as the app is in the memory. This is the right place for me to create the proxy object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eda411645f2d4902b8b90535dd56c93b/href">https://medium.com/media/eda411645f2d4902b8b90535dd56c93b/href</a></iframe><p>Note that in DataTaskNetworkOperation the property responseProxy is optional. We are only letting the proxy to take over the response-handling if it presents. This give the network layer a flexibility to fallback on to the original implementation.</p><h4>ErrorCenter</h4><p>Next, I need an entity that posts notification when an error is received by ResponseProxy. An entity where any objects can register to get notified, when a Network Operation or a group of Network Operations fails.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8b253561faa838d387d921475f7c3a46/href">https://medium.com/media/8b253561faa838d387d921475f7c3a46/href</a></iframe><h4>Error Observable</h4><p>Next thing I want is an error observer object. An objects that supplies essential information and provides an interface for ErrorCenter. Object that confirms to ErrorObservable can be registered to receive notifications when error received.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ff435ac512a3e2b881ec53abb72f37b/href">https://medium.com/media/3ff435ac512a3e2b881ec53abb72f37b/href</a></iframe><h4>ErrorHandlable</h4><p>The last piece I need is, an entity that can handle the error observed by ErrorObservable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d29672416a0aee92a926850347306054/href">https://medium.com/media/d29672416a0aee92a926850347306054/href</a></iframe><blockquote>Im only talking about the happy path with all the above code snippets. I haven’t included the complete implementation details.</blockquote><p>I have all the entities I need to compose a error handling flow. This is how it looks after i connect the individual entities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rnTmEorH6WSgWyW9lebNMA.png" /><figcaption>Error Handling Flow</figcaption></figure><p>To simple put,</p><ul><li>The OperationResponseProxy say’s, “<em>You got a response from API?, I can handle that.</em>”</li><li>Then the Response Proxy, check if the response is “error response”, if so then it handover the error to ErrorCenter</li><li>Then the ErrorCenter checks if anyone ErrorObservable registered to receive notification for that error and notify that observer.</li><li>Then the ErroObservable will ask ErrorHandlable to handle the error in the UI (Retry or Cancel or Update UI)</li></ul><h3>Putting it all together</h3><p>Now it time for me to link the new “modular sub architecture” with my current architecture. And this is how it looks like at the end,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s8dFNF6NkcEWdFHvdsfy7Q.png" /><figcaption>Complete Architecture with Error Handling</figcaption></figure><p>Note that the core app architecture(the one on the right) still maintains the same.</p><h3>Software Design Thinking</h3><p>Now lets come back to the title of this article, “Software Design Thinking”. How am I trying to relate this article with the title? I will answer that question in three points.</p><h4>Program to an Interface, not an Implementation</h4><p>If you notice almost all the entities, those are connecting my core architecture, are <strong><em>Protocols</em></strong> aka <strong><em>Interfaces</em></strong>. The concrete classes that conforms to the protocols. Because of this nature, we get two benifets,</p><ul><li>It gives the classes, the ability to dynamically change the implementation at runtime.</li><li>Classes are loosely coupled</li><li>Good use of Polymorphic :)</li></ul><p>Example, the Network Layer exposes an interface ResponseProxy doesn’t care about the implementation.</p><h4>Favor Composition Over Inheritance</h4><p>In my example above, all the screens, that handles timeout error, needs to display an alert message with <strong>Cancel</strong> &amp; <strong>Retry </strong>action buttons. I didn’t create a UIViewController that presents an alert. Instead I composed the class with ErrorObservable and ErrorHandlable. Doing so, gave the implementer a flexibility to create the observer it wants and handle the Retry &amp; Cancel logic.</p><h4>Embrace Design Patterns</h4><p>Design patterns are time-proven designs to provide a solution to a software design challenges. In my design, I didn’t try to implement my own patterns. When I saw this challenge we went on a search to find what are all the existing patterns that fits my problem. I found Proxy Pattern and Observer Pattern that would work better, so I used it.</p><p>I don’t always keep all the design patterns in my finger tip to program. When I see a problem space, I try to find a pattern that already solves the problem. This way I don’t to stress myself to reinvent a wheel.</p><blockquote>Note: I haven’t talked about all the implementation details and challenges that I encountered. That not what I this article about. In this article, I mainly wanna share how I think when I approach a problem than the implementation challenges.</blockquote><p>Hopefully this helps you in your projects. If you have any questions or you have a better solution than mine, please leave a comment.</p><p>Thanks for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5769ea31df84" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hash Table(Hash Map): O(n) to O(1)]]></title>
            <link>https://karthikkeyan.medium.com/hash-table-hash-map-o-n-n-to-o-1-386774066dda?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/386774066dda</guid>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Sat, 07 Jul 2018 00:26:14 GMT</pubDate>
            <atom:updated>2020-07-03T19:28:52.675Z</atom:updated>
            <content:encoded><![CDATA[<p>I been working in iOS project for a while, in which I had to built couple of screens those are completely driven by JSON returned from API. Every view and the nested hierarchy of views are driven by JSON. That seems interesting and this is what I got from the API.</p><p>Heres the sample JSON,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c6812da7cae66df9c684918ed02b5c5/href">https://medium.com/media/5c6812da7cae66df9c684918ed02b5c5/href</a></iframe><p>Heres the simple explanation,</p><p>viewType : Enum represents a different UI elements, like UIView , UIButton .. so on.</p><p>viewID : This is straight forward an unique identifier for each element</p><p>children : The child element that goes inside the view</p><p>This JSON will be parsed into to an object DynamicUIElement</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f13eecf6d98ac9b85043d1d0b3b3724a/href">https://medium.com/media/f13eecf6d98ac9b85043d1d0b3b3724a/href</a></iframe><p>Im not going to explain how I transform the JSON to UI, this article is not about that. This is about a specific case, and here it is,</p><p>We have built this view and the complete hierarchy. Now when the user interacts with the views, we need to find out which JSON object this view belongs. There you go! Thats what we are trying to solve here.</p><p>Lets list out what we have,</p><ul><li>UIView that user selected</li><li>viewID of that view, which is same as DynamicUIElement.viewID</li><li>Hierarchy of views</li><li>Hierarchy of `DynamicUIElement`</li></ul><p>Now, this was my first implementation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/16add0da319b9f462ed5a6283f26d2bf/href">https://medium.com/media/16add0da319b9f462ed5a6283f26d2bf/href</a></iframe><p>It works, we merged the PR. Then later when I read the same code couple of months back, I felt we could improve this logic. Two things I noticed,</p><ul><li>There interface could be better.</li><li>This logic seems brute force.</li></ul><p>I started by improving the interface. I have updated the above logic to this,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ca15e13ca933cc9263d3ea88fa4038ae/href">https://medium.com/media/ca15e13ca933cc9263d3ea88fa4038ae/href</a></iframe><p>I ran a measurement test for the above algorithm, now here’s result for that,</p><pre>self.measure {</pre><pre>    _ = viewModel.viewForID(22651)</pre><pre>}</pre><blockquote><strong>[0.002777, 0.000361, 0.000356, 0.000356, 0.000357, 0.000356, 0.000356, 0.000356, 0.000356, 0.000356]</strong></blockquote><p>Now I felt like I have accomplished something really good. Then I share this with my friend. He said, “Well, the interface looks good, but your algorithm is still <strong>O(n)</strong> which is good but now great algorithm, because we are still recursively iterating the children and its children and its children… and so on”, we could do better. The search performance is still not good. Then we discussed more and we came up with a better solution by taking advantage of HashTable(Hash Map) data structure.</p><p>What if we create a Hash Table to index the memory address of the DynamicUIElement objects?.</p><blockquote>Hash Table’s time complexity is <strong>O(1)</strong>.</blockquote><p>So I decided to take that route. This is how the Hash Table looks like,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be63872ba650b69aefde13478fec7822/href">https://medium.com/media/be63872ba650b69aefde13478fec7822/href</a></iframe><p>This hash table will stores the memory address of the a DynamicUIElement object against it&#39;s viewID, irrespective of the object’s depth in the hierarchy. Basically the index table is flat. With this table in our hand, we could avoid writing a search algorithm and find the object we are looking in a constant time <strong>O(1)</strong>.</p><p>All we have to do now, is to make sure we add the memory address of any newly created DynamicUIElement object to the index table while parsing the data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3957a22fb12554c7978ec9c0666a71a6/href">https://medium.com/media/3957a22fb12554c7978ec9c0666a71a6/href</a></iframe><p>Now send back the IndexTable along with the parsed model to the caller.</p><p>I ran the same measurement test again, but this time the performance of the algorithm is far better,</p><blockquote>[0.000046, 0.000008, 0.000004, 0.000004, 0.000004, 0.000004, 0.000003, 0.000003, 0.000003, 0.000003]</blockquote><p>The results were impressive. We reduced the execution time from <em>0.000356</em> to <em>0.000003</em>.</p><p>In HashTable approach, that I took, increases the space complexity, since we need to allocate extra memory for the IndexTable, but space wasn’t my worry, my goal was to improve the asymptotic time complexity of my algorithm.</p><p>Note that, there could be better algorithms that do well in both Time and Space such problems, if you find one please let me know in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=386774066dda" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging UIViewAlertForUnsatisfiableConstraints]]></title>
            <link>https://karthikkeyan.medium.com/debugging-uiviewalertforunsatisfiableconstraints-47697696c7c?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/47697696c7c</guid>
            <category><![CDATA[xcode]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[cocoa-touch]]></category>
            <category><![CDATA[uikit]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Wed, 18 Apr 2018 22:36:04 GMT</pubDate>
            <atom:updated>2018-04-18T22:36:04.667Z</atom:updated>
            <content:encoded><![CDATA[<p>As an app developer in iOS platform, I often ran into constraint warnings like below,</p><pre><strong>Unable to simultaneously satisfy constraints.</strong></pre><pre><strong>Probably at least one of the constraints in the following list is one you don&#39;t want.</strong></pre><pre><strong>Try this:</strong></pre><pre><strong>(1) look at each constraint and try to figure out which you don&#39;t expect;</strong></pre><pre><strong>(2) find the code that added the unwanted constraint or constraints and fix it.</strong></pre><pre><strong>(</strong></pre><pre><strong>&quot;&lt;NSLayoutConstraint:0x600000292660 UIView:0x7f94ff5b3890.leading == UILayoutGuide:0x6000001bf720&#39;UIViewSafeAreaLayoutGuide&#39;.leading   (active)&gt;&quot;,</strong></pre><pre><strong>&quot;&lt;NSLayoutConstraint:0x600000292750 UILayoutGuide:0x6000001bf720&#39;UIViewSafeAreaLayoutGuide&#39;.trailing == UIView:0x7f94ff5b3a80.trailing   (active)&gt;&quot;,</strong></pre><pre><strong>&quot;&lt;NSLayoutConstraint:0x600000292930 H:[UIView:0x7f94ff5b3890]-(0)-[UIView:0x7f94ff5b3a80]   (active)&gt;&quot;,</strong></pre><pre><strong>&quot;&lt;NSLayoutConstraint:0x600000292980 UIView:0x7f94ff5b3890.width == 375   (active)&gt;&quot;,</strong></pre><pre><strong>&quot;&lt;NSLayoutConstraint:0x604000095400 &#39;UIView-Encapsulated-Layout-Width&#39; UIView:0x7f94ff5b3c70.width == 320   (active)&gt;&quot;,</strong></pre><pre><strong>&quot;&lt;NSLayoutConstraint:0x6000002924d0 &#39;UIViewSafeAreaLayoutGuide-left&#39; H:|-(0)-[UILayoutGuide:0x6000001bf720&#39;UIViewSafeAreaLayoutGuide&#39;](LTR)   (active, names: &#39;|&#39;:UIView:0x7f94ff5b3c70 )&gt;&quot;,</strong></pre><pre><strong>&quot;&lt;NSLayoutConstraint:0x6000002925c0 &#39;UIViewSafeAreaLayoutGuide-right&#39; H:[UILayoutGuide:0x6000001bf720&#39;UIViewSafeAreaLayoutGuide&#39;]-(0)-|(LTR)   (active, names: &#39;|&#39;:UIView:0x7f94ff5b3c70 )&gt;&quot;</strong></pre><pre><strong>)</strong></pre><pre><strong>Will attempt to recover by breaking constraint</strong></pre><pre><strong>&lt;NSLayoutConstraint:0x600000292980 UIView:0x7f94ff5b3890.width == 375   (active)&gt;<br></strong></pre><pre><strong>Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.</strong></pre><p>When I see such issue we immediately set a symbolic breakpoint with <strong><em>UIViewAlertForUnsatisfiableConstraints.</em></strong> When I run the app again to reproduce the issue Xcode will stop at the above constraint warning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7wjE51q1yD0D0KHFGj9qew.png" /></figure><p>What to do now with pointers and assembly codes?</p><p>After some research, I found some solution to debug this breakpoint. If you see the above image you can see strings like <strong><em>%rbp, %rsp, %rbx, %r15</em></strong> &amp; etc. These properties holds the address of view(s) and constraint(s), those are the reason behind the constraint issue. We could print them in Xcode console to see more details about that.</p><p>I usually start by printing <strong><em>rbx</em></strong>, because it, usually in my experience, is <strong><em>NSArray</em></strong>, which contains all the views and constraints those are involved in the issue.</p><p>Open your Xcode console and execute the below command.</p><pre>po $rbx</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W2TLYGqKCR8-uq3TFh2FoA.png" /></figure><p>The above result looks exactly like what the warning message, so, what can we do with it. Three thinks to remember here,</p><ul><li>The program execution stopped at the breakpoint</li><li>You have the memory addresses of all the views those involved in the constraint issues.</li><li>LLDB lets your evaluate obj-c expression at runtime</li></ul><p>If you check the result of <strong><em>po $rbx</em></strong> command, you can see the memory addresses of view. e.g. <em>UIView: 0x7f94ff5b3c70</em></p><p>I usually chance the appearance of the some views and continue the program execution.</p><p>Execute the below command in the Xcode console, using the memory addresses you got from your previous print command.</p><pre><strong>ex [(UIView *)0x7f94ff5b3890 setBackgroundColor: [UIColor greenColor]]</strong></pre><pre><strong>ex [(UIView *)0x7f94ff5b3c70 setBackgroundColor: [UIColor greenColor]]</strong></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p1dx7P7yInG4Y9nxaWCzLw.png" /></figure><p>Now hit <strong><em>Continue program execution</em></strong> button to run the app. Now you will see two views one in red color and another in green color in your screen.</p><p>Now you know which views potential causes constraint issue. If everything is fine with the views then repeat the steps with different views till you find the issue.</p><p>Some time the views you changed the colors might be buried under other views, so it wont be immediately visible on the screen. In such case you could use <strong><em>Debug View Hierarchy</em></strong> to dig deeper in to your view hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*Sy-HA1kt5sEvWC9wtPWvbg.png" /></figure><p>In the snapshot of views hierarchy, you can clear all the top level views till you see your “colored” views,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ld68i4s5gmAobTdPzkA-Eg.png" /></figure><p>Hope this article helps. Leave a comment if there are any doubts.</p><blockquote>Sorry for the poor grammar</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47697696c7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How did I find myself]]></title>
            <link>https://karthikkeyan.medium.com/how-did-i-find-myself-5ad03e3c38f4?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ad03e3c38f4</guid>
            <category><![CDATA[life]]></category>
            <category><![CDATA[anxiety]]></category>
            <category><![CDATA[finding-yourself]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[low-self-esteem]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Sun, 11 Mar 2018 03:01:18 GMT</pubDate>
            <atom:updated>2018-08-28T00:57:53.441Z</atom:updated>
            <content:encoded><![CDATA[<p>For a long time, in fact very long time, in my life I asked this question to myself, I bet at some stage in life, everyone asked this same question to themselves.</p><blockquote>Who am I</blockquote><p>I will share my life experience, I hoping this article will help you or at least point you in a right direction. Also Im gonna use this article to let people know who I really am.</p><h3>Struggle is very real</h3><p>This is very vital for one to understand and be able to answer this question, each time our conscious raise this question to ourself. It bothered me deeply when I’m unable to answer this question. My mind was disturbed every time I touched this topic, I was clueless, nervous, angry and anxious. It gave me constant anxieties when I was alone and when I was with group of people. The concept of me not able to understand or define myself scared the hell out of me. I spent years and years trying to answer this question.</p><p>Being unable to to defined myself became a huge burden that Im carrying around every day without knowing how to take that off my shoulders. I was unable to tell or show who/what I am to others, which in result, I was unable to fit with anybody or any group.</p><p>Im, from southern part of India, culturally India is very social, compare to west. To give you an example, I remember, all the neighbors gather around in someone’s house every evening and they talk, share, laughs and be social. All the kids would be playing with each others till their father back from work. Everybody knows everybody. Nobody need an invitation or appointment to meet others. We cook food our neighbors, we helped each other with money when they are in need, we celebrated festivals and events with our neighbors. In festival time all the neighbors(regardless of their religions) cook food and share the food will every single once in their neighborhood. We were happy and proud to call our friends parents Ma &amp; Pa.</p><p>I grew up in such socialized culture. After 27 years of my life, when I looked back I didn’t have even a single friend who know me very well. Which got me thinking, there gotta be something wrong with me. The thought of “something wrong with me” leads me to couple of more thinks,</p><ul><li>Low esteem(The thought of, Not good enough or Not Interesting enough to lure others)</li><li>Socially Awkwardness</li><li>Sensitivity</li><li>Loneliness</li><li>Depression</li><li>Anxieties</li><li>Fatigue</li><li>Isolation</li><li>The worst part was, if certain smell or certain picture remained me of my past, I gave me unbearable anxieties.</li></ul><p>I moved to United States with all this problems within me already and it only gotten worst. There are pros and cons in western culture. One can get their privacy, people respect each other’s privacy in western culture, but cons are it is hard to make friends, it is easy to get lonely and get depressed. The west only added salt in my wounds. I felt more isolated than I ever did before. This inner struggle is unbearable.</p><p>I tried many thinks to help me distract from this, I bought thinks that makes me happy, I spend time doing outdoor activities, I went to gym, I joint kickboxing and sometimes I drank alcohol, but none of them help me. There are two reasons none of them worked out,</p><ul><li>All are merely a distraction, not an answer to my question</li><li>I have problem inside my mind, but I try to fix them outside.</li></ul><p>As soon as I realize that, I started digging inside me.</p><h3>Core Values</h3><p>Lets imagine a simple conversation at work place, if somebody(lets say Nathan) meet me for the first time,</p><p><strong>Nathan</strong>: Hi, im Nathan<br><strong>You</strong>: Hey, Im Karthik, how are you doing.<br><strong>Nathan</strong>: Good, what you do<br><strong>You</strong>: Im a software engineer, I work in iOS team. What you do.<br><strong>Nathan</strong>: Im a project manager. <br><strong>You</strong>: Great. Well nice to meet you. Looking forward to work with you.</p><p>May be, If Nathan works with me in any project he will know how good/bad I am at work. If Nathan is my facebook friend he will know I do hiking, gym and I drive a lot.</p><p>To put in Nathan perspective, this is what I am,</p><ul><li>Im Karthik</li><li>Im a software engineer</li><li>Im in iOS Team</li><li>Im good at my work</li><li>My hobbies are Hiking &amp; Gym</li><li>I like my car and I drive a lot</li></ul><p>All the above are true, however, none of the above define who I really am. But thats what the impression I gave it to him, wasn’t I?. So, if none of the above are not me, then who really am I. To answer this question, I had to dig deeper into myself and list out my core values. Let me list out the things I value the most,</p><ul><li>Humble<br>Humbleness is important to me, I put this first in the list and I want to write a little bit more, because I value this more. Ever since I could remember, I always tell myself this quote, I don’t know from I got this, “When we ask for help we should to humble, and when we help someone we should more humble. And always remember where I came from”. Well, this quote might not sound like a “word of wisdom”, but it important at least to me. Im really proud of what I have achieved in my life so far, especially when I look my life back a decade ago, but I never bragged about it and I never will.</li><li>Kind</li><li>Polite</li><li>Simple</li><li>Friendly</li><li>Respect</li><li>My Privacy</li><li>Peaceful Life</li><li>Integrity</li><li>Loyalty</li><li>Trust</li><li>Being meaningful than superficial</li></ul><p>I believe it a pretty good list. Everything above in the list is exact what i am. This gave me a clear perspective and definition of who I really am. Everything became clear after that. Now, think about the conversation I had with Nathan. He might be think that, Im a tech guy, running 100 miles per hour, in this constantly changing computer industry. But looking my values, Im totally opposite of what he thinks for me. No wonder, for a long time, almost a decade, people took me for what I really not am.</p><p>I could see why I was able and unable to get along with someone in the past. This might sound impossible or highly unlikely, but it is totally true, within an hour, in fact less than an hour, all my anxiety just vanished away. I felt very light, I never had anxiety after that. Even I couldn’t realize how easy and quick it was. I was able to connect the dots now. All my decisions that I made in the past were influenced by these values. I always somehow knew who I really am, but I took a decade of struggle to realize that. I still cannot believe it just took less than an hour to remove a decade of inner-struggle. However, I waited 2 full months to confirm and be 100% sure about it, before I write this article.</p><h3>Conclusion</h3><p>May be there could be more ways to find who really oneself is. In my experience, find my values helped me find who I am. I would recommend the same to others, those who struggling to find who they are. These values must not be negotiable.</p><p>This “non negotiable” part is very important. Let me give you a hypothetical example,<br>Let say if you value Polite and Respect a lot, and some one you know behave rude to you. Obviously you would expectation them to realize that their behavior not right. If you are polite person then you could let that go for time being. If you are friendly person you could come forth and say sorry, just in case to make sure it is not your fault, to patch things up. And even after that the other person didn’t care to say sorry for their behavior, then you will have to think about their friendship, because it challenges your core value of treated being respectfully. You can never get along with someone who insulted you and never care about there behavior.</p><p>Once you define these values, you will understand yourself better. Then you know what to expect from others. Eventually you will be surrounded by like-minded people and they will become your good friends. I believe surrounded by like-minded people will help you keep on track, if/when you deviate away from your values.</p><p>Thanks for reading. In my next article I will write how I find, “What to do with life“.</p><blockquote>Im sorry if I used the word “I”, “me”, “my”,.. too many times, and made it sound like its all about me. Well, I used my personal experience to right this article. As I said in the beginning, one of the reason Im writing this article is to let people know about me. Also pardon me if there are any grammatical errors.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ad03e3c38f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cliff]]></title>
            <link>https://karthikkeyan.medium.com/cliff-5a3176fa1d46?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a3176fa1d46</guid>
            <category><![CDATA[nature]]></category>
            <category><![CDATA[poetry]]></category>
            <category><![CDATA[life]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Sun, 25 Feb 2018 00:49:13 GMT</pubDate>
            <atom:updated>2019-12-22T14:55:46.067Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3svY5WQKTxuf0ZcYPais4w.jpeg" /><figcaption>Half Moon Bay, CA</figcaption></figure><p>Here I am</p><p>Sitting on the edge of a cliff</p><p>Couldn’t get better out of life</p><p>Here I am</p><p>Sitting close to cold water</p><p>Where past &amp; future doesn’t matter</p><p>Here I am</p><p>Sitting between cold and warm</p><p>Realizing nature could never be harm</p><p>Here I am</p><p>Looking at the roaring ocean</p><p>Feeling it’s power in my emotion</p><p>Here I am</p><p>Looking at waves</p><p>It feels the land</p><p>It compliments the land</p><p>It thanks the land,</p><p>Clears its way for the next one to feel the sand</p><p>Here I am</p><p>Looking at life</p><p>I’m feeling it</p><p>I’m complimenting it</p><p>I’m thankful for it</p><p>Someday I will clear my way for the new one!</p><p>— Karthikkeyan —</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a3176fa1d46" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[iOS App Architecture]]></title>
            <link>https://karthikkeyan.medium.com/ios-app-architecture-3f1d1400862f?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f1d1400862f</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Tue, 12 Jan 2016 12:33:05 GMT</pubDate>
            <atom:updated>2016-01-12T12:33:05.846Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I want to share my approach and experience I have used to architect iOS projects, which, at least, suits well for me.</p><p>In my earlier days of programming, I was scared of the term ‘Architecture’ and always avoided any discussion related to it. But after working on many projects I understood that,</p><blockquote><em>Architecting is nothing but organizing all, the independently working, layers in a best way that suits your project.</em></blockquote><p>There is no one fixed architecture that suits well for all the projects all the time. Each projects could have an unique approach.</p><p>Now that being said, it would introduce two questions to you,</p><ol><li>What are independently working layers</li><li>What do I mean by ‘suits your project’</li></ol><h4>What are ‘Independently Working Layers’</h4><p>This is a single or set of class/structure/protocols, basically code, that serves a specific purpose in project. Network Manager, Services Classes, Presentation Layer Class(View Controllers &amp; Views) are good examples. For example Network Manager and related files serves for only one purpose, that is, to handle network calls between server and client. This Network Manager should be working irrespective of what project it is, it can be plugged into some other projects as well.</p><h4>What is mean by ‘suits your project’</h4><p>Basically ‘<em>suits your project</em>’ is mean by ‘how data is passed between each layers of your project, from network manager to view controllers to views’.</p><p>Let me give you an example,</p><p>Let say the user is successfully logged in your app, you may need to fetch the user’s profile information from your REST API. You call the REST API and get back raw json object. Now that you have the raw json, you need to persist that data to your Core Data and get it back as a model object. Then the model object can be used by your view controllers to display.</p><p>The seems simple isn’t it?, Let me list out the layers involved in the single process,</p><ol><li><em>Views</em>: To display data physically and user interaction.</li><li><em>View Controller</em>: To manage views and models.</li><li><em>View Model</em>: To do all non-UI related operation of a View Controller.</li><li><em>Data Manager</em>: To persist your data to core data/sqlite/anything (we need not have call this as a separate layer, we could call it as a component).</li><li><em>Service</em>: The place where the network request/calls are constructed and initiated.</li><li><em>Network Manager</em>: The place where the actual network calls occurs.</li></ol><blockquote>Note: Some times you don’t need View Models, you can directly use Service Class. However, it is all based on your needs.</blockquote><p>I always go for MVVM pattern. I believe it is better than traditional MVC pattern. Check out this <a href="https://medium.com/@ramshandilya/lets-discuss-mvvm-for-ios-a7960c2f04c7#.y01n5qn1q">good article</a> to know more about MVVM.</p><p>The catch here is each layer can only talk to one layer below or above, not more than that. Example, View can talk to view controller but it definitely shouldn’t talk to Service Layer. Each layer does a specific task in your project and it should definitely do only that.</p><p>Here is the diagram,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*FX_sByV0ScsP3hleF3fGVQ.png" /><figcaption>High level Architecture that suits most of my projects</figcaption></figure><p>The above diagram is a high level architecture of most of my projects. All the layers are stacked one above the other. Meaning each layer can only communicate with the layer, one level, above or below.</p><p>Lets discuss each layers and its responsibility.</p><h4>View</h4><p>I don’t think we need an explanation for this. These are just views, where user can see and interact. In this layer you don’t have to do lot of work other than creating a clean and good UI &amp; UX.</p><p>The general mistakes I have seen(and I have done in the past ;P) in many projects is that, letting your views communicate with your Model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/236/1*d9EbmRxLbClz505hS0x84w.jpeg" /></figure><p>Let me give you an obvious example here,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*mj9u-2H0RJ8SLhQ_ls1C2A.png" /></figure><p>Here, FriendTableViewCell is a view and we are passing the Friend model object inside. So we are letting the cell extract information from our model object. This definitely is breaking the MVC pattern.</p><p>Here is how we should be writing,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*hyZdxAH0g6C10vBlGP01Qw.png" /></figure><p>I believe there is nothing wrong in this approach. Developers generally do these kind of mistakes in order to make their code clean.</p><blockquote>Breaking a design pattern to make your code clean is still an unclean code.</blockquote><h4>View Controller</h4><p>View controller is an important entity, it is where everything starts. It communicates with Views, Model Objects and View Models. Also optionally, some times, it communicates with Service Layer and Data Manager.</p><p>I recommend, always engage the view controller’s communication only with View Models. One of the main reasons is, if you interact with multiple layers, all your functionalities will be scattered around the entire place. It will make your debugging process hard and it makes the flow ugly. In my projects almost all view controllers will be backed by a separate view model.</p><h4>View Model</h4><p>There is no clear definition for view model so far, everyone has their own opinion on the concept of view model. I use view models to dump all the non-UI functionalities of a view controller or a particular module of my project. This strategy helps Unit Test the functionality of any view controllers.</p><p>List of things View Model could do,</p><ol><li>Communicate with appropriate Service Class</li><li>Communicate with Data Manager to save or retrieve data</li><li>Maintain controllers state. For example if user is filling a form, View Model can keep the all the filled form data.</li><li>Perform operation on view controllers data.</li><li>Parsing JSON object into your Model object</li></ol><p>Here is a simple example of View Model,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7f78b89aed9961a3d8e6a3d96bdd2bd/href">https://medium.com/media/c7f78b89aed9961a3d8e6a3d96bdd2bd/href</a></iframe><p>The above view model can be used by your Edit Profile View Controller. You can see that this view model does not contain UI code.</p><h4>Service Layer</h4><p>Service classes reside just above the Networking Layer, because your project specific API calls are handled here. In the beginning I confused myself between Network Layer and Service Layer, because both sounds like doing the same thing.</p><p>Let’s take user profile again as an example,</p><p>We could have a service class called <em>UserService</em>, this class knows how to compose user profile relate API requests and also knows how to interpret responses. When I say ‘interpret responses’, it means not only the knowledge of reading success responses, but also the knowledge of error responses(error codes &amp; error responses). So <em>UserService</em> is a complete package of profile related API calls.</p><blockquote>Note: Service layer compose the network requests and hand over that request to Network Layer to take care of physical API calls.</blockquote><p>Here is a simple example for Service Class,</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/45427ca88d213bbbb190cda552c7173b/href">https://medium.com/media/45427ca88d213bbbb190cda552c7173b/href</a></iframe><h4>Network Layer</h4><p>Network Layer is a general purpose component, which performs your physical API calls. It deals with underlying classes like <em>NSURLRequest</em>, <em>NSURLSession</em>, <em>NSURLConnection</em> and <em>NSOperationQueue</em>. <em>AFNetworking</em> would be good andand a well-known example for this Network Layer.</p><p>Basically your network layer knows nothing about your project and your server response. All it does is manage the underling network calls and give back the server responses.</p><p>In my experience, I understood one thing that, discussing with people would definitely help improve your approach. Each project by project and discussion by discussion, your architecting approach will progressively improve.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f1d1400862f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using C Libraries in Swift]]></title>
            <link>https://karthikkeyan.medium.com/using-c-libraries-in-swift-ea9279b0c3c3?source=rss-2beda720c2c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea9279b0c3c3</guid>
            <category><![CDATA[c-libraries]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Karthikkeyan Bala Sundaram]]></dc:creator>
            <pubDate>Mon, 04 Jan 2016 12:57:40 GMT</pubDate>
            <atom:updated>2016-01-04T12:59:25.093Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently, in one of my project, I got a requirement to sign all API requests with HMAC MD5.</p><p>Time to embrace Apple’s Cryptographic Libraries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*KBKwRF2mKRfTLT9VmlUReQ.jpeg" /></figure><p>There are many open source codes and tutorials available to accomplish it. I found below code by googling, thanks for someone who written this piece of code,</p><pre>import Foundation</pre><pre>import CommonCrypto</pre><pre>enum HMACAlgorithm {</pre><pre>    case MD5, SHA1, SHA224, SHA256, SHA384, SHA512</pre><pre>    func toCCEnum() -&gt; CCHmacAlgorithm {</pre><pre>        var result: Int = 0</pre><pre>        switch self { </pre><pre>        case .MD5:</pre><pre>          result = kCCHmacAlgMD5</pre><pre>        case .SHA1:</pre><pre>          result = kCCHmacAlgSHA1</pre><pre>        case .SHA224:</pre><pre>          result = kCCHmacAlgSHA224</pre><pre>        case .SHA256:</pre><pre>          result = kCCHmacAlgSHA256</pre><pre>        case .SHA384:</pre><pre>          result = kCCHmacAlgSHA384</pre><pre>        case .SHA512:</pre><pre>          result = kCCHmacAlgSHA512</pre><pre>        }</pre><pre>        return CCHmacAlgorithm(result)</pre><pre>    }</pre><pre>    func digestLength() -&gt; Int {</pre><pre>        var result: CInt = 0</pre><pre>        switch self {</pre><pre>        case .MD5:</pre><pre>          result = CC_MD5_DIGEST_LENGTH</pre><pre>        case .SHA1:</pre><pre>          result = CC_SHA1_DIGEST_LENGTH</pre><pre>        case .SHA224:</pre><pre>          result = CC_SHA224_DIGEST_LENGTH</pre><pre>        case .SHA256:</pre><pre>          result = CC_SHA256_DIGEST_LENGTH</pre><pre>        case .SHA384:</pre><pre>          result = CC_SHA384_DIGEST_LENGTH</pre><pre>        case .SHA512:</pre><pre>          result = CC_SHA512_DIGEST_LENGTH</pre><pre>        }</pre><pre>        return Int(result)</pre><pre>    }</pre><pre>}</pre><pre>extension String {</pre><pre>    func encrypt(algorithm: HMACAlgorithm, key: String) -&gt; String {</pre><pre>        let str = self.cStringUsingEncoding(NSUTF8StringEncoding)</pre><pre>        let strLen = UInt(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))</pre><pre>        let digestLen = algorithm.digestLength()</pre><pre>        let result = UnsafeMutablePointer&lt;CUnsignedChar&gt;.alloc(digestLen)</pre><pre>        let keyStr = key.cStringUsingEncoding(NSUTF8StringEncoding) </pre><pre>        let keyLen = UInt(key.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))</pre><pre>        CCHmac(algorithm.toCCEnum(), keyStr!, Int(keyLen), str!, Int(strLen), result)</pre><pre>        let data = NSData(bytesNoCopy: result, length: digestLen)</pre><pre>        result.destroy()</pre><pre>        return data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions())</pre><pre>    }</pre><pre>}</pre><h4>Module Mapping</h4><p>Everything is fine so far, isn’t it? The trouble comes when you import Common Crypto library into you code. You will see the below error,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*jap9uuJzthR0V0NXAQKi_Q.png" /><figcaption>Common Crypto Error</figcaption></figure><p>This is because swift compiler cannot find the <em>CommonCrypto </em>module because it is a <strong>C</strong> library. Again I googled for the solution and I found lots of answers which confused me even more. After a lot of trial-error I found a solution that works for me.</p><p>The solution is to help the swift compiler to find where the <em>CommonCrypto </em>library is located in your SDK path. In other words we need to map any <strong>C</strong> libraries to swift compiler.</p><p>Follow the steps below,</p><ol><li>Create a directory inside your project directory. The name of the your newly created directory must be the library name that you wanna use, in this case it is <strong>CommonCrypto</strong>.</li><li>Create <strong>module.map </strong>file inside the directory you have created.</li><li>Add the below code inside <strong>module.map </strong>file,</li></ol><pre>module CommonCrypto [system] {</pre><pre>    header “/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/CommonCrypto/CommonCrypto.h”</pre><pre>    link “CommonCrypto”</pre><pre>    export *</pre><pre>}</pre><p>So you project directory structure would looks something like this,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/367/1*_3zYyHyXeXo46PeliZzLXQ.png" /><figcaption>Module mapping directory structure</figcaption></figure><blockquote>Note: You don’t have to add these files in you project. Just create a directory and a map file.</blockquote><h4>Project Settings</h4><p>Now that you have your mapping files ready, we have to add that directory’s path, in <strong>Import Paths</strong> under <strong>Search Paths</strong> section in your <strong>Build Settings</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qa4EJ_gCeg3j1EHz3SNVdA.png" /><figcaption>Add Import Path</figcaption></figure><blockquote>Note: Since I have added <strong>CommonCrypto </strong>directory as a root level directory, I didn’t include the full path. Use <strong>$SRCROOT </strong>as a prefix if you created <strong>CommonCrypto</strong> directory in different location.</blockquote><p>Finally added <strong>$(SDKROOT)/usr/lib/system </strong>in your <strong>Library Search Paths</strong> under <strong>Search Paths</strong> section in your <strong>Build Settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JMQdR5PXk_g04F83qqsR7w.png" /><figcaption>Add Library Search Path</figcaption></figure><p>Thats it, now your should be able to use CommonCrypto C Library in your swift project.</p><p>Sample Encryption Code,</p><pre>print(“Hello World”.encrypt(HMACAlgorithm.MD5, key: “SecretKey123”))</pre><h4>Summary</h4><ol><li>Create a directory with your library Name</li><li>Add module.map inside that directory</li><li>Add that directory in Import Paths</li><li>Add <strong>$(SDKROOT)/usr/lib/system </strong>in Library Search Paths</li><li>Build and Run</li></ol><p>I have attached a sample project in <a href="https://github.com/karthikkeyan/Encryption.git">github</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea9279b0c3c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>