<?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 Nelson Leme on Medium]]></title>
        <description><![CDATA[Stories by Nelson Leme on Medium]]></description>
        <link>https://medium.com/@discovererxcviii?source=rss-21aeb3c0e3e2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*p0MvHWH5zFEEtAYG</url>
            <title>Stories by Nelson Leme on Medium</title>
            <link>https://medium.com/@discovererxcviii?source=rss-21aeb3c0e3e2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:45:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@discovererxcviii/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[Simplifying Using Spinners in Android]]></title>
            <link>https://medium.com/geekculture/simplifying-using-spinners-in-android-ad14f8f1213d?source=rss-21aeb3c0e3e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad14f8f1213d</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Nelson Leme]]></dc:creator>
            <pubDate>Mon, 01 Nov 2021 21:29:30 GMT</pubDate>
            <atom:updated>2021-11-02T09:14:57.570Z</atom:updated>
            <content:encoded><![CDATA[<h4>A nifty little class that will simplify a bunch using spinners in your Android apps (in Kotlin, of course!).</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r9EeCmcRUWkfLDEt" /><figcaption>Photo by <a href="https://unsplash.com/@sadswim?utm_source=medium&amp;utm_medium=referral">ian dooley</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Spinners are very useful widgets when creating user experiences in Android. They give a clear indication to the user of what choices are available when the user has to pick among different options, and they save space in small screens by collapsing once the user makes a choice. However, putting together the code for using a spinner unfortunately involves dealing with some boilerplate code: code that is not there to describe the functionality you are trying to achieve, but just to deal with some of the complications of using spinners in Android, and code that has to be repeated in many places.</p><p>Fortunately, though, one of the beauties of programming is that you can always find ways to get rid of repetitive chores. In this article, I show a small piece of code that you can reuse in many places when all you need is a simple spinner that displays the text of some options to the user and returns a string value that corresponds to the option the user selected. It is all encapsulated in a class called BindableSpinnerAdapter (I will be the first to admit that coming up with catchy names is not my forte) which you can see below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4b552810240c619bd9175141a6389ff1/href">https://medium.com/media/4b552810240c619bd9175141a6389ff1/href</a></iframe><p>Notice that this class is thought in terms of a MVVM (Model-View-ViewModel) architecture: if your app is not there yet, perhaps this will give you the impetus to get there! As such, this class makes the assumption that there will be a ViewModel object, and also that the ViewModel object will be available via Data Binding in the layout of your screen. With those assumptions in mind, the BindableSpinnerAdapter class makes things very easy for the developer: you don’t need to create an adapter, in fact you don’t even need to do anything at all about the spinner in the Activity class. Just put the code file above in your project (or, if you are so inclined, you can include the code above in a nice little library of Android utilities) and everything is automatically taken care for you just by adding this little changes in the layout of your Activity:</p><pre>&lt;Spinner<br> […]<br> spinnerItems=”@{viewModel.items}”<br> selectedSpinnerItem=”@={viewModel.selectedItem}” /&gt;</pre><p><strong>NOTE:</strong> the “@={…}” in the selectedSpinnerItem InverseBindingAdapter is important. That is what indicates to the XML processor that this is an <strong>inverse</strong> BindingAdapter. Without that this code does not work.</p><p>In your ViewModel, expose items and selectedItem properties as LiveData, and there you have it. Then, to populate the spinner, just post a value corresponding to a list of BindableSpinnerAdapter.SpinnerItem objects to items and that will do the trick. The SpinnerItem object contains two properties: a text to be displayed in the spinner, and a value, corresponding to any string value that corresponds to that spinner option (for example, a specific string code that needs to be sent over the wire to an API).</p><p>In order to get when the user selects an option in the spinner, you can just rely on the selectedItem property of the ViewModel. Just observe that LiveData property and your code will be called every time the user selects an option. However, remember that you cannot use lifecycleOwner objects inside of a ViewModel: the way to go is to transform the selectedItem LiveData property using a LiveData.map() call. Transform selectedItem into a spinnerOptionChanged LiveData property, for example, and don’t forget to observe spinnerOptionChanged in your Activity (LiveData objects don’t work if they don’t have a lifecycleOwner somewhere).</p><p>And with that, it becomes very easy to add spinners to the UI of your app and you can get rid of a lot of boilerplate code. Of course, the class above is not perfect: if I had more time, I think I could make some more improvements on it (maybe use some generics?…) but I think as it is it can help you quite some. Nevertheless, feel free to suggest modifications and/or improvements, or to change this code to whatever suits you best. That’s the beauty of developers sharing code: working together can make the work for all of us a little easier. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad14f8f1213d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/simplifying-using-spinners-in-android-ad14f8f1213d">Simplifying Using Spinners in Android</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The “Programming Popes”]]></title>
            <link>https://medium.com/geekculture/the-programming-popes-d4d08560881a?source=rss-21aeb3c0e3e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4d08560881a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Nelson Leme]]></dc:creator>
            <pubDate>Thu, 06 May 2021 19:56:32 GMT</pubDate>
            <atom:updated>2021-05-06T22:13:21.006Z</atom:updated>
            <content:encoded><![CDATA[<h4>Or how some people have a hard time believing that they are not infallible.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qpH9Aaropaxwcsav" /><figcaption>Photo by <a href="https://unsplash.com/@mudmanuk?utm_source=medium&amp;utm_medium=referral">Paul Carroll</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>I’ve seen this in various software development organizations. One of the developers in the team (possibly more than one, but then, I really pity you) is supposedly a “very knowledgeable” developer. A guy who really “knows a lot”. Pretty soon, you figure out that his word is law: if he has said it, then it is the end of the discussion, if there was even a discussion. Because he is never wrong, even when he is wrong. He is the “pope” of your development team.</p><p>Let me make a clarification at this point. I use “pope” in quotes because, evidently, I’m not referring to the leader of the Roman Catholic Church. I’m just making use of the word to refer to the software development professionals that you can not argue with because they judge themselves to be infallible. And not only that: through whatever dynamic you may have in a given development team, the ones in charge of the team start believing that the “pope” never makes a mistake.</p><p>But, of course, everybody makes a mistake.</p><p>And one day you may be the unfortunate developer that realized that the “pope” made a mistake.</p><p>There is no way around it: the “programming pope” in your team was wrong. You check and recheck, but clearly there is a problem, and you have no choice but report that the “pope” of your team made a mistake and it needs to be fixed. And that’s when <em>your </em>problems start! Because the “pope” will never, <em>ever</em>, admit that he was wrong (by the way, I use “he” here just as a convenience, but when it comes to “programming popes” they come in all genders, sexual orientations and pronouns). But he <em>is </em>wrong! So, with no other choice, you have to go above and beyond, and spend way more time than it is needed in order to prove that something is wrong and it needs to be done differently.</p><p>It can go to a ridiculous point: you feel like you will have to go all the way down to proving that Alan Turing was actually right when he defined the concept of Turing machines. It is a complete waste of time and it saps not only your morale, but the morale of your coworkers too: they see what’s happening and they all fear that they will be the next one to find a mistake by the “pope” and they will have to check and recheck everything numerous times and have their energy drained as well.</p><p>And the worst part is, after everything is proven beyond any shadow of a doubt, the “pope” will only very begrudgingly say something like “yeah, I guess you may be right” and immediately move on (<em>if </em>he accepts that he’s wrong). No recognition for all your effort in solving this problem. And, of course, no “sorry for your trouble”. Worst still, no learning from the experience: the “pope” will move on, still sure of his infallibility. And, finally, no recognition by management that whatever value the “pope” may be generating, it is being wasted by the time and effort that developers are having to spend to battle with the “pope”.</p><p>“Programming popes” are not all equal. There are different kinds of “popes”, some of which are worse than others. I would claim that the least bad of them is the <strong>truly knowledgeable pope</strong>: this is the developer who really knows a lot about a given subject, and indeed most of the time he is correct. However, given that nobody is infallible, now and then he makes a mistake, even though he will never admit that. Because he actually knows a lot, when you find an error by him, at the beginning you doubt yourself: it will take quite some time for you to believe that, actually, he was wrong. And the time you took for accepting that the pope made a mistake will have to be spent again in order to convince others, and finally to convince the pope himself. And he may never be convinced! The team may have to finally fix the issue, but the pope may still believe that he was just misunderstood.</p><p>On the opposite side of the scale you have the <strong>know nothing pope</strong>. This is the guy that, amazingly, actually knows very little but somehow managed to gather a reputation of being supremely knowledgeable. This guy should be a politician (and he may end up becoming one): he manages to talk a lot and give everybody the impression that he is imparting deep knowledge but when you look up close you realize that he did not say much, if anything at all. Again, on occasion, you will find out that something he made was wrong, but try proving that! Since the know nothing pope is aware that his existence depends on keeping a façade of ultimate knowledge, he will never let you show that he was wrong. You may end up silently fixing the problem and moving on. Eventually the “know nothing pope” will either be unmasked and unceremoniously kicked out of the company, or he will be promoted to VP due to his “distinguished knowledge” and he will keep on speaking a lot and making you feeling ignorant because you cannot get anything that he is saying.</p><p>Yet another kind is the <strong>this is my fiefdom pope</strong>. This happens when you have a developer that has been in charge of a given chunk of software code for some time, in many occasions a particularly important piece of code, and he feels like he is the only one that “truly understands” that piece of code and therefore he is the only one that can change anything there. Pointing to him that there is a problem in his code and that it can be fixed in a given way feels to him like the barbarians are trying to open a breach in the walls of his castle. He will fight that with all his might, even because letting somebody else see problems in <em>his </em>piece of code, let alone <em>fixing </em>said problems would lead to him losing his fiefdom and keeping his fiefdom is what gives him visibility and a way to advance his career. What’s more, sometimes a developer can acquire a personal connection to a piece of software, and pointing to failures in his piece of software is seen by him as pointing to failures in <em>himself</em>. Trying to fix issues in the code from a “this is my fiefdom pope” will feel as stressful as invading a medieval castle, and sometimes just as futile.</p><p>Finally, there is the <strong>just waiting to retire pope</strong>. In this case, you have a developer who used to know a lot… five or ten years ago. Eventually he reached a position of respect and consciously or unconsciously decided that he did not need to keep up with the times in software development. Therefore, when another developer points out that, you know, there are <em>newer and better</em> ways of doing something, the pope will reply with derision or outright hostility. Usually he will use phrases like “yeah, let’s adopt every single crazy fad that comes along” or “I never heard of anything like that, and I’m sure nobody has ever heard of it either” or “we can’t adopt something like that in software as complex and widespread as ours!” or… There are a lot, but it’s always the same thing: this kind of pope doesn’t want to learn something new, plus he doesn’t want to give the impression that somebody else may know better than him. He wants to keep his position of being the ultimate source of knowledge, so that he can coast along until he finally retires. Then, new developers will wonder how is it possible that the team is still using such archaic technologies.</p><p>There are two ways to avoid the occurrence of popes in a given software development organization:</p><ul><li>The first one is up to yourself. You should always keep the humility of knowing that, like all humans, you are capable of mistakes. In general, when developers are in the beginning of their careers, they feel insecure. As time passes, though, they become more confident. The danger, then, is that you become overconfident to the point that before you notice… you became a “pope” yourself. It is good to be confident in your work, but you should remember that you can make mistakes, and that is fine.</li><li>The second one is on the management side. Unfortunately, some “popes” come along because a manager decides to use a given employee as a crutch: instead of taking the time to look at some issues, and find out what is happening when there is conflict, the manager may just take the word of the “guy with lots of knowledge”. Of course, managers are busy people and it is natural to trust some people more than others. But a manager should avoid automatically relying on the same person all the time, so that that person does not end up becoming a “pope”.</li></ul><blockquote>Whatever benefit a “pope” brings will not compensate for the harm he does to the overall team.</blockquote><p>And if you are currently dealing with a “pope”… Well, what I can say is that you are certainly not the only one: I believe that most of us can relate to that experience. It is up to you to make the judgement if it is worth sticking around or finding a different place to work. Hopefully you will not have to deal with “popes” often in your career. However, when that happens at least you will gain some funny stories to tell to friends later. Happy free of “popes” coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4d08560881a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/the-programming-popes-d4d08560881a">The “Programming Popes”</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On the Importance of Error Codes]]></title>
            <link>https://medium.com/geekculture/on-the-importance-of-error-codes-7ca4254857b7?source=rss-21aeb3c0e3e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ca4254857b7</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[android-app-development]]></category>
            <dc:creator><![CDATA[Nelson Leme]]></dc:creator>
            <pubDate>Tue, 16 Mar 2021 01:48:23 GMT</pubDate>
            <atom:updated>2021-03-18T08:47:49.292Z</atom:updated>
            <content:encoded><![CDATA[<h4>Or why an often overlooked part of software development can be more important than you think.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rXkjCmcMnJG65tAl" /><figcaption>Photo by <a href="https://unsplash.com/@visuals?utm_source=medium&amp;utm_medium=referral">visuals</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Warning the user about an error in an app is a part of the job that most app developers do not like or do not care enough. After all, most app developers want to write code that <em>works</em>, and not code about dealing with what happens when things do not go well.</p><p>That behavior is exacerbated by how development teams are structured. We spend a lot of time discussing how features in our apps will work, but rarely we talk about what to do in anomalous situations. That’s understandable: we all like to provide our users with cool new features, and we don’t want to disappoint people by telling them that we cannot do something. However, in an age of user reviews and app ratings, error codes can have a significant impact on how your app is seen.</p><p>One practical example of that is when an app has to show a dialog box stating that something went wrong. For example, your mobile app may be having a problem because a cloud service that it depends upon is having issues. True, we all spend a lot of time trying to make sure that our cloud services are very reliable, but, still, problems happen. Then, in a situation like that, a typical way to deal with that situation is to just display a dialog box that says “Service down — try again later”. And then, the user tries again, and gets the same dialog box, and one more time, and again and again and again… Inevitably, that user gets angry: the user was really liking your app and then all of sudden it doesn’t work anymore. As it happens often, the user goes to the App Store or Google Play and leaves a not so nice review, and now the rating for your app got a little worse.</p><p>Because you really want your app to have great reviews and good ratings, you decide to get in touch with the user and find out what’s happening. Alas, your dialog boxes when errors happen just say “an error happened”. Therefore, you have to figure out what exactly the user was doing, what was the sequence of steps that took the user to that point, and etc, etc, etc… Problem is, the user doesn’t remember what he or she was doing! Even worse, the user was pretty quick in leaving a bad review for your app, but now that exact same person is not so eager to help you debug the issue. Repeat that for a lot more users, and debugging problems with your app that were reported from actual users can become very difficult and time consuming, and that <em>if</em> you can debug them at all. And we all had cases of users that were replying to us but suddenly disappeared.</p><p>In a situation like that error codes can be fundamental. I’m going to give an example of a possible scheme for error codes, but I would say that any scheme you prefer is better than no scheme at all. You could have a scheme defined like this:</p><pre>S-H-500</pre><p>That error code has 3 fields:</p><ul><li>The “area” or “module” in the app where an error happened. In this example, “S” tells you that an error happened in the Settings module of your app.</li><li>The type of error: in our example, “H” indicates that it is something went wrong in a HTTP connection.</li><li>The specific numeric code of the error. In this case, we’re reusing HTTP status codes, so the “500” tells you that a server error happened.</li></ul><p>Then, when an error happens, your app can display a dialog box that says “System down — Try again later (S-H-500)”, for example. So, when an user complains about an error, you can contact that user and ask for a screenshot of the dialog box. If the user doesn’t know how to do so (we have to remember that users of our apps, especially mobile apps, can vary widely in terms of tech savvy) then you can ask the user to just write down the code between parenthesis and report it back to you. And this way you can get a whole lot more information about what is going on, how you can possibly reproduce the error condition and how you can find a fix for the problem. What’s more, you can later reply back to the user stating that you discovered what the problem was and you have a fix, in the process creating an enthusiastic user of your app and transforming a bad review into a good review.</p><p>Just to emphasize what was said before, pretty much any error code will be better than none. One alternative, for example, would be a purely numerical code. Using the example given before, for that same error condition you could use the code “16500”, in which “1” represents the area or module in your app, “6”, an error in a HTTP connection, and “500” the specific code of the error, which in this case corresponds to the 500 HTTP status code. This scheme has the advantage that it is even easier to tell the user to write it down (“just look for the number between parenthesis”) but it has the disadvantage that a bigger number has a slightly larger chance of a mistake on the part of the user.</p><blockquote>In short, it pays to help the user help you.</blockquote><p>In conclusion, as you start the development of a new app, or you are taking over an already existing app, it is a good idea as one of your first steps to create a scheme for error codes and start using them in your code. It will lead to an easier time debugging issues from your users and potentially creating satisfied users, as opposed to frustrated ones. This is one of those ideas that seem pretty obvious, but from my experience I can say you would be quite surprised how many apps don’t have this. In fact, after reading this article, you may start noticing how many apps don’t show any error code when they have a problem. Hopefully that will not be the case of your apps anymore. Good coding and good luck in your apps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ca4254857b7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/on-the-importance-of-error-codes-7ca4254857b7">On the Importance of Error Codes</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Technical Interest, or how Technical Debt can bankrupt your code]]></title>
            <link>https://medium.com/swlh/technical-interest-or-how-technical-debt-can-bankrupt-your-code-60b1a5f61ac7?source=rss-21aeb3c0e3e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/60b1a5f61ac7</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[Nelson Leme]]></dc:creator>
            <pubDate>Thu, 14 May 2020 04:16:47 GMT</pubDate>
            <atom:updated>2020-05-17T01:28:19.968Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kruror3bJsPR_vtgsTuJcQ.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@paramir?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Ehud Neuhaus</a> on <a href="https://unsplash.com/s/photos/debt?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>At this point, the concept of <em>technical debt</em> has been thoroughly disseminated among developers. Just as a refresher, technical debt is what happens when developers, usually under pressure to finish quickly, cut some corners, take some shortcuts, hack something to make it work. In other words, compress development time at the expense of code quality. But the best way to illustrate this concept is with an (all too common) example.</p><p>We have all been there: you are trying to finish a project in time. But then an urgent business need comes around. You have to create a feature in your app to satisfy that business need. The problem, though, is that the feature in question doesn’t fit quite well with the architecture you came up with. The right thing to do would be to redesign the architecture so that things fit properly and you have clean code.</p><p>Alas, when you say that to various stakeholders, said stakeholders have a conniption. There is just no time for that: promises were made, there is a competitor breathing down your neck, you need to get your app out. So, as many developers have done since time immemorial, you hack something together so that the needed feature somehow fits in the current architecture. It doesn’t look nice, QA has to spend quite some time testing to make sure things work fine, but you get the app out the door. You have your ship party and everybody is happy.</p><p>That is, until you have to deal with that piece of code again.</p><p>Of course, you thought that after shipping your app, you would have time to go back, get rid of the hack you made, redesign the architecture, implement it, and make your code look good again. In other words, get rid of your <em>technical debt</em>. However, it just so happens that, sooner than you imagined, your competitor came up with a new feature that’s really enticing. Those same stakeholders come to you and say that the app needs to get that new feature as soon as possible.</p><p>You tell them that you are just trying to make the code be in good shape again. And you hear back that there is simply no time for that now, you can take care of that later. Resigned, you proceed to implement the feature that was requested. Part of that new feature overlaps with the hack you had made before. Without the proper time to remake your architecture, you have to write code on top of said hack, code that in itself is not that great either. In fact, it has to go through some loops and hoops in order to make it work.</p><p>Worse still, if you had the time to get rid of the technical debt before, and put your code back in proper shape, the time to implement this new feature would be shorter. The new feature would be implemented with less effort, less chance of bugs, QA wouldn’t need to check so many different corner cases, the whole process would be more efficient. But, without that refactoring, you just accept the fact that you have to write a patch on top of a patch, and go on with that.</p><p>You get that new feature out the door. At this point, there is the temptation in the organization to say, hey, we’ve been able to ship things without spending so much time refactoring things, so clearly it is not a priority. And so your code starts to collect more and more patches, until the situation becomes truly unsustainable and your software is unmanageable.</p><p>Here is where it comes the concept of <em>technical interest</em>. Debt, in real life, doesn’t stay static: as time passes, it gathers interest and it grows. Likewise, technical interest describes the concept that technical debt doesn’t stay the same either: the longer it is not dealt with, the bigger it will become.</p><blockquote>Technical interest makes it clear that technical debt is a problem that will only get worse as time passes.</blockquote><p>Again, taking a page from real life debt, we all know that if your interest is too high, given enough time, your debt will become unmanageable and you will have to declare bankruptcy. In software development, the accumulation of technical interest will result in a larger and larger technical debt that eventually will become unmanageable as well.</p><p>To go back to our original example, that organization tried to find some time, now and then, to get rid of the hacks and bad designs that accumulated in the app. However, at that point the accumulated technical interest had made the technical debt too big, so just punctual improvements were possible. The code was composed of patches over patches that only the original developer was capable of navigating through.</p><p>But, said developer found a better opportunity elsewhere. A new developer takes over and spends long days (and nights) trying to understand the codebase, without success. So, after some heated meetings, the inevitable conclusion is reached: a comprehensive rewrite is needed, and a lot of time and resources will be devoted writing brand new code. Not only that: we are talking about new code that has to closely emulate the behavior of the previous code, which is quite a challenge in itself. So, the company has to spend much larger resources than if it had dealt with the problem earlier.</p><p>And that is the idea behind technical interest: to add the dimension of <em>time</em> to the problem of technical debt. It is understandable that software development companies at times have to make hard choices and perhaps not deal with their technical debt. However, by taking technical interest in account, a development organization can add the factor of time to the calculations it makes in order to determine what to work on next, what work item has the highest priority and what can be postponed.</p><blockquote>Technical interest can expose clearly to all stakeholders that it is in their best interest to deal with technical debt sooner rather than later.</blockquote><p>I hope that this concept can lead to wiser decisions in software development and, even better, less technical debt all around. Sometimes, the most difficult part of dealing with a problem is <em>communicating</em> about it, and perhaps the idea of technical interest will help better communicate the problem of technical debt and its accumulation. And, fortunately, happier coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60b1a5f61ac7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/technical-interest-or-how-technical-debt-can-bankrupt-your-code-60b1a5f61ac7">Technical Interest, or how Technical Debt can bankrupt your code</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android: an idiom for Activity parameters (in Kotlin)]]></title>
            <link>https://medium.com/swlh/android-an-idiom-for-activity-parameters-in-kotlin-657d38361e9?source=rss-21aeb3c0e3e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/657d38361e9</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[programming-tips]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Nelson Leme]]></dc:creator>
            <pubDate>Sat, 28 Dec 2019 19:46:21 GMT</pubDate>
            <atom:updated>2019-12-28T23:56:12.889Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oo3MycXpaTRQ8vs_YlvTXw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kelly Sikkema</a> on <a href="https://unsplash.com/s/photos/programming?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></figcaption></figure><p>In a previous <a href="https://medium.com/swlh/android-an-idiom-for-activity-parameters-73198a5b7355">article</a>, I described a useful programming idiom for passing parameters to an Activity in Android. As I said then, I believe that idiom would help when refactoring some old and large Java codebase, in which you have an Activity with lots of parameters spread all over the code. However, as we all know, Kotlin is quickly overtaking Java as the language of choice for Android programming. I think that this idiom is useful for new codebases as well, so I’m giving its implementation here in Kotlin.</p><p>Kotlin makes the idiom even easier to write. For starters, you don’t need to resort to third party libraries like <a href="https://github.com/google/auto/blob/master/value/userguide/index.md">AutoValue</a> and <a href="https://jakewharton.github.io/butterknife/">ButterKnife</a>. You can use features of the language itself, plus more modern aspects of Android programming (like Data Binding) and make the implementation of this idiom ever clearer.</p><p>Given that, let’s take a look at some code snippets. This sample code will follow closely what I’ve done in the previous article, so that you can compare the implementations (and perhaps learn a little bit more about Kotlin in the process as well). With that, let’s see the Arguments class:</p><pre>class LivingRoomActivity : AppCompatActivity() {<br><br>    // [...]<br><em><br>    </em>class Arguments(val roomColor: String, val numOfRooms: Int) {<br><br>        companion object {<br><br>            private const val ROOM_COLOR_TAG = &quot;roomColorTag&quot;<br>            private const val NUM_OF_WALLS_TAG = &quot;numOfWallsTag&quot;<br>            private const val DEFAULT_NUM_OF_WALLS = 4<br><em><br>            </em>fun createFromIntent(intent: Intent): Arguments {<br>                return Arguments(<br>                    roomColor = intent.getStringExtra(ROOM_COLOR_TAG),<br>                    numOfRooms = intent.getIntExtra(NUM_OF_WALLS_TAG, DEFAULT_NUM_OF_WALLS))<br>            }<br><br>        } // companion object<br><em><br>        </em>fun startActivity(context: Context) {<br>            val intent = Intent(context, LivingRoomActivity::class.<em>java</em>)<br>            intent.putExtra(ROOM_COLOR_TAG, roomColor)<br>            intent.putExtra(NUM_OF_WALLS_TAG, numOfRooms)<br>            context.startActivity(intent)<br>        }<br><br>    } // Arguments class</pre><pre>    // [...]</pre><pre>} // LivingRoomActivity class</pre><p>As before, there is a LivingRoomActivity which takes two parameters: the number of walls in the room and the color of the walls. We make those into two read only properties of the Arguments class. Additionally, we define the tags for passing those values through an Intent object in an anonymous companion object, which also contains a method for creating an instance of Arguments from the Intent object: createFromIntent().</p><p>Finally, inside Arguments there is the method startActivity() to start a new instance of the LivingRoomActivity using the data contained in Arguments itself. Now, let me show how external code can use LivingRoomActivity.Arguments to launch the activity:</p><pre>val arguments = LivingRoomActivity.Arguments(<br>    roomColor = roomColor ?: &quot;&quot;,<br>    numOfRooms = Integer.parseInt(numOfRoomsStr ?: &quot;0&quot;))<br>arguments.startActivity(context)</pre><p>Here we take advantage of a nice feature of Kotlin: named arguments. Differently than Java, where we had to resort to the AutoValue library and its Builder pattern, in this case we have a similar effect by referring to each parameter by its name, which makes clear what values are passed. Then, a call to startActivity() will get the LivingRoomActivity launched. Also notice how the Elvis operator makes dealing with null values more concise.</p><p>Finally, to make use in LivingRoomActivity of the data contained in those parameters, we just have to do the following:</p><pre>class LivingRoomActivity : AppCompatActivity() {<br><br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        val binding: ActivityLivingRoomBinding = DataBindingUtil.setContentView(this, R.layout.<em>activity_living_room</em>)<br>        binding.<em>arguments </em>= Arguments.createFromIntent(<em>intent</em>)<br>    }<br><br>    // [...]<br><br>} // LivingRoomActivity class</pre><p>With Data Binding, we can use the data in Arguments in an elegant way: we can just pass the Arguments object itself and let the layout display the data contained in it properly. We just call Arguments.createFromIntent() to recreate the object from the data contained in the Intent and then pass it to the binding. Just to show how the data is displayed in the layout file, let me put a snippet of it here:</p><pre>&lt;data&gt;<br>    &lt;variable name=&quot;arguments&quot; type=&quot;com.discoverer.livingRoomKotlin.LivingRoomActivity.Arguments&quot;/&gt;<br>&lt;/data&gt;</pre><pre>&lt;!-- [...] --&gt;</pre><pre>&lt;TextView<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:textSize=&quot;18sp&quot;<br>    android:text=&quot;@{arguments.roomColor}&quot;/&gt;<br><br>&lt;TextView<br>    android:layout_width=&quot;match_parent&quot;<br>    android:layout_height=&quot;wrap_content&quot;<br>    android:layout_marginTop=&quot;20dp&quot;<br>    android:textSize=&quot;18sp&quot;<br>    android:text=&quot;@{Integer.toString(arguments.numOfRooms)}&quot;/&gt;</pre><p>Like in the previous article, this idiom can be used for passing data to a Fragment as well, by using the Arguments class to generate a Bundle object and then retrieve the data from the Bundle in the Fragment. Furthermore, you can also use the Arguments class to encapsulate the code to save and retrieve the parameters in the savedInstanceState bundle. The idea is to keep the parameters in a single class and let it deal with the different mechanisms for passing that data around in Android.</p><p>As we can see, the amount of boilerplate code is reduced to a minimum, by using features of Kotlin itself and of a modern Android library such as <a href="https://developer.android.com/jetpack/?gclid=Cj0KCQiAl5zwBRCTARIsAIrukdNXN-TxgZwJ-xmjo11sbif1IzKGq3aRfUtGyKxPXAX_Zz0lzZH0O6saAgFXEALw_wcB">Jetpack</a>. If you want to see the whole picture, I put the sample app for this example in GitHub: <a href="https://github.com/Discoverer98/living-room-kotlin">https://github.com/Discoverer98/living-room-kotlin</a>.</p><p>The previous article about this idiom was aiming at the past: how to deal with an existing codebase and refactor it into something more manageable. On the other hand, this article aims at the future: how to write a new codebase ensuring that it will have clean code from the start. And that is one of the big pushes in Android development recently: moving on from codebases with lots of boilerplate code to simpler and smaller ones. I hope this idiom can help you in that direction. Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=657d38361e9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/android-an-idiom-for-activity-parameters-in-kotlin-657d38361e9">Android: an idiom for Activity parameters (in Kotlin)</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android: an idiom for Activity parameters]]></title>
            <link>https://medium.com/swlh/android-an-idiom-for-activity-parameters-73198a5b7355?source=rss-21aeb3c0e3e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/73198a5b7355</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[idioms]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[refactoring]]></category>
            <dc:creator><![CDATA[Nelson Leme]]></dc:creator>
            <pubDate>Sat, 14 Dec 2019 19:12:37 GMT</pubDate>
            <atom:updated>2019-12-28T19:49:26.430Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cUOknyEHrQ6wGqynmp__Eg.jpeg" /></figure><p>These days, Android development is switching fast to use Kotlin as the standard programming language. However, there is still a lot of Java code written for Android and developers face the challenge of modifying (and hopefully improving) big codebases written in Java. In this article, I would like to show an idiom that can make the code for starting Activity objects a little easier to to deal with, and help you cope with some old Java codebase.</p><p>As Android developers know, in order to start an Activity, you have to create an Intent object. In that object, you can pass parameters to the Activity, which will be aggregated to the Intent as extra info. For each piece of information, you need to create a tag, as a string, so that the Activity on its onCreate() method will be able to retrieve each parameter from the extra info. This lead to a number of variations on how to do that in the most easily understandable and modifiable way.</p><p>One way that I’ve seen many times is to simply create the tag strings as public constants belonging to the Activity:</p><pre>public class SampleActivity : AppCompatActivity {</pre><pre>    public static final String NUM_ROOMS_TAG = &quot;com.sample.AppCompatActivity.numRoomsInfo&quot;;<br>    public static final String COLOR_ROOMS_TAG = &quot;com.sample.AppCompatActivity.colorRooms&quot;;</pre><pre>}</pre><p>Then, typically you would start SampleActivity this way:</p><pre>final Intent intent = new Intent(context, SampleActivity.class);<br>intent.putExtra(SampleActivity.NUM_ROOMS_TAG, 2);<br>intent.putExtra(SampleActivity.COLOR_ROOMS_TAG, &quot;Blue&quot;);<br>context.startActivity(intent);</pre><p>And then in the onCreate() method you would retrieve those values using the tags defined in the Activity itself. A variant of the above idiom is to define a static method in the Activity in which you pass the values and the method returns a new Intent. However, it would be nice if we could keep the “mechanics” of passing data to the Activity separated from the code of the Activity itself: this way, the Activity could focus solely on the functionality it is supposed to provide.</p><p>The way I propose to do that is by creating a static inner class whose purpose is solely to deal with the “mechanics” of passing the data around, and, furthermore, it also works as a data object to keep the parameters to the Activity separate from the rest of its data. Let me just show some sample code that implements that:</p><pre>public class LivingRoomActivity extends AppCompatActivity {<br><br>    private Arguments arguments;<br><br>    // [...]</pre><pre><em>    </em>@AutoValue<br>    public static abstract class Arguments {<br><br>        private static final String <em>ROOM_COLOR_TAG </em>= &quot;roomColorTag&quot;;<br>        private static final String <em>NUM_OF_WALLS_TAG </em>= &quot;numOfWallsTag&quot;;<br>        private static final int <em>DEFAULT_NUM_OF_WALLS </em>= 4;<br><br>        public abstract String roomColor();<br>        public abstract int numOfWalls();<br><br>        public static Arguments createFromIntent(final Intent intent) {<br>            return <em>builder</em>()<br>                    .setRoomColor(intent.getStringExtra(<em>ROOM_COLOR_TAG</em>))<br>                    .setNumOfWalls(intent.getIntExtra(<em>NUM_OF_WALLS_TAG</em>, <em>DEFAULT_NUM_OF_WALLS</em>))<br>                    .build();<br>        }<br><br>        public static Builder builder() {<br>            return new AutoValue_LivingRoomActivity_Arguments.Builder();<br>        }<br><br>        public void startActivity(final Context context) {<br>            final Intent intent = new Intent(context, LivingRoomActivity.class);<br>            intent.putExtra(<em>ROOM_COLOR_TAG</em>, roomColor());<br>            intent.putExtra(<em>NUM_OF_WALLS_TAG</em>, numOfWalls());<br>            context.startActivity(intent);<br>        }<br><em><br>        </em>@AutoValue.Builder<br>        public static abstract class Builder {<br><br>            public abstract Builder setRoomColor(String value);<br>            public abstract Builder setNumOfWalls(int value);<br>            public abstract Arguments build();<br><br>        } // Builder class<br><br>    } // Arguments class<br><br>} // LivingRoomActivity class<br></pre><p>In this case, we have a LivingRoomActivity that requires a couple of parameters: the number of walls of the room and the room color (this is just an example, typically you would employ this idiom on Activity classes that require a lot of parameters). Then, inside that class, you define a static inner class called Arguments which will encapsulate how those parameters will be passed to the Activity and how they are going to be retrieved. Additionally, the Arguments class is set up as an AutoValue class and makes use of the Builder pattern offered by it: this way, it minimizes the amount of lines of code to define each individual parameter and also allows us to use the very handy Builder pattern to create an instance of Arguments. Furthermore, the constants used as tags can live as private constants inside the Arguments class and nobody else needs to know about them.</p><p>Now, let’s look how some external code can start an instance of LivingRoomActivity:</p><pre>final LivingRoomActivity.Arguments arguments = LivingRoomActivity.Arguments.<em>builder</em>()<br>        .setRoomColor(roomColorEdittext.getText().toString())<br>        .setNumOfWalls(Integer.<em>parseInt</em>(numWallsEdittext.getText().toString()))<br>        .build();<br>arguments.startActivity(this);</pre><p>As you can see, there is no need to find out what are the tags for each parameter, all parameters are set individually by the Builder and you don’t even need to specify the class when starting the Activity. Then, when it comes the time for the LivingRoomActivity to retrieve those parameters, it can do the following:</p><pre>public class LivingRoomActivity extends AppCompatActivity {<br><br>    private Arguments arguments;<br><br>    @BindView(R.id.<em>wall_colors_text_view</em>) TextView wallColorsTextView;<br>    @BindView(R.id.<em>num_walls_text_view</em>) TextView numWallsTextView;<br><br>    @Override<br>    protected void onCreate(Bundle savedInstanceState) {<br>        super.onCreate(savedInstanceState);<br>        setContentView(R.layout.<em>activity_living_room</em>);<br>        ButterKnife.<em>bind</em>(this);<br><br>        arguments = Arguments.<em>createFromIntent</em>(getIntent());<br><br>        wallColorsTextView.setText(&quot;Room color: &quot; + arguments.roomColor());<br>        numWallsTextView.setText(String.<em>format</em>(&quot;Number of walls: %d&quot;, arguments.numOfWalls()));<br>    }</pre><pre>    // [...]</pre><pre>} // LivingRoomActivity class</pre><p>Pretty easy: just call Arguments.createFromIntent(getIntent()) and you’re good to go. Following that, you can just refer to the parameters by invoking arguments.roomColor() for example.</p><p>The whole mechanism is hidden from everybody and concentrated in the LivingRoomActivity.Arguments class. This has the additional benefit that, if you need to add (or remove) parameters for this Activity, you just need to go to one place to do so. Furthermore, if additionally you need to pass data to a Fragment, you can reuse the above class to put the data in a Bundle object and then create a static method in Arguments to create an instance of it based upon a Bundle, again keeping all the code and tags for it hidden from everybody else.</p><p>You can check a fully working example of the use of the above idiom in a sample app that I put on GitHub: <a href="https://github.com/Discoverer98/living-room">https://github.com/Discoverer98/living-room</a>. The code snippets I put above were taken from that project.</p><p>As I said at the beginning of this article, Android is quickly moving towards Kotlin: so, I intend to publish a follow up to this article describing this idiom in Kotlin. Nevertheless, for all those that still have to deal with Java code for Android, I hope this idiom can help make the code you’re dealing with a little cleaner and your job a little easier. Good luck in your coding!</p><p><em>Update: I just published the follow up to this article in which I describe the same idiom above but written in Kotlin. You can take a look at it </em><a href="https://medium.com/@discovererxcviii/android-an-idiom-for-activity-parameters-in-kotlin-657d38361e9"><em>here</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73198a5b7355" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/android-an-idiom-for-activity-parameters-73198a5b7355">Android: an idiom for Activity parameters</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>