<?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: Nahuel Garbezza</title>
    <description>The latest articles on DEV Community by Nahuel Garbezza (@ngarbezza).</description>
    <link>https://dev.to/ngarbezza</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%2F5375%2F519947.png</url>
      <title>DEV Community: Nahuel Garbezza</title>
      <link>https://dev.to/ngarbezza</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ngarbezza"/>
    <language>en</language>
    <item>
      <title>Clean Code Cleanups</title>
      <dc:creator>Nahuel Garbezza</dc:creator>
      <pubDate>Sun, 28 Jun 2020 03:21:13 +0000</pubDate>
      <link>https://dev.to/ngarbezza/clean-code-cleanups-3iod</link>
      <guid>https://dev.to/ngarbezza/clean-code-cleanups-3iod</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Once in a while, we face the task of cleaning up a piece of software. There could be several reasons for deleting code: users don't actually use it (or it is causing a bad experience), we made an experiment and we already got results, there was a temporary business need that is no longer relevant, or maybe it's better to remove it because we can't afford the maintenance cost; in other words, it is adding more problems than business value.&lt;/p&gt;

&lt;p&gt;Having features partially cleaned up is one of the most common problems we can see on any piece of software. It increases the level of uncertainty in the project, and a feeling of "so many things to fix that I don't know where to start". I'll walk you through different stages of cleanup, and things to have in mind to make it in an efficient way, based on my experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prep for cleanup
&lt;/h2&gt;

&lt;p&gt;Most of the time you know that a piece of code is going to disappear. You can &lt;em&gt;smell&lt;/em&gt; it (I heard about a skill of senior developers that is hard to explain which is an ability to smell things like complexity). If that's the case, you can start marking the code to easily find it later on, when you finally decide to make the actual cleanup.&lt;/p&gt;

&lt;p&gt;I remember in one of the teams I worked on, we had to implement the V2 of a feature (which was a rewrite of a successful experimental feature). When we made the project kickoff, in addition to the V2 work, we added two additional tasks to our backlog:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mark the V1 code for deprecation (this could be done right away, independently of the progress on the V2 implementation)&lt;/li&gt;
&lt;li&gt;Remove V1 code and data models associated (this might need more than 1 PR)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I still remember my first attempts to remove code: they were not so well organized, and they always took more time to complete than I initially expected. I clearly underestimated the task. Lesson learned!, Nowadays, I always try to leave marks in the code when appropriate.&lt;/p&gt;

&lt;p&gt;Another cool thing on one of our client projects is a simple deprecation mechanism, where you can mark your code using comments with a specific format:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;# DEPRECATE 2020-12-01; ticket number; brief description&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The cool thing about this snippet is that it has an expiration date. A script on the pre-commit goes through all the deprecation marks and looks for expired ones. If it finds any, a warning is raised and you have to make a decision: bumping the date or addressing the deprecation. It's a simple attempt to avoid leaving legacy code forever (thus becoming more legacy as time passes by).&lt;/p&gt;

&lt;p&gt;Another flagging mechanism I use a lot is in &lt;a href="http://www.cuis-smalltalk.org/"&gt;Cuis Smalltalk&lt;/a&gt;. There's a very simple built-in feature: you can call the &lt;code&gt;#flag:&lt;/code&gt; method on any object (because the method is defined in &lt;code&gt;Object&lt;/code&gt;) and then you can easily find it across your program. It's a &lt;strong&gt;live&lt;/strong&gt; deprecation notification because &lt;strong&gt;it is code&lt;/strong&gt;. You can play with metaprogramming and make cool things out of it: like measuring the technical debt. &lt;code&gt;#flag:&lt;/code&gt; receives an argument that you can use as a way to categorize your mark.&lt;br&gt;
Here's how it looks when we find all the places where &lt;code&gt;#flag:&lt;/code&gt; is used plus a concrete example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--XG5D6DOH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.10pines.com/content/images/2020/06/Screenshot_20200511_212138.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--XG5D6DOH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.10pines.com/content/images/2020/06/Screenshot_20200511_212138.png" alt="Using the live flagging system in Cuis Smalltalk"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Top-down or bottom-up?
&lt;/h2&gt;

&lt;p&gt;Code cleanup goes smoothly if we have a strategy. If you start deleting code randomly, it's very likely to leave things out. So I don't recommend that "strategy" (Or, actually, lack of it :-)).&lt;/p&gt;

&lt;p&gt;In the same way you can build a piece of software, you can clean it up: it could be top-down or bottom-up.&lt;/p&gt;

&lt;p&gt;Top-down means starting from the UI, looking at all the code it's being referenced there and start deleting: if it is a web application, the starting point is the HTML, then JS logic, CSS rules, assets, translation keys, and so on. Then proceeding with communication with the backend (routes/controllers), then services or other objects involved, and lastly the models/data models.&lt;/p&gt;

&lt;p&gt;Bottom-up is exactly the opposite: for instance, removing models and see where it breaks: that is the next thing to address, until you get to the outermost part, that could be the UI.&lt;/p&gt;

&lt;p&gt;I feel more comfortable with the top-down approach because you first remove usages and then definitions (if they are not used somewhere else). Code breaks progressively, while in the opposite approach it is broken in the first touch and it remains broken until you finish. To find unused code, in addition to finders in your IDE, you can rely on linters or tools like &lt;a href="https://unused.codes/"&gt;unused&lt;/a&gt;, which is technology agnostic, and it's easy to run on any project. I used it on Ruby on Rails and it caught a lot of code I missed on my initial searches. I strongly recommend it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Things to have in mind
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Linting rules&lt;/strong&gt;: sometimes, we can build our custom logic to detect unused code. One that I've seen in one of the projects I worked on is a script to detect unused i18n keys (one of the most common pieces of code that get forgotten in a cleanup).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tests coverage&lt;/strong&gt;: before start removing anything, it is a good idea to measure how covered by tests is the code affected by the cleanup, or how &lt;a href="https://medium.com/@kentbeck_7670/test-desiderata-94150638a4b3"&gt;confident&lt;/a&gt; we are with the existing tests (harder to measure because it's subjective). Tests should give us feedback on the cleanup process: if we have few tests, we could be under a false feeling of success. And if you don't have any test, it is a good time to write more, or you will spend a bunch of time on manual testing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Manual regression testing&lt;/strong&gt;: not everything can be caught by automated tests, so we need to know how to test manually, focusing on the most critical areas and parts that could be affected by the change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Metaprogramming&lt;/strong&gt;: cleaning code that makes use of metaprogramming is challenging. And on dynamic languages, it is even harder. We can't just do a text-based search to decide if we should remove a piece of code or not. What I do on these cases is to find where metaprogramming is used (in Ruby, that could be when someone is using &lt;code&gt;send&lt;/code&gt; or &lt;code&gt;method_missing&lt;/code&gt;, or &lt;code&gt;eval&lt;/code&gt; -HOPEFULLY NOT!-) and check if that code could affect or be affected by the cleanup I'm doing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conventions&lt;/strong&gt; (could be seen as a particular case of metaprogramming): sometimes, we can't find exact matches of terms in the code, but there is a functionality that a framework like Rails could be providing. Rails can make, among other conventions, plural/singular conversions automatically for you, so when searching code, you need to have that in mind. For instance, in things like routing, &lt;code&gt;store#index&lt;/code&gt; means to call an &lt;code&gt;index&lt;/code&gt; method on a &lt;code&gt;StoresController&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Not just business logic&lt;/strong&gt;: sometimes removing pieces of code imply removing libraries, configuration files, test fixtures, translation strings, assets, CI setup tasks, and more auxiliary things.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Commenting code instead of removing is not an option&lt;/strong&gt;: DO NOT LEAVE COMMENTED CODE. Commented code is dead and confusing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Version control history is your best friend&lt;/strong&gt;: If you look at the original commit/PR that added the code you want to remove, you might find related groups of code that can be probably deleted together. Also if you have the chance to talk with the person or team that added this feature, probably you could gather additional relevant information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Be prepared for the worst&lt;/strong&gt;: I usually make a revert PR in case something breaks, and let my team (or the person on-call if there are any) know when it is going to be merged/deployed. And if it is possible to make it in small PRs, go for that!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For the future&lt;/strong&gt;: if you are adding new code to your system, think about how you can clean it up. Is there anything that I can help today as the creator of this feature, in case someone (that could be also me) wants to clean it up in the future? Can some comments be helpful to explain WHY a piece of code was introduced? If I have to use metaprogramming (pro-tip: this should be your last resource), how can I make it "not obscure"?&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;p&gt;I'd just say do not underestimate code deletion tasks. There are a lot of things to have in mind. Make it part of your project backlogs, and think about strategies (like the top-down I recommend) to move towards cleaner and stronger codebases.&lt;/p&gt;

</description>
      <category>refactoring</category>
      <category>cleancode</category>
      <category>techdebt</category>
    </item>
    <item>
      <title>Ruby's Array: a Swiss Army Knife?</title>
      <dc:creator>Nahuel Garbezza</dc:creator>
      <pubDate>Sun, 15 Dec 2019 03:39:01 +0000</pubDate>
      <link>https://dev.to/ngarbezza/ruby-s-array-a-swiss-army-knife-39bb</link>
      <guid>https://dev.to/ngarbezza/ruby-s-array-a-swiss-army-knife-39bb</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;In one of the lectures about OOP I usually give at university we go through design patterns and antipatterns. When we first studied the &lt;a href="https://sourcemaking.com/antipatterns/swiss-army-knife"&gt;Swiss Army Knife antipattern&lt;/a&gt;, the students asked me for an example and I didn't hesitate for a second. I immediately thought of the &lt;code&gt;Array&lt;/code&gt; class in Ruby!&lt;/p&gt;

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

&lt;p&gt;On a very questionable design decision, Ruby has an &lt;code&gt;Array&lt;/code&gt; class that can be used as any type of collection. Want a fixed-size collection? use &lt;code&gt;Array&lt;/code&gt;. Want a queue or a stack? use &lt;code&gt;Array&lt;/code&gt;! Want a simple ordered collection? Use &lt;code&gt;Array&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;Next there's a list of all the methods instances of &lt;code&gt;Array&lt;/code&gt; understand:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; Array.instance_methods(false)
=&amp;gt; [:transpose, :fill, :assoc, :rassoc, :uniq, :uniq!, :compact, :compact!, :to_h, :flatten, :flatten!, :shuffle!, :include?, :permut
ation, :combination, :sample, :repeated_combination, :shuffle, :product, :bsearch, :bsearch_index, :repeated_permutation, :map!, :&amp;amp;,
:*, :+, :-, :sort, :count, :find_index, :select, :reject, :collect, :map, :pack, :first, :any?, :reverse_each, :zip, :take, :take_whi
le, :drop, :drop_while, :cycle, :insert, :|, :index, :rindex, :replace, :clear, :&amp;lt;=&amp;gt;, :&amp;lt;&amp;lt;, :==, :[], :[]=, :reverse, :empty?, :eql?,
:concat, :reverse!, :inspect, :delete, :length, :size, :each, :slice, :slice!, :to_ary, :to_a, :to_s, :dig, :hash, :at, :fetch, :last
, :push, :pop, :shift, :frozen?, :unshift, :each_index, :join, :rotate, :rotate!, :sort_by!, :collect!, :sort!, :select!, :keep_if, :
values_at, :delete_at, :delete_if, :reject!]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And I'm being a nice fella and didn't include the extension methods added in ActiveSupport (remember &lt;a href="https://apidock.com/rails/Array/forty_two"&gt;#forty_two&lt;/a&gt;?) ;-)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Array&lt;/code&gt;'s multipurpose use goes against several object-oriented principles. There are no single responsibilities and there are groups of messages only valid for certain contexts. The class loses its essence just to become an object that tries to make everyone happy. The different collection types are not reified at all. Furthermore, if I want to use a stack in my program, I would expect a &lt;code&gt;Stack&lt;/code&gt; class with an essential protocol of &lt;code&gt;push&lt;/code&gt;, &lt;code&gt;pop&lt;/code&gt;, &lt;code&gt;top&lt;/code&gt;, &lt;code&gt;empty?&lt;/code&gt; and nothing else. I'm definitely sure I wouldn't want to retrieve the third element of the stack, for instance. Or to add an element to the bottom.&lt;/p&gt;

&lt;h3&gt;
  
  
  Collection types
&lt;/h3&gt;

&lt;p&gt;The idea of specific collection types is not new: &lt;a href="https://www.cs.virginia.edu/~evans/cs655/readings/smalltalk.html"&gt;Smalltalk-80&lt;/a&gt; specification includes (as of today) the best, in my opinion, collection hierarchy with clearly defined collection types: &lt;code&gt;Array&lt;/code&gt;, &lt;code&gt;Set&lt;/code&gt;, &lt;code&gt;Bag&lt;/code&gt;, &lt;code&gt;OrderedCollection&lt;/code&gt;, &lt;code&gt;SortedCollection&lt;/code&gt; and so on. Even though this collection hierarchy has some design problems, it allows the developers to choose a collection type that fits the domain they are working with. You can use those collections in pretty much any Smalltalk dialect, such as &lt;a href="https://squeak.org/"&gt;Squeak&lt;/a&gt;, &lt;a href="http://www.cuis-smalltalk.org/"&gt;Cuis&lt;/a&gt; or &lt;a href="http://pharo.org/"&gt;Pharo&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Possible Solutions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Don't use Array for everything... have you heard about the Set class?
&lt;/h3&gt;

&lt;p&gt;Ruby has a &lt;a href="https://ruby-doc.org/stdlib-2.6.5/libdoc/set/rdoc/Set.html"&gt;&lt;code&gt;Set&lt;/code&gt; class&lt;/a&gt;! Unfortunately, I rarely see it on Ruby programs, maybe because it's easier to create an &lt;code&gt;Array&lt;/code&gt;. Just type &lt;code&gt;require 'set'&lt;/code&gt; and you'll be set (pun intended) to go. Now that you know about it, it's time to use it!&lt;/p&gt;

&lt;h3&gt;
  
  
  Metaprogramming to make Arrays more specific
&lt;/h3&gt;

&lt;p&gt;Let's say I want to enforce a list to be used as a fixed size collection. What I can do, given I don't want to implement a brand new collection class, is to "select" just the methods we want, depending on the type of collection we need.&lt;/p&gt;

&lt;p&gt;So I want to change default &lt;code&gt;Array&lt;/code&gt;’s behavior (and the way I want to use it) from this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; my_kind_of_array = [1,2,3]
=&amp;gt; [1, 2, 3]
&amp;gt; my_kind_of_array &amp;lt;&amp;lt; 4
=&amp;gt; [1, 2, 3, 4]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; my_true_array = [1,2,3].as_array
=&amp;gt; [1, 2, 3]
&amp;gt; my_true_array &amp;lt;&amp;lt; 4   
NoMethodError: undefined method `&amp;lt;&amp;lt;' for [1, 2, 3]:Array
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This would indicate that I want to use my list as a fixed size collection (that's the purpose of the &lt;code&gt;as_array&lt;/code&gt; message) and therefore, every method to add/remove elements should not be understood on that object. That way I can have (in a dynamic way and still using native &lt;code&gt;Array&lt;/code&gt; methods) the exact essential protocol I need.&lt;/p&gt;

&lt;p&gt;Here’s a way to implement this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;as_array&lt;/span&gt;
    &lt;span class="nb"&gt;instance_eval&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
      &lt;span class="k"&gt;undef&lt;/span&gt; &lt;span class="ss"&gt;:&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="c1"&gt;# and do the same for other methods that add/remove elements&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="nb"&gt;self&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By using &lt;code&gt;instance_eval&lt;/code&gt; I'm able to change that particular instance I'm using, and &lt;code&gt;undef&lt;/code&gt; makes sure that the method is completely removed, and for the end-user, it seems the message never existed at all.&lt;/p&gt;

&lt;p&gt;I can even change the semantics of some of the messages. For instance, &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; on a queue could mean "enqueue", and on a stack could mean "push". Everything you want could happen inside an &lt;code&gt;instance_eval&lt;/code&gt; block: removing methods, adding new ones, and even changing some semantics. Here’s an example of a change in the semantics of &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; to have an array working as a set.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Array&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;as_set&lt;/span&gt;
    &lt;span class="nb"&gt;instance_eval&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
      &lt;span class="k"&gt;undef&lt;/span&gt; &lt;span class="ss"&gt;:[]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:[]=&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:at&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:first&lt;/span&gt; &lt;span class="c1"&gt;# and more&lt;/span&gt;

      &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;&amp;lt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="kp"&gt;include&lt;/span&gt;&lt;span class="p"&gt;?(&lt;/span&gt;&lt;span class="n"&gt;object&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;

    &lt;span class="nb"&gt;self&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is just an experiment, the implementation is not complete but you might get an idea of the final goal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusions
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We still have some antipatterns living in our daily languages and tools. But sometimes, as in Ruby, we have the power to modify the language and/or extend it to suit our needs. This is an option we don't usually consider (maybe for historical reasons, and most people say it's "bad" without strong arguments) but it's perfectly valid.&lt;/li&gt;
&lt;li&gt;Metaprogramming is very helpful in this case, not to add new behavior but to "turn" the swiss army knife in a single, one-purpose tool.&lt;/li&gt;
&lt;li&gt;If collection classes only have essential behavior, developers get more "educated" and they are "forced" to think which kind of collection they want and use it consistently. This would prevent some unexpected hacks to happen.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ruby</category>
      <category>oop</category>
      <category>metaprogramming</category>
      <category>antipatterns</category>
    </item>
    <item>
      <title>6 tips for a powerful TDD session</title>
      <dc:creator>Nahuel Garbezza</dc:creator>
      <pubDate>Wed, 29 May 2019 23:32:11 +0000</pubDate>
      <link>https://dev.to/ngarbezza/6-tips-for-a-powerful-tdd-session-4lmh</link>
      <guid>https://dev.to/ngarbezza/6-tips-for-a-powerful-tdd-session-4lmh</guid>
      <description>&lt;p&gt;(Original article at &lt;a href="https://blog.10pines.com/2018/01/29/6-tips-for-a-powerful-tdd-session/"&gt;10Pines blog here&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;TDD is ~95% practice. The theory about it is really simple and you may already know the Red-Green-Refactor cycle and what to do in each step. Practice is harder, and it's always beneficial to have some guidance as you practice it. Here's a quick list of six things that work for me, and maybe can work for you.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Analysis Paralysis not allowed:&lt;/strong&gt; Sometimes we think too much, and thinking is good but it's also time-consuming and it's better to spend the time building your program, rather than thinking how it should be done. Questions like "how do I call this test?", "is it better to create a separate object or not?" appear all the time. Those kind of questions are ones that you need to ask yourself after your test is green, not before. And maybe you haven't built enough to have an answer, so don't lose much time on them, TDD will guide you sooner or later to the answers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Do not forget step 3:&lt;/strong&gt; Sometimes we make a test pass and we go immediately to the next one. But step 3 (refactor) is an important step, because you can fix the tech debt you just left. It'll be harder to fix later. Check namings as well! And don't forget to refactor the tests. Think about the interest you can accumulate by leaving tech debt. Don't hurt your future self ;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Assertions first:&lt;/strong&gt; in the Act-Arrange-Assert pattern, I like to go from bottom to top. This will help you focus on getting what you want, and then writing all the context you need to make that happen. At the end, you will probably have the minimum context you need for the test. Simplicity is a big win here. Nobody wants to maintain tests with lots of set-up lines of code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Break anxiety:&lt;/strong&gt; Sometimes we have an idea of what our final solution will be, and we cannot resist to code it and then we break the TDD cycle (I confess! It happens to me every day). We lose the flow. We might be introducing a bug (we always tend to think that our solutions are unbreakable). Do not think that because of TDD, you are going slow. Think about the long-term benefits. Starting again the cycle after you broke it, it's also time-consuming. So it's better to go at a constant velocity, without taking "shortcuts". If you do a lot of cycles, you may probably notice that you have already accelerated it.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Leave edge cases to the end:&lt;/strong&gt; Edge cases are usually hard to test, compared with the happy path. And they are not too valuable if you don't have the happy path already covered. Think about the future users of your system. What will be the first thing they will try to do? This should be your priority. Unless you are really sure about what you don't want to happen in your system.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Feel free to take another path if you are stuck:&lt;/strong&gt; Let's say you are stuck in step 2 or even in step 1 trying to get a green test. I suggest that if you are more than 10/15 minutes stuck, you need to do something else to move on. Diverge (leaving the test unfinished and trying another) or rollback (deleting the current work and starting with another test) are both valid options. In TDD we are always following a path, and sometimes it is wise to take a step back and change the path.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In summary:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Do not let anything block you.&lt;/li&gt;
&lt;li&gt;Do not miss opportunities to improve.&lt;/li&gt;
&lt;li&gt;Start small and unperfect, and do small steps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And you will rock!&lt;/p&gt;

</description>
      <category>tdd</category>
    </item>
  </channel>
</rss>
