<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Gervin Guevarra</title>
    <description>The latest articles on DEV Community by Gervin Guevarra (@gervg).</description>
    <link>https://dev.to/gervg</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F48870%2Fca362080-c86a-4b6f-b5c6-54363c07ec4b.jpg</url>
      <title>DEV Community: Gervin Guevarra</title>
      <link>https://dev.to/gervg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gervg"/>
    <language>en</language>
    <item>
      <title>Event Streaming and Event Sourcing: which one do you use?</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Wed, 31 Jan 2024 01:48:55 +0000</pubDate>
      <link>https://dev.to/gervg/event-streaming-and-event-sourcing-which-one-do-you-use-4e45</link>
      <guid>https://dev.to/gervg/event-streaming-and-event-sourcing-which-one-do-you-use-4e45</guid>
      <description>&lt;p&gt;A couple of months back, I read &lt;a href="https://event-driven.io/en/event_streaming_is_not_event_sourcing/"&gt;this article&lt;/a&gt; explaining that event streaming != event sourcing&lt;/p&gt;

&lt;p&gt;The understanding of these two has eluded me for years.&lt;/p&gt;

&lt;p&gt;I first heard of it back in 2017 when my mentor was introducing DDD to me. In my head, I oversimplified it as a pub-sub pattern but with flair 😆 &lt;/p&gt;

&lt;p&gt;That mental model remained useful as I worked on a few event-driven applications. Some utilized it on the application tier while some applied it as a way to orchestrate microservices.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://chriskiehl.com/article/event-sourcing-is-hard"&gt;“leitmotiv” article&lt;/a&gt; cited by the article above is something I’ve seen several times, and one I find myself agreeing with when I was working with architectures employing such. It is fancy. It seems elegant but it also introduces a lot of drawbacks. Add to that, it’s also a bit unintuitive versus a simple “let me handle that request, process it, write it to the database, here’s your response, and voila we’re done” -- very CRUD-y I suppose.&lt;/p&gt;

&lt;p&gt;But it turns out, I was conflating the two terms 🤦&lt;br&gt;
Looks like I’ve never tried event sourcing yet, and it's probably something I won’t be able to try anytime soon.&lt;br&gt;
I’m a little skeptical about how replaying the events will scale. Granted, I didn’t read the additional articles the author shared (he has one for modelling event sourcing streams and keeping them short).&lt;/p&gt;

&lt;p&gt;How about you? Have you tried event sourcing before? How was it?&lt;/p&gt;

&lt;p&gt;And if not, will you ever try event sourcing?&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>softwareengineering</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Newbie Anew</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Wed, 27 Dec 2023 13:48:08 +0000</pubDate>
      <link>https://dev.to/gervg/newbie-anew-5101</link>
      <guid>https://dev.to/gervg/newbie-anew-5101</guid>
      <description>&lt;p&gt;I always tell people that “new things” make working in software development constantly exciting. And when I say new things, I just don’t mean bleeding-edge technology. I mean new problems, new approaches, or new patterns - even if they are just new to the person. What I have not told them is that with these exciting opportunities comes the nerve-wracking ordeal of facing unknowns.&lt;/p&gt;

&lt;p&gt;When I was writing my &lt;a href="https://dev.to/gervg/musings-on-my-5th-year-as-a-software-engineer-5dcn"&gt;5th-year retrospect&lt;/a&gt;, I felt like I knew a lot. I thought I had already reached a certain level of mastery that would make me qualified to share my knowledge and experiences. And it was around the same time last year when I started a new job . That’s when I realized that &lt;em&gt;I don’t know sh*t&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;It was overwhelming, to say the least: different domain, tech stack, people, and culture. There were times when I felt dumb and undeserving to be there. Impostor syndrome perhaps? But…&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xFaxtT00--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vyxwxyevvdr5r3tav030.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xFaxtT00--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vyxwxyevvdr5r3tav030.png" alt="Impostor syndrome comic" width="800" height="578"&gt;&lt;/a&gt;&lt;br&gt;Artist: &lt;a href="https://twitter.com/gemmacorrell/status/1441500836840886275"&gt;Gemma Correll&lt;/a&gt;
  &lt;/p&gt;

&lt;p&gt;And since it's time for a "year in review" post anyway, I sat down and look back at the struggles I had and the steps I’ve taken so far.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unfamiliar Domain
&lt;/h2&gt;

&lt;p&gt;I previously worked for a digital bank for 3 years, and I more or less became the &lt;em&gt;de facto&lt;/em&gt; subject matter expert on a few of our microservices. While I did enjoy being the go-to person, I eventually hit a point where I began wanting to try something different.&lt;/p&gt;

&lt;p&gt;Which brought me to my current job at an HR tech company.&lt;/p&gt;

&lt;p&gt;I was excited of course, but I was not prepared to be hit like a truck. Many foreign concepts were being discussed during meetings and I found myself there sitting clueless.&lt;/p&gt;

&lt;p&gt;What we devs rarely talk about is that half of our job is actually understanding the business domain. We would often talk about the latest, fastest, or most elegant tech stacks and patterns. But at the end of the day, what we really want is simply a software that delivers value to our users. And we can’t do that if we do not understand the contexts it will be used in.&lt;/p&gt;

&lt;p&gt;To fill in these gaps, I had to ask a lot of who, what, where, when, and whys. Fortunately, my team was very understanding and welcoming. It took me some time until I gained some confidence. Until now, I don’t think I’ve already understood everything yet, but it was a significant progress from where I was a year ago.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Mystery That Is Frontend
&lt;/h2&gt;

&lt;p&gt;I &lt;strong&gt;was&lt;/strong&gt; of the opinion that fullstack devs don’t exist (might be a good topic for a future post). Yet I am now working as a fullstack dev.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eVo6Ae0---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwwecj8izru8lnrc0y56.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eVo6Ae0---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hwwecj8izru8lnrc0y56.png" alt="Meme - Emperor Palpatine saying ironic" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have been a (mostly) backend developer since the start of my career and the last time I touched frontend code was back in 2018. Even then, I was only exposed to JavaScript and a bit of JQuery. I know nothing about all these frameworks, tools, etc. What’s NodeJS? What’s NPM? What’s Babel? Webpack? What is this React thing? What’s with React vs Angular? ECMAScript? Typescript? &lt;/p&gt;

&lt;p&gt;… and the list goes on. The landscape of front-end development is truly intimidating.&lt;/p&gt;

&lt;p&gt;I’ve heard these things before, but I never had to learn any of them because I don’t need them for work. I am passionate about my career, but I don’t really like spending weekends learning things I probably won’t need. Do I regret it? Yeah, a bit. I may have unintentionally limited my “horizons” so to speak. But I am relatively quick to learn things when I have something I need them for. If I had studied these technologies in the past and not used them, I probably would’ve forgotten them anyway.&lt;/p&gt;

&lt;p&gt;Another &lt;em&gt;paradigm shift&lt;/em&gt; I had is the mental model for states. In backend, services are stateless - things go in, and things go out. The services themselves don’t get mutated nor do they have to “remember” what they did previously (well, technically they do with the help of the persistence layer but that’s not my point). In contrast, frontend components maintain states: Is the drawer open? Should I show the popover? Does the color change if ? These are things that I can’t simply think of as input → output models.&lt;/p&gt;

&lt;p&gt;Luckily, I was able to get by after learning React hooks and a fairly easy-to-use state manager called &lt;a href="https://github.com/pmndrs/zustand"&gt;Zustand&lt;/a&gt;. I think I understand them well enough to deliver features or issue fixes, but I do know for a fact that I haven’t really grasped React’s component lifecycle. Maybe I’ll seriously study it one of these days.&lt;/p&gt;

&lt;p&gt;CSS, however, remains to be the bane of my existence.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7fsOmbaC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kica4ujuuw0r1j1t3sqo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7fsOmbaC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kica4ujuuw0r1j1t3sqo.png" alt="Meme - The Babadook &amp;quot;why can't you be normal&amp;quot; but with CSS" width="500" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloud isn’t about rain
&lt;/h2&gt;

&lt;p&gt;It is somewhat annoying when a new tech is hyped and rapidly gains a following. I don’t hate the tech, but I hate it when people throw around buzzwords all the time. It does the opposite effect on me, and I very quickly lose interest in it.&lt;/p&gt;

&lt;p&gt;Cloud is one of them. I was still in college when I first heard about it. To me, it was just a marketing ploy. Just another term for servers you’re renting. That metaphor still kinda stands, but my arrogance kept me from understanding how much the tech has matured.&lt;/p&gt;

&lt;p&gt;Like in the case of front end, it just stayed in my periphery. I had experience with some &lt;a href="https://www.cncf.io/projects/"&gt;cloud-native technologies&lt;/a&gt;, but a lot of the nitty-gritty details were abstracted to me because we had a dedicated DevOps/SRE team in my previous job. I never really had my hands dirty in writing infra definitions from scratch (I shamelessly copied YAMLs from existing projects) much less in deploying resources to the cloud (CI/CD pipeline has already been setup; everything is magic).&lt;/p&gt;

&lt;p&gt;Enter: AWS - one of the most popular cloud service providers. It’s the platform that we’re currently using.&lt;/p&gt;

&lt;p&gt;And I don’t know sh*t about it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fJoQ48mI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.awsgeek.com/Periodic-Table-of-Amazon-Web-Services/Periodic-Table-of-Amazon-Web-Services.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fJoQ48mI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://www.awsgeek.com/Periodic-Table-of-Amazon-Web-Services/Periodic-Table-of-Amazon-Web-Services.jpg" alt="Periodic Table of AWS" width="800" height="504"&gt;&lt;/a&gt;&lt;br&gt;Periodic Table of AWS by &lt;a href="https://www.awsgeek.com/"&gt;AWS Geek&lt;/a&gt;
  &lt;/p&gt;

&lt;p&gt;The number of available services is just mind-blowing.  What the heck are all these? Which one do I pick?&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--e6syv6sg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yf52ba5b81osagx9ei98.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--e6syv6sg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yf52ba5b81osagx9ei98.gif" alt="Meme - John Travolta lost in Target" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Luckily, we already have some existing in-house tooling that helps us use AWS and spin up our own services (for development purposes). It abstracts some stuff too so learning how to deploy an infra becomes a little less intimidating. I’ve also developed a rough mental model on how different services are &lt;em&gt;connected&lt;/em&gt; to one another. Gotta give props to Amazon for making their suite of services cohesive (CDK docs are kinda bad though).&lt;/p&gt;

&lt;h2&gt;
  
  
  On hazy thoughts, accents, and stutters
&lt;/h2&gt;

&lt;p&gt;We, Filipinos, always had a weird relationship with the English language.&lt;/p&gt;

&lt;p&gt;It’s taught to us since kindergarten and we’re exposed to it in media. Despite the expectation of fluency, only a few regularly speak it outside of academic institutions or corporate settings.&lt;/p&gt;

&lt;p&gt;I still struggle a lot. I get very conscious and anxious about my grammar and word choices. I find it very difficult to express what’s in my head clearly and succinctly. Even more so now that I have teammates who are of different nationalities, some of which has English as their native language. Add to that the differences in accents which I don’t have the ear for yet.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jaT-gdb6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/febb8amggb6k85v8pbh0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jaT-gdb6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/febb8amggb6k85v8pbh0.png" alt="Meme - dumbfounded smiling dog" width="800" height="901"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It’s quite ironic that our work, whose requirement is to have expertise talking to computers, is also very collaborative in nature. We have no choice but to communicate with our teammates and stakeholders regularly. You see, talking to a computer is very precise. It does exactly what you tell it to do. The intricacies of human conversations, like idioms, slang, and tone, are not present in programming languages. I don’t have to think about my or their emotions. Nobody has to assume intent behind the words. And certainly, no one has to guess what will happen if they say one thing and not the other.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gHqq9rDJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kgkugyh8p063uw04b3l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gHqq9rDJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kgkugyh8p063uw04b3l.png" alt="Meme - smiling when talking to a computer; disappointed when talking to humans" width="500" height="834"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Being an introvert, I blamed my personality for the gaps in my communication skills. But lately, I have been thinking maybe that’s not the case.&lt;/p&gt;

&lt;p&gt;Recently, I’ve met my teammates and a few others in the office (oh hell yeah, I finally touched some grass after 3 years of working from home). Our interactions made me realize that I just needed something that would pique my interest then I would start pouring out everything from my mind, asking questions, and talking endlessly.&lt;/p&gt;

&lt;p&gt;One feedback that stuck with me is that I need to be more confident in articulating my ideas. I think that hit the bull’s eye. It takes me a long time to arrange my thoughts, and I feel very uncomfortable with the silence in between. Because of that, I get thrown off and I start speaking even when the things I like to say haven’t been formed yet. The result: stutters.&lt;/p&gt;

&lt;p&gt;I don’t think I’ll get over this wall anytime soon, but I’ll keep trying anyway.&lt;/p&gt;

&lt;h2&gt;
  
  
  AI craze
&lt;/h2&gt;

&lt;p&gt;Of course, this blog post won’t end without a single mention of this year’s AI craze that captured the attention of everyone, may they be in tech or not.&lt;/p&gt;

&lt;p&gt;While most people are busy arguing whether AI will take our jobs or not (they won’t at least not anytime soon, but that’s a topic for another day), I am more concerned about how I am going to utilize it to speed up my work.&lt;/p&gt;

&lt;p&gt;I was reluctant at first because I thought it was just another overly hyped technology. But there’s also a very strong “fear of missing out” feeling as I see my colleagues rave about it. To my surprise, it really gave me useful answers. Though they aren’t perfect and by no means you could start a multimillion-dollar startup company by just copying code from ChatGPT, it did help reduce the head scratching and typing for boilerplate code.&lt;/p&gt;

&lt;p&gt;Fast forward to a couple of months, I find myself using it a handful of times in a month. Not quite sure if that’s too much or too few. It seems very useful when you’re too lazy to read the docs or when your google-fu isn’t enough to get you the right answer quickly.&lt;/p&gt;

&lt;p&gt;And since I suck at closing paragraphs, &lt;a href="https://chat.openai.com/share/7ddbbab8-854e-4f21-b6ea-cf8c216a0632"&gt;here’s one written by ChatGPT&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In reflecting upon this transformative year as a software engineer, I've navigated through uncharted territories, from delving into unfamiliar business domains to grappling with frontend technologies and cloud services. Each challenge became an opportunity for growth, and while I initially stumbled through the intricacies of communication, I've learned to adapt and improve. This retrospective journey underscores not just the hurdles but the continuous strides forward. Embracing the discomfort, I've cultivated a resilience that fuels my passion for learning. As I stand at the intersection of challenges conquered and those yet to be faced, I am reminded that the essence of this journey lies not just in overcoming hurdles but in the relentless pursuit of knowledge and progress. The coming year holds the promise of further evolution, and I am eager to embrace it with the same curiosity and determination that defined this transformative chapter&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That sounds like a student trying to reach the minimum word count. I guess I’m not the only one struggling with communicating, eh?&lt;/p&gt;




&lt;p&gt;Cover photo by &lt;a href="https://unsplash.com/@rocinante_11"&gt;Mick Haupt&lt;/a&gt; on Unsplash&lt;/p&gt;

&lt;p&gt;&lt;em&gt;P.S. I had this in drafts for a long time and had already lost the source of the image. So I reverse image searched this and found an &lt;a href="https://www.reddit.com/r/Jung/comments/hnmayo/a_classic_example_of_the_shadow_self/"&gt;interesting interpretation&lt;/a&gt; of the image. I think that kinda fits with this post's theme&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>career</category>
      <category>careerdevelopment</category>
    </item>
    <item>
      <title>Test-Driven Development isn't about Unit Tests</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Thu, 29 Dec 2022 16:24:45 +0000</pubDate>
      <link>https://dev.to/gervg/test-driven-development-isnt-about-unit-tests-48e3</link>
      <guid>https://dev.to/gervg/test-driven-development-isnt-about-unit-tests-48e3</guid>
      <description>&lt;p&gt;I've met quite a number of people excitedly talking about how they wanted to adopt TDD (test-driven development), citing its ability to “catch bugs before you make them” or something about improving the code quality. While that is not entirely wrong, I think it's a bit misguided and overlooks TDD’s foremost benefit.&lt;/p&gt;

&lt;p&gt;Worse, some of them seemingly take TDD as if it's an interchangeable term with unit testing. I am not being pedantic - unit testing is an art of its own and you can write effective tests without doing TDD. Unit test's responsibility is to ensure that your code works as intended; TDD's job is to help you get your code working as intended. See the difference, no? Okay, let's first talk about unit tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Everyone loves unit tests
&lt;/h2&gt;

&lt;p&gt;Devs hate meetings. But what do devs love? Writing code, of course! So much so that we're also writing code to test code. The most common of which are unit tests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qzRgLc2n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbydg6bahqpfjxzbrn19.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qzRgLc2n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pbydg6bahqpfjxzbrn19.png" alt="I heard you like code" width="622" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unit tests help us slice our programs into smaller individual pieces (units) and test them independently. They're cheaper to write (relative to integration/end-to-end testing) and they provide very quick feedback to the developer. With just a quick run on the CLI or IDE, a dev can easily find out if something broke. Unit tests are your first line of defence against defects. Martin Fowler describes how it serves as the foundation of your &lt;a href="https://martinfowler.com/bliki/TestPyramid.html"&gt;testing pyramid&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When you write unit tests, your objective is to &lt;em&gt;test&lt;/em&gt; and ensure that your production code works as expected. Now let's move to TDD…&lt;/p&gt;

&lt;h2&gt;
  
  
  Driven by Tests
&lt;/h2&gt;

&lt;p&gt;There are A LOT of other &lt;em&gt;X-driven Development&lt;/em&gt;: BDD, DDD, FDD, etc.&lt;/p&gt;

&lt;p&gt;I'm starting to think the industry sometimes just loves to formalize processes and slap them with &lt;em&gt;-driven development&lt;/em&gt; on its name. Kidding aside, let's take our focus back on TDD.&lt;/p&gt;

&lt;p&gt;I believe there's a subtle problem with the name “test-driven”. Not that I think I can do a better job than Kent Beck, but it seems that the name led people to conflate testing with TDD.&lt;/p&gt;

&lt;p&gt;But the operative word here is “driven”. TDD is a development technique driven by tests. &lt;strong&gt;Tests are the means not the goal&lt;/strong&gt;. The goal is still to write functioning production code and you're just leveraging the power of tests while doing so.&lt;/p&gt;

&lt;h3&gt;
  
  
  F*ck around and Find out
&lt;/h3&gt;

&lt;p&gt;Have you seen this meme?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xsm_CyrA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fp3r87y3t5p7k1lelmvv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xsm_CyrA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fp3r87y3t5p7k1lelmvv.png" alt="Scientific method is f*ck around and find out" width="800" height="777"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's a funny, perhaps oversimplified, overview of the scientific method. But I think it's a very good analogy to what TDD is meant for in software development.&lt;/p&gt;

&lt;p&gt;Writing unit tests in TDD is similar to coming up with a hypothesis and preparing the workbench in a lab. You have an idea in your head, and you verify it with an experiment. Oh, the idea didn't work - tweak some variables and run the test again. Did it work this time? See if it can still be improved… the cycle repeats. &lt;a href="https://blog.cleancoder.com/uncle-bob/2014/12/17/TheCyclesOfTDD.html"&gt;Red-Green-Refactor&lt;/a&gt; is exactly that!&lt;/p&gt;

&lt;p&gt;TDD is for times when you don't have a clear path ahead yet. It's for discovering the solution and refinement. It is a &lt;a href="https://www.developerdotstar.com/mag/articles/reeves_design_main.html"&gt;design activity&lt;/a&gt;. Take for example, a method signature. When writing tests, you think about the signature first but not yet the implementation details. How do you want it to look like? Inputs? Outputs? Is it easy to wield? And so forth.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TDD is a technique meant to help you iteratively reach your objective: a working software&lt;/strong&gt;. So maybe, we can call it &lt;em&gt;experiment-driven&lt;/em&gt;. But after a quick Google search, that name is already taken. Gosh darn, naming is indeed hard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quality is a by-product
&lt;/h2&gt;

&lt;p&gt;Let's talk about quality on two fronts: correctness and maintainability.&lt;/p&gt;

&lt;p&gt;When you do TDD, you write tests (duh). These in turn cover a huge chunk of your code base. While code coverage is not necessarily indicative of good quality, the tests created through TDD gives some confidence that your production code works based on the assumptions you've established. These tests also create a safety net, guaranteeing that existing behaviours will not be accidentally changed when modifying the production code.&lt;/p&gt;

&lt;p&gt;TDD also levels up maintainability by producing testable code. Sometimes when writing tests after production code, you might find yourself having to deal with a lot of coupling between different parts. This makes it hard to test them independently. TDD inverts that process hence you end up with code that is surely testable.&lt;/p&gt;

&lt;p&gt;So yes, TDD helps improve quality. But &lt;strong&gt;it is not the quality gate&lt;/strong&gt;, tests are, regardless if you write them before or after.&lt;/p&gt;

</description>
      <category>tdd</category>
      <category>productivity</category>
      <category>testing</category>
      <category>programming</category>
    </item>
    <item>
      <title>Musings on my 5th year as a Software Engineer</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Sun, 17 Jul 2022 09:57:48 +0000</pubDate>
      <link>https://dev.to/gervg/musings-on-my-5th-year-as-a-software-engineer-5dcn</link>
      <guid>https://dev.to/gervg/musings-on-my-5th-year-as-a-software-engineer-5dcn</guid>
      <description>&lt;p&gt;I still remember my first day on the job. From the bus stop, I walked under the summer’s day heat dripping with sweat in my button-up shirt. And as I reach the surrounding buildings, I had hoped to seek comfort in the shade and breeze. But I was instead welcomed with what felt like a hot humid breath. Finally, there I was at the office door looking like I overcame an hour of trekking - not the first impression I wish to make. At that point, I’m no longer sure if I was sweating because of the weather or because of nervousness.&lt;/p&gt;

&lt;p&gt;You see, I never planned to be a software engineer (but that’s a story for another day). Heck, I don’t even know what “software engineering” was. All I knew was that these were people writing code for a living. So I wasn’t really confident I could stay in this field for a long time.&lt;/p&gt;

&lt;p&gt;But few months ago, I hit a milestone - I’m now in my 5th year in the industry working as a software engineer. While that may not seem much in the grander scheme of things, I still would like to take this opportunity to look back and share my experiences. Since I don’t think I can exhaustively list all my learnings in a single post, I just decided to make a summary of my thoughts, opinions, and probably some bits of wisdom I picked up in the past 5 years. I divided them into three categories as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
Career - general stuff that I have learned so far in my career progression&lt;/li&gt;
&lt;li&gt;
Way of Working - the nuances of working with other people and the software development process&lt;/li&gt;
&lt;li&gt;
Software craftsmanship - the tacit knowledge that influences me on how I write software&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The bullet points below are not written in any particular order. You may simply skim through them and pick up whichever you think interests (or intrigues?) you.&lt;/p&gt;

&lt;h2&gt;
  
  
  On Career
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The university where you graduated from no longer matters after your first job.&lt;/li&gt;
&lt;li&gt;Education and skill development does not stop once you leave the four corners of the classroom - it’s a life-long commitment.&lt;/li&gt;
&lt;li&gt;Be updated on the trending technologies but no need to dive deep into each one of them. &lt;a href="https://en.wikipedia.org/wiki/Just-in-time_learning"&gt;Just-in-time learning&lt;/a&gt; is enough&lt;/li&gt;
&lt;li&gt;Just because you love building software doesn’t mean you need to be the next big technopreneur. It doesn’t hurt if you really want to be one but it’s not the only path you can take.&lt;/li&gt;
&lt;li&gt;Job titles didn't matter as much as I thought they would and are not always indicative of one’s experience/talent.&lt;/li&gt;
&lt;li&gt;Debating about the difference between engineer, developer, programmer, coder, etc. is a moot point. Each person will have varying specializations and level of experience.&lt;/li&gt;
&lt;li&gt;Learn the market average for the position you are applying for.&lt;/li&gt;
&lt;li&gt;Do not overly boast your accomplishments as they may come off as annoying if not rude, but do not undersell your contributions either. &lt;em&gt;Brag responsibly&lt;/em&gt; as I would say.&lt;/li&gt;
&lt;li&gt;Don’t accept jobs without a formal contract or working agreement, and carefully read the clauses.&lt;/li&gt;
&lt;li&gt;If you have the time and resources to get them, certificates are nice.&lt;/li&gt;
&lt;li&gt;You don’t need to write code on weekends just to tell yourself that you’re a good developer.&lt;/li&gt;
&lt;li&gt;Create healthy relationships with your colleagues and build your network.&lt;/li&gt;
&lt;li&gt;Join and engage with software development communities&lt;/li&gt;
&lt;li&gt;Good performance at work is a by product of good personal development - don’t stop learning stuff may it be technical or soft skills.&lt;/li&gt;
&lt;li&gt;Soft skills are just as important as technical skills.&lt;/li&gt;
&lt;li&gt;Do not be afraid of finding new opportunities for career growth. But also do not jump so frequently as you will not experience how to handle a maturing product or service.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  On Way of Working
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;That I won't be writing code all the time. Software engineering is multi-faceted and its art goes beyond just programming

&lt;ul&gt;
&lt;li&gt;much of the work involves talking with the stakeholders and decision-makers&lt;/li&gt;
&lt;li&gt;managing work for yourself and sometimes even for your team&lt;/li&gt;
&lt;li&gt;negotiating the scope, forecasting work, managing expectations&lt;/li&gt;
&lt;li&gt;designing the system such that it is maintainable, scalable, secure, etc.&lt;/li&gt;
&lt;li&gt;supporting what you release in production&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Agile is an ideal, but the journey to it is an arduous and sometimes disruptive one

&lt;ul&gt;
&lt;li&gt;it requires conceptual integrity on what it means to be "agile"&lt;/li&gt;
&lt;li&gt;the whole organization has to be on board and supportive&lt;/li&gt;
&lt;li&gt;it is not a single defined process but an exploration of what works best for your team

&lt;ul&gt;
&lt;li&gt;but change can be difficult to adapt and may initially slow down progress&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A team is not just a bunch of individuals working on different parts of a single system. A healthy team is one whose members are willing to go beyond the &lt;em&gt;self&lt;/em&gt; mentality and are mutually committed to a common purpose or goal. It should be no silos.&lt;/li&gt;
&lt;li&gt;Software development is a collaborative effort rather than a mere collection of individual contributions. The stereotype that developers are lone wolves is not true.&lt;/li&gt;
&lt;li&gt;Estimations are &lt;em&gt;effin&lt;/em&gt; hard, especially in the face of the unknown. Oftentimes, you’d find yourself not knowing what you don’t know about a particular problem - worse you may not know what the problem is at all.&lt;/li&gt;
&lt;li&gt;Software engineers are passionate and strongly opinionated people

&lt;ul&gt;
&lt;li&gt;We care so much about how to do it the &lt;em&gt;right&lt;/em&gt; that &lt;a href="https://en.wikipedia.org/wiki/Tuckman%27s_stages_of_group_development#Storming"&gt;disagreements have become a natural part of the process&lt;/a&gt;. It doesn’t mean it’s toxic though.&lt;/li&gt;
&lt;li&gt;Software engineering requires careful assessment of pros and cons - there will be no single correct answer&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Pull requests should be egoless. It is an opportunity for discussion and knowledge sharing.&lt;/li&gt;
&lt;li&gt;Explicitly advocate for safe space. This will help empower team members to share ideas, ask questions (even if they’re silly), or try new things while also leaving ample margin for errors.&lt;/li&gt;
&lt;li&gt;Maximize the tools (i.e. a ticket tracking/project management system) you have in your team for documenting stuff. This will help give context to what a particular item is and is useful for asynchronous communication.&lt;/li&gt;
&lt;li&gt;If your process involves a lot of grunt work, look for ways to automate it so you or your team can focus on other stuff.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Software Craftsmanship
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Software development is a web of unknowns and possibilities - there will always be scenarios you’ve never anticipated and trade-offs you never accounted for.&lt;/li&gt;
&lt;li&gt;No software is bug-free&lt;/li&gt;
&lt;li&gt;The best tool is often one that you already know how to use. Conversely, &lt;em&gt;if all you have is a hammer, everything will look like a nail.&lt;/em&gt; Therefore, don’t just learn the tool. Understand the specific problems it is trying to solve.&lt;/li&gt;
&lt;li&gt;Code style depends on the team and the language conventions. What's easy to write or read for me may not be the same for everyone. When working with a team, it is important to establish this as early on and enforce it (i.e. linters, hooks, static code analysis tools, etc.). This will help improve consistency throughout the code base and possibly reduce cognitive load as everyone will know where and how to look for something.&lt;/li&gt;
&lt;li&gt;Code is read much more than it is written. Remember that you are writing code for another person to read later.&lt;/li&gt;
&lt;li&gt;Familiarize yourself with some of the popular language paradigms and type systems. It would make switching easier. And when writing, you may also start borrowing elegant concepts from one language to another&lt;/li&gt;
&lt;li&gt;Learn a version control system. &lt;em&gt;Git gud&lt;/em&gt; (pun intended)&lt;/li&gt;
&lt;li&gt;Learn your editor/IDE. It’s your most important tool. Customize/configure it to your liking to improve your workflow&lt;/li&gt;
&lt;li&gt;Debugger is your best friend&lt;/li&gt;
&lt;li&gt;Logs are essential but overdoing it may create too much noise. Investigation of issues may feel like looking for a needle in a haystack.&lt;/li&gt;
&lt;li&gt;You will never have dedicated time to refactor something. If you can &lt;strong&gt;safely&lt;/strong&gt; and &lt;strong&gt;timely&lt;/strong&gt; refactor something, refactor it now

&lt;ul&gt;
&lt;li&gt;easier said than done especially in legacy systems that can sometimes be too fragile&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;On writing tests:

&lt;ul&gt;
&lt;li&gt;Tests are akin to mathematical proof. If you declare that something behaves as such, then you have to prove it&lt;/li&gt;
&lt;li&gt;Tests are safety net for the next developer that will change something. This will ensure that the previous behavior of your system remained intact&lt;/li&gt;
&lt;li&gt;Tests can also serve as a form of documentation as it is a collection of &lt;em&gt;facts&lt;/em&gt; about a system&lt;/li&gt;
&lt;li&gt;Writing tests can be expensive, but the bug fix turnaround time can be more expensive. Write tests whenever you can and wherever&lt;/li&gt;
&lt;li&gt;TDD is a powerful design tool, but it is not about unit testing&lt;/li&gt;
&lt;li&gt;You don’t always need to do TDD especially when you already have a clear idea of the design and what steps to take to implement it&lt;/li&gt;
&lt;li&gt;Mocks are helpful but are also easily misused. Use them sparingly&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Knowledge and application of design patterns can be a &lt;em&gt;chicken and egg&lt;/em&gt; problem. Learning a design pattern might make you apply it to problems it doesn’t fit in. On the other end of the spectrum, not knowing any design patterns will likely make your code less organized and less maintainable. A possible solution is to work with your team, discuss the pros and cons, and let a design emerge.&lt;/li&gt;
&lt;li&gt;Premature optimization is bad, but that does not mean you’ll willingly write an obviously slow code. Do not let it be an afterthought. As mentioned earlier, conduct timely refactoring and make it sufficiently performant.&lt;/li&gt;
&lt;li&gt;Do not cling to popular conventions or approaches if it doesn’t work for your team lest you be a victim of &lt;em&gt;cargo cult&lt;/em&gt;. And that includes this blog post - don’t just believe everything I say. Critical thinking is necessary in order to achieve solutions that fit the context of your problem. &lt;a href="https://en.wikipedia.org/wiki/No_Silver_Bullet"&gt;There is no silver bullet&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@grakozy?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Greg Rakozy&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/milkyway-man?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>devjournal</category>
      <category>career</category>
      <category>beginners</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to Think in Object-Oriented Way</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Tue, 28 Jun 2022 16:22:00 +0000</pubDate>
      <link>https://dev.to/gervg/how-to-think-in-object-oriented-way-29a2</link>
      <guid>https://dev.to/gervg/how-to-think-in-object-oriented-way-29a2</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;A gentle introduction to Object-Oriented Design&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Who is this for?&lt;/li&gt;
&lt;li&gt;Things I won't cover&lt;/li&gt;
&lt;li&gt;What the heck is OOP?&lt;/li&gt;
&lt;li&gt;
Concepts and Uses

&lt;ul&gt;
&lt;li&gt;1. Categorization&lt;/li&gt;
&lt;li&gt;2. Blueprints and Construction&lt;/li&gt;
&lt;li&gt;3. Grouping of Data&lt;/li&gt;
&lt;li&gt;4. Segregation of Responsibility&lt;/li&gt;
&lt;li&gt;5. Boundaries or Layers&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Notes and Further Reading&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Who is this for?
&lt;/h2&gt;

&lt;p&gt;If you are any of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Someone who already has a decent understanding of any structured programming language. The examples are written in Java but it should be easy to follow as long as you already have a programming background&lt;/li&gt;
&lt;li&gt;Someone who is struggling to understand OOP&lt;/li&gt;
&lt;li&gt;Someone who didn’t study their entire semester and now wants to do a crash course (kidding)&lt;/li&gt;
&lt;li&gt;Or just curious about what this 3 letter acronym is&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;…then this guide is for you.&lt;/p&gt;

&lt;p&gt;Otherwise, you might still get a thing or two here. Maybe this serves a good refresher. Perhaps, you’d notice some mistakes as well, in which case please let me know and I’ll be more than happy to make the correction and credit you :) &lt;/p&gt;

&lt;h2&gt;
  
  
  Things I won’t cover
&lt;/h2&gt;

&lt;p&gt;This is not meant to be a comprehensive guide on OOP. There are already hundreds of books and videos for that. Instead, this is a primer for those who are just starting to get their feet wet with OOP. I will try my best to limit the jargon and terminologies to avoid bogging you down, or else I’ll be defeating the very purpose of this guide.&lt;/p&gt;

&lt;p&gt;As such, I won’t be discussing things here like the &lt;strong&gt;4 pillars of OOP, GoF design patterns, SOLID&lt;/strong&gt;, or other software development principles rooted in OOP. Some of these topics will be (sneakily) touched upon as it is impossible not to do so, but I won’t go into detail to avoid information overload.&lt;/p&gt;

&lt;p&gt;With that out of the way, let’s jump right into it.&lt;/p&gt;




&lt;h2&gt;
  
  
  What the heck is OOP?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;OOP&lt;/strong&gt; stands for &lt;strong&gt;O&lt;/strong&gt;bject-&lt;strong&gt;O&lt;/strong&gt;riented &lt;strong&gt;P&lt;/strong&gt;rogramming, sometimes referred to as &lt;strong&gt;OO&lt;/strong&gt; when used as an adjective. As the name suggests, it is an approach wherein you model parts of your code as if they are individual objects with specific characteristics, states, or behaviors.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;✅ OOP is all about thinking and modeling your code like it’s an actual real-world object&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can think of your program as an actual piece of hardware with individual components that when combined together works as a single unit. Each component would have their own characteristics, their own behavior, and their own state at a given time.&lt;/p&gt;

&lt;p&gt;A good analogy is a desktop computer. Within the system unit, it contains many parts each with their own responsibility (i.e. memory/disk for storage, CPU for all the processing needs, etc.). Then you’ll also have peripherals like keyboard, mouse, or display devices, which serve as your bridge to the external world - accepting inputs or giving outputs.&lt;/p&gt;

&lt;p&gt;Your program, in a way, can also be modeled like that. It can be divided into multiple logical parts then combine them together. If you’ve modeled it properly, you can should also be able to easily swap out same type of parts but with probably different characteristics like how you can switch out a graphics card for another that has better specs and performs differently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concepts and Uses
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Categorization
&lt;/h3&gt;

&lt;p&gt;One of the first things that you’ll learn in programming is the data type or simply &lt;em&gt;type&lt;/em&gt;. You’ve probably already encountered this when declaring or assigning variables like so&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;What this basically does is that it tells your computer that the data you are storing is of type &lt;em&gt;integer&lt;/em&gt;, denoted by &lt;code&gt;int&lt;/code&gt; keyword, and should be treated as such. Its &lt;em&gt;category&lt;/em&gt; is an integer and not a floating-point number, boolean, nor a string, etc.&lt;/p&gt;

&lt;p&gt;In OOP, you have the power to create your own &lt;em&gt;type.&lt;/em&gt; In most OO languages, this comes in the form of a &lt;code&gt;class&lt;/code&gt;. To demonstrate, let’s have a simple &lt;code&gt;Box&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Box&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//fields here&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There can be many types of box:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;shoe box&lt;/li&gt;
&lt;li&gt;jewelry box&lt;/li&gt;
&lt;li&gt;music box&lt;/li&gt;
&lt;li&gt;mail box&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;to name a few.&lt;/p&gt;

&lt;p&gt;These are all wildly different but they all fit our basic idea of what a box should be: some sort of an enclosure to store something.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1na2kruf45avng4qqse1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1na2kruf45avng4qqse1.jpg"&gt;&lt;/a&gt;&lt;br&gt;Assorted Boxes. Image by &lt;a href="https://unsplash.com/@chuttersnap" rel="noopener noreferrer"&gt;Chuttersnap&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/7eQlPra81zQ" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt; 
  &lt;/p&gt;

&lt;p&gt;If we were to play a &lt;a href="http://rosietheclown.ca/parties/?p=116" rel="noopener noreferrer"&gt;Bring Me game&lt;/a&gt; and I say “bring me a box”, I can accept any of those boxes we’ve mentioned. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Box&lt;/span&gt; &lt;span class="n"&gt;box&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;    &lt;span class="c1"&gt;//any box will be accepted&lt;/span&gt;
    &lt;span class="c1"&gt;//do some action here&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;But if I said “bring me a lunch box”, then I won’t accept a shoe box or any other kind of box.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;LunchBox&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Box&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;//fields here&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;accept&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;LunchBox&lt;/span&gt; &lt;span class="n"&gt;lunchBox&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;    &lt;span class="c1"&gt;//will only accept a LunchBox&lt;/span&gt;
    &lt;span class="c1"&gt;//do some action here&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This gives us the option to be either very specific or more generic depending on our expectations or use-cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Blueprints and Construction
&lt;/h3&gt;

&lt;p&gt;When houses or buildings are made, they don’t just magically appear out of thin air (duh). It starts with a careful plan detailing its structure and contents - the blueprint. The blueprint then becomes the basis when the construction begins.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7m9kdax60ea65rjknrfq.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7m9kdax60ea65rjknrfq.jpg"&gt;&lt;/a&gt;&lt;br&gt;Blueprint. Image by &lt;a href="https://unsplash.com/@d_mccullough" rel="noopener noreferrer"&gt;Damon McCullough&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/HtBlQdxfG9k" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt; 
  &lt;/p&gt;

&lt;p&gt;In OOP, it’s the same. You start with a &lt;code&gt;class&lt;/code&gt; that defines how your object is going to behave and look like. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;House&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;floors&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;doors&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;//other characteristics here&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is your object’s blueprint but it doesn’t necessarily mean that your object already exists. That’s why you need to instantiate or create it using the &lt;em&gt;constructor.&lt;/em&gt; Think of your constructors as the actual workers and heavy machinery that helps build your brand new house.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="nc"&gt;House&lt;/span&gt; &lt;span class="n"&gt;aBrandNewHouse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;House&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 &lt;strong&gt;What is a constructor?&lt;/strong&gt;&lt;br&gt;
In class-based OOP languages, a constructor is the a special method of a class whose sole purpose is to create an &lt;em&gt;object instance&lt;/em&gt; for that class.&lt;/p&gt;

&lt;p&gt;By default, every class has a &lt;code&gt;public&lt;/code&gt; (accessible by anyone) no-args constructor. You can change that by having an explicit &lt;code&gt;private&lt;/code&gt; constructor but that’s already beyond the scope of this guide.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is neat because you have the ability to create multiple independent instances. If you need to, you may change one &lt;code&gt;House&lt;/code&gt; without affecting the other. But even then, they are still considered to houses because that is their type.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="nc"&gt;House&lt;/span&gt; &lt;span class="n"&gt;aBrandNewHouse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;House&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;aBrandNewHouse&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"red"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//A red house&lt;/span&gt;

&lt;span class="nc"&gt;House&lt;/span&gt; &lt;span class="n"&gt;anotherBrandNewHouse&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;House&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="n"&gt;anotherBrandNewHouse&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;color&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"blue"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;//A blue house&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h3&gt;
  
  
  3. Grouping of Data
&lt;/h3&gt;


  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn7x3bejhg4o3aoevzd8u.jpg"&gt;Pizza in a box. Image by [Lukas Bee](https://unsplash.com/@lukasbee) on [Unsplash](https://unsplash.com/photos/T-SkHm-18qQ) 
  


&lt;p&gt;Suppose we want to create an app for a pizza shop. One may write &lt;code&gt;Pizza&lt;/code&gt; as follows:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pizza&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;toppings&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;slices&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;BigDecimal&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This is not necessarily wrong. But going back to our earlier definition, OOP is about modelling our code like it’s a real-world object. If you think about it, &lt;code&gt;price&lt;/code&gt; isn’t part of an actual pizza. Otherwise, we’ll being eating pizzas with price tag.&lt;/p&gt;

&lt;p&gt;Instead, we can have a separate class that can contain that information. And in doing so, we can even add more details that’s not part of the pizza itself! &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PizzaOrder&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Pizza&lt;/span&gt; &lt;span class="n"&gt;pizza&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;BigDecimal&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;ServingType&lt;/span&gt; &lt;span class="n"&gt;servingType&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;    &lt;span class="c1"&gt;//enum - DineIn, Delivery, or TakeOut&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the future, if we needed to change &lt;code&gt;Pizza&lt;/code&gt; , say we wanted to offer different kinds of &lt;code&gt;Crust&lt;/code&gt;, we can do so without affecting &lt;code&gt;PizzaOrder&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Pizza&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;toppings&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;Crust&lt;/span&gt; &lt;span class="n"&gt;crust&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;slices&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Whenever you write classes, ask which goes with which. Remember that the members (e.g. fields, methods, etc.) in a class should have &lt;em&gt;high cohesion&lt;/em&gt; - meaning they should be closely related and should be part of the enclosing class. In this example, we created a new &lt;code&gt;PizzaOrder&lt;/code&gt; which can group the information in a more sensible way.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Segregation of Responsibility
&lt;/h3&gt;

&lt;p&gt;A physical system like a machine would usually be composed of different parts each with their own purpose. Let’s take for example a car.&lt;/p&gt;

&lt;p&gt;For the purposes of this discussion, we’re going to oversimplify the parts of a car, namely:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Engine - provides power&lt;/li&gt;
&lt;li&gt;Wheels - translates that engine power to a rolling motion&lt;/li&gt;
&lt;li&gt;Brakes - slows down the car&lt;/li&gt;
&lt;li&gt;Steering - points the car to a certain direction&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With just this basic parts, maybe our car would look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz7atjfsu41skhm8a46qi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz7atjfsu41skhm8a46qi.png"&gt;&lt;/a&gt;&lt;br&gt;The first automobile. I don’t even know if this thing has brakes. Source: &lt;a href="https://group.mercedes-benz.com/company/tradition/company-history/1885-1886.html" rel="noopener noreferrer"&gt;Mercedez-Benz Group&lt;/a&gt; 
  &lt;/p&gt;

&lt;p&gt;Notice how each of the parts have their distinct purpose? So instead of just dumping every behavior in a single class called &lt;code&gt;Car&lt;/code&gt; , we can opt to a separate each part into their own classes and assemble together later.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Engine&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;generatePower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// some implementation here&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Wheels&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;roll&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//some implementation here&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Brakes&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;reduceSpeed&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//some implementation&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Steering&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;steer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Direction&lt;/span&gt; &lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;//some implementation&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;Engine&lt;/span&gt; &lt;span class="nx"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;Wheels&lt;/span&gt; &lt;span class="nx"&gt;wheels&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;Brakes&lt;/span&gt; &lt;span class="nx"&gt;brakes&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;Steering&lt;/span&gt; &lt;span class="nx"&gt;steering&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;//constructor here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This seems to be a lot of code. But why do we have to do this?&lt;br&gt;
Much like in the real world, software components can be swapped out for something else that has a more desired characteristic or behavior.&lt;/p&gt;

&lt;p&gt;Suppose we wanted to have a faster car and we’d want to swap the engine. We can easily do so by giving the car a different engine.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;SuperPowerfulEngine&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Engine&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// some fields here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="c1"&gt;// in some other class, we instantiate a Car&lt;/span&gt;

&lt;span class="nx"&gt;SuperPowerfulEngine&lt;/span&gt; &lt;span class="nx"&gt;engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;SuperPowerfulEngine&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;Wheels&lt;/span&gt; &lt;span class="nx"&gt;wheels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Wheels&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;Brakes&lt;/span&gt; &lt;span class="nx"&gt;brakes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Brakes&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;Steering&lt;/span&gt; &lt;span class="nx"&gt;steering&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Steering&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;//then we give our super powerful engine to our car&lt;/span&gt;
&lt;span class="nx"&gt;Car&lt;/span&gt; &lt;span class="nx"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Car&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;engine&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;wheels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;brakes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;steering&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Imagine our modern day cars if the parts are not distinct from the car itself and could not be replaced, shall we buy an entire car every time something breaks?&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Boundaries or Layers
&lt;/h3&gt;

&lt;p&gt;Now we know how we can categorize things, group relevant information together, and separate responsibilities, we can take it up a notch and create divisions **between two distinct parts so they become independent of each other.&lt;/p&gt;

&lt;p&gt;Take a look at your phone. See that hole below? That’s your charging port, right? That’s also where you plug the cable in case you want to make file transfers to and from your computer.&lt;/p&gt;

&lt;p&gt;If you’re using an Android phone, then that’s a USB-C port you’re looking at. If you have an iPhone, then that’s a Lightning port.&lt;/p&gt;

&lt;p&gt;USB-C and Lightning are types of interfaces. They allow you to connect different things to your phone as long as they follow the form factor. You can think of that form factor as the &lt;em&gt;contract&lt;/em&gt; between your phone and whatever cable or device you’re connecting to it.&lt;/p&gt;

&lt;p&gt;In OOP, we do this with… guess what? An &lt;em&gt;interface&lt;/em&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;UsbCPort&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;transferFile&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;LightningPort&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;charge&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;transferFile&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AndroidPhone&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;UsbCPort&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;//some methods here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IPhone&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;LightningPort&lt;/span&gt; &lt;span class="nx"&gt;port&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;//some methods here&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Remember the &lt;em&gt;Bring Me Example&lt;/em&gt; earlier? This is exactly the same except that the we’re looking at interfaces instead of classes. What this tells us is that an Android phone wouldn’t care whatever you connect to its port, may it be a charger or a computer, as long as it fits the contract - a USB-C. The same is true for iPhone but with Lightning.&lt;/p&gt;

&lt;p&gt;The port creates a physical boundary between the phone and the external device. And this allows us to easily swap out the device we’re connecting to it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Agnostic and loose coupling&lt;br&gt;
The phone port is a good demonstration of how components should be &lt;em&gt;agnostic&lt;/em&gt; and &lt;em&gt;loosely coupled&lt;/em&gt; to one another.&lt;br&gt;
Agnostic refers to a component being ignorant of the thing being plugged to it as long as it fits certain characteristics. In this case, the phone can handle either charging or file transfer as long as you use the designated connector for its port.&lt;br&gt;
Loosely coupled means you can attach or detach something from a component and the component can still act independently without the other. When you disconnect your charger from your phone, your phone still functions normally (as long as you have battery of course!)&lt;br&gt;
In significantly large projects, software components are designed to be loosely coupled so they can be easier to modify, fix, or test in isolation. One example is the database access. With interfaces, we can connect our application to a different database i.e. an in-memory database which only stores data temporarily. This can serve as a fake database where we can conduct our tests safely instead of connecting directly to a real persistent one.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Notes and Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Alan Kay, who coined the term object-oriented, said that the real big idea in OOP is messaging rather than objects. I dare not question his authority on the proper definition of OOP. But I also think that there is value to what it has become and how it is being used today even though it may have deviated from the original intent. If you want to read more about Alan Kay’s clarifications on OOP, check these out:

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://wiki.c2.com/?AlanKayOnMessaging" rel="noopener noreferrer"&gt;Alan Kay On Messaging (c2.com)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://userpage.fu-berlin.de/~ram/pub/pub_jf47ht81Ht/doc_kay_oop_en" rel="noopener noreferrer"&gt;Dr. Alan Kay on the Meaning of "Object-Oriented Programming" (fu-berlin.de)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;While writing about using types to categorize things, I couldn’t help but remember the existence of &lt;em&gt;category theory&lt;/em&gt;. While OOP may have its roots in mathematics, I did not mean &lt;em&gt;category&lt;/em&gt; in that sense. I won’t dare use that in my explanation since I don’t have sufficient knowledge for it. I simply felt that &lt;em&gt;category&lt;/em&gt; may be an easier word than &lt;em&gt;type&lt;/em&gt; but I failed to consider that it might imply another thing. But in case you want to read more, you may check out &lt;em&gt;Category Theory for Programmers&lt;/em&gt; by Bartosz Mileweski. It’s on my reading list as well. Here’s a free copy:

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/hmemcpy/milewski-ctfp-pdf" rel="noopener noreferrer"&gt;https://github.com/hmemcpy/milewski-ctfp-pdf&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Earlier I mentioned “GoF Design Patterns”. This refers to the the book &lt;em&gt;Design Patterns: Elements of Reusable Object-Oriented Software&lt;/em&gt; written by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides aka the Gang of Four (GoF). It’s considered a classic among OO programmers. Here’s a summary I frequent to whenever I need a refresher:

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/kamranahmedse/design-patterns-for-humans" rel="noopener noreferrer"&gt;https://github.com/kamranahmedse/design-patterns-for-humans&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;SOLID is a set of design principles which helps you write elegant and maintainable code. It is formally introduced by Robert Martin aka Uncle Bob, the author of &lt;em&gt;Clean Code&lt;/em&gt; book - also a classic. Personally, I only appreciated OOP after I learned SOLID. That may or may not be the case for you but SOLID is still an indispensable knowledge. There are a lot of great resources about this topic but here’s one that I found straight from the man himself:

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://sites.google.com/site/unclebobconsultingllc/getting-a-solid-start" rel="noopener noreferrer"&gt;Getting a SOLID start. - Clean Coder&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;The examples written here are in Java, a class-based OOP language. But there is another kind which is the prototype-based OOP e.g. used by Javascript.

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Prototype-based_programming" rel="noopener noreferrer"&gt;Prototype-based programming - MDN Web Docs Glossary&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@nahakiole" rel="noopener noreferrer"&gt;Robin Glauser&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/zP7X_B86xOg?utm_source=63921&amp;amp;utm_medium=referral" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>oop</category>
      <category>java</category>
    </item>
    <item>
      <title>Fluent If-Else statements?</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Fri, 15 Oct 2021 06:49:54 +0000</pubDate>
      <link>https://dev.to/gervg/fluent-if-else-statements-mc3</link>
      <guid>https://dev.to/gervg/fluent-if-else-statements-mc3</guid>
      <description>&lt;p&gt;Some showerthoughts for the day:&lt;/p&gt;

&lt;p&gt;I think it would have been nice if languages support &lt;a href="https://martinfowler.com/bliki/FluentInterface.html"&gt;fluent&lt;/a&gt; conditional statements.&lt;/p&gt;

&lt;p&gt;So instead of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;someFunction&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;anotherCondition&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;anotherFunction&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;doSomething&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Maybe have something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;someFunction&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;elseIf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;anotherCondition&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;anotherFunction&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;else&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;doSomething&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or go further and make it return a value&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;someVar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;someFunction&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;elseIf&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;anotherCondition&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="n"&gt;anotherFunction&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
                    &lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;else&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;defaultValue&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pros&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;you get a more succinct and arguably more expressive statement&lt;/li&gt;
&lt;li&gt;if used properly, it may read like a prose&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;it's probably unnatural or unintuitive to some people; more cognitive load perhaps?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'm not actually sure if this already exists elsewhere and I'm too lazy to find out if it does.&lt;br&gt;
But what do you guys think? Is this useful or am I just overthinking it? 😆&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>programming</category>
      <category>java</category>
      <category>functional</category>
    </item>
    <item>
      <title>My Experiences in Writing and Publishing My First Java Library</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Sat, 07 Aug 2021 08:01:40 +0000</pubDate>
      <link>https://dev.to/gervg/my-experiences-in-writing-and-publishing-my-first-java-library-11hc</link>
      <guid>https://dev.to/gervg/my-experiences-in-writing-and-publishing-my-first-java-library-11hc</guid>
      <description>&lt;p&gt;More than a year ago, a friend introduced me to the concept of &lt;a href="https://fsharpforfunandprofit.com/rop/"&gt;Railway-Oriented Programming&lt;/a&gt; (ROP). I liked the idea and the &lt;a href="https://martinfowler.com/bliki/FluentInterface.html"&gt;fluency&lt;/a&gt; that comes with it, but it was a style born out of functional programming - something that is not fully embraced in Java despite the introduction of &lt;a href="https://www.marcobehler.com/guides/a-guide-to-java-versions-and-features#_java_features_8_16"&gt;lambdas and streams in Java  8&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Though there were already a few existing Java libraries for this, I thought it might be a good idea to write one myself as it was a good opportunity for me to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;understand what ROP is&lt;/li&gt;
&lt;li&gt;practice TDD&lt;/li&gt;
&lt;li&gt;learn how to publish a Java library to a publicly available package repository (i.e. Sonatype Nexus)&lt;/li&gt;
&lt;li&gt;try to use GitHub actions to setup a pipeline and automatically publish the library to the package repository&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zfUAEzAC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/29xg9or0flxhj7a7v8fh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zfUAEzAC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/29xg9or0flxhj7a7v8fh.png" alt="many-months-later-meme" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After a couple of months and tons of procrastination, I was able to came up with something usable albeit not production-ready (that wasn't the goal anyway).&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Gerv-G"&gt;
        Gerv-G
      &lt;/a&gt; / &lt;a href="https://github.com/Gerv-G/jrail"&gt;
        jrail
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Railway-oriented Programming with Java
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;If you're curious, you can get the snapshot &lt;a href="https://oss.sonatype.org/#nexus-search;quick~io.github.gerv-g"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I'm planning to do a write up on what JRail is, what it can do and what I think are its shortcomings (though I think what I've made is not a true ROP). But that's not what this post is all about. For now, here are some thoughts and highlights from the journey:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Naming is (still) hard&lt;/li&gt;
&lt;li&gt;I suck at GitHub&lt;/li&gt;
&lt;li&gt;I don't think I truly understood Monads&lt;/li&gt;
&lt;li&gt;Spock is great but it didn't fit my needs&lt;/li&gt;
&lt;li&gt;Open-source Licensing Options&lt;/li&gt;
&lt;li&gt;Dipping my toes on GitHub Actions&lt;/li&gt;
&lt;li&gt;Creating and approving my own PR&lt;/li&gt;
&lt;li&gt;Publishing the library&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Naming is (still) hard
&lt;/h2&gt;

&lt;p&gt;As clichéd as it may be but naming is really hard. I've been mulling over the name for almost a week before I settled for &lt;em&gt;JRail,&lt;/em&gt; since most Java things either starts or ends with "J". It was only after the creation of the repository that I realized it looks like a name for Japan Rail. But hey, it has already been created and I don't wanna spend another week thinking for a name.&lt;/p&gt;

&lt;h2&gt;
  
  
  I suck at GitHub
&lt;/h2&gt;

&lt;p&gt;Prior to this, I don't have any serious repositories in my Github account. Most of what I have were more like scratch paper scribbles rather than showcase-worthy projects. So yeah, that's a pretty lengthy way to say I don't code outside of work.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zxTBI0wR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvvwwal5fwk83sofg77z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zxTBI0wR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yvvwwal5fwk83sofg77z.png" alt="my-almost-empty-calendar" width="800" height="164"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Look at that contribution calendar. So impressive /s&lt;/p&gt;

&lt;p&gt;It also took me an embarrassing amount of time to setup my SSH keys and the repository which should have only taken a few minutes if not seconds. This is a nice refresher, I guess.&lt;/p&gt;

&lt;h2&gt;
  
  
  I don't think I truly understood Monads
&lt;/h2&gt;

&lt;p&gt;And at this point, I don't think anyone does.&lt;/p&gt;

&lt;p&gt;Kidding aside, I really wanted to understand the underlying theory in this. I believe it's perilous to simply do something without understanding why it is done in such a way. I remember consuming a lot of materials about category theory and functional programming when I first ventured into this project, but wasn't able to retain much information (my brain isn't great).&lt;/p&gt;

&lt;p&gt;The closest I got to understanding it is with &lt;a href="https://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html"&gt;this explanation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;So I tried explaining it my own words to a friend, because "the best way to learn is to teach", right? But I couldn't answer his questions, so perhaps I really didn't get monads after all.&lt;/p&gt;

&lt;p&gt;Like a normal person, I gave up. I may come back to it later if I ever had the motivation again but for now I think I've learned enough to proceed. I then shifted my focus on how I can make the API intuitive enough to use, of course with the help of tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spock is great but it didn't fit my needs
&lt;/h2&gt;

&lt;p&gt;You've probably heard of the testing framework called &lt;a href="https://spockframework.org/"&gt;Spock&lt;/a&gt;, which is written in &lt;a href="https://groovy-lang.org/"&gt;Groovy&lt;/a&gt;. It's great and I love using it everyday for work. So I initially wrote all my tests using it.&lt;/p&gt;

&lt;p&gt;But I realized that having a dynamically-typed language doesn't help me that much in designing the APIs (the not-so-strict Java generics isn't helping either). I also wanted to know what it's like to use the APIs I've made. So to avoid shooting myself on the foot, I decided to rewrite the tests with JUnit instead.&lt;/p&gt;

&lt;p&gt;Another reason is that I wanted to let my tests serve as a documentation or a compilation of examples. I wrote this library with Java devs in mind, and having tests in Groovy is sort of a step towards a different direction. One of the few differences is Groovy closures where the syntax for lambda expressions uses curly braces instead of parentheses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight groovy"&gt;&lt;code&gt;&lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="n"&gt;closureParameters&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;  &lt;span class="n"&gt;statements&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While that may not be so significant for an experienced dev, I didn't want to add any additional cognitive load to the readers anymore. Writing the tests in Java made the "examples" clearer and consistent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open-source Licensing Options
&lt;/h2&gt;

&lt;p&gt;Why the heck are there too many of them? Thankfully, GitHub created &lt;a href="https://choosealicense.com/"&gt;https://choosealicense.com/&lt;/a&gt; to help noobs like me pick the proper license.&lt;/p&gt;

&lt;p&gt;It's unlikely that people are gonna use this anyway. But just in case, I wanted to let them know that I don't care what they want to do with it and I'm not liable whatever chaos they caused.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dipping my toes on GitHub Actions
&lt;/h2&gt;

&lt;p&gt;It's my first time to setup my own CI and it was actually easier than it is to type this whole blog post. GitHub has already provided some workflow templates to get you started so it really is just a matter of clicking. It's also fairly easy to play around with since it's just YAML (as most DevOps things are).&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating and approving my own PR
&lt;/h2&gt;

&lt;p&gt;I don't think I need to explain this. This is the best part of this project&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V6GNfc_v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7gmfodeyacvhuui1o5e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V6GNfc_v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a7gmfodeyacvhuui1o5e.png" alt="self-approve" width="800" height="625"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Publishing the library
&lt;/h2&gt;

&lt;p&gt;This is the most exciting yet frustrating part of the project. I was only able to &lt;a href="https://oss.sonatype.org/#nexus-search;quick~io.github.gerv-g"&gt;publish a snapshot&lt;/a&gt;, but I couldn't sign it properly. After multiple failures in my CI, I decided to skip the signing and just publish a snapshot. I didn't want to publish an unsigned package but I was too lazy to continue. I felt like I've already done what I ought to do so this is already enough of an achievement for me.&lt;/p&gt;

&lt;p&gt;Yup, I'm lazy. I know.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LULtUhEG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fm8tm1ophxnvcknw5a32.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LULtUhEG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fm8tm1ophxnvcknw5a32.jpg" alt="Alt Text" width="800" height="658"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Building JRail was a pretty fun exercise despite my failure to complete it. I may comeback to it later to improve it and to revisit its paradigm since I don't think I've followed ROP. But realistically speaking, I'll probably just leave it as it is because I usually prefer to stay away from coding after work hours. It's just my own way of balancing things and taking the time to enjoy some other stuff.&lt;/p&gt;

&lt;p&gt;Nonetheless, it's still a nice reminder for myself to always practice the basics and to sometimes explore what else I can do other than those that I learn on the job. I think I'll borrow some principles in ROP and apply them to our code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;p&gt;In case you're interested and wanted to try it or do some reading on your own, here are some of resources to get you started:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://fsharpforfunandprofit.com/rop/"&gt;Railway-oriented Programming&lt;/a&gt; by Scott Wlaschin.
This is the original source of the idea as far as I know.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://entzik.medium.com/how-to-publish-open-source-java-libraries-to-maven-central-70f9232462f5"&gt;How to Publish Open Source Java Libraries to Maven Central&lt;/a&gt; by Emil Kirschner.
I read other guides too but his is the easiest to follow despite it being written in Kotlin&lt;/li&gt;
&lt;li&gt;&lt;a href="http://irtfweb.ifa.hawaii.edu/~lockhart/gpg/"&gt;GPG Cheat Sheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;A bunch of functional-programming articles

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html"&gt;Functors, Applicatives, And Monads In Pictures&lt;/a&gt; by Adit Bhargava&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://medium.com/@lettier/your-easy-guide-to-monads-applicatives-functors-862048d61610"&gt;Your easy guide to Monads, Applicatives, &amp;amp; Functors&lt;/a&gt;
This really looks cool with its animations&lt;/li&gt;
&lt;li&gt;&lt;a href="https://stackoverflow.com/a/194207"&gt;This answer in Stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/hmemcpy/milewski-ctfp-pdf/"&gt;Category Theory for Programmers&lt;/a&gt; by Bartosz Milewski.
I haven't finished reading this book but it's really interesting especially if you're interested in the abstract topics of math&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>functional</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>In Defense of the Spaghetti Code</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Sun, 01 Aug 2021 05:50:07 +0000</pubDate>
      <link>https://dev.to/gervg/in-defense-of-the-spaghetti-code-1oha</link>
      <guid>https://dev.to/gervg/in-defense-of-the-spaghetti-code-1oha</guid>
      <description>&lt;p&gt;Anyone working in software would have probably seen a piece of code they wish was never written. Or at least was not written like it was meant to summon creatures from the underworld.&lt;/p&gt;

&lt;p&gt;Funny enough that this tangled ball of mess is so common that we gave it a name: &lt;em&gt;spaghetti code.&lt;/em&gt; And there are probably hundreds of articles, books, and memes about it - yes, we all love to hate it. Dealing with bad unmaintainable code is never fun. No one likes to touch a program that feels like a disaster waiting to happen.&lt;/p&gt;

&lt;p&gt;So why defend it then?&lt;/p&gt;

&lt;p&gt;Well folks, spaghetti code is still &lt;em&gt;spaghetti&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/11uoNyauChZR16/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/11uoNyauChZR16/giphy.gif" alt="girl-eating-pasta"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Everybody Cooks Pasta
&lt;/h2&gt;

&lt;p&gt;When I started my career as a junior software engineer, I was surprised to learn about the rate at which our code changes. Before that, I've only worked with school assignments and projects. Once I've written it and it works, that's final. That's the &lt;em&gt;product&lt;/em&gt; of my work. &lt;/p&gt;

&lt;p&gt;The real world isn't as nice though. Requirements will always change yet the product is expected to adapt as quickly possible. It is interesting that we, as an industry, has created subject areas, or a disciplines if you will, about making changes to software again and again - agile, refactoring, CI/CD, and a slew of other jargons. I don't know much about civil works, but it's probably crazy to think if they do have something similar to how we do software. Can you imagine bridges getting restructured on a daily or weekly basis?&lt;/p&gt;

&lt;p&gt;But that's just the nature of software - nothing is ever permanent. Unlike a bridge, it is &lt;em&gt;soft&lt;/em&gt; in a way that you can mold it in any way you want. It can change and be shaped to fit the ever changing requirements. You know, kinda like a dough.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.bonappetit.com%2Fphotos%2F57d828806520aa8f7013c947%2F1%3A1%2Fw_2560%252Cc_limit%2Ffresh-pasta-dough.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.bonappetit.com%2Fphotos%2F57d828806520aa8f7013c947%2F1%3A1%2Fw_2560%252Cc_limit%2Ffresh-pasta-dough.jpg"&gt;&lt;/a&gt;&lt;br&gt;Pasta Dough. Image by Alex Lau via &lt;a href="https://www.bonappetit.com/recipe/fresh-pasta-dough" rel="noopener noreferrer"&gt;Bonappetit&lt;/a&gt;
  &lt;/p&gt;

&lt;p&gt;But what starts as a simple chunk of dough soon becomes pasta noodles. Cook it, add some sauce, meat, basil on top and voila!&lt;/p&gt;

&lt;p&gt;I'm pretty convinced that spaghetti code (or its variants) exist everywhere, &lt;em&gt;c'est la vie.&lt;/em&gt; That wouldn't stop me from checking  &lt;code&gt;git blame&lt;/code&gt; , but I at least have grown to understand that most are just accidental chefs.&lt;/p&gt;

&lt;h2&gt;
  
  
  A little empathy to the Accidental Chef
&lt;/h2&gt;

&lt;p&gt;I don't think that anyone have intended to write code that looks and feels cursed from the get go. Maybe at the time that was the best way the authors knew how to implement it. Maybe their technical and/or domain knowledge is not ripe enough. Maybe they have limited resources and it was their conscious decision to cut corners. Maybe, maybe...&lt;/p&gt;

&lt;p&gt;My point really is that software projects don't always go our way. We have to accept that it will grow over time and we have to weed out things that we don't like.&lt;/p&gt;

&lt;p&gt;And the spaghetti authors? I'm not gonna jump my gun and call them incompetent or evil. I am pretty sure that I unknowingly have been in their shoes, and those who have to work with my code written months/years ago are probably cursing me right now.&lt;/p&gt;

&lt;h2&gt;
  
  
  It's edible (and can be delicious)
&lt;/h2&gt;

&lt;p&gt;So is it okay to write spaghetti code? No, it is not but mistakes are always bound to happen and this is one of the few things I'd treat as &lt;em&gt;excusable&lt;/em&gt; and &lt;em&gt;remediable&lt;/em&gt; (easier said than done, I know).&lt;/p&gt;

&lt;p&gt;At the end of the day, we write code to create solutions. That spaghetti legacy code may be shitty as it can be. But if it works, provides value for the users, and generates income for you then it's still great.&lt;/p&gt;

&lt;p&gt;"We can write clean code and still provide value to our users", you'll probably say. Then that's even better! Good for you. And that should be everyone's goal. Clean code improves developer experience and can improve turnaround time. But the reality is that not everyone may be capable of reaching that ideal state right away.&lt;/p&gt;

&lt;p&gt;So I'd rather take baby steps with a little bowl of pasta than rush, trip over, and plant my face to a cake.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@dariox" rel="noopener noreferrer"&gt;Dario&lt;/a&gt; at &lt;a href="https://unsplash.com/photos/TtadVut4jsg" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>codequality</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Step by Step Introduction to Unit Testing in Java</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Sat, 10 Apr 2021 07:02:50 +0000</pubDate>
      <link>https://dev.to/gervg/step-by-step-introduction-to-unit-testing-in-java-3ae7</link>
      <guid>https://dev.to/gervg/step-by-step-introduction-to-unit-testing-in-java-3ae7</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Table of Contents&lt;/li&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Naive way of testing code&lt;/li&gt;
&lt;li&gt;
What is Unit testing?

&lt;ul&gt;
&lt;li&gt;An analogy&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

Getting your feet wet

&lt;ul&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;A sample existing code&lt;/li&gt;
&lt;li&gt;Setting up the testing framework&lt;/li&gt;
&lt;li&gt;Separating source code and test code&lt;/li&gt;
&lt;li&gt;Writing your first unit test&lt;/li&gt;
&lt;li&gt;Running the test and using the results to debug&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Final notes&lt;/li&gt;

&lt;li&gt;Further Reading&lt;/li&gt;

&lt;/ul&gt;



&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Hey folks! So I kinda promised to someone I forgot who that I'll write a unit testing guide for this &lt;a href="https://www.facebook.com/groups/649943542157470?_rdc=1&amp;amp;_rdr" rel="noopener noreferrer"&gt;group&lt;/a&gt;. There must be hundreds of similar guides out there in the wild, but I feel like most of those I've seen are too short and doesn't really explain the rationale behind unit testing. I think unit testing is one of the most underrated skill that a programmer should learn and sadly it isn't taught in schools (in our country, at least). So here's my take on a (hopefully) gentle introduction to the world of automated testing. &lt;/p&gt;

&lt;p&gt;Anyway, enough with my babbling. Let's get right into it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Naive way of testing code
&lt;/h2&gt;

&lt;p&gt;When we first started learning programming, what we'd normally do is write code, run the program. Then conduct tests by entering some inputs hoping that the output is as we desired. If not, we go back writing our code again and fixing bugs.&lt;/p&gt;

&lt;p&gt;Well, there's nothing wrong with that. In fact, for your entire life as a programmer you'd be doing all these three things:&lt;/p&gt;

&lt;p&gt;1) &lt;strong&gt;write&lt;/strong&gt; code&lt;/p&gt;

&lt;p&gt;2) &lt;strong&gt;run&lt;/strong&gt; the program&lt;/p&gt;

&lt;p&gt;3) &lt;strong&gt;test&lt;/strong&gt; the behavior of your program&lt;/p&gt;

&lt;p&gt;Then repeat again&lt;/p&gt;

&lt;p&gt;But you won't always be writing simple console applications. Sooner or later, you'll find yourself doing repetitive tests with slightly varying inputs.&lt;/p&gt;

&lt;p&gt;In the real world where you'd be dealing with much much bigger and more complex software, doing those three things every time will be &lt;strong&gt;very time consuming&lt;/strong&gt;. There will also be cases where you need to isolate your changes and just &lt;strong&gt;test a specific part&lt;/strong&gt; rather than the whole system.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Unit testing?
&lt;/h2&gt;

&lt;p&gt;So instead of running and testing your entire program every time you have to a change in your code, we can automate it by &lt;strong&gt;writing code to test our code&lt;/strong&gt;. More specifically, write code that would test a single part of the system isolated from everything else. That's unit testing.&lt;/p&gt;
&lt;h3&gt;
  
  
  An analogy
&lt;/h3&gt;

&lt;p&gt;For example, you are building a house and you need some light bulbs. So you go to the store and buy a light bulb. In order to make sure that the light bulb you just bought works, you need to test it. &lt;/p&gt;

&lt;p&gt;But the good thing about it is that it's independent of your house. You can test it by itself. No need to actually install it in your house and see if it lights up. Instead, you or the sales assistant can install it to a test bulb socket (found in most hardware or appliance stores) and see if it lights up. You are essentially &lt;strong&gt;testing&lt;/strong&gt; a single &lt;strong&gt;unit&lt;/strong&gt; of a light bulb which is meant to be part of your house (i.e. the entire system) under construction.&lt;/p&gt;

&lt;p&gt;Imagine if it wasn't possible to test the light bulb alone. You have to go back to your house first, finish building it, install the light bulbs and test if it actually switches on. Quite a hassle, isn't it?&lt;/p&gt;
&lt;h2&gt;
  
  
  Getting your feet wet
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Prerequisites
&lt;/h3&gt;

&lt;p&gt;Before taking this guide, be sure that you are already familiar with Java language as I will not be going through the detail of compiling and running your Java program. Also be sure to have an internet connection as we will be downloading some tools, and libraries. This guide also assumes that you have an existing project where you want to add unit testing. If not, you can just copy-paste the Java files below and follow along.&lt;/p&gt;

&lt;p&gt;It's also worth noting that the guide, for now, is also written to suit MacOS or Linux users. But experienced Windows users may also want to try anyway (and let me know where it gets difficult! I'll make updates on this guide where necessary).&lt;/p&gt;

&lt;p&gt;Below is short list of everything you need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Java 8&lt;/strong&gt; or higher (I'm using Java 8. But to follow this guide, it doesn't matter if you're using a newer version)&lt;/li&gt;
&lt;li&gt;Favorite &lt;strong&gt;Code editor or IDE&lt;/strong&gt; (I use IntelliJ IDEA myself, but you're free to use whatever you want)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gradle&lt;/strong&gt; build tool (download and follow the guide &lt;a href="https://gradle.org/install/" rel="noopener noreferrer"&gt;here&lt;/a&gt;)

&lt;ul&gt;
&lt;li&gt;in case you are already using Gradle, you may want to skip to this step and just add JUnit to your dependencies
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Command Line (Shell or Command Prompt)

&lt;ul&gt;
&lt;li&gt;we'll be doing things from scratch, so having familiarity working in terminal is a great plus&lt;/li&gt;
&lt;li&gt;this also makes this guide IDE-agnostic, meaning you don't have to be very dependent on a specific IDE just to make this work&lt;/li&gt;
&lt;li&gt;if you're on Windows, you may opt to use WSL or the bash prompt that comes with Git (if you are already using one).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  A sample existing code
&lt;/h3&gt;

&lt;p&gt;Say we have an existing console application which accepts input of any length from the user and then our program outputs the reverse of the input. Classic problem.&lt;/p&gt;

&lt;p&gt;So we can implement this by writing the following:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You might notice a "bug" here. That's intentional. We'll delve into that later&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fif9sag99945nq0la5pi3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fif9sag99945nq0la5pi3.png" alt="File structure 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, your project structure should look similar to this. It's alright if you don't have the  &lt;em&gt;.idea&lt;/em&gt; folder or the *&lt;em&gt;.iml&lt;/em&gt; file. Those are just IntelliJ IDEA generated files.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up the testing framework
&lt;/h3&gt;

&lt;p&gt;The testing framework that we're gonna use is &lt;strong&gt;&lt;a href="https://junit.org/junit4/" rel="noopener noreferrer"&gt;JUnit&lt;/a&gt;.&lt;/strong&gt; To add it in our project, we need a &lt;em&gt;dependency manager&lt;/em&gt; such as Gradle.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 &lt;strong&gt;Dependency Manager&lt;/strong&gt;&lt;br&gt;
The great thing about OOP is that it allows us to reuse somebody else's code. Those reusable pieces of code often mature enough that they can be standalone libraries or frameworks. They then get redistributed by various means, either by downloading the JAR files, as in the case of Java, or getting the source code and building it by yourself. These libraries or frameworks become the &lt;em&gt;dependencies&lt;/em&gt; of your project. Some of these libraries/frameworks have dependencies of their own, so you also have to take care of them and add them to your project.&lt;/p&gt;

&lt;p&gt;But doing so multiple times over the duration of your project can be time-consuming, entails difficulties, and is a very repetitive processes. This is where dependency manager comes in.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;dependency manager&lt;/strong&gt; is a tool that helps you download libraries and/or frameworks, as well as their dependencies, to add to your project; while also keeping track of the version you are using for each. Some examples of popular dependency managers for Java projects are &lt;strong&gt;Gradle&lt;/strong&gt; and &lt;strong&gt;Maven&lt;/strong&gt; (which also functions as build tools).&lt;/p&gt;

&lt;p&gt;For further reading about dependency managers and what they can do, check out &lt;a href="https://medium.com/prodsters/what-are-dependency-managers-26d7d907deb8" rel="noopener noreferrer"&gt;this article&lt;/a&gt; by Seun Matt in Medium&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you have prepared the prerequisites listed earlier, you should have Gradle already installed in your system. To check, enter the following in your terminal and it should output a directory where you installed Gradle.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;which gradle
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next, we need to turn our existing console application project into a Gradle project. Expand each step by clicking the drop-down then follow the instructions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Go to your project directory&lt;/p&gt;

&lt;p&gt;In my case, my project is saved in &lt;code&gt;Users/gerv/Source/HelloUnitTesting&lt;/code&gt;.  I can use &lt;code&gt;~&lt;/code&gt; as short hand for my User home directory.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/Source/HelloUnitTesting
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Initialize a Gradle project&lt;/p&gt;

&lt;p&gt;Simple enter the following command and follow the on-screen instructions to setup gradle for your project&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gradle init
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;If you're confused, you can just follow the screenshot below.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmc5th1thg62gq2qx3cj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftmc5th1thg62gq2qx3cj.png" alt="Gradle init output"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might notice that my shell prompt is different. That's because I'm using zsh with oh-my-zsh, but that's a topic for another day. For now, think of that fancy arrow as the &lt;code&gt;$&lt;/code&gt; sign you normally see.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run your first Gradle build&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gradle build
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Then you should see an output similar to this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56g7yqfcq02u295fwdfj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F56g7yqfcq02u295fwdfj.png" alt="Gradle build output"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You might notice that there are a bunch of files added to your project folder. These are files that are generated by &lt;code&gt;gradle init&lt;/code&gt; and will be used by Gradle when building your project. You may happily ignore them for now, but I want to quickly introduce you to one of them, the &lt;code&gt;build.gradle&lt;/code&gt; file. This is the file that contains the list of your dependencies and repositories (from which your dependencies will be downloaded). Take a quick look at it and notice that JUnit is already added; this because we picked JUnit earlier when we ran &lt;code&gt;gradle init&lt;/code&gt; .&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;You may also notice that &lt;code&gt;main&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt; folders are added to the project. We will use them to reorganize our code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Separating source code and test code
&lt;/h3&gt;

&lt;p&gt;Gradle isn't smart enough to know that you already have existing code in your project, and assumes that you are starting a Gradle project from scratch. So it creates its own folders, package, the class named &lt;code&gt;App.java&lt;/code&gt; with the &lt;code&gt;main()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;After running &lt;code&gt;gradle init&lt;/code&gt; , your project directory should look like this.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmi16gb61bwdwg0txi115.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmi16gb61bwdwg0txi115.png" alt="File structure after gradle init"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But we already have ConsoleApplication.java and that serves as the main entry point of our application so we can just get rid of &lt;code&gt;App.java&lt;/code&gt;. We also don't need the package &lt;code&gt;HelloUnitTesting&lt;/code&gt; since we already have an existing one from before. Delete them as you normally would, or if you're like me and you like doing everything in terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; src/main/java/HelloUnitTesting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; src/test/java/HelloUnitTesting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



  &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcs66g1h560qctdwjtvkn.png"&gt;Project directory after deleting some files
  


&lt;p&gt;Then we need to reorganize our code and put them inside the &lt;code&gt;main/java/&lt;/code&gt; folder. To do this, you can either drag the &lt;code&gt;com.gerv.guev&lt;/code&gt; (or whatever your existing package name is) to &lt;code&gt;main/java/&lt;/code&gt; or do it via terminal again&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;mv &lt;/span&gt;src/com src/main/java/com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you're also using IntelliJ IDEA, you might notice that &lt;code&gt;main/java&lt;/code&gt; is marked like a package even though it isn't. To make them appear like normal folders, simply right click on the &lt;code&gt;src&lt;/code&gt; then point to &lt;em&gt;Mark Directory As&lt;/em&gt; and pick &lt;em&gt;Unmark as Sources Root&lt;/em&gt;. Then right click on &lt;code&gt;java&lt;/code&gt; folder under &lt;code&gt;main&lt;/code&gt; then &lt;em&gt;Mark Directory As&lt;/em&gt; and pick &lt;em&gt;Sources Root.&lt;/em&gt; Do the same thing with the &lt;code&gt;java&lt;/code&gt; folder under &lt;code&gt;test&lt;/code&gt;, but pick &lt;em&gt;Test Sources Root&lt;/em&gt;. For the &lt;code&gt;resources&lt;/code&gt; folder, mark them as &lt;em&gt;Resources Root&lt;/em&gt; and &lt;em&gt;Test Resources Root&lt;/em&gt; for &lt;code&gt;main&lt;/code&gt; and &lt;code&gt;test&lt;/code&gt; respectively.&lt;/p&gt;

&lt;p&gt;If you've carefully followed the instructions, your project directory should now look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ouc7hj2jat8l5bh4fr0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6ouc7hj2jat8l5bh4fr0.png" alt="File structure after setting up Gradle"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To quickly check if everything still works, run this and it should tell you "Build Successful". You may also want to try and run your program if it still works as before.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gradle build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If your gradle build is successful but your IDE is complaining (i.e. squiggly red lines, you can just reimport/reopen your project and hopefully your IDE recognizes that it's now a Gradle project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick Recap!&lt;/strong&gt;&lt;br&gt;
That's a lot of things we've already covered. Here's what we've done so far:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;turn our project into a Gradle project&lt;/li&gt;
&lt;li&gt;add JUnit to our dependencies&lt;/li&gt;
&lt;li&gt;Reorganize our project folders&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Writing your first unit test
&lt;/h3&gt;

&lt;p&gt;Now that we have finished setting up our project and its dependencies, we are now ready to write our unit test!&lt;/p&gt;

&lt;p&gt;Under the &lt;code&gt;test/java&lt;/code&gt; folder, create a package &lt;code&gt;com.gerv.guev&lt;/code&gt; or whatever package name you already used in your project. Then create a file named &lt;code&gt;MyStringUtilitiesTest.java&lt;/code&gt;. You may copy the contents of the class for now, I'll explain what it does along the way.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Then we are going to add a test method that actually does nothing. We're taking very small steps to make sure we're not making mistakes and everything is still working as it is.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In the code above, &lt;code&gt;@Test&lt;/code&gt; is an annotation that tells our compiler that the method that we just wrote is a &lt;strong&gt;test method&lt;/strong&gt;. &lt;code&gt;@Test&lt;/code&gt; annotation is located under the &lt;code&gt;org.junit&lt;/code&gt; package (notice the &lt;code&gt;import&lt;/code&gt; statement above).&lt;/p&gt;

&lt;p&gt;A method marked as a &lt;strong&gt;test method&lt;/strong&gt; will be checked by the test runner if it satisfies some conditions we are expecting. In this case, the test should always pass because we told it to &lt;code&gt;assert true&lt;/code&gt; which will always be true no matter what. The point of writing this the first time is to check if our unit testing framework was really set up correctly. After you've written one or if you're already familiar with the testing framework your are using, there's no need to write this one every time.&lt;/p&gt;

&lt;p&gt;To run the test, type in this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gradle &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--tests&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"com.gerv.guev.MyStringUtilitiesTest.someUselessTest"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In the command above, we are telling Gradle to run the test found in a fully qualified name. In this case we're telling it to specifically run &lt;code&gt;someUselessTest()&lt;/code&gt; test method.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;fully qualified name&lt;/strong&gt; consists of the package name, class name, and method name. It represents the hierarchical location of your file or folder and should always be unique.&lt;/p&gt;

&lt;p&gt;But if you have multiple tests inside a class or package, you can just replace it with an asterisk (*) and it should still run&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;gradle &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--tests&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"com.gerv.guev.MyStringUtilitiesTest.*"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  Running the test and using the results to debug
&lt;/h3&gt;

&lt;p&gt;Now, let's replace that useless test with a real one to test our earlier code for reversing a string.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Go ahead and run the test using the command mentioned earlier, and you should see an error similar to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; Task :test FAILED

com.gerv.guev.MyStringUtilitiesTest &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; shouldReturn_ReverseString FAILED
    org.junit.ComparisonFailure at MyStringUtilitiesTest.java:14

1 &lt;span class="nb"&gt;test &lt;/span&gt;completed, 1 failed

FAILURE: Build failed with an exception.

&lt;span class="k"&gt;*&lt;/span&gt; What went wrong:
Execution failed &lt;span class="k"&gt;for &lt;/span&gt;task &lt;span class="s1"&gt;':test'&lt;/span&gt;&lt;span class="nb"&gt;.&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; There were failing tests. See the report at: file:///Users/gerv/Source/HelloUnitTesting/build/reports/tests/test/index.html

&lt;span class="k"&gt;*&lt;/span&gt; Try:
Run with &lt;span class="nt"&gt;--stacktrace&lt;/span&gt; option to get the stack trace. Run with &lt;span class="nt"&gt;--info&lt;/span&gt; or &lt;span class="nt"&gt;--debug&lt;/span&gt; option to get more log output. Run with &lt;span class="nt"&gt;--scan&lt;/span&gt; to get full insights.

&lt;span class="k"&gt;*&lt;/span&gt; Get more &lt;span class="nb"&gt;help &lt;/span&gt;at https://help.gradle.org

BUILD FAILED &lt;span class="k"&gt;in &lt;/span&gt;1s
3 actionable tasks: 1 executed, 2 up-to-date
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This tells us that our test failed. Gradle has a pretty neat way of telling this to us and generates an HTML report. Copy that file path and open it using your browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F070wb3e4wcjqcw6bn0b6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F070wb3e4wcjqcw6bn0b6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From here it says: &lt;code&gt;org.junit.ComparisonFailure: expected:&amp;lt;[olleh]&amp;gt; but was:&amp;lt;[????o]&amp;gt;&lt;/code&gt; on the first line of the stack trace. It tells us many things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;our input string was not reversed hence it is not equal to our expected output &lt;em&gt;"olleh"&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;the actual result does not contain the correct characters or is probably empty. Instead, it's displaying multiple question marks.&lt;/li&gt;
&lt;li&gt;The actual output has the same length as our expected output. It has 5 characters.&lt;/li&gt;
&lt;li&gt;The last character "o" is still the last character in the actual output&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Don't fear the stack trace!&lt;/strong&gt;&lt;br&gt;
Most beginners find the error messages in the stack trace intimidating, but it's actually quite easy to decipher. All you have to do is to read the first line to have a general idea of what caused the failure. If you still don't know at first glance what the error was, skim through the lines and look for your package and class ****then check the line number.&lt;/p&gt;

&lt;p&gt;In our example, it says:&lt;br&gt;
&lt;code&gt;org.junit.ComparisonFailure: expected:&amp;lt;[olleh]&amp;gt; but was:&amp;lt;[????o]&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then I skip lines until I see a familiar package name:&lt;br&gt;
&lt;code&gt;at com.gerv.guev.MyStringUtilitiesTest.shouldReturn_ReverseString(MyStringUtilitiesTest.java:14)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That tells us that there was a &lt;code&gt;ComparisonFailure&lt;/code&gt; at line 14 of our &lt;code&gt;MyStringUtilitiesTest&lt;/code&gt; class. &lt;/p&gt;

&lt;p&gt;Given those findings, we can check back our code to see what was wrong. Here's the current code now with comments. Can you spot what's wrong?&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;From our original code, what we did is we took each letter of the input from left to right then transferring it to the new character array from right to left &lt;strong&gt;but we did not move the index.&lt;/strong&gt; To fix this, we have to decrement the index for it to move from right to left.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now run your test again and it should give that sweet success&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;gradle &lt;span class="nb"&gt;test&lt;/span&gt; &lt;span class="nt"&gt;--tests&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"com.gerv.guev.MyStringUtilitiesTest.*"&lt;/span&gt;

BUILD SUCCESSFUL &lt;span class="k"&gt;in &lt;/span&gt;1s
3 actionable tasks: 2 executed, 1 up-to-date
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Suppose we are going to add features in our string utilities class, like detection of palindrome&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Then all we have to do is to write another unit test and run all of them. The beauty of unit tests is that you'll always have a proof that your older features are still working even after adding new ones. And there's no need to run your console application every time just to do a manual test.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You may continue adding other tests, say a different input word or maybe an entirely different test, then run it as usual. I am leaving that as an exercise for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final notes
&lt;/h2&gt;

&lt;p&gt;We've barely scratched the surface of unit testing and there's a lot more to it than just testing inputs and outputs. We haven't even discussed yet its best practices but that's enough for now. I hope that you get the rough idea of how to use unit testing to your advantage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Parasoft has a quick guide on setting up JUnit and it even teaches how to use it without build tools like Gradle or Maven. Go check it out &lt;a href="https://www.parasoft.com/junit-tutorial-setting-up-writing-and-running-java-unit-tests/" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;There are other excellent testing frameworks available for Java such as &lt;a href="https://testng.org/doc/" rel="noopener noreferrer"&gt;TestNG&lt;/a&gt; and &lt;a href="http://spockframework.org/spock/docs/1.3/index.html" rel="noopener noreferrer"&gt;Spock&lt;/a&gt;. I personally prefer Spock over JUnit because of some features and syntactic sugars. The caveat is it's written using &lt;a href="https://groovy-lang.org/" rel="noopener noreferrer"&gt;Groovy&lt;/a&gt; which is a dynamically-typed language. It might be hard for beginners to quickly grasp it on top of understanding unit-testing.&lt;/li&gt;
&lt;li&gt;For .NET users, there's &lt;a href="https://xunit.net/" rel="noopener noreferrer"&gt;XUnit&lt;/a&gt; as the de facto testing framework for .NET applications. It's (arguably) the successor of the older &lt;a href="https://nunit.org/" rel="noopener noreferrer"&gt;NUnit&lt;/a&gt;. For other languages, just try appending the first few letters of what ever language you're using then "-Unit". For example, JSUnit, PhpUnit, PyUnit, etc.&lt;/li&gt;
&lt;li&gt;Some software development techniques such as &lt;a href="https://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530" rel="noopener noreferrer"&gt;Test-Driven Development (TDD)&lt;/a&gt; and Behavior-Driven Development (BDD) are anchored in the mastery of unit testing. These techniques will help you consciously develop features while also maintaining robustness of your system over time.&lt;/li&gt;
&lt;li&gt;If you're an intermediate or advanced programmer, I strongly recommend that you read Martin Fowler's articles on &lt;a href="https://martinfowler.com/bliki/UnitTest.html#:~:text=I%20think%20that%20the%20term,that%20unit%20is%20working%20correctly" rel="noopener noreferrer"&gt;Unit Testing&lt;/a&gt;, other &lt;a href="https://martinfowler.com/articles/practical-test-pyramid.html#UnitTests" rel="noopener noreferrer"&gt;levels of testing&lt;/a&gt; and the concept of &lt;a href="https://martinfowler.com/bliki/SelfTestingCode.html" rel="noopener noreferrer"&gt;self-testing code&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Unit testing can also help you abstract away the layers of your application by using Test Doubles. You can read another Fowler's article &lt;a href="https://martinfowler.com/bliki/TestDouble.html" rel="noopener noreferrer"&gt;here&lt;/a&gt; or the equally comprehensive &lt;a href="https://docs.microsoft.com/en-us/archive/msdn-magazine/2007/september/unit-testing-exploring-the-continuum-of-test-doubles" rel="noopener noreferrer"&gt;blog&lt;/a&gt; of Mark Seeman at Microsoft.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>beginners</category>
      <category>testing</category>
      <category>java</category>
    </item>
    <item>
      <title>On Trunk-based Development</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Fri, 09 Apr 2021 14:16:12 +0000</pubDate>
      <link>https://dev.to/gervg/on-trunk-based-development-3n10</link>
      <guid>https://dev.to/gervg/on-trunk-based-development-3n10</guid>
      <description>&lt;p&gt;&lt;em&gt;Observation and insights on our team's attempt at Trunk-based development&lt;/em&gt;&lt;/p&gt;




&lt;ul&gt;
&lt;li&gt;Background&lt;/li&gt;
&lt;li&gt;
Here comes the Trunk-based

&lt;ul&gt;
&lt;li&gt;What's not comfortable?&lt;/li&gt;
&lt;li&gt;The transition&lt;/li&gt;
&lt;li&gt;Our experience and some insights&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Verdict&lt;/li&gt;

&lt;li&gt;Notes and Tangential Thoughts&lt;/li&gt;

&lt;li&gt;Sources and further reading&lt;/li&gt;

&lt;/ul&gt;




&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;Earlier last year, our team was asked to switch from GitFlow to Trunk-based development. The change of course didn't happen without receiving opposition, complaints, and whatnots.  But it is worth noting that using GitFlow has its own fair share of pain points, which is likely the reason why our engineering leads decided to try Trunk-based development instead.&lt;/p&gt;

&lt;p&gt;Trunk-based development was introduced to us using the &lt;a href="https://docs.microsoft.com/en-us/azure/devops/learn/devops-at-microsoft/release-flow#:~:text=The%20Release%20Flow%20model%20is,our%20developers%20can%20keep%20working." rel="noopener noreferrer"&gt;Microsoft's Release Flow&lt;/a&gt;, which admittedly I still don't know the difference versus the generic &lt;a href="https://trunkbaseddevelopment.com/" rel="noopener noreferrer"&gt;trunk-based development&lt;/a&gt;. Given that Microsoft have hundreds of developers (and at the time of writing, our IT engineering department is well over 200) and we are also using Azure DevOps, most thought it is probably a good idea that we also use the same strategy that Microsoft has.&lt;/p&gt;

&lt;p&gt;But changing our process for the sake of imitating a model organization or fitting ourselves around a tool seems like a lame excuse. So what exactly needs fixing?&lt;/p&gt;

&lt;h2&gt;
  
  
  The GitFlow problem
&lt;/h2&gt;

&lt;p&gt;One of my observations in using GitFlow is that it tends to have a lot and I mean A LOT of branches, some which are long-living, just to release a feature or issue fixes. Just take a look at this diagram:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy9e3rkj9gktfxvo3zsiq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy9e3rkj9gktfxvo3zsiq.png"&gt;&lt;/a&gt;&lt;br&gt;Fig1. GitFlow branching strategy. &lt;a href="https://nvie.com/posts/a-successful-git-branching-model/" rel="noopener noreferrer"&gt;Source&lt;/a&gt;
  &lt;/p&gt;

&lt;p&gt;Having multiple branches isn't bad per se. In fact, GitFlow is great for simultaneously managing multiple versions, such as in our case, where we have different versions in production, UAT, and DevTest environments. I think GitFlow is really good at enabling developer independence and isolation of changes. That way, you can work with one version without worrying that the other versions will be affected.&lt;/p&gt;

&lt;p&gt;But as our team and repositories grow, it became quite difficult to have a mental model of it. There were also occasions when our team forgot to merge the release branches back to master and develop. There is also a latency (for the lack of a better term) before the fixes issued in the release branches becomes available in the develop branch, where other developers are already working.&lt;/p&gt;

&lt;h2&gt;
  
  
  Here comes the Trunk-based
&lt;/h2&gt;

&lt;p&gt;If using GitFlow has become difficult, then why are we not willing to try a different strategy? Well, there's a couple of reasons but everything probably boils down to comfort.&lt;/p&gt;

&lt;h3&gt;
  
  
  What's not comfortable?
&lt;/h3&gt;

&lt;p&gt;Since we started migrating from &lt;em&gt;monorepo&lt;/em&gt; to &lt;em&gt;service repo&lt;/em&gt; (that's one repository per microservice), different squads can have their own branching strategy especially those that work exclusively with the backend services. Our squad decided to use GitFlow because we wanted to clearly separate the branch we are working on (develop) and those that are in different environments (release, prod/master).&lt;/p&gt;

&lt;p&gt;This was not the case with our front-end teams as they have been using trunk-based development ever since (as what I've been told). And from different anecdotes around the office, we hear that they often have issues with some commits getting removed or replaced by accident. That's like reading bad user reviews on Amazon or [insert your favorite online marketplace here]. Can't expect us to be happy knowing that we're going to move to something that messy.&lt;/p&gt;

&lt;p&gt;We also expect that there will be a learning curve in every adoption of a process or technology. While we welcome learning opportunities, at that time we were in the middle of multiple releases. Given the time that we have, inserting steps or modifying our existing processes doesn't sound justifiable if we just going to do it for the sake of compliance.&lt;/p&gt;

&lt;p&gt;Then there's the notion of &lt;a href="https://trunkbaseddevelopment.com/branch-for-release/#fix-production-bugs-on-trunk" rel="noopener noreferrer"&gt;cherry-picking&lt;/a&gt;, which seems to be norm in trunk-based development. We are wary of using cherry-pick as it feels hacky and probably prone to mistakes. We also rarely use cherry-pick so again this is about the team not being comfortable with our level of knowledge on something.&lt;/p&gt;

&lt;h3&gt;
  
  
  The transition
&lt;/h3&gt;

&lt;p&gt;We merged our feature and release branches to develop, then merged develop to master. Develop is now deprecated and we will now be merging only back to master as it is now the trunkline.&lt;/p&gt;

&lt;p&gt;The change wasn't sudden, and it took as weeks if not months before completely shifting to it. This is due to several releases at the time that has to be completed and merged back to master first. The sad thing was, as far as I know, that there was no concrete plan for the transition. Looking back, it probably was a good thing that we were left to do it at our own pace. With delivery deadlines approaching, we're probably more concerned with how the change would disrupt our timelines rather than the strategy itself.&lt;/p&gt;

&lt;p&gt;Our squad at the time was managing about 7 repositories and they all have to switch to trunk-based. A bit inconvenient, yes, but something we are willing to take on in hopes of having a better workflow.&lt;/p&gt;

&lt;p&gt;It probably won't be fair if I judge it just after a few weeks of use. So I'm gonna stop here for now and come back to this write-up after a few months...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2w4d3cvy31s8dpwh7d4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw2w4d3cvy31s8dpwh7d4.png" alt="Many months meme"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;(I actually forgot I was writing this, so it took longer than it should haha)&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Our experience and some insights
&lt;/h3&gt;

&lt;p&gt;It was not as chaotic as I expected, but it's definitely not the promise land we hoped it would be. One advantage that I see is that all of us can confidently pull from &lt;code&gt;master&lt;/code&gt; every time, knowing that all the changes are always merged first to it. This solves the above mentioned problem where we sometimes forget to merge the release branch back to master.&lt;/p&gt;

&lt;p&gt;The trade-off, however, seems a little too much than the benefits we're reaping. In the absence of feature flags, it's quite hard to manage which gets to production and which doesn't. Suppose there are 3 sets of code changes and let's call them &lt;strong&gt;FeatureA&lt;/strong&gt;, &lt;strong&gt;FeatureB&lt;/strong&gt;, &lt;strong&gt;BugFixC.&lt;/strong&gt; FeatureA and FeatureB are independent features, while BugFixC is a fix issued to address the bugs found during [manual] testing. After applying the fix, &lt;strong&gt;FeatureA+BugFixC&lt;/strong&gt; is ready to reach production but FeatureB isn't (i.e. because it hasn't gone through QA yet or some other sort of manual testing).&lt;/p&gt;

&lt;p&gt;What happens is that we checkout a branch from FeatureA merge commit then we cherry-pick BugFixC to it. Perhaps not an elegant way, but this is the only option we know so far given that we haven't invested time to learn and develop our features around feature flags.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verdict
&lt;/h2&gt;

&lt;p&gt;The truth is &lt;strong&gt;I still don't know.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This might be rather disappointing after the lengthy blabber but my knowledge of trunk-based development is severely limited to what we are currently doing in our squad. While some of my peers are convinced that trunk-based development is another cargo cult, I think that it is our own execution and development process that is failing us. I've talked with friends, former colleagues from other organizations who are currently using trunk-based development and they are finding success with it. So I'm leaning towards the possibility that we are really just not using it correctly and were unable to maximize its potential.&lt;/p&gt;

&lt;p&gt;So are we going to continue using it? Yup, and I don't see us changing it anytime soon. Doing so will be another learning-curve that we have to overcome.&lt;/p&gt;

&lt;p&gt;And we haven't even climbed this trunk yet.&lt;/p&gt;




&lt;h2&gt;
  
  
  Notes and Tangential Thoughts
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Resistance to change might actually be a good thing. It makes us think about the implications thoroughly and it also shows that we really care about what we do.&lt;/li&gt;
&lt;li&gt;You may have noticed my usage of the term "squad". We are trying to adopt the Spotify-flavored agile. Whether that's a good idea or another cargo cult destined to fail is still subject for observation. Currently, there are a lot of difficulties and there seems to be a relapse to non-agile methodologies. I don't think we are doing it right (yet), which perhaps is the reason why we are also having difficulties with our branching strategy. Maybe our processes should mature first, then hopefully our branching strategy will soon evolve to fit our needs.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Sources and further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://trunkbaseddevelopment.com/" rel="noopener noreferrer"&gt;Trunk Based Development&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/azure/devops/learn/devops-at-microsoft/release-flow" rel="noopener noreferrer"&gt;Release Flow - Azure DevOps&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nvie.com/posts/a-successful-git-branching-model/" rel="noopener noreferrer"&gt;A successful Git branching model&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hackernoon.com/gitflow-is-a-poor-branching-model-hack-d46567a156e7" rel="noopener noreferrer"&gt;Gitflow is a Poor Branching Model Hack | Hacker Noon&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://georgestocker.com/2020/03/04/please-stop-recommending-git-flow/" rel="noopener noreferrer"&gt;Please stop recommending Git Flow!&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/alediaferia/git-tips-for-trunk-based-development-1i1g"&gt;Git tips for trunk-based development&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Disclaimer: views, thoughts, and opinions expressed in this text belong solely to the author, and not necessarily to the author's employer, organization, committee or other group or individual&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@niko_photos?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;niko photos&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/tree?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>devops</category>
      <category>devjournal</category>
    </item>
    <item>
      <title>Finally starting a blog</title>
      <dc:creator>Gervin Guevarra</dc:creator>
      <pubDate>Fri, 09 Apr 2021 11:43:20 +0000</pubDate>
      <link>https://dev.to/gervg/finally-starting-a-blog-3i3l</link>
      <guid>https://dev.to/gervg/finally-starting-a-blog-3i3l</guid>
      <description>&lt;p&gt;&lt;em&gt;Cover photo by &lt;a href="https://unsplash.com/@glenncarstenspeters?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Glenn Carstens-Peters&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/typing?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;Hello World, Hello Dev! I'm Gervin and I have been a lurker here in &lt;a href="http://dev.to"&gt;dev.to&lt;/a&gt; since 2017 (I think it was still called Practical Dev back then?), around the same time I started my career as a software engineer.&lt;/p&gt;

&lt;p&gt;Fresh from college, I was hungry for knowledge and immersion. I was really glad when I found this community. I never knew that there's so much more in software development than just knowing how to write code, and &lt;a href="http://dev.to"&gt;dev.to&lt;/a&gt; helped me realize that.&lt;/p&gt;

&lt;p&gt;As one former colleague puts it:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Oh how wrong are you, my sweet summer child&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Aside from reading lots and lots of articles here, I always dreamt of writing my own blog and sharing my thoughts with the rest of the world. I always enjoy discussing with my friends and colleagues about crafting software, so I thought maybe it would be fun too if I put them down in writing.&lt;/p&gt;

&lt;p&gt;And so I made multiple drafts about different topics here and there but I ended up not publishing anything for 3 years. Most of which either went to the bin or were stuck in the &lt;em&gt;eternal drafts&lt;/em&gt; folder haha!&lt;/p&gt;

&lt;h2&gt;
  
  
  What's stopping me?
&lt;/h2&gt;

&lt;p&gt;Well I think there are two things: I'm lazy and there's this paralyzing fear of a blank canvas (or paper/editor, I guess)&lt;/p&gt;

&lt;p&gt;Though I'm not proud, I'm not denying that I'm lazy as f*ck. I would always find some good alibi not to start something or avoid it altogether. Taking "minimizing the work that needs to be done" to the next level except in a bad way.&lt;/p&gt;

&lt;p&gt;Then every time I get a sliver of inspiration to get things done, I feel like the blank editor is staring back at me pressuring me to write something perfect - words flowing with wisdom and expertise. But boy, I'm not a prolific writer and English isn't even my native language. How am I supposed to do this and do it well?&lt;/p&gt;

&lt;p&gt;Yup, there's the alibi.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting over perfectionism
&lt;/h2&gt;

&lt;p&gt;I've been called a perfectionist a handful of times, but never took them seriously as I always felt that I'm not doing good enough or perhaps they were just sarcastic. It was not until I came across this article (which was stuck in my reading list for so long, by the way), that I tried reevaluating myself.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="https://humanparts.medium.com/laziness-does-not-exist-3af27e312d01" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ht0MoR98--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/fit/c/96/96/1%2A36EepSt3AQBEbSSXj6jTug.jpeg" alt="Devon Price"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://humanparts.medium.com/laziness-does-not-exist-3af27e312d01" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;Laziness Does Not Exist. Psychological research is clear: when… | by Devon Price | Human Parts&lt;/h2&gt;
      &lt;h3&gt;Devon Price ・ &lt;time&gt;Jul 15, 2020&lt;/time&gt; ・ 
      &lt;div class="ltag__link__servicename"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hnDHPsJs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/medium-f709f79cf29704f9f4c2a83f950b2964e95007a3e311b77f686915c71574fef2.svg" alt="Medium Logo"&gt;
        humanparts.Medium
      &lt;/div&gt;
    &lt;/h3&gt;
&lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;And to quote:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When a person fails to begin a project that they care about, it’s typically due to either a) anxiety about their attempts not being “good enough” or b) confusion about what the first steps of the task are. Not laziness. In fact, procrastination is more likely when the task is meaningful and the individual cares about doing it well.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Maybe it's in the nature of writing that you have to expose yourself and be vulnerable, for your thoughts are no longer only yours. So you'd want to put enough effort to it to make it factual and enjoyable to read. It's a part of you after all. &lt;/p&gt;

&lt;p&gt;Perhaps, I have just been overthinking. And in my pursuit of writing good essays and articles, I forgot that all I really wanted is to share, discuss, and learn ideas with everyone else. &lt;/p&gt;

&lt;h2&gt;
  
  
  YOLO
&lt;/h2&gt;

&lt;p&gt;So here's me attempting to get it going, starting to setup my profile and writing my first post. I'll try to stop being overly conscious and just put it out there no matter how short or long, good or bad.&lt;/p&gt;

&lt;p&gt;Maybe I'll make mistakes, but those will also be precious learning opportunities.&lt;/p&gt;

&lt;p&gt;Maybe I don't and everything goes well. Then I guess I'll just have fun writing again.&lt;/p&gt;




&lt;p&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Relevant articles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.freecodecamp.org/news/how-to-overcome-your-fear-of-writing-by-writing-like-you-code-d0d6edb9ff62/"&gt;How to overcome your fear of writing by writing like you code&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.freecodecamp.org/news/why-developers-should-know-how-to-write-dc35aa9b71ab"&gt;Why developers should know how to write&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dev</category>
      <category>writing</category>
      <category>firstpost</category>
    </item>
  </channel>
</rss>
