<?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 Tal Kanel on Medium]]></title>
        <description><![CDATA[Stories by Tal Kanel on Medium]]></description>
        <link>https://medium.com/@talkanel?source=rss-e4c8f13737b3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mjVPDdunc-lZQpCIqwvgFw.jpeg</url>
            <title>Stories by Tal Kanel on Medium</title>
            <link>https://medium.com/@talkanel?source=rss-e4c8f13737b3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 04:55:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@talkanel/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[Drawing the Line Where Engineering Become Over-Engineering]]></title>
            <link>https://medium.com/@talkanel/drawing-the-line-where-engineering-become-over-engineering-a8af6674d266?source=rss-e4c8f13737b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/a8af6674d266</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Tal Kanel]]></dc:creator>
            <pubDate>Sun, 01 Nov 2020 12:29:41 GMT</pubDate>
            <atom:updated>2020-11-01T21:29:48.370Z</atom:updated>
            <content:encoded><![CDATA[<h4>The deep-abstractions principle</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gmahCBO2LdErxepJB8KMFA.jpeg" /><figcaption>credits: <a href="https://github.com/eric19960304/hello-world-overengineering">https://github.com/eric19960304/hello-world-overengineering</a></figcaption></figure><p>I’m always thrilled to discover a new software principle. when I come across a good one, I experience a eureka. I know I’ll never see the code the same way.</p><p>In this article, I’m going to discuss the problem of over-engineering. I think the problem is that we don’t have a concrete definition, of when software engineering becomes an over-engineering. When we do know, it might be too late.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F5fXN7x7a5So%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D5fXN7x7a5So&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F5fXN7x7a5So%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8771c35ddb3799d2ffe1c40c03f502fd/href">https://medium.com/media/8771c35ddb3799d2ffe1c40c03f502fd/href</a></iframe><p>I’m going to explain an awesome principle addressing that problem. It suggested by <a href="http://web.stanford.edu/~ouster/cgi-bin/home.php">John Ousterhout</a>, Professor of Computer Science at Stanford University, and the author of the book <a href="https://www.goodreads.com/en/book/show/39996759-a-philosophy-of-software-design">A Philosophy of Software Design</a>. This guy isn’t another computer-science professor who’s disconnected from the software industry. He lives and breaths code. Folks like him, are exactly what our community needs!</p><p>We’re about to start. But first, it’s important we’ll clarify a thing on abstraction.</p><h3>What is abstraction?</h3><p>I believe there’s a misperception in the software industry about what abstraction really is: Some believe abstraction is about polymorphism, abstract classes, and interfaces. I myself used to think so.</p><p>In fact, abstraction is about a much greater idea: Encapsulating complexity and providing a way to communicate with it simply.</p><p>Take for example a laptop. It’s encapsulating an enormous amount of software and hardware layers. This complexity is spared from the user by a keyboard and screen, making communication with it easy.</p><p>In OOP languages, we create abstractions by extracting code to classes and functions with meaningful names. We don’t need any abstract classes or interfaces to do that. In other words, <strong>abstraction is modeling or, engineering. And over-abstraction is over-engineering.</strong></p><p>For the rest of the article, I’m going to refer to abstraction as a Class. But, the same ideas apply to other abstraction technics, such as components, modules, and micro-services.</p><p>As discussed, software abstractions are everywhere. it’s one of our fundamental tools to handle complexity. without it, the codebase will be a big ball of mud, that is impossible to understand.</p><p>But abstractions are not free. To add abstraction we need to add classes and functions, which adds some complexity to the codebase. There are many scenarios in which that complexity can do more damage than good. This raises a dilemma: <strong>How can we know if the complexity of adding the abstraction is worth the complexity it reduces?</strong></p><h3>A Java-made over-engineering case-study</h3><p>One of the over-engineered API’s ever made is Java’s <strong>original</strong> file’s IO mechanism. Someone at Oracle thought that providing a dedicated API to read and write to files is not generic enough. So they came up with the idea of the generic input/output streams. As result, this is how you use the API:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c4e03ab2489e002e0b9aaee359e6676/href">https://medium.com/media/4c4e03ab2489e002e0b9aaee359e6676/href</a></iframe><p>I’m 15 years programming in Java and still confuse between InputStream to OutputStream. And what the hell is BufferedInputStream anyway?<br>This API is very hard to understand.</p><h4>What went wrong?</h4><p>Looking only at Java’s API doesn’t tell the entire story. Java’s Sun JVM is written in C, which is a much lower-level language. You would expect from that to see a much more complex code to do the same in C. The problem is that this is the code you need to write in C to do the same:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bbd5f665c74f7cf1392ef9a77da1263/href">https://medium.com/media/8bbd5f665c74f7cf1392ef9a77da1263/href</a></iframe><p>The code in C is actually simpler and more elegant. This is crazy!</p><h3>The Deep Abstractions Principle</h3><p>According to Ousterhout, in order to reduce the overall software’s complexity, a class’s interface should be significantly simpler than its implementation. The only way to achieve that is to leave classes with some “meat”. Otherwise, you won’t gain anything out of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T0mCsBIGEmWrTzzr79LcVA.png" /><figcaption>Image created by the author of the article</figcaption></figure><p>As you can see, the class’s internal implementation should have some depth of complexity. How much depth? That’s relative to the complexity of its interface. It means, that API like Java’s streams, that requires it’s client to build five objects, should have a pretty deep implementation to justify that.</p><h3>Deep class example</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/15f0b4267076cfbf25548de3449fa816/href">https://medium.com/media/15f0b4267076cfbf25548de3449fa816/href</a></iframe><p>You can see clearly that the class’s interface isEligibleForPublish() is simple. Actually, it doesn’t get any simpler than a boolean function with no arguments…<br>The point is, that calling this function will replace a significantly more complex code. So the class is definitely deep. Therefore, this abstraction will likely reduce complexity.</p><h3>Shallow class example</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1306f9bfb3be5ddd17a5207b00cf60cd/href">https://medium.com/media/1306f9bfb3be5ddd17a5207b00cf60cd/href</a></iframe><p>While there is some information hiding here of the PersistencDataStore, and updateUserName() improves the readability, the function’s implementation is very shallow. The ratio between the interface to the implementation is almost one-to-one. According to the Deep Abstractions principle, there are high chances this class will add more complexity than do any good. In other words: Adding UserService is over-engineering.</p><h3>Some thoughts</h3><p>I think that the deep-abstractions principle makes perfect sense. What I love about it is, that it provides a great contrast to the single responsibility principle, which when taken to too literally, encourage tearing the code recursively into smaller parts. So the deep-abstractions principle keeps us from crossing the red line.</p><h3>Don’t let speculation and fears drive your design decisions</h3><p>Have you considered wrapping framework API’s just because their interface might change in the future? Have you added an abstraction layer just to make a code testable? And how many times you’ve added abstractions in the name of reusability, without knowing when or how you’ll need it?</p><p>In some scenarios, it makes sense to do so. Just keep in mind that adding an abstraction has a price, and it might slow you down.</p><p>The deep-abstractions principle will be useful in those cases. You could ask yourself questions like:</p><ul><li><em>Will this “Unplugger” device do any good?</em></li><li><em>What I had to do to unplug a device without having this “Unplugger” button?</em></li></ul><p>Watch the video, and think of it:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FbvjUpH5Yrus%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DbvjUpH5Yrus&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FbvjUpH5Yrus%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8a8e925a33049294eda5dbf5f105aa17/href">https://medium.com/media/8a8e925a33049294eda5dbf5f105aa17/href</a></iframe><h3>Summary</h3><p>The deep-abstractions principle helps to avoid over-engineering by drawing a line where additional modeling does more damage than good. Finding the right balance of where to apply it is a skill that should be practiced. I believe that keeping it in mind together with other programming principles brings the best outcomes.</p><p>Thank you for reading, and hope you find it useful. Feel free to share your thoughts or ask me questions on that matter.</p><p>For further reading:</p><ul><li><a href="https://www.amazon.com/t/dp/1732102201#ace-9859629705">A Philosophy of Software Design</a></li><li><a href="https://medium.com/@nakabonne/depth-of-module-f62dac3c2fdb">Depth of module</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a8af6674d266" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Private Functions Shouldn’t Be Used. Here’s What You Should Do Instead]]></title>
            <link>https://levelup.gitconnected.com/private-functions-shouldnt-be-used-here-s-what-you-should-do-instead-ceec746d5fd5?source=rss-e4c8f13737b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/ceec746d5fd5</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Tal Kanel]]></dc:creator>
            <pubDate>Wed, 21 Oct 2020 02:29:04 GMT</pubDate>
            <atom:updated>2020-10-21T16:24:23.339Z</atom:updated>
            <content:encoded><![CDATA[<h4>Friendly advice to produce a better codebase</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nshHnA-sGXs-OqiB" /><figcaption>Photo by <a href="https://unsplash.com/@mecdjino?utm_source=medium&amp;utm_medium=referral">Sitraka Rakotoarivelo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Every good programming concept can be explained with a simple real-life analogy. But is there an analogy to private functions?</p><p>In fact, there isn’t such. There are tons of examples of private fields, but none for private functions.</p><p>Take for example a car. Pressing the gas pedal is a public function. Its output is the movement of the wheels. This function has a very complex implementation, so private functions are expected.</p><p>When looking closely, no function is private. All there is are several parts interacting with each other, publically. Apparently, The only private functions you’ll find in the car are the ones in the car’s computer, within its software.</p><p>The same pattern can be found everywhere: Complex functionality is realized by the encapsulation of several connected parts. There aren’t any private functions fused directly to the public interface.</p><p>If private functions do not appear in any engineering branch, it doesn’t have a place in object-oriented software either.</p><p>Why? Because private functions are typically written in order to abstract from the public functions lower-level details. In other words, <strong>private functions make the class to violate the Single Responsibility Principle.</strong></p><p>Extracting code to functions is important. But, when doing so it’s better to seize this opportunity to <strong>write them as public functions of a different class</strong>.</p><h3>Example</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/25eae80c416b470728e715a5cccfa0e9/href">https://medium.com/media/25eae80c416b470728e715a5cccfa0e9/href</a></iframe><p>While extracting the email validation to the isValidEmail() function is a smart move, LoginPresenter is still busier with email validation more than it busy with its real work: Coordinating between the UI and the domain logic.</p><h3>Extracting email validation to another class</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2b8ef09a8915a92929c63ee4025ee38/href">https://medium.com/media/a2b8ef09a8915a92929c63ee4025ee38/href</a></iframe><p>By extracting the email validation to EmailValidator the following benefits are automatically granted:</p><ul><li>No noise of lower-level details</li><li>All the class is written in the same abstraction level</li><li>EmailValidator could be reused trivially</li><li>Email validation behavior can be tested in isolation</li><li>LoginPresentercould be tested by providing mocked EmailValidator</li></ul><p>Another problem is that private functions encourage private fields modifications. While sometimes it’s desired behavior, unintentional mutation of a field inside a private function tends to go under the radar. Therefore, private functions increase the likelihood of unexpected side effects.</p><p>Lastly, private functions give you a false illusion of encapsulation. Ironically, the existence of the private function is what makes breaking the class’s encapsulation easy: It is common to see programmers naively change access “private” to “public” at any opportunity, without necessarily giving too much thought to whether it’s safe.</p><h3>Conclusion</h3><p>By systematically extracting functions to specialized classes, the overall software architecture is improved. Going that path requires at first a different mindset, but from my experience, it pays off, and fast.</p><p>For further reading:<br><a href="https://carlosschults.net/en/are-private-methods-a-code-smell/">https://carlosschults.net/en/are-private-methods-a-code-smell/</a></p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! <a href="https://www.youtube.com/channel/UC3v9kBR_ab4UHXXdknz8Fbg?sub_confirmation=1"><strong>Subscribe to our YouTube channel</strong></a> or join the <a href="https://skilled.dev/"><strong>Skilled.dev coding interview course</strong></a>.</p><p><a href="https://skilled.dev/">Coding Interview Questions + Land Your Dev Job | Skilled.dev</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ceec746d5fd5" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/private-functions-shouldnt-be-used-here-s-what-you-should-do-instead-ceec746d5fd5">Private Functions Shouldn’t Be Used. Here’s What You Should Do Instead</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Dependency Injection Is a Good Thing for Us, the Programmers]]></title>
            <link>https://levelup.gitconnected.com/why-dependency-injection-is-a-good-thing-for-us-the-programmers-4bfcae3b485f?source=rss-e4c8f13737b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bfcae3b485f</guid>
            <category><![CDATA[software]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Tal Kanel]]></dc:creator>
            <pubDate>Tue, 21 Jul 2020 03:42:14 GMT</pubDate>
            <atom:updated>2020-07-21T12:57:22.663Z</atom:updated>
            <content:encoded><![CDATA[<h4>It’s all about loosely coupling. Let’s take a short coffee break in which I’ll explain it all.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r8VGaNQ91JdGcryD" /><figcaption>Photo by <a href="https://unsplash.com/@hautier?utm_source=medium&amp;utm_medium=referral">Christophe Hautier</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The examples are written in <strong>Kotlin</strong> but don’t make use of its special syntax capabilities so that every programmer will be able to understand.</p><p>What if our coffee machine wasn’t at the coffee station? What if instead, there was an empty space, and every time we wanted to drink coffee, we would have to construct the machine from scratch.</p><p>In software, everything runs a million times faster than reality, so it is legitimate to write code like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f403de81615f0ce121fe485ade3061c/href">https://medium.com/media/5f403de81615f0ce121fe485ade3061c/href</a></iframe><p>The problem though is that, in reality, no coffee machine can be built with an empty constructor. While construction performance might not be a factor, the construction complexity involved when using the coffee machine certainly will:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff8652c259ef3f26eb695d7608e07545/href">https://medium.com/media/ff8652c259ef3f26eb695d7608e07545/href</a></iframe><p>Can you tell by that code what the programmer is doing on her break?<br>Should a programmer return to work without drinking coffee just because she failed to construct a coffee machine? And how would it be possible to talk with all of these providers before drinking the coffee in the first place?<br>All of these are now the concerns of the poor programmer, who only wished to drink her coffee.</p><h4>But you can move it all to another class that is responsible to create a coffee machine, right?</h4><p>Good idea. This is exactly what the <a href="https://en.wikipedia.org/wiki/Factory_method_pattern">Factory design pattern</a> is all about.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9811744abcfb52faf7d52dc8c9540f76/href">https://medium.com/media/9811744abcfb52faf7d52dc8c9540f76/href</a></iframe><p>It cleans the code, but sooner or later it will have to change again. That’s because we, the programmers, are spoiled: We like to taste coffee from different machines that are not necessarily constructed in the same factory.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/81981f641b44d0d49b92e77969deedf5/href">https://medium.com/media/81981f641b44d0d49b92e77969deedf5/href</a></iframe><p>So as you can see, the <strong>Factory postpones construction complexity</strong> but does not make it disappear.</p><h4>Ok. So what is your suggestion?</h4><p>In real life, tool construction and its usage are two different processes segregated from each other. Humankind has always taken advantage of that. Think about it. Did the prehistoric-man build his spear just before he was about to stab the mammoth?</p><p>Our programmer doesn’t need to be busy in coffee machine construction during his break. She surely doesn’t need to bring a new machine from the factory. A coffee machine is just a tool used by the programmer to quickly make the coffee so that she could get back to the real work: writing code!</p><h4>Nice theory. What does Dependency Injection have to do with that?</h4><p>Dependency Injection is an architectural approach in which the construction code of classes and their usage are segregated systematically. <strong>How?</strong> There are several techniques, but one of them is <a href="https://en.wikipedia.org/wiki/Dependency_inversion_principle"><strong>construction dependencies inversion</strong></a><strong>.</strong> It means that the CoffeeMachine construction shouldn’t be tightly coupled<strong> </strong>to the Programmer who uses it. Instead: The Programmer’s construction, unintuitively, should depend on the CoffeeMachine:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8f46c0a2eb800866a2339b2409fdb083/href">https://medium.com/media/8f46c0a2eb800866a2339b2409fdb083/href</a></iframe><h4>But doesn’t this just move the coffee machine construction to the class that holds the Programmer?</h4><p>Not necessarily. Take for example a SoftwareCompanyX who wishes to hold aProgrammer: By following again <strong>Dependencies Inversion Principle</strong>, we will just make the SoftwareCompanyX’s construction depend upon the Programmer instead of tightly coupling the Programmer’s construction to the SoftwareCompanyX:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2894b38d57a19aae49b91a1d0cfad017/href">https://medium.com/media/2894b38d57a19aae49b91a1d0cfad017/href</a></iframe><p>This is great because the Programmer can move easily to another SoftwareCompany and take the coffee breaks there. All she will need is someone who provides her a reference to the CoffeeMachine, and she’s back in business!</p><h4>Are you kidding me? Eventually, someone will have to construct everything</h4><p>Exactly! This someone will be <strong>the only one</strong> who needs to handle construction details for one particular cluster of classes. This will also be his single responsibility. This root of composition is what is known in most dependency injection frameworks as Module.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a327b95fbee6a106d673d296db93bd2b/href">https://medium.com/media/a327b95fbee6a106d673d296db93bd2b/href</a></iframe><p>So the SoftwareCompanyModule is taking care of connecting everything and exposes externally only the SoftwareCompany.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d89bb1c56d29db5861f19467be8ad4b7/href">https://medium.com/media/d89bb1c56d29db5861f19467be8ad4b7/href</a></iframe><h4>Interesting. So why do I need a Dependency Injection framework?</h4><p>There are still some questions that need an answer:</p><ul><li>Who should instantiate a module?</li><li>What if a module depends on other modules?</li><li>How to share the same object instance in several places?</li><li>What about unit testing?</li></ul><p>Dependency Injection frameworks help with these challenges, so you can focus on your own domain challenges instead of reinventing the wheel.</p><p>Coffee break is over now. Thank you for listening, and I hope you learned something new. I’d love to hear your thoughts and answer questions on this topic that you might have.</p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! <a href="https://www.youtube.com/channel/UC3v9kBR_ab4UHXXdknz8Fbg?sub_confirmation=1"><strong>Subscribe to our YouTube channel</strong></a> or join the <a href="https://skilled.dev/"><strong>Skilled.dev coding interview course</strong></a>.</p><p><a href="https://skilled.dev/">Coding Interview Questions + Land Your Dev Job | Skilled.dev</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bfcae3b485f" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/why-dependency-injection-is-a-good-thing-for-us-the-programmers-4bfcae3b485f">Why Dependency Injection Is a Good Thing for Us, the Programmers</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why the Dagger Needs a New Hilt?]]></title>
            <link>https://blog.devgenius.io/why-the-dagger-needs-a-new-hilt-e6ed7012b228?source=rss-e4c8f13737b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6ed7012b228</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Tal Kanel]]></dc:creator>
            <pubDate>Thu, 02 Jul 2020 02:49:33 GMT</pubDate>
            <atom:updated>2020-07-07T04:49:58.256Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why the Dagger Needs a New Hilt</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*om-_lsw_18ixFvpiWPIrjw.jpeg" /></figure><p>In my fifth year as a programmer, I finally understood what <a href="https://en.wikipedia.org/wiki/Dependency_injection#:~:text=In%20software%20engineering%2C%20dependency%20injection,object%20is%20called%20a%20service.">dependency injection</a> is all about, and why I need it. Soon after, I realized going that way without a DI framework is impractical. I found Dagger and decided to use it. This was my initial thought when I followed the guidelines:</p><blockquote>What the hell is a component??!! All I wanted is to use classes from my module!</blockquote><p>I believe the source of confusion in Dagger is that besides being a DI framework, it also dictates an additional architectural approach: <a href="https://en.wikipedia.org/wiki/Component-based_software_engineering">Component-based application development</a>.</p><h4>Understanding components by example from real life</h4><p>The human body is a complex system. It contains millions of functionalities and trillions of cells. But it also can be described as a small discrete number of independent organs with clear boundaries. Thanks to that, doctors can provide the right treatment for a specific organ, and even replace it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*wO5tUT-nnQPmicsM6HxWmw.jpeg" /></figure><p>This pattern appears everywhere: big systems are divided into a small discrete number of parts, each of which has its own functionality.</p><p>An Android application is a software system. Can software be understood from its classes’ descriptions? <br>Of course not! A common software project will have thousands of classes. We will have to use an additional abstraction layer that is not part of Java or Kotlin.</p><h4>Software component</h4><p>A <a href="https://simplicable.com/new/software-components#:~:text=Software%20components%20are%20parts%20of,interchangeable%20parts%20of%20a%20machine.">software component</a> is a bunch of functionalities encapsulated behind an interface that creates a clear boundary defining what is internal or external to the component. <br>A component will usually be made up of several classes joined together for achieving a purpose. Some of these classes might be part of its public API, and some might be internal to its implementation:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1b2193900dc86cb796b7a5a12d147dfd/href">https://medium.com/media/1b2193900dc86cb796b7a5a12d147dfd/href</a></iframe><p>In this particular example: LocationManager<em>, </em>LocationListener<em>, </em>and Location are the APIs exposed by the LocationManager component<strong>,</strong> but there are probably many more classes under the hood used internally for the implementation.</p><h4>Ok. So what does Dagger have to do with it?</h4><p>When your code is properly arranged into components — classes don’t just float on the project’s space in a module, waiting to be grabbed. Classes should not be the <a href="https://en.wikipedia.org/wiki/First-class_citizen">first citizens</a> at all! They are just building blocks for components.</p><p>With this mindset, Dagger’s API provides a mechanism to <strong>build components and not classes.</strong></p><p>I personally believe that packaging code by components is the way to go, but making it part of the DI framework APIs has certainly made Dagger harder to understand.</p><p>If that’s not enough, Since Android does not let you instantiate the Activity / Service<em> </em>component, Dagger can’t build it. So for android constructs, <strong>the interface annotated with </strong><strong>@Component is not really the component</strong>. It’s just the internal content of the “real” component that during a call to onCreate()<em> </em>should be injected into itself:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3692b153fb392d201afafec2959fd74/href">https://medium.com/media/e3692b153fb392d201afafec2959fd74/href</a></iframe><h4>So what changed in Hilt?</h4><p>Google understood these conceptual gaps but wanted to provide a backward-compatible solution. Therefore, in Hilt, they created an additional abstraction layer on top of Dagger’s API that <strong>creates these components for you</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d82c4177a5cff29909de544002eb0755/href">https://medium.com/media/d82c4177a5cff29909de544002eb0755/href</a></iframe><p>Instead of creating the Dagger component, you just need to extend ComponentActivity<em>, </em>add @AndroidEntryPoint and specify in the modules definition into which component type it can be “installed”.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fa8edf1c6c2bc5c9b3c5c1c928f635c/href">https://medium.com/media/1fa8edf1c6c2bc5c9b3c5c1c928f635c/href</a></iframe><p>So finally, the component is really the component, and things make sense.</p><h4>Conclusion</h4><p>If you are already using Dagger — replacing it with Hilt won’t gain you extra superpowers. If you are new to DI frameworks — Hilt will probably be easier to integrate. Consider that Hilt will add additional <a href="https://www.techyourchance.com/dagger-hilt/">annotation processing on top of Dagger’s that might slow your build time</a>. By understanding Dagger’s “component” philosophy and pitfalls, you can avoid it.</p><p>If you liked my explanation then you may also find the <a href="https://medium.com/@talkanel/my-recipe-for-a-rock-solid-system-design-d1ff3d63cb55">approach I’m suggesting to define application components</a> to be useful.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6ed7012b228" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/why-the-dagger-needs-a-new-hilt-e6ed7012b228">Why the Dagger Needs a New Hilt?</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My recipe for a rock-solid system design]]></title>
            <link>https://blog.devgenius.io/my-recipe-for-a-rock-solid-system-design-d1ff3d63cb55?source=rss-e4c8f13737b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1ff3d63cb55</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Tal Kanel]]></dc:creator>
            <pubDate>Mon, 01 Jun 2020 13:56:19 GMT</pubDate>
            <atom:updated>2020-07-14T16:40:17.440Z</atom:updated>
            <content:encoded><![CDATA[<h3>My Recipe for a Rock-Solid System Design</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wUB2pRL2FmeA2acPlZepwQ.jpeg" /></figure><p>One critical aspect of system architecture is efficiently organizing functionalities across classes and packages.</p><p>A class with too many functions (i.e. god class) will likely be changed frequently and as a result, will be unstable. Furthermore, any client of that class will be unstable too.</p><p>On the other hand, splitting functions across too many classes will result in an unpractical, fragmented system that is over-engineered and hard to understand.</p><p>Therefore, deciding which functionalities should be packed together will have major consequences on the future maintainability of the system.</p><p>But how do we group together the right functions?</p><h3>How things work in non-software systems</h3><p>Let’s reverse engineer an elevator system:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*NcH1iu-tLYxJ8hrCoDjUPA.jpeg" /></figure><p>This system obviously has several functions grouped together:</p><ul><li><em>orderElevator(moveDirection: MoveDirection)</em></li><li><em>getCurrentCabinFloor() //to display in what floor the elevator at.</em></li></ul><p>but inside the elevator’s cabin, there are additional functions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*TVknJ0HDVmFhYmcahIXkTg.jpeg" /></figure><p>So there’s an additional, separate interface in the system:</p><ul><li><em>selectFloor(floorNum: Int)</em></li><li><em>openDoor()</em></li><li><em>closeDoor()</em></li><li><em>alert()</em></li></ul><p>Each elevator should be maintained and configured, so there will be all kinds of functions for those purposes:</p><ul><li><em>setTimeBeforeCloseDoor(time: Long)</em></li><li><em>activate() //Turns on the elevator service</em></li><li><em>deactivate() //Turns off elevator service</em></li></ul><p>Where would these functionalities go? Should they be added to one of the former interfaces?</p><p>Of course not! <br>The user of an elevator service should be restricted from using functionalities intended only for an elevator operator.</p><p>The operator will usually get its own interface to control these functions.</p><p>In other words, in the elevator system, functions are grouped based on <strong>actors </strong>and <strong>use-cases:</strong></p><p>The <strong>actors</strong> are:</p><ul><li><em>Caller</em></li><li><em>Passenger</em></li><li><em>Operator</em></li></ul><p>The use-cases are:</p><ul><li><em>Call elevator</em></li><li><em>Choose floor</em></li><li><em>Configure elevator</em></li></ul><p>So the functionalities are separated into the following interfaces:</p><ul><li><strong><em>ElevatorBookingService</em></strong><em><br>+ orderElevator()<br>+getCurrentCabinFloor()</em></li><li><strong><em>ElevatorCabinService</em></strong><em><br>+selectFloor()<br>+openDoor()<br>+closeDoor()<br>+alert()</em></li><li><strong><em>ElevatorOperatorService</em></strong><em><br>+activate()<br>+deactivate()<br>+setTimeBeforeClose()</em></li></ul><p>Extracting a dedicated interface for each use-case ensures each actor using the system will <strong>depend only on the functionality it needs, according to its role.</strong></p><p>Many similar examples can be found in the physical world, such as telephone systems, cars, and so on.</p><p>The principles that apply in all of these system’s interfaces are:</p><ul><li>Functionalities used together by the same actor are packed together in the same component interface.</li><li>An actor who uses a <strong>specific</strong> system interface should<strong> </strong>make use of this<strong> whole </strong>interface.</li></ul><p>The combination of these two principles ensures that every actor in the system depends only on what it needs. This separation reduces system vulnerability to the wrong type of usages and redundant dependencies between roles.</p><p>If these principles apply in several systems engineering disciplines — are software systems an exception?</p><h3>Component-based system design algorithm</h3><p>If what you are looking for is a system with components segregation feats to your <strong>specific system requirements — </strong>I’ve made up an <strong>algorithm to design a system</strong> that <strong>ensures </strong>this property.</p><p>The algorithm is based on the <a href="https://link.springer.com/chapter/10.1007/978-3-540-85289-6_4">KobrA approach</a> suggested by the Fraunhofer Institute for Experimental Software Engineering.</p><ol><li><em>Create an empty functions list &#39;L&#39;</em></li><li><em>For</em><strong><em> each use case</em></strong><em> identified in the system’s analysis:<br> For each action in the use-case </em><strong><em>performed by an actor</em></strong><em>:<br>add to ‘L’ an appropriate function ‘f’ (if it does not already </em>exist<em>)</em></li><li><em>For each function ‘f’ in ‘L’ :<br> if there is an interface ‘I’ for which adding ‘f’ to it preserves the same </em><strong><em>using actors</em></strong><em> </em><strong><em>group </em></strong><em>then add ‘f’ to ‘I’.<br>otherwise: create a new interface ‘I’ and add ‘f’ to it.</em></li><li><em>Go over all created interfaces and functions, and provide meaningful names based on what each interface contains</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*FFC7dXq4gWdyZgfp1GZjsg.jpeg" /></figure><h3>Example</h3><p>Let’s analyze part of a typical Android alarm clock application:</p><p><em>use-case name: </em><strong><em>Create new alarm</em></strong><em><br>known actors: AlarmConfigurationPresenter<br>sequence flow:</em></p><ol><li><em>The actor provides the system a request-form with alarm description</em></li><li><em>The system saves the alarm.</em></li></ol><p><em>use-case name: </em><strong><em>Delete an alarm</em></strong><em><br>known actors: AlarmConfigurationPresenter, AlarmsListPresenter<br>sequence flow:</em></p><ol><li><em>The actor provides the system alarmId it wishes to delete.</em></li><li><em>The system searches if there is such alarmId. if found → deletes it.</em></li></ol><p><em>use-case name: </em><strong><em>Get saved alarms</em></strong><em><br>known actors: AlarmsListPresenter<br>sequence flow:</em></p><ol><li><em>The actor requests from the system list of of all alarms</em></li><li><em>The system performs a search and returns the list of all alarms</em></li></ol><p><em>use-case name: </em><strong><em>Toggle alarm activation</em></strong><em><br>known actors: AlarmConfigurationPresenter, AlarmsListPresenter<br>sequence flow:</em></p><ol><li><em>The actor requests the system to activate or deactivate an alarmId</em></li><li><em>The system taking care of scheduling or unscheduling of the alarm based on the actor’s request.</em></li></ol><h3>Applying the algorithm</h3><p><strong>Steps 1&amp;2</strong> (list of all actions performed by actors):</p><p><strong><em>fun </em></strong><em>addNewAlarm(request: AddRequest)<br></em><strong><em>fun </em></strong><em>deleteAlarm(alarmId)<br></em><strong><em>fun </em></strong><em>getAllAlarms(): List&lt;AlarmInfo&gt;<br></em><strong><em>fun </em></strong><em>activateAlarm(alarmId)<br></em><strong><em>fun </em></strong><em>deactivateAlarm(alarmId)</em></p><p><strong>Steps 3 </strong>(divide to interfaces by actors combinations groups):</p><ul><li><em>ComponentInterface1<br></em><strong><em>actors:</em></strong><em> AlarmConfigurationPresenter <br></em><strong><em>fun </em></strong><em>addNewAlarm(request: AddRequest)</em></li><li><em>ComponentInterface2 <br></em><strong><em>actors: </em></strong><em>AlarmsListPresenter<br></em><strong><em>fun </em></strong><em>getAllAlarms(): List&lt;AlarmInfo&gt;</em></li><li><em>ComponentInterface3 <br></em><strong><em>actors:</em></strong><em> AlarmConfigurationPresenter, AlarmsListPresenter<br></em><strong><em>fun </em></strong><em>activateAlarm(alarmId: String)<br></em><strong><em>fun </em></strong><em>deactivateAlarm(alarmId: String)<br></em><strong><em>fun </em></strong><em>deleteAlarm(alarmId: String)</em></li></ul><p><strong>Steps 4</strong> (re-evaluate all namings based on the segregation context):</p><ul><li><strong><em>AlarmsRegistryService</em></strong><em><br></em><strong><em>fun </em></strong><em>register(request: RegisterAlarmRequest)</em></li><li><strong><em>AlarmsStoreService</em></strong><em><br></em><strong><em>fun </em></strong><em>getAllAlarms(): List&lt;AlarmInfo&gt;</em></li><li><strong><em>AlarmsMaintenanceService</em></strong><em><br></em><strong><em>fun </em></strong><em>activate(id: String)<br></em><strong><em>fun </em></strong><em>deactivate(alarmId: String)<br></em><strong><em>fun </em></strong><em>delete(alarmId: String)</em></li></ul><p>What I love about this approach is that I really couldn’t predict before applying the algorithm that these are the components I would end up with.</p><p>Now we have components for which each user <strong>depends on the entire component;</strong> no user has access to unused functionalities.</p><p>Looking closely at the generated interfaces —the segregation makes perfect sense. Take for example the <em>AlarmsRegistryService:<br></em>A use-case related to alarm registration should not have access to functionalities affecting existing alarms.<br>Furthermore, as the system will grow, there will probably be additional functionalities and data models related to alarm registration; because they would be used in conjunction with the <em>register() </em>function<em>, </em>they could reasonably depend on <em>AlarmsRegistryService</em>.</p><p>One might argue that this type of interface segregation is too circumstantial and sensitive to future product requirements. For example — creating new alarms directly from the AlarmsListPresenter<em>. </em>Yes, it is. But, because every component<strong> </strong>is <strong>designed specifically to its use-case</strong> — it will be perfectly clear <strong>which use-cases might be affected</strong>. Therefore, it will be easy to change. Furthermore, there is not really a way to design a system to be future-proof to all possible requirements; an attempt to do so will probably result in a complex, over-engineered system.</p><p>Another good “side-affect” of this design technique is that the structure that emerges from this modeling tends to reflect clearly the business domain structure, which makes developers and other business stakeholders speak in the same language. That’s in contrast to the structure that emerges when focusing <strong>primarily </strong>on software layers, architectural patterns, or specific framework rules.</p><p>Lastly, the design algorithm ensures that for the same system analysis — the <strong>same design will be made</strong>; in a team of several programmers working on the same code base, this saves time and improves consistency.</p><p>Like a good song’s lyrics &amp; melody hanging on by a thread on the edge of ever-changing sound effects and genres, so too does sound code quality on the edge of the ever-changing technologies and frameworks.</p><p>Let’s make together a future of great music!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1ff3d63cb55" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/my-recipe-for-a-rock-solid-system-design-d1ff3d63cb55">My recipe for a rock-solid system design</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Write Professional Code Using the Command Query Separation Principle]]></title>
            <link>https://medium.com/better-programming/writing-professional-code-with-command-query-separation-principle-470c096949e9?source=rss-e4c8f13737b3------2</link>
            <guid isPermaLink="false">https://medium.com/p/470c096949e9</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Tal Kanel]]></dc:creator>
            <pubDate>Thu, 27 Feb 2020 11:02:30 GMT</pubDate>
            <atom:updated>2020-03-03T22:56:46.879Z</atom:updated>
            <content:encoded><![CDATA[<h4>Improve your codebase</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hqaqaXqqxJ6s-sXJpUpbTQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@0asa?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Vincent Botta</a> on <a href="https://unsplash.com/s/photos/particles?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p><a href="https://www.youtube.com/watch?v=Q1YqgPAtzho&amp;t=3s">One fundamental fact of quantum mechanics </a>challenges our basic perception of the world: Observing something alters its behavior.</p><p>This is crazy! In real life, you wouldn’t expect the act of watching television to alter the original content recorded in the studio.</p><p>For the same reason, you wouldn’t expect a file browser application to make changes to the files it displays every time it is opened. This behavior would be useless — you couldn’t afford to open the file browser without worrying about unwanted changes.</p><p>In software engineering, the same principle, of dividing data observation from modification, applies. Take a database, for example. There’s a clear separation between the query, insertion and deletion methods. You wouldn’t write data-changing code in the implementation of the query() method.</p><p>This segregation makes it easy to use the database API without having to reason about what could happen when each of these functionalities is used.</p><p>If this segregation makes sense for the database, why not enforce it in every functionality we write in our code-base? After all, each piece of code eventually comes down to querying data or executing commands which affect data.</p><h3>Example</h3><p>It might be tempting to pack some code in a function like this:</p><pre>fun scheduleAlarmIfNeeded(alarmInfo: AlarmInfo)</pre><p>You can have an idea of what it does, but let’s take a moment and think about how can we describe its behavior in a single sentence.</p><p>In fact, there is no way to describe the behavior in one sentence because you must split the function behavior to two different scenarios:</p><ol><li>Function called if alarm already scheduled.</li><li>Function called when alarm is not scheduled.</li></ol><p>This means that a reader of code using this function has to invest additional effort to understand what it does. They would probably have to also read the function implementation, just to be on the safe side.</p><p>When we declare a function, we hope to reuse it more than once. Functions like this have no chance to be used anywhere other than in very high-level business logic procedures.</p><h3>Applying Command Query Separation</h3><pre>if (!isAlarmScheduled(alarmInfo.id)) {<br>    scheduleAlarm(alarmInfo)<br>}</pre><p>There are now two separate functionalities. High-level procedure will now have to contain three lines instead of one, but it will be much more readable.</p><p>Another positive effect of this separation is that there are plenty of good examples of how each one of these two functions (or different APIs) could be reused. For example:</p><ul><li>Other business logic could make use of knowledge if alarm scheduled or not.</li><li>They could show the current scheduling state in the UI to the user.</li></ul><p>This architectural approach goes hand in hand with the functional programming paradigm, which encourages you to isolate and avoid state-dependent code and write descriptive functions with clear inputs and outputs.<br>Separating “commands” functionality, which mutates something in the system, from functionalities responsible for querying data, makes functional code inevitable.</p><p>It can be easy to approach software engineering as a craft or an art.<br>However, I believe our goal should be to set rules and principles to ensure a deterministic way to produce robust, reusable and scalable code.</p><p>From my experience, following rules like CQS (Command Query Separation) improves these factors dramatically.</p><p>Further reading:</p><ul><li><a href="https://en.wikipedia.org/wiki/Command%E2%80%93query_separation">Command-query separation - Wikipedia</a></li><li><a href="https://martinfowler.com/bliki/CommandQuerySeparation.html">bliki: Command Query Separation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=470c096949e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/writing-professional-code-with-command-query-separation-principle-470c096949e9">How to Write Professional Code Using the Command Query Separation Principle</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>