<?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: Cameron Presley</title>
    <description>The latest articles on DEV Community by Cameron Presley (@pcameronpresley).</description>
    <link>https://dev.to/pcameronpresley</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%2F416598%2F0c652a14-8407-40e4-b974-3d50cb2679ef.jpg</url>
      <title>DEV Community: Cameron Presley</title>
      <link>https://dev.to/pcameronpresley</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pcameronpresley"/>
    <language>en</language>
    <item>
      <title>Mars Rover – Intro to Testing</title>
      <dc:creator>Cameron Presley</dc:creator>
      <pubDate>Tue, 26 May 2020 13:30:44 +0000</pubDate>
      <link>https://dev.to/pcameronpresley/mars-rover-intro-to-testing-2f4i</link>
      <guid>https://dev.to/pcameronpresley/mars-rover-intro-to-testing-2f4i</guid>
      <description>&lt;p&gt;Before we continue onto the Mars Rover kata, I wanted to spend some time covering unit testing, the concepts you need to be aware of, and the naming conventions that I’ll be using for the kata. If you’re already well-versed with unit testing practices and methodologies, feel free to skip this post!&lt;/p&gt;

&lt;h2&gt;
  
  
  What This Is and What This Isn’t
&lt;/h2&gt;

&lt;p&gt;The goal of this post isn’t to try to convince you that you should be unit testing your code, but to give you enough information that if you need to unit test your code or if you’re in a codebase that expects tests, you will have the knowledge to hold your own. If you are looking for reasons why you should be testing, there are some great resources in the &lt;em&gt;Additional Reading&lt;/em&gt; section at the end of the post!&lt;/p&gt;

&lt;h2&gt;
  
  
  Unit Testing 101
&lt;/h2&gt;

&lt;p&gt;At its core, &lt;em&gt;unit testing&lt;/em&gt; is the practice of writing code that tests that your code is working correctly. Confused? It’ll make sense in a minute, I promise! If you’ve ever made changes to a project, how confident were you that your changes worked? If I had to guess, there’s a high level of confidence that your changes solved the problem. However, how confident were you that your changes didn’t break some other piece of functionality? I imagine that your confidence is a bit lower. For me, I’m reasonably confident that my changes are solid, but I’m not always sure that I didn’t break some other features elsewhere. The most straightforward approach to verify everything is working correctly is to run the application and try it out, right? For small applications, that’s a pretty reasonable approach to take and wouldn’t take too much time. However, what if you’re working on a more complicated application? How much time is it taking for you to compile the application, launch it, and start navigating through the UI? The premise of unit testing is that we can exercise the same logic that’s running in the application but without having to go through the interface. This type of testing is generally faster and less error-prone since your test code will do the same tests over and over again. The downside is that you’ll spend more time writing code, but for me, I feel much more confident in my work when I can run the full test suite and know pretty quickly if I’ve broken something.&lt;/p&gt;

&lt;h3&gt;
  
  
  Naming Again?!
&lt;/h3&gt;

&lt;p&gt;If you’ve been following along with the Mars Rover kata series then you know I’m a huge fan of using the same language as my Subject Matter Experts (SMEs) when it comes to the problem at hand as it prevents confusion when different terminology is used for the same concept. When it comes to naming my tests, I take this approach one step further and name my tests in such a manner that if you read the class name followed by the method, then you’ll have a clear idea of what the test’s intent is. The main reason I name my tests this way is that if my test fails, I want to know what requirement or workflow is not working so I can see if it makes sense for that workflow to be impacted. Sometimes, a test will start to fail because requirements have changed, so the test needs to be updated or removed. In other cases, the test failure reveals a contradiction in rules so it helps me if I can clearly see the use case and ask the right questions to my SMEs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Framing Context with Given/When/Then
&lt;/h3&gt;

&lt;p&gt;When it comes to naming my test classes and method, I borrow inspiration from the &lt;em&gt;Given/When/Then&lt;/em&gt; naming methodology. I came across this convention when learning about Behavior Driven Development (BDD) early on in my career but I was familiar with the naming convent from working with user stories. The intent of Given/When/Then is that it provides the &lt;em&gt;context&lt;/em&gt;, an &lt;em&gt;action&lt;/em&gt;, and a &lt;em&gt;result&lt;/em&gt;. Going to Mars Rover, an example user story would be  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Given that the rover is at (0, 0) facing North, when it receives the move forward command, then it should be at (0, 1) facing North&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s break this user story down and examine the various parts:&lt;/p&gt;

&lt;h4&gt;
  
  
  Given
&lt;/h4&gt;

&lt;p&gt;The &lt;em&gt;Given&lt;/em&gt; portion of the user story sets up the context of the application. It can be as simple as &lt;em&gt;Given that the user is logged into the system&lt;/em&gt; or as complex as &lt;em&gt;Given that today is a holiday and that a user wants to make a reservation&lt;/em&gt;. The goal here is that someone can read this portion of the story and understand what is being accomplished. For this user story, the context is that we have a Rover that’s located at (0, 0) facing North.&lt;/p&gt;

&lt;h4&gt;
  
  
  When
&lt;/h4&gt;

&lt;p&gt;The &lt;em&gt;When&lt;/em&gt; portion of the user story gives what action is being taken in the application. At this level, we’d typically stay away from technical jargon (i.e. the user clicks the reservation button) and focus more on the workflow being accomplished. For this user story, the action is that the Rover received the Move Forward command.&lt;/p&gt;

&lt;h4&gt;
  
  
  Then
&lt;/h4&gt;

&lt;p&gt;The &lt;em&gt;Then&lt;/em&gt; portion of the user story tells us what the expected result or behavior is. It can be as simple as &lt;em&gt;then the total is $42.55&lt;/em&gt; or as complex as &lt;em&gt;then the sale is declined and the user is informed that there was an issue processing the payment&lt;/em&gt;. For this user story, we’re expecting that after the Rover receives the Move Forward command, then the rover is at (0, 1) facing North.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test Structure and Naming Conventions
&lt;/h3&gt;

&lt;p&gt;Now that we’ve learned a bit more about Given/When/Then, let’s talk about how this can influence your test structure. When I’m writing tests, I’ll typically place them in a unit test project that’s separate from production code so that we don’t deploy the unit tests with the production code. In the case of Mars Rover, if I have a project called &lt;em&gt;MarsRover&lt;/em&gt;, then I’d have a project called &lt;em&gt;MarsRover.UnitTests&lt;/em&gt;. Once I have this new project created, I’ll create a folder called &lt;em&gt;xyzTests&lt;/em&gt; where &lt;em&gt;xyz&lt;/em&gt; is the name of the class I’m writing tests against. So if I’m writing tests against the &lt;em&gt;Rover&lt;/em&gt; class in the &lt;em&gt;MarsRover&lt;/em&gt; project, then I would have a folder called &lt;em&gt;RoverTests&lt;/em&gt; in the &lt;em&gt;MarsRover.UnitTests&lt;/em&gt; project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i2.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/example-test-layout.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8iXwtaVp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/example-test-layout.png%3Fresize%3D228%252C463" alt="Solution Layout for Mars Rover in VS Code"&gt;&lt;/a&gt;Project naming conventions outlined in red. The test class and folder naming conventions outlined in blue&lt;/p&gt;

&lt;p&gt;From here, I’ll generally create a file per method or workflow that I want to test for the class. So based on our user story above, I would have a file called &lt;em&gt;WhenMovingForward&lt;/em&gt; and this file will contain all the different tests for this functionality. Once a file is in place, we can start writing the various test methods for different behaviors. When naming methods, I will include the context for the setup and what the expectations were. By combining the test name and the method name, it will sound like a user story.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i0.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/test-class-with-names.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_whEVaXx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/test-class-with-names.png%3Fresize%3D313%252C267" alt="Shows the test class with names in the test runner"&gt;&lt;/a&gt;VS Code Test Runner showing test classes with test names&lt;/p&gt;

&lt;h3&gt;
  
  
  Organizing Your Test With Arrange/Act/Assert
&lt;/h3&gt;

&lt;p&gt;At this point, we have the infrastructure in place for our tests, so how do we write a good test? Every good test will have three parts, &lt;em&gt;Arrange, Act, and Assert&lt;/em&gt;. In the &lt;em&gt;Arrange&lt;/em&gt; step, we’re going to focus on creating dependencies and getting the initial state setup for the test. For simple tests, this step may only consist of creating the class that we’re testing. For more complicated tests, there may be more dependencies to create, some methods to call, and possibly modifying the local environment. The &lt;em&gt;Act&lt;/em&gt; step is where the method or property that we’re testing is called. This step should be the simplest portion of the test since it should only be a line or two of code. The third and final step is the &lt;em&gt;Assert&lt;/em&gt; step where we check that the result we observed was correct. For simple tests, this could be a single line where check a value whereas more complicated tests may need to check various properties. Using &lt;em&gt;WhenMovingForward&lt;/em&gt; as an example, here’s what an example test might look like.&lt;/p&gt;


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


&lt;p&gt;I like to think of Arrange/Act/Assert (AAA) as a science experiment because we have to first find a hypothesis, design some test to prove or disprove the hypothesis, get all the necessary ingredients together for the test, run the test, and see if we have evidence to support our hypothesis.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;In this post, we took a brief break from the Mars Rover kata to get a quick understanding of unit testing and the naming conventions we’ll be leveraging for the rest of the series! We first talked about the importance of naming and how if we follow &lt;em&gt;Given, When, Then&lt;/em&gt; syntax, we can turn our user stories into readable test names for future engineers. From there, I showed you &lt;em&gt;Arrange, Act, Assert&lt;/em&gt; notation for tests, and an example test using the convention. Next time, we’ll start implementing Rover!&lt;/p&gt;




&lt;h2&gt;
  
  
  Additional Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.jeremybytes.com/Demos.aspx#UTMMF"&gt;&lt;em&gt;Unit Testing Makes Me Faster&lt;/em&gt;&lt;/a&gt; (presentation) by Jeremy Clark&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;&lt;a href="https://martinfowler.com/bliki/GivenWhenThen.html"&gt;Given, When, Then&lt;/a&gt;&lt;/em&gt; by Martin Fowler&lt;/li&gt;
&lt;li&gt;&lt;a href="https://smile.amazon.com/Starting-Unit-Test-Hard-Think-ebook/dp/B00KIZ6JAC"&gt;&lt;em&gt;Starting to Unit Test: Not as Hard as You Think&lt;/em&gt; by Erik Dietrich&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://smile.amazon.com/Art-Unit-Testing-examples/dp/1617290890/"&gt;&lt;em&gt;The Art of Unit Testing: with examples in C# 2nd Edition&lt;/em&gt; by Roy Osherove&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://taylonr.com/talks/everything-i-needed-to-know-about-debugging-i-learned-in-elementary-physics/"&gt;Everything I Needed To Know About Debugging I Learned In Elementary Physics&lt;/a&gt; (presentation) by Nate Taylor&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>learningthroughexample</category>
      <category>marsrover</category>
      <category>unittesting</category>
    </item>
    <item>
      <title>Mars Rover – Modeling Concepts</title>
      <dc:creator>Cameron Presley</dc:creator>
      <pubDate>Tue, 19 May 2020 13:30:46 +0000</pubDate>
      <link>https://dev.to/pcameronpresley/mars-rover-modeling-concepts-1c71</link>
      <guid>https://dev.to/pcameronpresley/mars-rover-modeling-concepts-1c71</guid>
      <description>&lt;p&gt;In the last post, we took a look at the problem description for Mars Rover and developed a set of concepts for the problem. From these concepts, we were able to develop common terminology and determine the relationships between the concepts. In this post, I’m going to show how I think about software design in general and how to apply them when modeling in code.&lt;/p&gt;

&lt;p&gt;As a note, I’ll be showing code in both C# (for Object-Oriented approaches) and F# (for Functional Programming approaches). Once again, these concepts are fundamentals, but depending on your technology stack, the implementations will vary.&lt;/p&gt;

&lt;h2&gt;
  
  
  Design Guidelines
&lt;/h2&gt;

&lt;p&gt;When I’m designing my models, my end goal is to produce software that captures the problem at hand using the same terms that the business uses. By striving for this goal, I can have richer conversations with my stakeholders when I run into interesting interactions of various business rules and can speak to them using the right terminology. In addition to capturing the problem, I will focus on designing my models in such a way that a developer _can’t violate a business rule __because the code won’t compile. _At this point, I would have made &lt;a href="https://fsharpforfunandprofit.com/posts/designing-with-types-making-illegal-states-unrepresentable/"&gt;illegal states unrepresentable&lt;/a&gt; in my code.&lt;/p&gt;

&lt;p&gt;I first came across this term while reading &lt;a href="https://twitter.com/ScottWlaschin"&gt;Scott Wlashcin&lt;/a&gt;‘s work on the terrific &lt;a href="https://fsharpforfunandprofit.com/"&gt;F# for Fun and Profit&lt;/a&gt; website and it immediately resonated with me. I’ve definitely been bitten before working in a codebase where I wrote some code that compiled but blew up in my face during runtime because the parameter I passed in wasn’t valid for the method I was calling. Wouldn’t it be nice if the compiler told me while I was writing the code that what I was doing wouldn’t work? By thinking a bit more about the models being used and what some of their properties are, we can make this goal achievable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Modeling Types
&lt;/h2&gt;

&lt;p&gt;With these goals in mind, when it comes to modeling concepts, I naturally gravitate to types and find that types will fall in one of three categories.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Type Has a Finite Number of Values
&lt;/h3&gt;

&lt;p&gt;If the type has a finite number of valid values, then we can remove error conditions by defining the type to only be one of those possible options. For those from an Object-Oriented background, &lt;em&gt;enums&lt;/em&gt; are a great example of modeling these types as you can explicitly set a label for the different values. For those from a Functional background, &lt;em&gt;sum types&lt;/em&gt; are a great way to model these choices. &lt;/p&gt;

&lt;p&gt;Some examples of such a type include the states in the U.S., the suits for a deck of playing cards, or the months in a year.&lt;/p&gt;


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



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


&lt;h3&gt;
  
  
  The Type Has an Infinite Number of Values
&lt;/h3&gt;

&lt;p&gt;For other types, however, there are so many possible valid values that it’s impossible to list all of them. For example, if we were looking at valid house numbers for an address, any positive integer would be valid so good luck on defining every positive number as an &lt;em&gt;enum&lt;/em&gt; or &lt;em&gt;sum type&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In these cases, I will leverage built-in primitives to model the concept at first. So in the case of &lt;em&gt;HouseNumber&lt;/em&gt;, an integer might be a good enough spot to start. However, if I then find myself writing code that can work on integers, but shouldn’t work on &lt;em&gt;HouseNumbers&lt;/em&gt;, then I might wrap a stronger type around the integer (see below).&lt;/p&gt;


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



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


&lt;h3&gt;
  
  
  The Type Is a Composition of Other Types
&lt;/h3&gt;

&lt;p&gt;As the saying goes, large programs are built by composing a bunch of smaller programs, and types are no different. As we begin to model more complicated types, it’s natural to start thinking about types being composed of other types. For these types, we’ll leverage either &lt;em&gt;objects&lt;/em&gt; (if following OO) or &lt;em&gt;records&lt;/em&gt; (if following FP).&lt;/p&gt;

&lt;p&gt;One way you can determine if you’re needing a composite type like this is if you find yourself using the word &lt;em&gt;and&lt;/em&gt; or &lt;em&gt;has&lt;/em&gt; when describing the type, then it’s a composition. For example:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An Address &lt;em&gt;has&lt;/em&gt; a HouseNumber, it _has _a StreetName, it _has _a State.&lt;/p&gt;

&lt;p&gt;An Address consists of a HouseNumber &lt;em&gt;and&lt;/em&gt; a StreeName &lt;em&gt;and&lt;/em&gt; a State&lt;/p&gt;
&lt;/blockquote&gt;


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



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


&lt;h2&gt;
  
  
  Modeling Types
&lt;/h2&gt;

&lt;p&gt;Now that we’ve talked about some different modeling techniques, let’s see how we can apply those rules as we start to model Mars Rover. From the previous post, we were able to derive the following concepts and relationships:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;em&gt;Rover&lt;/em&gt; has a &lt;em&gt;Location&lt;/em&gt; and an &lt;em&gt;Orientation&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Orientation&lt;/em&gt; is the &lt;em&gt;Direction&lt;/em&gt; that a &lt;em&gt;Rover&lt;/em&gt; is facing&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Location&lt;/em&gt; is the coordinates that the &lt;em&gt;Rover&lt;/em&gt; is located at&lt;/li&gt;
&lt;li&gt;A &lt;em&gt;Command&lt;/em&gt; is something that a &lt;em&gt;Rover&lt;/em&gt; receives from the User&lt;/li&gt;
&lt;li&gt;A &lt;em&gt;Direction&lt;/em&gt; can be North, East, South, or West&lt;/li&gt;
&lt;li&gt;A &lt;em&gt;Command&lt;/em&gt; can be Move Forward, Move Backward, Turn Left,  Turn Right, or Quit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yielding the following graph&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i0.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/simple-domain-model-relationships.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kFUivJH9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/simple-domain-model-relationships.png%3Fresize%3D341%252C301" alt="Domain model for Mars Rover"&gt;&lt;/a&gt;Domain model relationships where Rover has a Location and an Orientation. Orientation is a Direction and Command is not related to anything.&lt;/p&gt;

&lt;p&gt;Given the above rules, we can start taking a look at how to model these in code! We’ll first start with the models that don’t have a dependency, and then build up from there&lt;/p&gt;

&lt;h3&gt;
  
  
  Modeling Direction
&lt;/h3&gt;

&lt;p&gt;From the above requirements, &lt;em&gt;Direction&lt;/em&gt; can only be one of four possible values (North, East, South West). So based on that, it looks like we can leverage the first rule and model &lt;em&gt;Direction&lt;/em&gt; like so:&lt;/p&gt;


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



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


&lt;h3&gt;
  
  
  Modeling Command
&lt;/h3&gt;

&lt;p&gt;From the above requirements, &lt;em&gt;Command&lt;/em&gt; can only be one of five possible values (MoveForward, MoveBackward, TurnLeft, TurnRight, and Quit). Based on that, we can once again leverage the first rule and model &lt;em&gt;Command&lt;/em&gt; like so:&lt;/p&gt;


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



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


&lt;h3&gt;
  
  
  Modeling Location
&lt;/h3&gt;

&lt;p&gt;After talking more with our Subject Matter Expert, a &lt;em&gt;Location&lt;/em&gt; is the &lt;em&gt;Coordinate&lt;/em&gt; where the Rover is located.&lt;/p&gt;

&lt;p&gt;Aha! A new concept!&lt;/p&gt;

&lt;p&gt;When we ask additional questions, we find out that a &lt;em&gt;Coordinate&lt;/em&gt; refers to the &lt;a href="https://en.wikipedia.org/wiki/Cartesian_coordinate_system#Two_dimensions"&gt;Cartesian Coordinate System&lt;/a&gt; and for the problem we’re solving, we can assume that a &lt;em&gt;Coordinate&lt;/em&gt; represents two numbers where the first number represents the location from the x-axis and the second number represents the location from the y-axis.&lt;/p&gt;

&lt;p&gt;With this new information, our mental model has changed to be the following&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i0.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/domain-model-relationships-1.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_sF4bOKo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/domain-model-relationships-1.png%3Fresize%3D406%252C427" alt="Domain Model Relationships"&gt;&lt;/a&gt;Domain model relationships where Rover has a Location and an Orientation. Location is a Coordinate where Coordinate has an X and Y value. Orientation is a Direction and Command is not related to anything.&lt;/p&gt;

&lt;p&gt;Going into further discussion, we find out that both X and Y will be whole numbers for our emulation and that they can be negative. Based on these properties, it sounds like X and Y can be modeled as integers and therefore fall under the second rule.&lt;/p&gt;

&lt;p&gt;Given that a Coordinate has to have both an X and Y value, it sounds like &lt;em&gt;Coordinate&lt;/em&gt; falls under the third rule and that this concept is a composition of X and Y.&lt;/p&gt;


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



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


&lt;h3&gt;
  
  
  Modeling Orientation
&lt;/h3&gt;

&lt;p&gt;From the above requirements, it seems like &lt;em&gt;Orientation&lt;/em&gt; is what we call the &lt;em&gt;Direction&lt;/em&gt; that the &lt;em&gt;Rover&lt;/em&gt; is facing. Based on that, this sounds like a property that &lt;em&gt;Rover&lt;/em&gt; would have.&lt;/p&gt;

&lt;h3&gt;
  
  
  Modeling Rover
&lt;/h3&gt;

&lt;p&gt;Now that we have both the &lt;em&gt;Direction _and _Coordinate&lt;/em&gt; concepts designed, we can start designing &lt;em&gt;Rover&lt;/em&gt;. From the requirements, it looks like &lt;em&gt;Rover _is a combination of _Direction&lt;/em&gt; (known as Orientation) and a &lt;em&gt;Coordinate&lt;/em&gt; (known as a Location). Based on that, _Rover _falls under the third rule and looks like the following.&lt;/p&gt;


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



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


&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;In this post, we implemented the basic types needed to solve the Mars Rover kata! We first started by taking a look at the concepts identified earlier and thought about the characteristics of the type which helped guide us to build software that both uses the terms of the problem domain and also prevents us from creating errors by making illegal states unrepresentable. In the next post, we’ll start adding functionality to our application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://fsharpforfunandprofit.com/posts/designing-with-types-making-illegal-states-unrepresentable/"&gt;Designing with types: Making illegal states unrepresentable&lt;/a&gt; by Scott Wlaschin&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://martinfowler.com/eaaCatalog/domainModel.html"&gt;Domain Model&lt;/a&gt; by Martin Fowler&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>learningthroughexample</category>
      <category>csharp</category>
      <category>fsharp</category>
      <category>functional</category>
    </item>
    <item>
      <title>Mars Rover – Defining The Problem</title>
      <dc:creator>Cameron Presley</dc:creator>
      <pubDate>Tue, 12 May 2020 13:30:29 +0000</pubDate>
      <link>https://dev.to/pcameronpresley/mars-rover-defining-the-problem-2nnm</link>
      <guid>https://dev.to/pcameronpresley/mars-rover-defining-the-problem-2nnm</guid>
      <description>&lt;p&gt;In this installment, we’ll be looking at the problem description for Mars Rover. After becoming more familiar with the problem, we’ll start by identifying the terminology that we should be using when talking about the problem by defining a &lt;em&gt;ubiquitous language.&lt;/em&gt; From there, I’ll show you how to break down the problem into various concepts and how to find the relationships between the various pieces. By the end of this post, you should feel comfortable exploring a new domain, understanding the terminology used, and defining relationships.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Description
&lt;/h2&gt;

&lt;p&gt;Congratulations and welcome to the S.P.A.C.E¹ Institute, good to have you aboard! Our big focus for the year is to develop a rover that can navigate the surface of Mars! While the engineers are working on the design and building of the rover, we can focus on building the navigation module and start iterating on its design. With that in mind, here are a couple of assumptions we’re going to make for this version.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The rover will be traveling on a two-dimensional plane that should be modeled as a coordinate (X, Y)&lt;/li&gt;
&lt;li&gt;The rover is guaranteed to be able to travel in a chosen direction (no worries about obstacles or other landmarks)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Given the above assumptions, here are the business rules that the emulation will need to follow&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When the emulation starts, the rover will always be at (0, 0) and facing North&lt;/li&gt;
&lt;li&gt;There are a series of commands that the rover can receive that can change its location or direction

&lt;ul&gt;
&lt;li&gt;When the rover is told to move forward, then it will move one rover unit in the direction it’s facing&lt;/li&gt;
&lt;li&gt;When the rover is told to move backward, then it will move rover unit away from the direction it’s facing&lt;/li&gt;
&lt;li&gt;When the rover is told to turn left, it will rotate 90 degrees to the left, but not change its location&lt;/li&gt;
&lt;li&gt;When the rover is told to turn right, it will rotate 90 degrees to the right, but not change its location&lt;/li&gt;
&lt;li&gt;When the emulation is told to quit, the rover will stop receiving commands&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;For the emulation, valid directions include North, East, South, and West&lt;/li&gt;
&lt;li&gt;In order to help troubleshoot failures with the emulation, every time a command is received, both the command received, the rover’s location, and the rover’s orientation should be logged.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;¹ Simple Programming Application Checks Expertise&lt;/p&gt;




&lt;h2&gt;
  
  
  Identifying the Domain
&lt;/h2&gt;

&lt;p&gt;When building software, I want to understand the various business terms that are being used to describe the problem so that when I’m talking to subject matter experts (SMEs), I’m using the same terminology as they are. For those who are familiar with &lt;a href="https://en.wikipedia.org/wiki/Domain-driven_design"&gt;&lt;em&gt;Domain-Driven Design&lt;/em&gt;&lt;/a&gt;, this practice of using the same terminology is known as defining a &lt;a href="https://martinfowler.com/bliki/UbiquitousLanguage.html"&gt;ubiquitous language&lt;/a&gt; and the goal is to make sure that when someone says &lt;em&gt;Command&lt;/em&gt;, then we are all referring to the same concept. If you’ve ever worked in a codebase where something was called one thing, but the business referred to it as something different, then you are familiar with the pain of having to map between the two concepts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Find The Nouns
&lt;/h3&gt;

&lt;p&gt;When working to define the ubiquitous language, a common approach is to find the &lt;em&gt;nouns&lt;/em&gt; that are being used in the description as this can create the foundation of your classes (if following Object-Oriented principles) or your types (if following Functional Programming principles).&lt;/p&gt;

&lt;p&gt;Looking over the description again, these nouns stood out to me:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i2.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/domain-models.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VB0xsxPy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i2.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/domain-models.png%3Fresize%3D732%252C72" alt="Identifies domain (Rover, Command, Location, Direction, and Orientation)"&gt;&lt;/a&gt;Domain models: Rover, Command, Location, Direction, and Orientation&lt;/p&gt;

&lt;h3&gt;
  
  
  Find The Relationships
&lt;/h3&gt;

&lt;p&gt;Once the nouns have been found, I’ll pivot to finding out how these different concepts are related to each other. One approach to finding these relationships is using “has-a” and “is-a” relationships. At a high level, if two things are related through “has-a”, then those concepts should be composed together. If two concepts have an “is-a” relationship, then I know that the concepts should be interchangeable for one another.&lt;/p&gt;

&lt;p&gt;To help identify these relationships, I would work with the SME to understand what each of these concepts means and how they relate to each other. Since it’ll be a bit hard to simulate a conversation, here’s the information that we would learn from our SME.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;em&gt;Rover&lt;/em&gt; has a &lt;em&gt;Location&lt;/em&gt; and an &lt;em&gt;Orientation&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Orientation&lt;/em&gt; is the &lt;em&gt;Direction&lt;/em&gt; that a &lt;em&gt;Rover&lt;/em&gt; is facing&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Location&lt;/em&gt; is the coordinates that the &lt;em&gt;Rover&lt;/em&gt; is located at&lt;/li&gt;
&lt;li&gt;A &lt;em&gt;Command&lt;/em&gt; is something that a &lt;em&gt;Rover&lt;/em&gt; receives from the User&lt;/li&gt;
&lt;li&gt;A &lt;em&gt;Direction&lt;/em&gt; can be North, East, South, or West&lt;/li&gt;
&lt;li&gt;A &lt;em&gt;Command&lt;/em&gt; can be Move Forward, Move Backward, Turn Left,  Turn Right, or Quit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With this new understanding, our concepts and relationships would look something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i0.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/simple-domain-model-relationships.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kFUivJH9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i0.wp.com/blog.thesoftwarementor.com/wp-content/uploads/2020/05/simple-domain-model-relationships.png%3Fresize%3D341%252C301" alt="Domain model for Mars Rover"&gt;&lt;/a&gt;Domain model relationships where Rover has a Location and an Orientation. Orientation is a Direction and Command is not related to anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up
&lt;/h2&gt;

&lt;p&gt;In this post, we explored the problem description for the Mars Rover kata and built up our understanding of the various concepts by exploring the nouns. After finding the nouns, we leveraged “has-a” and “is-a” thinking to come up with a rough idea of how the various concepts related to one another. In the next post, we’ll be focusing on how to model these concepts in code!&lt;/p&gt;

</description>
      <category>learningthroughexample</category>
      <category>marsrover</category>
      <category>softwaredesign</category>
    </item>
    <item>
      <title>Learning Through Example – Mars Rover Kata</title>
      <dc:creator>Cameron Presley</dc:creator>
      <pubDate>Tue, 05 May 2020 13:30:02 +0000</pubDate>
      <link>https://dev.to/pcameronpresley/learning-through-example-mars-rover-kata-232b</link>
      <guid>https://dev.to/pcameronpresley/learning-through-example-mars-rover-kata-232b</guid>
      <description>&lt;p&gt;Over my career, I’ve spent a lot of time bringing new engineers up to speed on how to break down problems, how to write better code, and how to write automated tests. What I’ve come to find out is that there are a ton of resources on how to do each of these things individually, but not very many that brings all of these concepts together in one place. The purpose of this series is to bring all of these ideas together as we solve the &lt;a href="https://kata-log.rocks/mars-rover-kata"&gt;Mars Rover kata&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Purpose
&lt;/h2&gt;

&lt;p&gt;For new engineers, this kata has about the right amount of complexity to explore these various concepts and help identify things to improve on. As a team lead at &lt;a href="https://www.sentryone.com/"&gt;SentryOne&lt;/a&gt;, I’ve onboarded interns and our associate engineers using this kata as a launch point to teach them the tooling and processes we use. In addition, this kata serves as a method to evaluate their current skills so we can help round out a solid foundation for their career.&lt;/p&gt;

&lt;p&gt;By the end of this series, you will have a better understanding of how to break down a problem into small, deliverable pieces while being able to write tests around new functionality. Even though there will be a lot of code to look at, none of these concepts are technology-specific so I challenge you to follow along with your tech stack of choice and see how you would implement some of these concepts in that stack. &lt;/p&gt;

&lt;h2&gt;
  
  
  Technologies Used
&lt;/h2&gt;

&lt;p&gt;On the topic of technologies, I’ll be using the following for my implementation of this kata. As long as you find the relevant tool for your technology stack, you should be able to follow along!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Source Control: &lt;a href="https://github.com/cameronpresley/lte-mars-rover"&gt;GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Language/Framework: C# on &lt;a href="https://dotnet.microsoft.com/download"&gt;.NET Core 3.1&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Unit Testing Framework: &lt;a href="https://nunit.org/"&gt;NUnit&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Mocking Framework: &lt;a href="https://nsubstitute.github.io/"&gt;NSubstitute&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Editor: &lt;a href="https://code.visualstudio.com/"&gt;Visual Studio Code&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Series
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blog.thesoftwarementor.com/learning-through-example-mars-rover-kata/"&gt;Part 0 – Introduction&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.thesoftwarementor.com/mars-rover-defining-the-problem/"&gt;Part 1 – Defining the Problem&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.thesoftwarementor.com/mars-rover-modeling-concepts/"&gt;Part 2 – Modeling Concepts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.thesoftwarementor.com/mars-rover-intro-to-testing/"&gt;Part 3 – Intro to Testing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.thesoftwarementor.com/mars-rover-creating-a-rover/"&gt;Part 4 – Creating a Rover&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.thesoftwarementor.com/mars-rover-moving-forward/"&gt;Part 5 – Rover Moving Forward&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.thesoftwarementor.com/mars-rover-moving-backward/"&gt;Part 6 – Rover Moving Backward&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.thesoftwarementor.com/mars-rover-turning-left/"&gt;Part 7 – Rover Turning Left&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://blog.thesoftwarementor.com/mars-rover-refactoring-rover/"&gt;Part 8 – Refactoring Rover&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Part 9 – Rover Turning Right&lt;/li&gt;
&lt;li&gt;Part 10 – Creating a Logger&lt;/li&gt;
&lt;li&gt;Part 11 – Logging to a File&lt;/li&gt;
&lt;li&gt;Part 12 – Combining Rover and Logger &lt;/li&gt;
&lt;li&gt;Part 13 – Implementing the User Interface&lt;/li&gt;
&lt;li&gt;Part 14 – Reflection&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>learningthroughexample</category>
      <category>marsrover</category>
    </item>
  </channel>
</rss>
