<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Andrea Koutifaris - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Andrea Koutifaris - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sat, 23 May 2026 16:26:59 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/author/koutifaris/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How I Developed My First Adventure Game ]]>
                </title>
                <description>
                    <![CDATA[ It's hard to tell exactly when my journey creating Occulto, a point and click adventure game, started. But I have a significant date in mind: 3 May 2018. Here's one thing that got the ball rolling: Luigi: Hello Andrea. Sorry to bother you. I would l... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-i-developed-my-first-game/</link>
                <guid isPermaLink="false">66d46011b6b7f664236cbe00</guid>
                
                    <category>
                        <![CDATA[ Art ]]>
                    </category>
                
                    <category>
                        <![CDATA[ C ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #Game Design ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Game Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ lessons learned ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ unity ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Andrea Koutifaris ]]>
                </dc:creator>
                <pubDate>Wed, 09 Mar 2022 20:05:24 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2022/03/presentazione-new.min.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>It's hard to tell exactly when my journey creating Occulto, a point and click adventure game, started. But I have a significant date in mind:</p>
<p>3 May 2018.</p>
<p>Here's one thing that got the ball rolling:</p>
<blockquote>
<p>Luigi: Hello Andrea. Sorry to bother you. I would like to learn how to develop an app. Am I crazy?</p>
<p>Me (Andrea): Hmm... I don't have your number... who are you?</p>
</blockquote>
<p>Reading those two WhatsApp messages now makes me smile. But there are also two other pieces of interesting information:</p>
<p>First, that was May 2018. Now it is 2022... 3 years and some months later, we have published our very first game DEMO. So yes, it took us 3 years to release a demo.</p>
<p>But we are now producing at a steady pace, and in the first months of 2023 we will release the whole game.</p>
<p>That said, if you are planning to develop a game yourself, it won't necessarily take you 4 years…and I have some advice that hopefully will help!</p>
<p>Second, an app – everyone wants to make an app. Do we really need another app? What about a game instead? What I mean is: an adventure game is like a book, you install it, play it, enjoy and eventually uninstall it. It is not yet another app polluting your phone's memory.</p>
<p>Before I start, let me step back and explain what this article is about.</p>
<h2 id="heading-what-well-discuss-in-this-article">What We'll Discuss in This Article</h2>
<p>This article is about how I (Andrea) and Luigi developed <em>Occulto</em>, our first adventure game.</p>
<p>It will cover some technical aspects of the project, as well as how we managed creating and developing it. I'll discuss both psychological and practical parts of the journey.</p>
<p>I'll also provide a shallow comparison between using web technologies (like WebGL) for development vs Unity 2D.</p>
<p>This article consists of:</p>
<ul>
<li><p>A brief story about my passion for Adventure P&amp;C games, and how I ended up developing my own game.</p>
</li>
<li><p>A section about <em>Occulto</em>, the game I am developing</p>
</li>
<li><p>A tech section with a comparison between web technologies and Unity 2D</p>
</li>
<li><p>A section about what I learned through the process, along with some advice if you're creating your own game.</p>
</li>
</ul>
<h2 id="heading-how-i-got-into-adventure-games">How I got Into Adventure Games</h2>
<p>Many years ago, a good friend introduced me to <a target="_blank" href="https://amanita-design.net/games/machinarium.html">Machinarium</a>. Machinarium is one of the best adventure games I've ever played.</p>
<p>After I finished it, I felt the need to create my own adventure game. This feeling was not immediate, but grew stronger over time. Eventually it led me to find Luigi and be actually able to create my own indie game.</p>
<h3 id="heading-first-adventure-game-attempt">First adventure game attempt</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/newton-scene.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In my first attempt at building a game, I contacted some friends and created a small group of people who were enthusiastic about creating an artistic P&amp;C game.</p>
<p>We managed to create a draft of the first scene (see the illustration above). The idea was to make an apple fall on Newton's head, who is resting under the tree.</p>
<p>I used the <a target="_blank" href="https://github.com/playn/playn">Playn Java framework</a> to write in Java and export to Android, iOS and web. At the time I was a Java developer. Playn is still an active project, it may be worth considering if you are looking for a Java 2D game framework.</p>
<p>This first attempt didn't last long. We had a dinner all together, and asked two friends to present us with a draft story of the game. And then I didn't get any feedback from the others and the project vanished into nothing.</p>
<h3 id="heading-second-attempt">Second attempt</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/cover-red-moony.min.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In my second attempt I managed to create four scenes and some game-play among them. But the project failed because I wasn't ready to lead the project. You'll read about that soon.</p>
<p>Below you can see an image of one of the scenes of the game. It was intended to be a modern revisiting of Little Red Riding Hood were wolves were not bad :).</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/room.min.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-third-and-final-adventure-game-attempt-occulto">Third and Final Adventure Game Attempt: Occulto</h2>
<p>Developing <em>Occulto</em> is my 3rd attempt at creating an adventure game – and hopefully this one is successful!</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/village-editor.min.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>Unity Editor: 1° Village</em></p>
<h3 id="heading-intro-to-the-game">Intro to the game</h3>
<p>It is a beautiful morning, and Eliot, a young mage apprentice, is going to the studio of his magister for a lesson about magical potions. Something is wrong from the first moment: why isn't the magister opening the door?</p>
<p>Inside the studio everything is a mess, and a note tells Eliot to go to the church in the village. What is going on? Where is the magister?</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/studio.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>2° Magister studio</em></p>
<p>Will you help Eliot in his journey to find his magister and regain possession of the powerful forbidden book titled "The never written book" that an evil figure is trying to steal?</p>
<p>The demo consists of four scenes:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/monastery.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>3° Monastery</em></p>
<p>and one secret passage between the monastery and the private studio of a monk.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/secret-passage.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>4° Secret passage</em></p>
<p>Below you can see the last scene of the demo.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/hunckback-studio.jpg" alt="Image" width="600" height="400" loading="lazy"></p>
<p><em>5° Monk private studio</em></p>
<h2 id="heading-tech-i-used-to-build-my-adventure-game">Tech I Used to Build My Adventure Game</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/unity-vs-pixijs.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We developed <em>Occulto</em> in the beginning using <a target="_blank" href="https://pixijs.com/">Pixi.JS</a> and HTML. Then, later, I switched to Unity using the 2D features that are now included as default in the editor.</p>
<p>Since this article is quite long, I will not enter in the details of the code. But I will provide a description of the technologies we used and the process of creating the game.</p>
<p>I am planning to write a second article for the technical part.</p>
<p>We are a group of 3 people:</p>
<ul>
<li><p>Myself, Andrea, the developer and project/technical manager. I contribute to the story and game/riddle design as well. I am a software engineer.</p>
</li>
<li><p>Luigi, the wonderful artistic designer who designs and draws the scenes. He is also responsible for the game story and game-play. If you like the illustrations above, then you like Luigi's work :). He graduated in Mathematics.</p>
</li>
<li><p>Antonio is the music and sounds designer. He is a software engineer.</p>
</li>
</ul>
<p>Luigi draws the scenes using <a target="_blank" href="https://www.adobe.com/products/photoshop.html">Photoshop</a> and makes the animations using <a target="_blank" href="https://www.adobe.com/products/aftereffects.html">After Effects</a>. Then he exports everything into images (jpg and png) that I later use to assemble the scenes.</p>
<p>In addition Antonio provides me with the sounds and music for the scenes. We are using mp3 files at the moment, but we are planning to switch to <a target="_blank" href="https://www.fmod.com/">FMOD</a> in the future.</p>
<p>The game uses FHD (1920x1080) images, and runs also on low end mobile devices. If you want to run on a device with 1 GB of RAM, you need to reduce the amount of FHD images. If you load in memory more than 50/60 FHD images, the game may crash on devices with not enough memory.</p>
<p>In normal Unity memory management, the entire scene is loaded on memory, so you have to pay attention to what you add to the scene.</p>
<p>A simple and classic solution to reduce the memory imprint, is to use sprite sheets for the animations. Most of the time an animation will fit in a 2048x2048 sprite. I use <a target="_blank" href="https://www.codeandweb.com/texturepacker">Texture Packer</a> to create and import animation sprite sheets in Unity.</p>
<p>In addition I use <a target="_blank" href="https://imagemagick.org/index.php">ImageMagick</a> <a target="_blank" href="https://en.wikipedia.org/wiki/Command-line_interface">CLI</a> to trim images with an object inside. My input is a FHD transparent PNG with an object inside placed in the right position. Then I use:</p>
<pre><code class="lang-bash">magick mogrify -trim -verbose *.png &gt; trim.txt
</code></pre>
<p>to trim the image and get the precise position of the object.</p>
<p>Finally I add the trimmed image to the scene and place it using a script I made that maps the coordinates inside <em>trim.txt</em> file to the x,y values of the Unity scene.</p>
<p>By trimming and using sprite-sheets, I solved all memory problems. Also smaller images means lower time when loading a scene. In cheap mobile devices, loading a scene can require like 5 or 6 seconds (whereas in more powerful devices it takes less than a second).</p>
<p>Regarding fps and performance, Unity is good – so basically you don't have to do anything special. You just need to avoid bad design. And pay attention to <a target="_blank" href="https://en.wikipedia.org/wiki/Time_complexity">time complexity</a>. For example, avoid searching for an element on every tick of the game loop.</p>
<p>As I mentioned earlier, I am planning to write a tech article about how I developed the game using Unity 2D. If you are interested, follow me or follow us on one of our social accounts.</p>
<h3 id="heading-unity-vs-webgl">Unity vs WebGL</h3>
<p>Even if I used both technologies, I am not an expert (this is my first game). So below I will just list some of the pro and cons of both technologies.</p>
<h4 id="heading-pros-of-webgl">Pros of WebGL</h4>
<ul>
<li><p>Easy to port everywhere with <a target="_blank" href="https://capacitorjs.com/">Capacitor</a> or <a target="_blank" href="https://www.electronjs.org/">Electron</a>.</p>
</li>
<li><p>Programmers friendly: <a target="_blank" href="https://pixijs.com/">PixiJS</a> makes it very easy.</p>
</li>
<li><p>Almost the only working solution if you need a web responsive version.</p>
</li>
<li><p>Continuous integration and delivery to web is very easy, since the output is a bunch of files.</p>
</li>
<li><p>Web development is mature, and you have access to tons of libraries, utilities as well as a web packers, like <a target="_blank" href="https://webpack.js.org/">Webpack</a>.</p>
</li>
<li><p>Collaboration is very easy and mature with Git. There is something about collaboration in Unity, I didn't explore it. I don't know what happens if two people work on the same scene.</p>
</li>
</ul>
<h4 id="heading-cons-of-webgl">Cons of WebGL</h4>
<ul>
<li><p>Slightly lower performances compared to more native frameworks.</p>
</li>
<li><p>Subject to WebViews bugs (which you cannot solve).</p>
</li>
<li><p>It can be difficult for programmers who do not know web development.</p>
</li>
<li><p>WebViews doesn't seem to be ready to perfectly support WebGL. The game wasn't working well on my Neffos, and who knows on which devices it had issues. Maybe WebViews are not yet ready for gaming, but they are definitely ready for HTML and hybrids app.</p>
</li>
</ul>
<h4 id="heading-pros-of-unity">Pros of Unity</h4>
<ul>
<li><p>Graphical editor: it is easier to visualize/update the scene and fine tuning.</p>
</li>
<li><p>Easy and complete: it has almost everything you need.</p>
</li>
<li><p>Good performance: 60 fps even on low end devices at 1920 x 1080 resolution.</p>
</li>
<li><p>Cross platform, but the WebGL version does not work well on mobile phones.</p>
</li>
<li><p>A lot of indie games are made using Unity. If the Unity team introduces a bug, it will be found very soon.</p>
</li>
</ul>
<h4 id="heading-cons-of-unity">Cons of Unity</h4>
<ul>
<li><p>Graphical editor: you need a working updated Unity editor in each of the computers you are going to use. With Linux it's not that simple.</p>
</li>
<li><p><a target="_blank" href="https://store.unity.com/compare-plans">Closed licence</a> but it has a free tier if you earned up to $100K in the last 12 months.</p>
</li>
<li><p>At the moment the mobile web version is not officially supported.</p>
</li>
<li><p>Linux Unity editor is alpha (and I managed to make it work after many attempts).</p>
</li>
<li><p>Not a lot of helpful info about it: most of the posts I read to find help about a particular topic were low quality or were videos. That's far away from stack overflow quality. But the documentation is well done.</p>
</li>
</ul>
<p>Keep in mind that this section is not intended to be an exhaustive comparison between Unity 3D and WebGl frameworks. Depending on your target, one technology could be better than the other.</p>
<p>That said, even if I am a web developer, I must admit that Unity is great for developing a 2D games (and I guess 3D games too).</p>
<h2 id="heading-what-i-learned-while-building-occulto">What I learned While Building Occulto</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2022/03/1_zGuG4nFo8O4e0WMoNWVbMA.jpeg" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-someone-needs-to-lead-the-project">Someone needs to lead the project</h3>
<p>This is my first insight: if it is you who propose a project to others (a game, an app or whatever), they will assume you will lead the project.</p>
<p>At the time I was thinking that I was just a programmer, and didn't act like a project leader. It won't work if someone doesn't actively follow every person in the project.</p>
<h3 id="heading-have-the-right-attitude">Have the right attitude</h3>
<p>It is important to have the right attitude towards people that are participating in the project. You also need to understand if they can be productive.</p>
<p>In this context, "productive" does not have the same meaning it has at work. Productive means "actually able to produce". At work it means how much you produce and how good is your output.</p>
<p>Before I go on, let me tell you a story:</p>
<p>Before embarking on <em>Occulto</em> game development, I decided to help a guy develop the interface for his board game. I did it because I thought the game he invented was a good game that had some brilliant parts to it.</p>
<p>In this case I was the developer, and he was leading the project (being the inventor of a game, doesn't unfortunately imply that you are also good as a project leader).</p>
<p>In the beginning everything was good, and I enjoyed developing the game. In addition I was learning React, which I used as the framework to build the game app. (It is a board game, not a classic one, so React was a good choice, and also it had a lot of pages, not just the game page).</p>
<p>Then things started to become weird: he started asking for deadlines, complaining about delays on the development, and asking for features which I thought weren't really useful in the first version of the game.</p>
<p>In the end it didn't work out and I couldn't work well with him, so I blocked all communication. Remember that I worked on his game for free, and I even solved a nasty bug that caused the back end side of the game to stop working.</p>
<p>So, why this story? To tell you that making a game with a bunch of friends is a very different job than what you do at work. Some advice:</p>
<ul>
<li><p><strong>Don't push people too hard</strong>: if you are making a game for fun, it must be fun. Motivate people and help them. They are working (as you are) for free on a project they believe in.</p>
</li>
<li><p><strong>Don't act like a boss</strong>: even if you direct and follow every step of the game, people should regard you more as a project manager/team leader than a boss.</p>
</li>
</ul>
<h3 id="heading-work-in-your-spare-time">Work in your spare time</h3>
<p>Being able to be "productive" applies also to you. Are you able to work in your spare time on the game? Can you provide a steady output, without long periods of time away from the project?</p>
<p>This is the first obstacle I encountered in my previous attempts. I wasn't able to provide a constant, timely output and people thought the project was falling apart.</p>
<p>In this case, as a programmer, it is important to integrate the output of your other team members (images, animations and sounds) as soon as possible. People will be more engaged if they see their work quickly integrated in the game. Also the sooner you integrate others' work, the sooner you will find and solve problems.</p>
<h3 id="heading-remove-as-many-obstacles-as-you-can">Remove as many obstacles as you can</h3>
<p>In order to work in your spare time, you have to reduce or remove all the obstacles. These can be physical (slow computer, too small a screen, ...) or psychological. The psychological ones are the most subtle. I will try to list some of them:</p>
<p><strong>Feeling guilty for not working</strong>: this is hard, and I think is one of the main reasons for quitting. You have to enjoy working on your project. So deadlines, pushing others to produce more, threatening (like "If you don't work enough you are out") do NOT work.</p>
<p>It is better to motivate people and help them understand what's blocking them (or you) to produce some output.</p>
<p><strong>Obstacles that delays the moment you can actually work</strong>: you may think something like "I'd like to finish that thing I started, I think I can complete it in 10 minutes." Then you think: "But the PC is slow and it will take forever to start... may be tomorrow, now I'll just serf on Instagram".</p>
<p>It is important that when you think you can work a bit on the game, you can actually do it without any delay or obstacle.</p>
<p><strong>Too tired to work on the game</strong>: indeed you must not overdo it. It is important to find a balance between how much you work and how much you rest. But it is also important to avoid long periods of not working on the game.</p>
<p>I noticed that small actions can help: for example for me it is enough to start the Unity Editor to increase the chances that I'll actually work on the game.</p>
<p><strong>Share your results with the others</strong>: even though non technical people may not fully understand what you are doing (and vice-versa), it is satisfying to explain that you solved a performance problem, or that you reduced the bundle size, for example.</p>
<p>In fact, in agile methodologies, telling what you did and what your are going to do is one of the main points.</p>
<p><strong>Persist</strong>. Not everything will be easy. You will have to persist. Even though you are probably making a game because of passion, it is still requires a lot of work and sometimes you have to persevere and overcome problems/blocks. You probably do that all the time at work, you can do it also for your game.</p>
<p><strong>Not every moment is a moment of pleasure</strong>. Imagine when I discovered that the demo, almost ready to be published, wasn't working on some mobile devices and I had to rewrite everything in Unity. I really had a bad weekend.</p>
<p>But then I manage to change my attitude, start with Unity, and regain pleasure in working on the game.</p>
<p>Fortunately Luigi, my partner in the game, understood it and accepted that we needed to delay the release date of the game demo. While it took a lot of time to write the demo (2 years, if you count from the first commit), it took me 3 months to rewrite it.</p>
<h3 id="heading-focus-on-developing-the-game">Focus on developing the game</h3>
<p>It is extremely important to focus on making the game, and not the framework for the game.</p>
<p>Being a programmer you will probably want to write more code than necessary and use your preferred language. Chose a framework based on your needs (cross platform? 2D or 3D? ...) and try to develop a simple level to understand if you made the right choices.</p>
<p>When you start, you won't necessarily have a clear view of the possible frameworks/technologies available to build a game – and there are a lot. In addition you will be biased towards some languages/features.</p>
<p>About that, I can tell you 2 mistakes I made:</p>
<p>I used PixiJS and HTML technologies at first. As opposite as you may think, I was able to go at 60 fps with FHD (1920x1080) resolution even in medium performance mobile devices.</p>
<p>This is because most of the work is done by WebGL. But at a certain point the game started flickering on my old mobile phone (Neffos X1 Max) when ported to a mobile app using Capacitor (webview). But it was working well on the browser and on the other phones I had. Even on my Motorola Moto G first generation (2013 low end device).</p>
<p>I should have tested earlier on mobile (not just with the browser). Also the game wasn't smooth on the my lower end device Moto G (still it was running near 30 fps).</p>
<p>I decided that I wanted my game to run smoothly even on low end devices, so I switched to Unity 2D. Unity is used by a lot of indie game developers, and C# is quite easy. I didn't try Unreal Engine, because I am too rusty on C++. Now it runs smoothly also on my Moto G (60 FPS).</p>
<p>The second thing that was almost a mistake is that I developed a library to find the shortest path on polygon areas with polygon holes. <a target="_blank" href="https://github.com/Kouty/shortest-path-polygon-area">Here</a> you can find the JS code (I have ported it to C#, but not yet release on GitHub).</p>
<p>I took me 3 attempts to get it working properly, and a lot of time. Fortunately by the time I started developing <em>Occulto</em>, the library was ready and working. Now I can just draw the walkable area and have the main character move inside it, avoiding obstacles (polygon holes).</p>
<p>The fact is that having an algorithm to move things inside a walk-able area is not strictly necessary, and it is better to focus on actually making the game. Other P&amp;C games do not use this feature, they just move characters along predefined paths.</p>
<p>So, before you embark on something that is not strictly necessary for the game, see if you can find something already implemented or if it is really worth it.</p>
<h3 id="heading-release-a-one-scene-version-of-the-game">Release a one scene version of the game</h3>
<p>After you've chosen the right framework, take a scene, and develop the entire game which will consist on one scene plus a menu and every UI component that is cross scene. It is important to learn everything you need and to find problems as soon as possible.</p>
<p>Also, submit the game for internal testing (not public) to the stores you are going to use. Yes, do everything that's necessary from developing to publishing (privately) the game.</p>
<p>When I published the game demo on iOS, one animation wasn't working. It was working on Android, Desktop, and even on iPhone with the developer build. So yes, you need to test everything as soon as possible, even the process of publishing.</p>
<p>I made the mistake to first develop the whole demo (four scenes, plus menu and some other screens) just to find out that WebGL technology was not the right choice for my game.</p>
<h2 id="heading-final-notes">Final Notes</h2>
<p>I hope you enjoyed reading this article and found some interesting advice. Maybe I will write another article when I have published the whole game, sharing other insights.</p>
<p>If you are curious about <a target="_blank" href="https://www.sirioartgames.com/"><em>Occulto</em></a> game, follow us on:</p>
<ul>
<li><p>Twitter: <a target="_blank" href="https://twitter.com/SirioArtGames">https://twitter.com/SirioArtGames</a></p>
</li>
<li><p>Instagram: <a target="_blank" href="https://www.instagram.com/sirioartgames/">https://www.instagram.com/sirioartgames</a></p>
</li>
<li><p>Our website: <a target="_blank" href="https://www.sirioartgames.com/">https://www.sirioartgames.com</a></p>
</li>
</ul>
<p>or <a target="_blank" href="http://onelink.to/mxsak4">try the demo</a>: <a target="_blank" href="http://onelink.to/occulto">http://onelink.to/occulto</a>!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Test Driven Development – What it Is, and What it Is Not ]]>
                </title>
                <description>
                    <![CDATA[ Test driven development has become popular over the last few years. Many programmers have tried this technique, failed, and concluded that TDD is not worth the effort it requires. Some programmers think that, in theory, it is a good practice, but tha... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/test-driven-development-what-it-is-and-what-it-is-not-41fa6bca02a2/</link>
                <guid isPermaLink="false">66d46013bd438296f45cd391</guid>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ technology ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Testing ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Andrea Koutifaris ]]>
                </dc:creator>
                <pubDate>Mon, 02 Jul 2018 23:11:08 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*W93Ke-ezhfWJ6cTbmCdaPQ.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Test driven development has become popular over the last few years. Many programmers have tried this technique, failed, and concluded that TDD is not worth the effort it requires.</p>
<p>Some programmers think that, in theory, it is a good practice, but that there is never enough time to really use TDD. And others think that it is basically a waste of time.</p>
<p>If you feel this way, I think you might not understand what TDD really is. (OK, the previous sentence was to catch your attention). There is a very good book on TDD, <a target="_blank" href="https://www.amazon.com/Test-Driven-Development-Kent-Beck/dp/0321146530">Test Driven Development: By Example, by Kent Beck</a>, if you want to check it out and learn more.</p>
<p>In this article I will go through the fundamentals of Test Driven Development, addressing common misconceptions about the TDD technique. This article is also the first of a number of articles I’m going to publish, all about Test Driven Development.</p>
<h3 id="heading-why-use-tdd">Why use TDD?</h3>
<p>There are studies, papers, and discussions about how effective TDD is. Even though it is definitely useful to have some numbers, I don’t think they answer the question of why we should use TDD in the first place.</p>
<p>Say that you are a web developer. You have just finished a small feature. Do you consider it enough to test this feature just by interacting manually with the browser? I don’t think it’s enough to rely just on tests done by developers manually. Unfortunately this means that part of the code is not good enough.</p>
<p>But the consideration above is about testing, not TDD itself. So why TDD? The short answer is “because it is the simplest way to achieve both good quality code and good test coverage”.</p>
<p>The longer answer comes from what TDD really is… Let’s start with the rules.</p>
<h3 id="heading-rules-of-the-game">Rules of the game</h3>
<p><a target="_blank" href="https://en.wikipedia.org/wiki/Robert_C._Martin">Uncle Bob</a> describes TDD with three rules:</p>
<blockquote>
<ul>
<li>You are not allowed to write any production code unless it is to make a failing unit test pass.</li>
</ul>
<ul>
<li>You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.</li>
</ul>
<ul>
<li>You are not allowed to write any more production code than is sufficient to pass the one failing unit test.</li>
</ul>
</blockquote>
<p>I also like a shorter version, which I found <a target="_blank" href="http://www.javiersaldana.com/tech/2014/11/26/refactoring-the-three-laws-of-tdd.html">here</a>:</p>
<blockquote>
<ul>
<li>Write only enough of a unit test to fail.</li>
</ul>
<ul>
<li>Write only enough production code to make the failing unit test pass.</li>
</ul>
</blockquote>
<p>These rules are simple, but people approaching TDD often violate one or more of them. I challenge you: can you write a small project following <strong>strictly</strong> these rules? By small project I mean something real, not just an example that requires like 50 lines of code.</p>
<p>Those rules define the mechanics of TDD, but they are definitely not everything you need to know. In fact, the process of using TDD is often described as a Red/Green/Refactor cycle. Let’s see what it is about.</p>
<h3 id="heading-red-green-refactor-cycle">Red Green Refactor cycle</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/JN8oQMbYFGuFdXSJJEybTQ8rCFwVclmyRANN" alt="Image" width="800" height="544" loading="lazy"></p>
<p><em>Red Green Refactor</em></p>
<h4 id="heading-red-phase">Red phase</h4>
<p>In the red phase, you have to write a test on a behavior that you are about to implement. Yes, I wrote <strong>behavior</strong>. The word “test” in Test Driven Development is misleading. We should have called it “Behavioral Driven Development“ in the first place. Yes, I know, some people argue that BDD is different from TDD, but I don’t know if I agree. So in my simplified definition, BDD = TDD.</p>
<p>Here comes one common misconception: “First I write a class and a method (but no implementation), then I write a test to test that class method”. It actually doesn’t work this way.</p>
<p>Let’s take a step back. Why does the first rule of TDD require that you write a test before you write any piece of production code? Are we TDD people maniacs?</p>
<p>Each phase of the R.G.R. cycle represents a phase in the code’s lifecycle and how you might relate to it.</p>
<p>In the red phase, you act like you’re a demanding user who wants to use the code that’s about to be written in the simplest possible way. <strong>You have to write a test that uses a piece of code as if it were already implemented.</strong> Forget about the implementation! If, in this phase, you are thinking about how you are going to write the production code, you are doing it wrong!</p>
<p>It is in this phase where you concentrate on writing a clean interface for future users. <strong>This is the phase where you design how your code will be used by clients.</strong></p>
<p>This first rule is the most important one and it is the rule that makes TDD different from regular testing. You write a test so that you can then write production code. You don’t write a test to test your code.</p>
<p>Let’s look at an example.</p>
<pre><code class="lang-python">// LeapYear.spec.jsdescribe(<span class="hljs-string">'Leap year calculator'</span>, () =&gt; {  it(<span class="hljs-string">'should consider 1996 as leap'</span>, () =&gt; {    expect(LeapYear.isLeap(<span class="hljs-number">1996</span>)).toBe(true);  });});
</code></pre>
<p>The code above is an example of how a test might look in JavaScript, using the Jasmine testing framework. You don’t need to know Jasmine — it is enough to understand that <code>it(...)</code> is a test and <code>expect(...).toBe(...)</code> is a way to make Jasmine check if something is as expected.</p>
<p>In the test above, I’ve checked that the function <code>LeapYear.isLeap(...)</code> returns <code>true</code> for the year 1996. You may think that 1996 is a magic number and is thus a bad practice. It is not. In test code, magic numbers are good, whereas in production code they should be avoided.</p>
<p>That test actually has some implications:</p>
<ul>
<li><p>The name of the leap year calculator is <code>LeapYear</code></p>
</li>
<li><p><code>isLeap(...)</code>is a static method of <code>LeapYear</code></p>
</li>
<li><p><code>isLeap(...)</code> takes a number (and not an array, for example) as an argument and returns <code>true</code> or <code>false</code> .</p>
</li>
</ul>
<p>It’s one test, but it actually has many implications! Do we need a method to tell if a year is a leap year, or do we need a method that returns a list of leap years between a start and end date? Are the name of the elements meaningful? These are the kinds of questions you have to keep in mind while writing tests in the Red phase.</p>
<p>In this phase, you have to make decisions about how the code will be used. You base this on what you really need at the moment and not on what you think may be needed.</p>
<p>Here comes another mistake: do not write a bunch of functions/classes that you think you may need. Concentrate on the feature you are implementing and on what is really needed. Writing something the feature doesn’t require is over-engineering.</p>
<p>What about abstraction? Will see that later, in the refactor phase.</p>
<h4 id="heading-green-phase">Green phase</h4>
<p>This is usually the easiest phase, because in this phase you write (production) code. If you are a programmer, you do that all the time.</p>
<p>Here comes another big mistake: instead of writing enough code to pass the red test, you write all the algorithms. While doing this, you are probably thinking about what is the most performing implementation. No way!</p>
<p>In this phase, you need to act like a programmer who has one simple task: write a straightforward solution that makes the test pass (and makes the alarming red on the test report becomes a friendly green). In this phase, you are allowed to violate best practices and even duplicate code. Code duplication will be removed in the refactor phase.</p>
<p>But why do we have this rule? Why can’t I write all the code that is already in my mind? For two reasons:</p>
<ul>
<li><p>A simple task is less prone to errors, and you want to minimize bugs.</p>
</li>
<li><p>You definitely don’t want to mix up code which is under testing with code that is not. You can write code that is not under testing (aka legacy), but the worst thing you can do is mixing up tested and untested code.</p>
</li>
</ul>
<p>What about clean code? What about performance? What if writing code makes me discover a problem? What about doubts?</p>
<p>Performance is a long story, and is out of the scope of this article. Let’s just say that performance tuning in this phase is, most of the time, premature optimization.</p>
<p>The test driven development technique provides two others things: a to-do list and the refactor phase.</p>
<p>The refactor phase is used to clean up the code. The to-do list is used to write down the steps required to complete the feature you are implementing. It also contains doubts or problems you discover during the process. A possible to-do list for the leap year calculator could be:</p>
<pre><code class="lang-python">Feature: Every year that <span class="hljs-keyword">is</span> exactly divisible by four <span class="hljs-keyword">is</span> a leap year, <span class="hljs-keyword">except</span> <span class="hljs-keyword">for</span> years that are exactly divisible by <span class="hljs-number">100</span>, but these centurial years are leap years <span class="hljs-keyword">if</span> they are exactly divisible by <span class="hljs-number">400.</span>
</code></pre>
<pre><code class="lang-python">- divisible by <span class="hljs-number">4</span>- but <span class="hljs-keyword">not</span> by <span class="hljs-number">100</span>- years divisible by <span class="hljs-number">400</span> are leap anyway
</code></pre>
<pre><code class="lang-python">What about leap years <span class="hljs-keyword">in</span> Julian calendar? And years before Julian calendar?
</code></pre>
<p>The to-do list is live: it changes while you are coding and, ideally, at the end of the feature implementation it will be blank.</p>
<h4 id="heading-refactor-phase">Refactor phase</h4>
<p>In the refactor phase, you are allowed to change the code, while keeping all tests green, so that it becomes better. What “better” means is up to you. But there is something mandatory: <strong>you have to remove code duplication</strong>. Kent Becks suggests in his book that removing code duplication is all you need to do.</p>
<p>In this phase you play the part of a picky programmer who wants to fix/refactor the code to bring it to a professional level. In the red phase, you’re showing off your skills to your users. But in the refactor phase, you’re showing off your skills to the programmers who will read your implementation.</p>
<p>Removing code duplication often results in abstraction. A typical example is when you move two pieces of similar code into a helper class that works for both the functions/classes where the code has been removed.</p>
<p>For example the following code:</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Hello</span> {  <span class="hljs-title">greet</span>() {    <span class="hljs-title">return</span> <span class="hljs-title">new</span> <span class="hljs-title">Promise</span>(<span class="hljs-params">(<span class="hljs-params">resolve</span>) =&gt; {      setTimeout(<span class="hljs-params">(<span class="hljs-params"></span>)=&gt;resolve(<span class="hljs-params"><span class="hljs-string">'Hello'</span></span>), <span class="hljs-number">100</span></span>);    }</span>);  }}<span class="hljs-title">class</span> <span class="hljs-title">Random</span> {  <span class="hljs-title">toss</span>() {    <span class="hljs-title">return</span> <span class="hljs-title">new</span> <span class="hljs-title">Promise</span>(<span class="hljs-params">(<span class="hljs-params">resolve</span>) =&gt; {      setTimeout(<span class="hljs-params">(<span class="hljs-params"></span>)=&gt;resolve(<span class="hljs-params">Math.random(<span class="hljs-params"></span>)</span>), <span class="hljs-number">200</span></span>);    }</span>);  }}<span class="hljs-title">new</span> <span class="hljs-title">Hello</span>().<span class="hljs-title">greet</span>().<span class="hljs-title">then</span>(<span class="hljs-params">result =&gt; console.log(<span class="hljs-params">result</span>)</span>);<span class="hljs-title">new</span> <span class="hljs-title">Random</span>().<span class="hljs-title">toss</span>().<span class="hljs-title">then</span>(<span class="hljs-params">result =&gt; console.log(<span class="hljs-params">result</span>)</span>);</span>
</code></pre>
<p>could be refactored into:</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Hello</span> {  <span class="hljs-title">greet</span>() {    <span class="hljs-title">return</span> <span class="hljs-title">PromiseHelper</span>.<span class="hljs-title">timeout</span>(<span class="hljs-params"><span class="hljs-number">100</span></span>).<span class="hljs-title">then</span>(<span class="hljs-params">(<span class="hljs-params"></span>) =&gt; <span class="hljs-string">'hello'</span></span>);  }}<span class="hljs-title">class</span> <span class="hljs-title">Random</span> {  <span class="hljs-title">toss</span>() {    <span class="hljs-title">return</span> <span class="hljs-title">PromiseHelper</span>.<span class="hljs-title">timeout</span>(<span class="hljs-params"><span class="hljs-number">200</span></span>).<span class="hljs-title">then</span>(<span class="hljs-params">(<span class="hljs-params"></span>) =&gt; Math.random(<span class="hljs-params"></span>)</span>);  }}<span class="hljs-title">class</span> <span class="hljs-title">PromiseHelper</span> {  <span class="hljs-title">static</span> <span class="hljs-title">timeout</span>(<span class="hljs-params">delay</span>) {    <span class="hljs-title">return</span> <span class="hljs-title">new</span> <span class="hljs-title">Promise</span>(<span class="hljs-params">resolve =&gt; setTimeout(<span class="hljs-params">resolve, delay</span>)</span>);  }}<span class="hljs-title">const</span> <span class="hljs-title">logResult</span> = <span class="hljs-title">result</span> =&gt; <span class="hljs-title">console</span>.<span class="hljs-title">log</span>(<span class="hljs-params">result</span>);<span class="hljs-title">new</span> <span class="hljs-title">Hello</span>().<span class="hljs-title">greet</span>().<span class="hljs-title">then</span>(<span class="hljs-params">logResult</span>);<span class="hljs-title">new</span> <span class="hljs-title">Random</span>().<span class="hljs-title">toss</span>().<span class="hljs-title">then</span>(<span class="hljs-params">logResult</span>);</span>
</code></pre>
<p>As you can see, in order to remove the<code>new Promise</code> and <code>setTimeout</code> code duplication, I created a <code>PromiseHelper.timeout(delay)</code> method, which serves both <code>Hello</code> and <code>Random</code> classes.</p>
<p>Just keep in mind that you cannot move to another test unless you’ve removed all the code duplication.</p>
<h3 id="heading-final-considerations">Final considerations</h3>
<p>In this section I will try to answer to some common questions and misconceptions about Test Drive Development.</p>
<ul>
<li>T.D.D. requires much more time than “normal” programming!</li>
</ul>
<p>What actually requires a lot of time is learning/mastering TDD as well as understanding how to set up and use a testing environment. When you are familiar with the testing tools and the TDD technique, it actually doesn’t require more time. On the contrary, it helps keep a project as simple as possible and thus saves time.</p>
<ul>
<li>How many test do I have to write?</li>
</ul>
<p>The minimum amount that lets you write all the production code. The minimum amount, because every test slows down refactoring (when you change production code, you have to fix all the failing tests). On the other hand, refactoring is much simpler and safer on code under tests.</p>
<ul>
<li>With Test Driven Development I don’t need to spend time on analysis and on designing the architecture.</li>
</ul>
<p>This cannot be more false. If what you are going to implement is not well-designed, at a certain point you will think “Ouch! I didn’t consider…”. And this means that you will have to delete production and test code. It is true that TDD helps with the “Just enough, just in time” recommendation of agile techniques, but it is definitely not a substitution for the analysis/design phase.</p>
<ul>
<li>Should test coverage be 100%?</li>
</ul>
<p>No. As I said earlier, don’t mix up tested and untested code. But you can avoid using TDD on some parts of a project. For example I don’t test views (although a lot of frameworks make UI testing easy) because they are likely to change often. I also ensure that there is very a little logic inside views.</p>
<ul>
<li>I am able to write code with very a few bugs, I don’t need testing.</li>
</ul>
<p>You may able to to that, but is the same consideration valid for all your team members? They will eventually modify your code and break it. It would be nice if you wrote tests so that a bug can be spotted immediately and not in production.</p>
<ul>
<li>TDD works well on examples, but in a real application a lot of the code is not testable.</li>
</ul>
<p>I wrote a whole Tetris (as well as progressive web apps at work) using TDD. If you test first, code is clearly testable. It is more a matter of understanding how to mock dependencies and how to write simple but effective tests.</p>
<ul>
<li>Tests should not be written by the developers who write the code, they should be written by others, possibly QA people.</li>
</ul>
<p>If you are speaking about testing your application, yes it is a good idea to ask other people to test what your team did. If you are speaking about writing production code, then that’s the wrong approach.</p>
<h3 id="heading-whats-next">What’s next?</h3>
<p>This article was about the philosophy and common misconceptions of TDD. I am planning to write other articles on TDD where you will see a lot of code and fewer words. If you are interested on how to develop Tetris using TDD, stay tuned!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
