<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yulia Kleb on Medium]]></title>
        <description><![CDATA[Stories by Yulia Kleb on Medium]]></description>
        <link>https://medium.com/@yulia.kleb?source=rss-7ff0cbafa4b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Y3j2wlThtmzKivWw</url>
            <title>Stories by Yulia Kleb on Medium</title>
            <link>https://medium.com/@yulia.kleb?source=rss-7ff0cbafa4b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 18:59:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yulia.kleb/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Your first software engineering job: an ultimate guide]]></title>
            <link>https://medium.com/appsflyerengineering/your-first-software-engineering-job-an-ultimate-guide-a429d6b84ab9?source=rss-7ff0cbafa4b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/a429d6b84ab9</guid>
            <category><![CDATA[guides-and-tutorials]]></category>
            <category><![CDATA[find-a-job]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[junior-developer]]></category>
            <category><![CDATA[first-job]]></category>
            <dc:creator><![CDATA[Yulia Kleb]]></dc:creator>
            <pubDate>Sun, 13 Dec 2020 10:44:41 GMT</pubDate>
            <atom:updated>2020-12-13T10:46:41.593Z</atom:updated>
            <content:encoded><![CDATA[<p>Or how to begin your journey to the wonderful world of high tech</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3uoWyC_YkIatTgiD8ugDlw.png" /></figure><blockquote>A journey of a thousand miles begins with a single step.</blockquote><blockquote>– Lao Tzu</blockquote><h3>Intro</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/0*KJ5e68apiuZKBzgf" /></figure><p>CS student? Just graduated from the academy and searching for a first job in the software (SW) sphere? Not sure what to choose and which technologies to learn? Would like to apply for a job, but not sure where to start? Starting your career at software engineering, but not considering yourself a hacker? Scared of technical interviews?</p><p>No worries, we got you covered!</p><h3>My career story (to inspire you)</h3><p>First of all, nice to meet you! I’m Yulia, I have been working at AppsFlyer as a software engineer for four years already. And I’m yet another person to give you advice! Just kidding, I’ve passed through the difficulties in my career as a SW engineer and would like to make it easier for you.</p><p>For someone that has been around the block for a while in the high tech industry, I can tell you the beginning wasn’t easy at all. Although my parents were software engineers, and my brother as well, I wasn’t born with a keyboard in my hands, and being a third generation engineer in the family doesn’t help as well.</p><p>My journey started back then, in 2005, when I was a schoolgirl, having to make a life choice — what I will do for my future living. It was quite a hard choice for the age of 15 and for a kid with no special talents. But I thought to myself: “This industry will definitely grow and incorporate loads of money in itself, I need to learn how things work in it”. And, I guess, that was not the silliest point.</p><p>So I went to the university to study math and programming. It all took place in Moscow, Russia where universities are still very far from the industry. You simply cannot learn being a SW developer or cutting-edge technologies there. But what you can do is to learn thinking in a technological way. And general systems knowledge. So once I graduated after 5 years of education, I felt like not knowing anything in the industry: I had no skills in systems design and architecture, no modern programming languages knowledge, no idea of data structures, algorithms or complexity (which also were not a part of what we learned).</p><p>This was not the same for all the students in my University: some had skills, because they learned on their own, watching tutorials on YouTube and reading books. But I was not anything like that: my personal life events didn’t leave me enough time to do extra to the university training to succeed that much in my professional path.</p><p>So I was scared and didn’t know what to do with myself, so I didn’t go to work as a software engineer right away.</p><p>After 3 long years of activities of different kinds I moved to Israel. Moving to a new country imposes new challenges like learning a new language, adapting to the new environment and finally finding the first local job!</p><p>After adopting myself a bit in the new environment, I took my free time and spent it on upgrading my tech stack and improving my programming skills to find my dream job. Since I had no job back then, I took this opportunity to learn and improve on a full-time basis.</p><p>I took (paid) courses¹ for Python/Django full stack engineers to create some portfolio and find a job². They also offered an internship as a part of the course to gain experience, so it was the original plan: learning courses, preparing a portfolio, taking part in the internship, finding a job having the experience already.</p><p>While learning, I’ve managed to create and deploy my personal portfolio website to Heroku. I also learnt working with SQLite, HTML/CSS/Bootstrap, jQuery, though JavaScript turned out not to be for me already at that point :D. It took me something like 6 months to learn all the technologies I needed (Git, backend, frontend, working with databases, Python, etc.), gain some skills in coding and create a full stack portfolio.</p><p>During this period I had an idea to create a CRM for my previous company. I was aware of their needs and specifics of their work, so I decided that it can be both good for my portfolio and for their daily routines. It also gave me a lot of motivation: I knew it was something that will be used by the people I know, and they will give me feedback. Eventually I think they don’t use the CRM I created though: it was my very first system created, so it was not working very well and not convenient. But the main goal was achieved — I gained experience!</p><p>Eventually I felt ready to start searching for my very first job in Israel. I updated my LinkedIn account and filled it with all the courses I passed and links to my GitLab projects. I created a CV and started applying to all possible companies. I somehow ran into AppsFlyer’s open junior position, checked the company’s website and fell in love: it was a match.</p><p>Then I got very lucky: AppsFlyer, which back then was a relatively small startup, responded to my application! I had no idea what the interviewing process would be like (I wish I’d known things I know now!). But what helped me was my LinkedIn profile with the courses and portfolio listed: I still remember my future manager told me that the most important thing they learned was that I am a self-learner: someone who can learn and create things on their own.</p><p>This is the end of the story: I was hired as a junior data developer! I was the first female programmer (not a manager) in our RnD (which I’m kind of proud of).</p><p>Since then I’ve tried 3 different teams in two domains in 4 years, learned writing quality code in Clojure and Go, importance of tests and different approaches to writing them, creating micro services and infrastructure, SW architectural principles, and basically everything I know now. This was a long road, and now I am still new. New to the team I’ve just switched to recently. This and having several friends of mine graduating university and having no idea what to do, inspired me to write something to help you guys in this path.</p><h3>How is it going to help you?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/214/0*g87Vte04QYOaY0Fo" /></figure><p>The good thing about all that is now I know how you feel (probably lost in technologies and development spheres) and what to do! I wish someone would have explained those basics to me back then.<br>In case you wonder what I can tell you that was not told in the academy, mind that most universities still do not have a well-established educational system. It happens for some obvious reasons: the technologies in the high-tech change too fast, the books are not being updated accordingly and the teachers cannot stay updated with the cutting-edge technology all the time. You need to learn a lot on your own in this industry. To help you with that, I’ve added links into the detailed articles and materials that can help you to understand the provided information precisely.</p><h3>Basic steps for a new developer</h3><p>Technical stack:</p><ol><li>Choose your <strong>area</strong>: Web development (front-end, back-end, etc.), Mobile applications, Infrastructure (DevOps, SRE, etc.) and Data Engineering</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/0*xLpyWl3z95lFr0sO" /></figure><p>(see short description of them below) to start with. Most companies have all the spheres present in their RnDs, so if your choice was not optimal for you at the beginning, you can switch teams later (it’s always easier within one company).</p><p>2. Learn <strong>basic technologies</strong>: <a href="https://www.codecademy.com/learn/learn-git">to work with source control</a> (<a href="https://git-scm.com/">Git</a>), some <a href="https://en.wikipedia.org/wiki/Integrated_development_environment">IDE</a> (e.g, <a href="https://www.jetbrains.com/idea/download/">IntelliJ</a>), <a href="https://restfulapi.net/">REST APIs</a>, <a href="https://www.postman.com/">Postman</a>, basic SQL (e.g., MySQL) and no-SQL (e.g., MongoDB) databases, basic of working with <a href="https://en.wikipedia.org/wiki/Docker_(software)">Docker</a>. You don’t have to know them perfectly well, but basic understanding and hands-on skills are essential.</p><p>3. Find the description of the open position in the desired company and find out what the requirements are. Learn the technologies required at least on the basic level.</p><p>4. Create the <strong>portfolio</strong> for the desired position using the technologies required in the job description:</p><ul><li>Create the service: your FE/BE/whatever program, which does something: it can be even code that you’ve created learning from some tutorial — the only thing that matters is that it works and does whatever is relevant for your desired position.</li><li>Cover it with <a href="https://medium.com/hardwareandro/what-is-unit-testing-435e8134b16e">unit</a> and <a href="https://medium.com/@lawrey/unit-tests-ui-tests-integration-tests-end-to-end-tests-c0d98e0218a6">integration tests</a>.</li><li><em>Advanced level</em>: Make it production-ready and easy to demonstrate: <a href="https://medium.com/codingthesmartway-com-blog/docker-beginners-guide-part-1-images-containers-6f3507fffc98">dockerize</a> the BE project/deploy full-stack project to some free hosting (e.g., <a href="https://www.heroku.com/">Heroku</a>).</li></ul><p>Public presence:</p><p>5. <a href="https://medium.com/free-code-camp/how-to-write-a-software-engineering-resume-cv-the-definitive-guide-updated-for-2019-2821d42b2fce">Check your <strong>CV</strong></a>: it should be in English and take no more than one A4 page. It should contain your name, your contact details, links, relevant (only!) experience if you have any, education and languages you speak (mind that it should be ordered this way!). You might also want to include your technical skills and stack. Make your CV tell your exceptional career and life story: you can highlight your learning or communication skills, your achievements in education, etc. Make sure it points out that you are passionate about what you do! Another good thing is to ask your friend to read your CV (especially if you have an HR/developer friend :D).</p><p>6. Create/update your <strong>LinkedIn</strong> profile (including your technical skills and stack!): it’s the modern way to search for a job. It also makes you visible to the market and HRs.</p><p>7. <a href="https://medium.com/job-advice-for-software-engineers/where-do-i-find-software-engineering-jobs-253dc08a8e54">Search</a> for the right <strong>company</strong>: not the top, not the bottom, having seniors and experts to learn from, developed processes, training for new developers. Small startups are easier to get in (usually), but consider that usually <a href="https://medium.com/free-code-camp/how-to-avoid-these-7-mistakes-i-made-as-a-junior-developer-a7f26ce0f7ed">there is no time to teach juniors and the code base (as well as processes) might be not the best</a>, and we would like to first learn the best practises (again — usually).</p><p>8. Search for student positions/internships/junior positions. It’s the best practice in general — to start working in the industry as early as possible. If you are able to start working (not full hours) at the second grade of university, it will help you to understand better what you learn at the Academy and ask your teachers questions about your work. Plus, think of the fact that once you graduate, you have some experience already and can earn more money!</p><p>9. If you have a friend working for some company you’d like to join, ask them to send your CV internally to the company HRs: such candidates usually have a preference.</p><p>10. Before you apply for this position, take time to <a href="https://medium.com/hackernoon/10-data-structure-algorithms-and-programming-courses-to-crack-any-coding-interview-e1c50b30b927">prepare for the job <strong>interview</strong></a>. FAQ for junior developers are data structures, algorithms, your student experience, portfolio design (make sure you can explain everything in it, including the choice of the technologies involved), why you fit this position the best. Make sure to learn what the company does. Prepare a short pitch (2–3 min) about yourself and why you would like to get this job.</p><p>11. To check what it is actually like to work in some company, what the employees’ reviews are, to see interviewees’ experience and to learn which questions they usually ask in interviews, use <a href="https://www.glassdoor.com/Reviews/index.htm">Glassdoor</a>.</p><p>12. Set up your salary expectations: check <a href="https://www.glassdoor.com/Salaries/israel-software-engineer-salary-SRCH_IL.0,6_IN119_KO7,24.htm">the average salaries</a> on Glassdoor (or whatever Google will find for you) and decide what fits you best.</p><p>13. If you have a dream company, don’t apply there first. <em>Start with other companies</em> you are less interested in: this way you will have the opportunity to try your skills and gain self confidence before you get into the interview at your dream company. Basically, what you can do is to create a list of SW development companies in your area and contact all of them.</p><p>Interviewing process:</p><p>14. Recruiting process for medium and big tech companies usually consists of several steps (3–6 steps in most cases):</p><ul><li>Phone call with HR/direct manager</li><li>Coding homework</li><li>Tech interview (data structures/algorithms)</li><li>Tech interview (architecture)</li><li>HR interview</li><li>Interview with the senior management.</li></ul><p>Those steps can vary for different companies, you can have more or less technical interviews. Homework is also not obligatory, but quite typical for a first job.</p><p>15. Failed the interview? Ask for the feedback — it’s a good experience and can help you to improve for your next one.</p><p>16. <a href="https://medium.com/swlh/finding-freelance-work-as-a-new-developer-f5c6e839f129">Freelancing</a> is a perfect option to consider (especially when it takes time to find the job): gaining experience without stressful interviews is the perfect way to find the job at your dream company!</p><p>17. Applied to dozens of companies and it didn’t work out? Don’t be desperate, it happens to everyone in our sphere, even seniors. It just takes time. It also depends on the market situation: it might be there is no hiring (e.g., due to covid-19) or there are too many engineers searching for a job in the market. Be patient. You can reapply to the companies after a certain period of time (usually 6 months-year, but depends on the company).<br>Looking for a job for more than half a year is completely okay — you will find it eventually!</p><p>Once you found a job:</p><p>18. Once you got hired, learn as much as possible, but <em>don’t kill yourself</em> with work — it’s not everything in your life! Remember about burning out, which happens a lot in SW engineering.</p><p>19. Another thing to remember: <em>you cannot know everything</em>, you cannot learn everything in one day: you have time for that, a lot of time — most developers learn their whole life. You should not feel ashamed by the fact that you don’t know something or you need to ask. Moreover, no-one expects you to know everything. You will learn it all with time.</p><p>20. If you have started working in a new place and feel that you don’t understand anything, it’s also okay, we all were there. Don’t be confused though and don’t try to learn everything at once: you will learn step by step! Things that are complicated now will seem like a piece of cake in half a year.</p><p>21. Keep the <strong>balance</strong> between asking questions and trying to find answers on your own: before taking team lead/senior’s time, make sure you’ve googled your problem, searched in internal repositories for similar solutions, asked other people who you feel comfortable to ask. Also remember that in large companies there are usually dedicated people whose job includes helping newly arrived developers with any questions — use it!</p><p>22. Try to establish a good relationship with your colleagues — this makes it easier to ask questions (especially those you consider dummy ones), work together, pair program and enjoy your work. Small talks near the coffee machine or water cooler about your hobbies and interests can help here. Moreover, people in the same industry usually have similar state of mind and interest — you can find a lot of new friends at work!</p><p>23. Show your interest in what the team does — it will be appreciated by your manager.</p><p>24. Learn soft skills by just looking at how others behave: how to ask help, perform code reviews, give/ask feedback and criticism and advocate your opinion.</p><p><em>25. Don’t be scared — you’ll make it!</em></p><h3>Programming areas intro</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*SqX38i_QiDzvO7C9" /></figure><h3>Disclaimer</h3><p>I’m coming from the world of backend and big data, so my opinion is biased, of course. But I’ll do my best to be as less engaged as possible.</p><p>All the development/engineering/programming (call it anything!) world can be roughly split into several spheres: <a href="https://medium.com/hackernoon/qa-engineering-roles-skills-tools-and-responsibilities-in-a-testing-team-7c499adc8057">testing (QA)</a>, <a href="https://medium.com/@ansertechgeek/front-end-vs-back-end-which-and-why-31c2a6b96b2c">backend (BE)</a>, <a href="https://medium.com/edureka/front-end-developer-skills-ebb32d19f488#:~:text=A%20front%20end%20developer%20is,HTML%2C%20CSS%2C%20and%20JavaScript.&amp;text=If%20you%20head%20to%20any,looks%20different%20from%20your%20phone.">frontend (FE)</a>, <a href="https://medium.com/better-programming/new-engineers-start-with-mobile-development-130210d1b93">mobile</a>, DevOps, full stack (which is a combination of BE + FE in various proportions), cyber, data analysts, data scientists, QA automation engineers and many, many others. We’ll cover only QA, BE, FE, mobile and a bit of DevOps as a basic choice here.</p><h3>QA</h3><p><a href="https://business.linkedin.com/talent-solutions/resources/talent-engagement/job-descriptions/quality-assurance#:~:text=A%20quality%20assurance%20specialist%20ensures,the%20delivery%20of%20satisfactory%20outcomes.">A quality assurance specialist ensures that the final product observes the company’s quality standards</a>. This basically means you are a person who checks if the program developed behaves as expected in all the business use cases, starting from functionality, design, reliability, and resiliency to meet customer expectations.</p><p>The sphere has a variety of methods: manual testing, automated checks, visual and usability website testing, performance testing , API testing and others.</p><p>QA engineers develop code in case they have to automate verifications on business use cases and run them as part of progression (new feature developments) , regression, continuous integration and continuous deployment (CI/CD) .</p><p>Talking about the technology stack, there are various ready-made solutions, tools, and frameworks. Most common programming languages used in this field are Python and Java, though other regular languages are used as well.</p><p>The reason we cover this sphere first is that it’s the easiest way to enter the industry. You can switch to the developer’s position in the same company afterwards (it’s a common practise).</p><h3>Backend</h3><p>The <a href="https://medium.com/tech-tajawal/modern-backend-developer-in-2018-6b3f7b5f8b9">BE</a> world represents all the possible functionality you can imagine. It is the heart of every digital product you see: website, mobile app, etc. It is the layer that actually does the work: stores your data, media, information about you; computes whatever needs to be computed; performs authentication and authorization; sending emails, transforming your input into output of some other kind; calculates rates, means, average, distances, renders maps, etc. It does basically everything!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/0*ELNImCaK_Nsn9wte" /></figure><p>It includes writing <a href="https://medium.com/extend/what-is-rest-a-simple-explanation-for-beginners-part-1-introduction-b4a072f8740f">REST</a> and other types of servers, APIs, working with <a href="https://medium.com/omarelgabrys-blog/database-introduction-part-1-4844fada1fb0">databases</a>, <a href="https://medium.com/@mrashish/design-strategies-for-building-big-data-pipelines-4c11affd47f3">data pipelining</a> (message queues, channels, etc.), data transformations (<a href="https://medium.com/better-programming/what-are-etls-and-why-are-important-b65b301607d1">ETL</a>), logging and audit systems and much more. It can work on one machine (your computer) or hundreds of cloud machines.</p><p>This is why the BE sphere is so broad: it includes dozens of design patterns, technologies, a variety of databases and their types, message queues, libraries and programming languages. It’s a huge world, where you can learn and develop endlessly and never get bored.</p><p>It’s the most common and most big sphere of programming.</p><h3>Frontend</h3><p>The FE front represents the visual side of the services: it is what the end user sees and interacts with. It’s very important since it represents the face of your company.</p><p>Developing FE includes working with UI/UX designers and product managers a lot, making things beautiful and seeing results immediately, in a concrete form. Adapting your code to be displayed the best way in the different devices is also an important part of the game here.</p><p>The main problems this sphere solves are “make it work fast” (your page should load within milliseconds and be optimised), “make it scalable” (or how to reuse your code components) and “make it beautiful” (adjust it to what designers and products want).</p><p>There is a variety of technologies and methodologies in this area. The most basic are HTML, CSS and JavaScript; the most common — React, Vue, Angular, TypeScript, etc. The majority of modern tools present in the market solves most of the problems above, is well-designed and comfortable to use.</p><p>The big advantage of FE is that it gives people the ability to be creative in usability and visibility. Also it fits well for people who like working with visuals.</p><h3>Mobile</h3><p><em>By </em><a href="https://medium.com/u/815c61d5f85e"><em>Maxim Shoustin</em></a></p><p>The world of Mobile Development is a very large ecosystem. Android (by Google) and iOS (by Apple) are the main operating systems used by mobile devices around the world. The Android/iOS ratio globally stands at around 5/1. Android is open source and iOS is closed source.</p><p>The platforms are very different from the perspective of lifecycle, thread management, API and languages. Native Android code is written in Java and Kotlin using Android Studio IDE, and iOS is written in Objective-C and Swift using Xcode.</p><p>In addition, many developers do not want to duplicate their code in multiple programming languages, so they chose to use cross-platform technologies. Some of these technologies include Flutter, React-Native and Cordova. Gaming companies tend to use gaming specific cross-platform engines such as Unity, Unreal Engine and Cocos2dx.</p><p>Mobile development is not only related to creating mobile apps. Many developers create and maintain SDKs (Software Development Kit) that include tools and libraries to help create apps. These libraries can be a UI Component, background service, themes and so on.</p><p>An SDK can be included in thousands of mobile apps and run on billions of devices simultaneously (like the AppsFlyer’s SDK) so one small bug can affect billions of users. Since the only way to fix a bug is for the user to update the app, every line of code needs to be carefully written and tested.</p><h3>DevOps</h3><p><a href="https://en.wikipedia.org/wiki/DevOps#:~:text=DevOps%20is%20a%20set%20of,aspects%20came%20from%20Agile%20methodology.">DevOps</a> is a set of practices that combines software development (Dev) and IT operations (Ops). What it basically means is that regular SW engineers develop for clients outside the company, and DevOps develop for the clients inside the company — for SW engineers. In other words, some developers are in charge of the code which performs client-oriented operations, or what the company actually sells as a product and everything related; and, on the other hand, other developers are in charge of the environment of the product development and deployment: version control tools, cloud servers, autoscaling, server healing, <a href="https://en.wikipedia.org/wiki/CI/CD">CI/CD</a>, storage, databases, data processing clusters, staging and production environments and all kinds of things which are crucial for the delivery.</p><p>This job requires a lot of patience and knowledge. It is the center of all the development of the company, this is why DevOps engineers need to communicate to other engineers and manage their requests.</p><p>DevOps include both IT operations and programming as we said, meaning that they both write code (services) and set up and configure systems, which is challenging, but super important.</p><h3>Conclusion</h3><p>Yes, it’s tough. Yes, you have to do a lot to enter this field. Yes, you have to do even more to become an expert, and it’s not going to be easy. Yes, it’s a very demanding job. But gaining your place under this sun is usually tough. Remember, if you will do things and be patient, you will see the result. I did it with no understanding of the process, no outstanding skills, no connections in the industry. So you CAN do it, too! Good luck!</p><h3>WE ARE HIRING!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/224/0*lqvl3NbDF7RU7F1U" /></figure><p>AppsFlyer is the right company for you to start from: we are not too big and impossible to get into like Google, we are not a small startup company, where everything should be done quickly and there is no time to take care of the code quality, tests, best practices and educating engineers. We have well-established processes of learning, training, development, QA and having fun. AppsFlyer has been recognized as #12 out of the 25 Highest rated cloud companies to work for! And, what’s more important, we have over 120 open positions!</p><p>We are looking for young talents to grow with us! Come join us — we are waiting for YOU!</p><h3>P.S. Feel free to reach out and ask your questions — I am here to help!</h3><h3>P.S.S. Have something to add from your experience? Please comment!</h3><p><em>Thanks to </em><a href="https://medium.com/u/11c491308616"><em>Michael Arenzon</em></a><em> , </em><a href="https://medium.com/u/98795e8fa095"><em>Max Kleb</em></a><em>, </em><a href="https://medium.com/u/8384b46b1071"><em>Liaz Kamper</em></a><em>, </em><a href="https://medium.com/u/27ebd5929c8d"><em>Sergey Vinickiy</em></a><em>, </em><a href="https://medium.com/u/5a8d1924db8b"><em>David Dvora</em></a><em>, </em><a href="https://medium.com/u/b2137615cdff"><em>Danny Tourgeman</em></a><em>, </em><a href="https://medium.com/u/815c61d5f85e"><em>Maxim Shoustin</em></a><em>, Nitzan Amir.</em></p><p>[1] The courses are in Russian though, so I’m not sharing the link.</p><p>[2] The important point here is that it was much harder for other students in the course, who had no technical education/background. So don’t underestimate your education if you have some.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a429d6b84ab9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appsflyerengineering/your-first-software-engineering-job-an-ultimate-guide-a429d6b84ab9">Your first software engineering job: an ultimate guide</a> was originally published in <a href="https://medium.com/appsflyerengineering">AppsFlyer Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Railway oriented programming, clojure and exception handling: why and how?]]></title>
            <link>https://medium.com/appsflyerengineering/railway-oriented-programming-clojure-and-exception-handling-why-and-how-89d75cc94c58?source=rss-7ff0cbafa4b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/89d75cc94c58</guid>
            <category><![CDATA[clojure]]></category>
            <category><![CDATA[error-handling]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[functional]]></category>
            <category><![CDATA[rop]]></category>
            <dc:creator><![CDATA[Yulia Kleb]]></dc:creator>
            <pubDate>Tue, 01 Sep 2020 05:37:51 GMT</pubDate>
            <atom:updated>2020-09-01T05:37:51.480Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="AppsFlyer, railways and clojure" src="https://cdn-images-1.medium.com/max/1024/1*YQ5Ppic6AEUhvGi_Wd_KWQ.png" /></figure><p>AppsFlyer has a broad functionality offering many products. For us as software developers it means writing complicated business flows on a daily basis. Complicated flows can mean basically anything: business logic containing many I/O operations, complex data transformations pipelines, etc. Anything complicated in code already contains potential exceptions, errors and bugs by definition.</p><p>What is also important, we at AppsFlyer use Clojure, a functional language, as the primary backend language for production.</p><p>This raises the question of how to tackle exception handling in a functional manner, which should be both human readable and functionally elegant. This challenge can be solved with a beautiful programming principle — Railway Oriented Programming (ROP), broadly used in other functional languages, but not really common in Clojure. In this blog post I would like to introduce the basics of ROP while hoping to increase the popularity of this powerful yet elegant tool. To discover more advanced features of ROP, please check out <a href="https://medium.com/u/c842d836f25b">Scott Wlaschin</a>’s amazing <a href="https://fsharpforfunandprofit.com/rop/">talk</a> about ROP and F#, which this post is inspired by.</p><h3>Happy path</h3><p>Let’s say we need to develop a user sign up web page, which will be pretty similar to <a href="https://www.appsflyer.com/get-started/">AppsFlyer</a>’s one. The page contains a form to collect a user’s details. In this article, we’ll focus on the backend part of the flow:</p><figure><img alt="flow algorithm diagram: happy path" src="https://cdn-images-1.medium.com/max/122/1*y4Zvwy2cnpRdphBRZdeknA.png" /></figure><p>The clojure code reflecting the flow is pretty straightforward:</p><pre>(<strong>defn</strong> create-user<br>  &quot;Gets data from UI, decodes, validates, enriches the data,<br>  saves it to the DB, sends verification email to the user and returns response&quot;<br>  [request]<br>  (<strong>-&gt;</strong> request<br>      decode-request<br>      validate-user-input<br>      enrich-input<br>      update-DB<br>      send-email<br>      build-response-with-status))</pre><p>Thanks to clojure’s threading macro the code looks so good. What could possibly go wrong?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/335/1*PfKyR_AXAM_B1bJkVNsulg.jpeg" /></figure><h3>Sad path</h3><p>Basically everything:</p><figure><img alt="flow algorithm diagram: sad path" src="https://cdn-images-1.medium.com/max/313/1*6kYU3PrmBKWMclG5Q6g0fg.png" /></figure><p>So instead of our elegant piped code at the beginning we are getting a monster like this:</p><pre>(<strong>defn</strong> create-user<br>  &quot;Gets data from UI, decodes, validates, enriches the data,<br>    saves it to the DB, sends verification email to the user and returns response&quot;<br>  [request]<br>  (<strong>try</strong><br>    (<strong>let</strong> [data (<strong>decode-data</strong> request)<br>          validation-result (<strong>validate-user-input</strong> data)]<br>          (<strong>if</strong> (<em>:valid?</em> validation-result)<br>            (<strong>let</strong> [enriched-data (<strong>enrich-input</strong> data) ; can&#39;t escape this let: bindings used in several places<br>                  DB-response (<strong>update-DB</strong> enriched-data)]<br>              ; type of response and sending email depend on DB response status<br>              (<strong>if</strong> (<strong>=</strong> (<em>:status</em> DB-response) 201) <br>              ; the response depends on sending email<br>                (<strong>build-response-with-status</strong> enriched-data <br>                                            (<strong>send-email</strong> data)) <br>                {<em>:success</em> false<br>                <em>:error</em>   (<strong>str</strong> &quot;Failed creating user: &quot;<br>                            (<strong>-&gt;</strong> (<strong>json/parse-string</strong> DB-response true)<br>                              <em>:body</em><br>                              <em>:error</em>))}))<br>              validation-result))<br>        (<strong>catch</strong> Exception e<br>            (<strong>log/error</strong> &quot;Failed creating user, exception: &quot; e))))</pre><h3>The problem</h3><p>Basically the code works. Sometimes if the code does its job, it’s good enough, and it’s the developer’s right to decide to leave it this way. But it hurts to see this kind of code when writing in functional language: keeping state with lets (as we need the declared bindings in several places), a lot of ifs to check the state of the operations and select the “path” of “success”/”failure”, try-catch with its catch’s performance penalties.</p><figure><img alt="nested `if`s and `else`s" src="https://cdn-images-1.medium.com/max/360/1*MlHI_FUwZTUTNiXQkwwIvQ.jpeg" /></figure><p>What is more, the code is not readable at all: it’s hard to understand the order of the operations, to detect which “else” line corresponds to which if, and what the overall logic is. The last, but the most important point is that if-else, let as state keeper and try-catch are very imperative by their nature.</p><p>Sometimes it’s difficult to stay away from imperative approach, but we should remember that we have a choice: the functional paradigm offers us tooling for error handling and flow control.</p><h3>A way out</h3><p>What we usually can see in clojure code is splitting the whole flow into 2 things: small “worker” functions which actually do the job and an orchestration function that unites them altogether and is responsible for flow control and error handling.</p><p>The orchestration function calls the “workers” in a required order. The workers are piped with the threading macro again, so each of them should return the input the next one expects. Each “worker” throws an exception if something goes wrong inside of it. The orchestration function has a central “catch” point, where all the exceptions are handled:</p><pre>(<strong>defn</strong> create-user<br>  &quot;Gets data from UI, decodes, validates, enriches the data,<br>  saves it to the DB, sends verification email to the user and returns response&quot;<br>  [request]<br>  (<strong>try</strong><br>      (<strong>-&gt;</strong> request<br>          decode-request<br>          validate-user-input<br>          enrich-input<br>          update-DB<br>          send-email<br>          build-response-with-status)<br>      (<strong>catch</strong> Exception e<br>          (<strong>log/error</strong> &quot;Failed creating user&quot;<br>                     {<em>:error</em>   (<strong>.getMessage</strong> e)<br>                      <em>:request</em> (<strong>json/generate-string</strong> request)}))))</pre><p>An example of “worker” function:</p><pre>(defn- update-DB<br>  &quot;Sends request to DB to create user from the enriched data. Returns input or throws exception&quot;<br>  [input]<br>  (<strong>let</strong> [{<em>:keys</em> [success message]} <br>          (<strong>-&gt;</strong> (<strong>get-http-response-from-url-with-retries</strong> <em>:post</em><br>                                                    (<em>:DB-api</em> config)<br>                                                    body)<br>              <em>:body</em><br>              (<strong>json/decode</strong> true))]<br>     (<strong>if</strong> success<br>       input ;returning input to pass it to the next function<br>       <strong>throw</strong> (<strong>Exception.</strong> (<strong>str</strong> &quot;Failed updating DB: &quot; message))))))</pre><p>The function is pretty straightforward: it tries sending the user’s details which are passed as an input to the DB. If it succeeds, it returns the input (to pass it to the next function). Otherwise it throws an exception with the details of the event occurred. This trick also helps to bypass the following functions calls, once the error occurs.</p><p>So everything looks good, understandable, functional, elegant and readable, right? Right, but… there is always this “but”, and in our case it’s performance. The problem is in using catch a lot: it is expensive, so if the code is throwing a lot of exceptions and using the try-catch for flow control, then performance is an issue.</p><figure><img alt="Yoda" src="https://cdn-images-1.medium.com/max/520/1*GVmOFSdokvWXG-CsbBm85Q.jpeg" /><figcaption>– Do or do not, there is no try. (Yoda)</figcaption></figure><p>Basically, the Clojure community has no consensus about try-catch: some people think it’s essential to use it since clojure itself is written with this method, others consider it non-functional. It is a matter of a personal choice, but for us performance is important.</p><p>What are we left to do then? Where is the way?</p><h3>A new hope</h3><p>So how can we keep the code containing a lot of operations and conditions clear and functional on one hand, and performance-optimised on the other? Railway oriented programming is the answer! But what do railways have to do with programming? Let’s see!</p><p>Let’s imagine a function that expects one input parameter, e.g., a validator expecting some data and returning true or false, indicating if the input is valid or not. In other words, the function returns <em>either</em> true or false:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bJZCph3DwcdBE5CX" /></figure><p>In the functional programming world it is known as <a href="https://hackage.haskell.org/package/category-extras-0.52.0/docs/Control-Monad-Either.html">Either</a> <a href="http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html">monad</a> and has analogies in many programming languages.</p><p>Depending on the result of validation, we usually decide what to do next: we continue our flow if the input is valid or we log it and quit if the input is invalid (as we have nothing to do with invalid input). So we have one input (track) and two options of output track — continue or quit:</p><figure><img alt="two track-function model" src="https://cdn-images-1.medium.com/max/1024/0*GKYLPY7ONXVOBU_O" /></figure><p>So here are the tracks, the railway tracks! Indeed, we can imagine any of our operations as a dual track function:</p><figure><img alt="different dual track functions" src="https://cdn-images-1.medium.com/max/1024/0*rmxPSEGpu06i6D8g" /></figure><p>It’s easy to see that every function in this example has one input track (expects one parameter) and has two outcome tracks: success track/happy path and failure track/sad path. The reasonable question here is: what is the sense of all those tracks if we cannot connect them into one flow? The answer is simple: the sense is that we actually can. How? Let’s see together!</p><p>Let’s imagine our happy path with no disruptions, taking just three of our operations to simplify the explanation:</p><figure><img alt="happy path (the first track)" src="https://cdn-images-1.medium.com/max/1024/0*joTkhCuKV8Br8Apr" /></figure><p>We get the request, we validate it. The validation passes, and we pass the request data to the DB update function. Let’s say, everything goes smoothly, and we manage to update the DB and get the 200 response. Then we just send the email, which also succeeds, and return the response. The track is straight, passing from one “station” to another with no problem.</p><p>Once it comes to the sad path, we know that every step can fail, meaning that every “station” has a choice of either success or failure track:</p><figure><img alt="sad track: every step can fail" src="https://cdn-images-1.medium.com/max/1024/0*BbxBOVUwwHI_Ekqh" /></figure><p>Again we start with the request, passing it to the validator. Let’s say, the request is valid. Then we proceed to the following “station” and get to the DB update stage. Let’s say the DB is not available. What are we to do? We do not want to proceed to sending the verification email to the user, as the user was not actually created — there is nothing to verify. The following stages also will not be relevant in this case.</p><p>What we actually need to do is to choose a failure track: to log the error and quit the whole flow, bypassing the following steps. This is relevant for every “station” — wherever we fail (in the validator, DB updating, etc.), and every of them has its own failure track. But basically what we would like to do in all of those failure tracks is the same: to log error and quit the whole flow.</p><figure><img alt="how to unite all the failures into one track" src="https://cdn-images-1.medium.com/max/1024/0*No7Fi6fiKjJdDoct" /></figure><p>So it is reasonable to compose all of the tracks into one unite failure track:</p><figure><img alt="connecting two dual track functions" src="https://cdn-images-1.medium.com/max/1024/0*V19UkR4sM0oWpoNC" /></figure><p>Thus, we now can connect our “stations” into one duo-track:</p><figure><img alt="duo-tack flow" src="https://cdn-images-1.medium.com/max/1024/0*9d1qrHFWZ8IoTH8W" /></figure><p>Eventually, all of our functions can be connected together in this manner. Note that we get just one request with input data, which is represented by one success track. After the last “station” of the rail, we can return either two things as two tracks or one response (just wrapping the result with the regular function which returns one thing, e.g. a map for HTTP response).</p><p>Okay, so now we understand the rails, stations, connecting them and choosing our paths. Looks good in the pictures, but how is it all related to the code? The implementation is as interesting and easy, as the theory — stay tuned!</p><h3>Implementation</h3><p>First of all, let’s think of the building blocks — our functions which actually do the job and have to decide which track to choose. How can the function decide? Short answer: “with if”. Long answer: the function does not know if the operation will succeed or fail before it actually performs it. Once it’s performed, it is too late to decide though. So the next function should know the result of the previous one to decide, whether to perform the current operation or not: if the previous operation has failed, there is no sense to perform the current operation, so the function needs to choose the failure path. In contrast, if the previous function has succeeded, nothing prevents us from executing the current functionality.</p><p>Example: we start with the request, passing it to the validator. There was no previous action, so we are still on a success track, meaning that we should perform the validation. So the function validates the input and has to return some simple indication, if it has succeeded or failed, for the next function (DB updating) to be able to decide whether it should send the data to the DB or not.</p><p>We can implement this logic in every single function, but we don’t want boilerplate code doing the same for every “worker” function inside our flow. The solution is to create a <a href="https://adambard.com/blog/acceptable-error-handling-in-clojure/">wrapper function</a> which will do it for every single “worker”:</p><pre>(<strong>defn</strong> apply-or-error [f [val err]]<br>  (<strong>if</strong> err<br>    [val err]<br>    (<strong>f</strong> val)))</pre><p>This function gets two parameters: f, which is the next function in our flow, and a vector of val and err, which is the response of our current function. val is the indication of success instructing that the next function should also be executed and passing input value for this function. err is the indication of failure of the current function, instructing that we should take a failure path and preventing the following function’s execution. It is also a description of the error occurred to log and return it in the resulting response if needed. Of course, if the function succeeded, err is nil.</p><p>Now it’s obvious what this function does: it is executed before the current “worker” function, and it checks if the previous “worker” has failed or not. In case of success, it calls the following “worker” function and passes the output value of the previous function — the val — as an input parameter. If the error is not nil, it returns a vector of the val and err.</p><p>You might ask, why return val in case of a sad path. Good question! We do not have to, as in case of failure the next function won’t be executed anyway, so the form of indication of success and failure does not matter anymore. But you still might want to log the val. Why? Imagine, you got a request to add a new user to the DB. Let’s say, the validation has passed, but the DB update has failed. The error that we get from the DB will be something like “Failed updating DB: no connection” or similar. It’s hard to understand from it, which request for which exact user has failed. But once you log the val, which contains the data you send to DB (at least, some user-id for sure), you are able to find the exact reason of failure for the exact user in your logging system.</p><p>Also it’s worth mentioning, that vector is used just to simplify the example. It brings additional complexity to the code, making us remember, which place is for success and failure indication (<a href="https://www.infoq.com/presentations/Value-Values/">place oriented programming</a>). It’s more convenient to use hash-maps instead: {<em>:success</em> true <em>:error</em> nil}.</p><p>Back to business! So now we have some function, which will decide for us which track to take. How do we use it? We need the decision on every step, so the function should be applied to every “worker” function we have, starting with adding the request and nil as a vector indicating that there was no failure (sure — nothing happened yet):</p><pre>(<strong>clojure.core/-&gt;&gt;</strong> [request nil]<br>                 (<strong>apply-or-error</strong> decode-request)<br>                 <strong>(apply-or-error</strong> validate-user-input)<br>                 (<strong>apply-or-error</strong> enrich-input)<br>                 (<strong>apply-or-error</strong> update-DB)<br>                 (<strong>apply-or-error</strong> send-email)<br>                 (<strong>apply-or-error</strong> build-response-with-status))</pre><p>It does not make any sense to duplicate for every single function. Here comes power of clojure <a href="https://adambard.com/blog/acceptable-error-handling-in-clojure/">macros</a>:</p><figure><img alt="clojureman flying to help with macros power" src="https://cdn-images-1.medium.com/max/1024/0*BRfUmvmjtLnE6oJQ" /></figure><p>Don’t be afraid of this terrifying word, it is pretty simple:</p><pre>(<strong>defmacro</strong> =&gt;&gt;<br>  &quot;Threading macro, will execute a given set of functions one by one.<br>  If one of the functions fails, it will skip the rest of the functions and will return a fail cause.&quot;<br>  [val &amp; funcs]<br>  (<strong>let</strong> [steps (<strong>for</strong> [f funcs] <strong>`(apply-or-error</strong> ~f))]<br>    <strong>`(-&gt;&gt;</strong> [~val nil]<br>           ~<a href="http://twitter.com/steps">@steps</a>)))</pre><p>The macro gets initial val and all the workers funcs. It is pretty much the same to -&gt; that is used inside of it, the only difference is that our macro applies apply-or-error to every single input function. So we don’t need to apply it manually, our macro does the job (as you can see in the previous code snippet which was actually macroexpand of this macro and our “workers”).</p><p>Looks good, huh? Yes, but not 100% yet! We have piped the functions together, we have a “switchman” to decide which path to take, what are we missing? How does apply-or-error decide which path to take? Right, it has the output of the previous function. It means that all the functions should return unified output that will be clear to the switchman. This is the last building block — a wrapper unifying the “workers” output.</p><p>Indeed, our regular validator function can return basically anything at any form, from simple boolean to hash-maps: {<em>:valid?</em> bool <em>:error</em> string <em>:invalidity-code</em> int}. It does not look like our standardised railway path indication [val error]. To unify the output, we can wrap the function’s regular output inside the function itself:</p><pre>(<strong>defn</strong> validate-user-input<br>  &quot;Railway oriented programming (ROP) wrapper. Returns both validation result<br>  and input parameters for the next step, and in case of<br>  success: [result nil]<br>  failure: [result error]&quot;<br>  [input]<br>    (<strong>let</strong> [validation-result (<strong>create-user-input-valid?</strong> input)] ;returns `{:valid? bool :error string :invalidity-code int}`<br>      (<strong>if</strong> (<em>:valid?</em> validation-result)<br>        [input nil]<br>        [input validation-result])))</pre><p>Looks like we are good to go finally! Let’s put it all together:</p><pre>(<strong>defn</strong> create-account-handler<br>  [data]<br>  (<strong>try</strong><br>    (<strong>let</strong> [[result error] (<strong>=&gt;&gt;</strong> request<br>                              decode-request<br>                              validate-user-input<br>                              enrich-input<br>                              update-DB<br>                              send-email<br>                              build-response-with-status)]<br>      (<strong>if</strong> error<br>        (<strong>do</strong><br>          (<strong>log/erro</strong>r &quot;Failed creating new user&quot;<br>                     {<em>:error</em> error <em>:input</em> data})<br>          error)<br>        result)))<br>   (<strong>catch</strong> Exception e<br>       (<strong>log/error</strong> &quot;Failed creating new user&quot; {<em>:error</em> e <em>:input</em> data})))</pre><p>Just look how beautiful our code is! First of all, it’s readable, it’s so easy to see the operations order in the flow. Then, it’s clear what we do with the exceptions returned. It still has a let and an if, but no nested structures — much more beautiful and functional!</p><figure><img alt="i don’t always have errors, but when I have I use ROP" src="https://cdn-images-1.medium.com/max/606/1*swdffBMHgbCJIBo0zxaq9w.jpeg" /></figure><p>The only question left here is why still use try-catch if we were aiming so heavily to get rid of it?! Well, we indeed managed to eliminate it in everything that depends on us. But there are always things like unexpected errors or third-party libraries exceptions that you cannot handle any other way, because they are designed to be <em>thrown</em>, and you just cannot change it. It is always possible to get them, and we don’t want to crash everything because of it, we want to log them gracefully and go on — this is why try-catchis still here, but hopefully won’t be used.</p><h3>What now?</h3><p>Now you turn to implement ROP! How do you decide whether ROP fits your situation? Easily, there are several signs:</p><ul><li>You have flow with a lot of sequential operations;</li><li>You have nested ifs and lets, and you don’t like it;</li><li>You have many try-catch, and you care about performance;</li><li>You used threading macros, but not sure what if something fails;</li><li>You would like to bypass some of the functions is some scenarios;</li><li>You just would like to functionize your code and try ROP.</li></ul><p>How do you start coding it? First of all, you should read before you write. I recommend you to try the “Further reading” section before you add ROP into your production code. The first article is pretty basic, the second and the third are by legendary <a href="https://medium.com/u/c842d836f25b">Scott Wlaschin</a> and explore ROP in detail. If you’d like to optimise your ROP code with monads, consider the links number 4, 5, 6.</p><p>Basically you can take code examples from here or any other article or invent something new. You can use clojure built-in macros like -&gt;&gt;, -&gt;&gt;, some-&gt;, some-&gt;&gt; and others.</p><p>But I highly recommend to take a look into the ready-made ROP libraries (see the list at the end), as the less code you write on your own, the less tests you need to cover it, the less bugs you create. Good luck!</p><h3>Conclusion</h3><p>Railway oriented programming is a principle which can be used in a variety of ways. It is also flexible in implementation as function composition is essential for clojure. What is more, ROP way of validation and flow control can help us minimize the need of excessive error handling. It also offers a unique opportunity to bypass part of the functions in the flow if needed. ROP is power!</p><h3>Further reading</h3><ol><li><a href="https://adambard.com/blog/acceptable-error-handling-in-clojure/">“Good Enough” error handling in Clojure</a></li><li><a href="https://fsharpforfunandprofit.com/rop/">Railway Oriented Programming</a></li><li><a href="https://fsharpforfunandprofit.com/posts/recipe-part2/">Railway Oriented programming part II</a></li><li><a href="http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html">Functors, Applicatives, And Monads In Pictures</a></li><li><a href="http://learnyouahaskell.com/a-fistful-of-monads">A Fistful of Monads</a></li><li><a href="https://funcool.github.io/cats/latest/">Cats Documentation</a></li></ol><h3>Clojure ROP libraries</h3><p><a href="https://github.com/druids/rop">https://github.com/druids/rop</a></p><p><a href="https://github.com/fmnoise/flow">https://github.com/fmnoise/flow</a></p><p><a href="https://github.com/HughPowell/railway-oriented-clj">https://github.com/HughPowell/railway-oriented-clj</a></p><p><a href="https://funcool.github.io/cats/latest/">Cats Documentation</a></p><p>Thanks to <a href="https://medium.com/u/76a39a91ba32">Nir Rubinstein</a> and <a href="https://medium.com/u/ded353ffdf6b">Ethan Pransky</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89d75cc94c58" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appsflyerengineering/railway-oriented-programming-clojure-and-exception-handling-why-and-how-89d75cc94c58">Railway oriented programming, clojure and exception handling: why and how?</a> was originally published in <a href="https://medium.com/appsflyerengineering">AppsFlyer Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clojure: automated property-based tests for complicated inputs]]></title>
            <link>https://medium.com/appsflyerengineering/clojure-automated-property-based-tests-for-complicated-inputs-786de23de8f0?source=rss-7ff0cbafa4b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/786de23de8f0</guid>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[property-based-testing]]></category>
            <category><![CDATA[clojure]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Yulia Kleb]]></dc:creator>
            <pubDate>Tue, 04 Aug 2020 10:19:07 GMT</pubDate>
            <atom:updated>2020-08-04T10:19:07.333Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*5IzAiHDQchq68SKQV4Y2hA.jpeg" /></figure><blockquote><em>– Don’t write tests — generate them!</em></blockquote><blockquote><em>John Hughes (QuickCheck’s creator)</em></blockquote><p>We at AppsFlyer use Clojure as the primary backend language for production. This means writing complicated business flows on a daily basis. Complicated flows can mean basically anything: business logic containing many I/O operations, complex data transformations pipelines, etc. Whatever the flow is, it requires proper testing — both unit and system tests. But the more complex the logic gets, the more complex tests we have to add. What tools does clojure offer for this purpose? A lot!</p><p>In this post, we’d like to focus on the recent and less known addition to Clojure — spec — and the broad functionality it offers. We will discuss it using a real life example¹ which lays behind <a href="https://www.appsflyer.com/get-started/">AppsFlyer’s SignUp page</a> and will include a guide to introduce clojure.spec into your project from ground up.</p><h3>What is spec?</h3><p>As the official guide describes, <a href="https://clojure.org/about/spec">clojure.spec</a> is a built-in library (available from clojure 1.9) which specifies the structure of data, validates or conforms it, and can generate data based on the spec. This library adds strict typing functionality into dynamically typed language, which creates broad opportunities for input validation and tests creation.</p><p>Any good API/feature/code piece starts with design. Working with sensitive user data, we in AppsFlyer have to validate our input. In case of clojure, this is where spec comes in. It is used for validating input that API/function gets. On the other hand, spec provides the ability to build automated tests. How? Let’s see in the example!</p><h3>Basic flow architecture</h3><p>The flow of sign up at AppsFlyer is pretty complex and includes a lot of parts, developed in different teams. It starts with the UI you can see in the URL above, then the user’s input gets into SalesForce DB. After some enrichments it is also shared with the Domain team and saved into Domain DB, which actually creates an account in our system, and eventually it is passed to some other teams. The part of the flow that we’ll zoom in is the Domain part of creating accounts.</p><h3>Input</h3><p>The whole flow starts with the input. It can vary and depends on the account’s business type (which are Advertiser, Agency and Partner). Basic API JSON input example²:</p><pre>{ “account-type”: “Advertiser”,<br>  “subject”: “admin@appsflyer.com”,<br>  “account-data”:{<br>    “email”: “test-advertiser@email.ghostinspector.com”,<br>    “first-name”: “Test”,<br>    “last-name”: “Advertiser”,<br>    “company”: “appsflyer”,<br>    “website”: “http://www.appsflyer.com&quot;,<br>    “password”: “kjkjkklk14543”,<br>    “package”: “legacy”,<br>    &lt;…&gt;<br>  }<br>}</pre><p>Note that here:</p><ul><li>&lt;…&gt; means that it’s not the full list, production actually contains more fields which are omitted here to simplify the example;</li><li>“account-type” field’s value should be one of the predefined types mentioned above;</li><li>“subject” should be email and a user existing in the system;</li><li>“email” should be indeed email (containing “@”, some domain and a valid top level domain (TLD);</li><li>“first-name”, “last-name”, “company” and “password” should be non-empty strings;</li><li>“website” should be either nil or a valid website — string containing “http://” or ”https://” and a valid TLD;</li><li>“package” should be either nil or non-empty string with the business package name existing in the system;</li><li>The field set provided in the example is relevant for this account type only; additional fields are expected for other account types as must-have.</li></ul><p>To validate it, we can use regular clojure.spec built-in functions like:</p><pre>(<strong>ns</strong> my-project.validator<br>  (:require [clojure.spec.alpha :as s]))<br>  (<strong>s/def</strong> ::password (<strong>s/and</strong> string? not-empty))</pre><p>But it’s pretty clear that it turns to be not enough once we have more complex types like, e.g., email. For this case we’ll need something like:</p><pre>(<strong>def</strong> email-regex #&quot;^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$&quot;)<br>(<strong>s/def</strong> ::email-type (<strong>s/and</strong> string? #(<strong>re-matches</strong> email-regex %)))<br>(<strong>s/def</strong> ::email ::email-type)</pre><p>When creating a new user, we also need to check that the user’s email does not exist in our DB yet. So it’s obvious to add this check into validating function as well using spec and some additional function that goes to the DB and searches the provided email in it³:</p><pre>(<strong>defn-</strong> existing-user?<br>  &quot;Checks that email provided exists in DB&quot;<br>  [email]<br>  (<strong>does-user-exist?</strong> email)) ;placeholder for your DB search here ;)</pre><p>So, combining two conditions described above, we’ll get:</p><pre>(<strong>s/def</strong> ::email (<strong>s/and</strong> ::email-type #(<strong>not</strong> (<strong>existing-user?</strong> %)))) ;validates that email is of a specific type and  user does NOT exist ;in DB</pre><p>We can combine all those small specs into full input spec ::create-account-input (using <a href="https://clojuredocs.org/clojure.spec.alpha/keys">keys</a>), as well as validating functions into a general validator:</p><pre>(<strong>defn</strong> create-account-input-valid?<br> [input]<br> (<strong>if</strong> (<strong>s/valid?</strong> ::create-account-input input)<br>  {:valid? true}<br>  {:valid?  false<br>  :reason  (<strong>str</strong> &quot;Invalid input format: &quot; (<strong>s/explain-str</strong> ::create-account-input input))}))</pre><p>So having a validator like that, we are getting into the situation of using not only built-in clojure functionality, but self-written functions as well. Which is obviously a possible place for bugs. How to make sure we haven’t created any? Adding tests, of course!⁴</p><h3>Testing &amp; generators</h3><p>Obviously, we need to test our validator as a black box with unit tests. Unit tests paradigm expects testing all the fields’ possible combinations — valid and invalid — and checking that the output meets expectations.</p><p>But having that big input and so many validation rules creates an endless quantity of fields’ values permutations. Under those circumstances, it’s not possible to write tests for all the edge cases and permutations manually. What are we to do then? Now it’s time to use the power of spec, which will allow us to:</p><ol><li>Generate the needed input for tests in an automated way</li><li>Build automated property tests with <strong>no</strong> manual work.</li></ol><p>Having generators inside it, spec can create all those permutations for us. As we know from the <a href="https://clojure.org/guides/spec#_generators">documentation</a>, built-in spec generators can generate anything conforming standard clojure types:</p><pre>(<strong>ns</strong> my-project.validator <br> (:require [clojure.spec.alpha :as s]<br>   [clojure.spec.gen.alpha :as gen]))</pre><pre>(<strong>gen/generate</strong> (<strong>s/def</strong> ::password (<strong>s/and</strong> string? not-empty))) ;will generate non-empty string</pre><p>But as we saw in our input example, it is not enough in real life, when it comes to cases like checking that the “email” value we get is actually an email. Then <a href="https://clojure.org/guides/spec#_custom_generators">custom generators</a> come to help. The idea is pretty straightforward — as clojure itself cannot generate emails conforming our spec out of the box, we need to tell it how to generate the required value or even give it a set of sample values. Indeed, let’s explore an example of giving rules to generate email⁵:</p><pre>(<strong>def</strong> email-regex #&quot;^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,63}$&quot;)</pre><pre>(<strong>defn-</strong> email-generator<br>&quot;Generates email with <a href="/service/mailto:string@string.co.il">string@string.co.il</a> for tests auto-generated input&quot;<br> []<br> (<strong>gen/fmap</strong> #(<strong>str</strong> % &quot;@&quot; % &quot;.co.il&quot;) (<strong>gen/string-alphanumeric</strong>)))</pre><pre>(<strong>s/def</strong> ::email-type (<strong>s/and string?</strong> #(<strong>re-matches</strong> email-regex %)))</pre><pre>(<strong>s/def</strong> ::email (<strong>s/with-gen</strong> ::email-type email-generator)) ;validates that user does NOT exist in DB</pre><p>As we can see from the code above, email-generator function is a generator that knows how to create strings according to our “email” rules. Works great for this example.</p><p>But what if we need our email to exist in the DB like the “subject” field? The code we’ve just explored has no idea if the email exists in some external resource. To explain to clojure how to do it as well, we can add a part that takes generated email and checks if it exists in the DB into email-generator, but it will need to sample so many emails before it actually finds one existing in the DB, which is not efficient anymore. In this case we can use another option generators provide us — giving it a set of ready-made examples meeting our validation rules:</p><pre>(<strong>s/def</strong> ::subject (<strong>s/with-gen</strong> ::email-type #(<strong>s/gen</strong> #{&quot;<a href="/service/mailto:domain-test-1@appsflyer.com">test-0@appsflyer.com</a>&quot; &quot;<a href="/service/mailto:domain-test-1@appsflyer.com">test-1@appsflyer.com</a>&quot;})))</pre><p>So this way we can add generators to any input field we have. This will let us generate all the fields we need just calling the spec from our validator namespace and `generate` function from spec library:</p><pre>(<strong>ns</strong> my-project.unit-tests <br> (:require [my-project.validator :as validator]<br>   [clojure.spec.gen.alpha :as gen]))</pre><pre>(<strong>defn</strong> generate-input-template <br>  &quot;Generates hash-map account input by a predefined template&quot;<br>  [] <br>  {:account-type (<strong>gen/generate</strong> (<strong>s/gen</strong> ::validator/account-type)),<br>   :subject      (<strong>gen/generate</strong> (<strong>s/gen</strong> ::validator/subject)),<br>   :account-data<br>   {:package     (<strong>gen/generate</strong> (<strong>s/gen</strong> ::validator/package)),<br>    :email       (<strong>gen/generate</strong> (<strong>s/gen</strong> ::validator/email)),<br>    :salt        (<strong>gen/generate</strong> (<strong>s/gen</strong> ::validator/salt))<br>    :website     (<strong>gen/generate</strong> (<strong>s/gen</strong> ::validator/website)),<br>    :company     (<strong>gen/generate</strong> (<strong>s/gen</strong> ::validator/company))}})</pre><p>Looks good, right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*AW6T5z_U7FuddBjRD0Xc7A.png" /></figure><p>But not good enough: we would expect something like one-line generation and test like seen in <a href="https://clojure.org/guides/spec#_instrumentation_and_testing">clojure.spec test documentation</a> examples:</p><pre>(<strong>require</strong> &#39;[clojure.spec.test.alpha :as stest])</pre><pre>(<strong>s/gen</strong> ::validator/create-account-input) ; generating input of the ;same structure as a JSON at the beginning of the post<br>(<strong>stest/check</strong> `validator/validate-account-input) ; unit test checking ;validator function</pre><p>But how can we achieve it, having nested fields in the input structure (see “account-data” nested map in the input example)? Moreover, as we’ve mentioned above, the JSON input example at the beginning of the post is just a basic example and will have additional must-have fields for other account types, e.g.:</p><pre>{<strong>&quot;account-type&quot;: &quot;Partner”,</strong><br>   &quot;subject&quot;: &quot;<a href="/service/mailto:admin@appsflyer.com">admin@appsflyer.com</a>&quot;,<br>   &quot;account-data&quot;:{<br>    <strong>“partner-acc-id”: “testPartner0”,</strong><br>    &quot;email&quot;: &quot;<a href="/service/mailto:test-partner@email.ghostinspector.com">test-partner@email.ghostinspector.com</a>&quot;,<br>    &quot;first-name&quot;: &quot;Test&quot;,<br>    &quot;last-name&quot;: &quot;Partner&quot;,<br>    &quot;company&quot;: &quot;appsflyer&quot;,<br>    &quot;website&quot;: &quot;<a href="http://www.appsflyer.com/">http://www.appsflyer.com</a>&quot;,<br>    &quot;password&quot;: &quot;996jklhef&quot;,<br>    &quot;package&quot;: &quot;legacy&quot;,<br>    &lt;...&gt;<br>   }<br>}</pre><p>The previously discussed fields can be found here, as well as the “<em>partner-acc-id</em>” field which is a must for Partner accounts (and must be a non-empty string), though it must not exist for other account types. Thus, there is a dependency between fields: existence of the “<em>partner-acc-id</em>” field depends on the “account-type” field’s value.</p><p>So it’s easy to see that this structure cannot be generated by clojure.spec automatically. Don’t worry — clojure.spec is full of surprises and has power to cope with this challenge as well!</p><h3>Multi-spec power</h3><p>Clojure.spec provides us <a href="https://clojure.org/guides/spec#_multi_spec">multi-spec</a> tooling to create different sets for different types of the same input. Based on that, we can add a selector indicating the type of input (account type in our case), a base set of fields relevant for every account type and a separate method with its own additional fields for each account type required:</p><pre>;account type selector which is actually the same to account type ;possible values<br>(<strong>s/def</strong> ::account-type-key (<strong>s/with-gen</strong> keyword? #(<strong>s/gen</strong> #{:Advertiser :Agency :Partner}))) <br>;case switcher for multispec with the values similar to “account-type” values</pre><pre>(<strong>s/def</strong> ::base-input <br>       (<strong>s/keys</strong> :req-un [::email ::password ::first-name ::last-name ::company]<br>               :opt-un [::website ::package]))</pre><pre>;multi-spec is used to identify whether the instance type needs ;special props <br>;e.g., partner-acc-id for Partner accounts only</pre><pre>(<strong>defmulti</strong> account :account-type-key)<br>(<strong>defmethod</strong> account :Advertiser [_]<br>   (<strong>s/merge</strong> (<strong>s/keys</strong> :req-un [::account-type-key]) ::base-input))<br>(<strong>defmethod</strong> account :Partner [_]<br>   (<strong>s/merge</strong> (<strong>s/keys</strong> :req-un [::account-type-key ::partner-acc-id]) ::base-input))<br>(<strong>defmethod</strong> account :Agency [_]<br>   (<strong>s/merge</strong> (<strong>s/keys</strong> :req-un [::account-type-key ::agency-field]) ::base-input))<br>(<strong>defmethod</strong> account :default [_]<br>    (<strong>s/merge</strong> (<strong>s/keys</strong> :req-un [::account-type-key]) ::base-input))</pre><pre>;creating nested account-data structure<br>(<strong>s/def</strong> ::account-data (s/multi-spec account :account-type-key))</pre><pre>;creating the whole input structure and defining fields dependency<br>(<strong>s/def</strong> ::create-account-input <br>  (<strong>s/and</strong> (<strong>s/keys</strong> :req-un [::account-type ::subject ::account-data])<br>    (<strong>fn</strong> [{:keys [account-type account-data]}]<br>      (<strong>=</strong> (:account-type-key account-data) (keyword account-type)))))</pre><p>This piece of code gives us an ability to generate maps of the same structure as the JSON we have as an input (and which is eventually also parsed to a map), including one additional field of :account-type-key which was used as a selector. Its presence does not affect unit tests, but can be dissoced if needed. Let’s check out the output:</p><pre>(<strong>gen/generate</strong> (<strong>s/gen</strong> ::create-account-input))</pre><p>will create the following example outputs: they differ both in account types/<em>partner-acc-id</em> presence and other fields presence (Partner output is missing :package and :website, and it’s okay since they can be nil, according to our spec/validation rules)⁵:</p><pre>{:account-type &quot;Advertiser&quot;,        {:account-type &quot;Partner&quot;,<br> :subject &quot;<a href="/service/mailto:test-0@appsflyer.com">test-0@appsflyer.com</a>&quot;,   :subject &quot;<a href="/service/mailto:test-1@appsflyer.com">test-1@appsflyer.com</a>&quot;,<br> :account-data                      :account-data<br>  {:account-type-key :Advertiser,    {:partner-acc-id &quot;P6Jcwp1FKm3&quot;,<br>   :package &quot;legacy&quot;,                 :email &quot;<a href="/service/mailto:zP8zAx8zg@zP8zAx8zg.co.il">zP8zAx@zP8zAx.co.il</a>&quot;,<br>   :website &quot;<a href="http://www.9ewsc.com/">http://www.9EWsC.com</a>&quot;,   :password &quot;Of6wP55QD&quot;,<br>   :email &quot;<a href="/service/mailto:yclXhm2@yclXhm2.co.il">yclXhm2@yclXhm2.co.il</a>&quot;,    :first-name &quot;26rjol&quot;,<br>   :password &quot;0s2TZv5&quot;,               :last-name &quot;Nht9yP4pdv69&quot;,<br>   :first-name &quot;JCN69Ya85Klx&quot;,        :company &quot;YcOFdLRSkt&quot;,<br>   :last-name &quot;54e37ezGUII9UeTX&quot;,     :account-type-key :Partner<br>   :company &quot;7f29khk&quot;                 &lt;...&gt;<br>   &lt;...&gt;                             }}<br>}}</pre><p>Now we have got a one-line complex input generation — the first goal achieved!</p><p>What now? Now it is time to create one-line unit tests and explore clojure.spec generative opportunities for tests in general!</p><h3>Tests</h3><p>We can be sure now that clojure.spec itself can generate our complex input in every possible permutation automatically. It means that now clojure does not need us to do manual work to test the validator function, stest/check should be enough.</p><p>Let’s assume that we would like to test the mentioned earlier create-account-inout-valid? validator function. According to the <a href="https://clojure.org/guides/spec#_specing_functions">documentation</a>, to be able to do it in an automated way, we need first to add fdef to define specifications for our function:</p><pre>(<strong>s/fdef</strong> create-account-input-valid?<br>  :args (<strong>s/cat</strong> :input ::create-account-input))</pre><p>Now we basically can call</p><pre>(<strong>ns</strong> my-project.unit-tests <br> (:require [my-project.validator :as validator]<br>   [clojure.spec.test.alpha :as stest]))<br> <br> (<strong>stest/check</strong> `validator/create-account-input-valid?)</pre><p>It will only return</p><pre>;;=&gt;({:spec #object[clojure.spec.alpha$fspec_impl$reify__13728 ...],<br>;;  :clojure.spec.test.check/ret {:result true, :num-tests 1000, :seed 1466805740290},<br>;;  :sym spec.examples.guide/ranged-rand,<br>;;  :result true})</pre><p>which is not that informative. To get some human readable results we can add the following wrapper:</p><pre>(<strong>deftest</strong> test-create-account-input-valid-spec<br>  (<strong>testing</strong> &quot;Testing input conforming spec&quot;<br>    (<strong>refresh</strong>)<br>      (<strong>timbre/set-level!</strong> :report) <br>      (<strong>let</strong> [results (<strong>stest/check</strong> `validator/create-account-input-valid?)]<br>        (<strong>run!</strong> #(<strong>timbre/report</strong> %) results)<br>        (<strong>is</strong> (<strong>every?</strong> nil? (<strong>mapv</strong> :failure results))))))</pre><p>In case of success it returns:</p><pre>REPORT [create-account.create-account-unit-test:37] - {:spec #object[clojure.spec.alpha$fspec_impl$reify__2524 0x34934bc8 &quot;clojure.spec.alpha$fspec_impl$reify__2524@34934bc8&quot;], :clojure.spec.test.check/ret {:result true, :pass? true, :num-tests 1000, :time-elapsed-ms 53011, :seed 1585735274690}, :sym my-project.validators.validator/create-account-input-valid?}</pre><p>In case of error, it will display the relevant exception.</p><p>Basically, this is it — our second (and the main) goal is achieved!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*3Tnl3rWmsOjt6r922G73dg.png" /><figcaption>No need to write verbose tests anymore!</figcaption></figure><p>But if we have passed such a long way understanding clojure.spec, let’s see what other abilities it gives us.</p><p>The other interesting opportunity is to use the power of clojure’s <a href="https://clojure.org/guides/test_check_beginner">test.check</a> library combined with spec’s generators, which offers a broad variety of property-based test tools. We’ll check out only the basic one here:</p><pre>(<strong>require</strong> ‘[org.clojure/test.check &quot;0.10.0&quot;])</pre><pre>(<strong>def</strong> positive-answer {:valid? true})</pre><pre>(<strong>def</strong> validator-property-test<br>  ;generating input<br>  (<strong>prop/for-all</strong> [input (<strong>s/gen</strong> ::validator/create-account-input)] <br>    ;how to get the result<br>    (<strong>let</strong> [result (<strong>validator/create-account-input-valid?</strong> input)] <br>      ;success condition<br>      (<strong>is</strong> (<strong>=</strong> positive-answer result)))))</pre><pre>(<strong>deftest</strong> input-validator-unit<br>  (<strong>testing</strong> &quot;Creating new account: input validator unit tests:&quot;<br>    (<strong>testing</strong> &quot;Validator property testing&quot; (<strong>tc/quick-check</strong> 100 validator-property-test)))) ; test itself</pre><p>The nice option here is having control of basically everything: input, operation to check, success criteria and number of tests to run. This function expects more optional arguments like max-size, seed, etc.</p><p>Another option is combining spec’s generators, test.check and manual checks:</p><pre>(<strong>def</strong> positive-answer {:valid? true})<br>(<strong>def</strong> negative-answer {:invalidity-type :invalid-permission<br>                      :reason &quot;Subject does not exist or is not an existing user&quot;<br>                      :valid? false})</pre><pre>;input validation unit tests<br>(<strong>deftest</strong> input-validator-unit<br>  (<strong>testing</strong> &quot;Creating new account: input validator unit tests:&quot;<br>    (<strong>testing</strong> &quot;Validator property testing&quot; (tc/quick-check 100 validator-property-test))<br>       (<strong>testing</strong> &quot;Positive&quot;<br>         (<strong>is</strong> <br>           (<strong>=</strong> positive-answer <br>              (<strong>validator/create-account-input-valid?</strong> <br>                 (<strong>gen/generate</strong> (<strong>s/gen</strong> ::validator/create-account-input))))))<br>       <br>       (<strong>testing</strong> &quot;Negative – subject does not exist&quot;<br>         (<strong>is</strong> <br>           (<strong>=</strong> negative-answer <br>           (<strong>validator/create-account-input-valid?</strong> <br>               (<strong>assoc</strong> (<strong>gen/generate</strong> (<strong>s/gen</strong> ::validator/create-account-input)) :subject &quot;<a href="/service/mailto:some-random-email-that-does-not-exist@appsflyer.com">some-random-email-that-does-not-exist@appsflyer.com</a>&quot;)))))))</pre><p>Thus we can manually inject some field instead of the generated one. This approach can be used if we’d like to check some specific scenarios or when having manual validations in addition to specs.</p><p>Furthermore, clojure.spec/generators can be used to generate input for system tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HZ4_1oO2UvmNOSinNuQXpQ.png" /></figure><h3>Conclusion</h3><p>Clojure.spec is still in alpha and tends to look complicated at the beginning, but it offers a broad functionality that can simplify the developer’s life. You might think of using it developing APIs/functions, where:</p><ul><li>Input types do matter;</li><li>Having complex structured input;</li><li>Having a large number of input fields;</li><li>Property testing is needed, etc.</li></ul><p>If you’d like to introduce automated property-based tests into your clojure project, just follow the following steps:</p><ol><li>Add clojure.spec dependencies;</li><li>Add specs for your input fields;</li><li>Create general validator function containing specs and your custom validations;</li><li>Add custom generators into your specs definitions where applicable;</li><li>Add `fdef` definition to your validator function;</li><li>Use stest/check, stest/check or their combination;</li><li>Enjoy!</li></ol><p><em>Thanks to </em><a href="https://medium.com/u/76a39a91ba32"><em>Nir Rubinstein</em></a><em>, </em><a href="https://medium.com/u/232356bf7007"><em>Morri Feldman</em></a><em> and </em><a href="https://medium.com/u/115d9f3d06c5"><em>Ben Sless</em></a><em>.</em></p><p>[1] Omitting some technical details to reduce the example’s complexity (e.g., password encryption, etc.).</p><p>[2] This is a very simplified example that doesn’t fully reflect the real production input and validation process that we do, but it’s sufficient for our example.</p><p>[3] Mind that this function omits the actual process of searching the DB to simplify the example.</p><p>[4] Note that tests cannot guarantee that there are no bugs at all for 100%.</p><p>[5] Remember that this is a very simplified example that doesn’t fully reflect the real production input, validators and generators, but it’s sufficient for our example.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=786de23de8f0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appsflyerengineering/clojure-automated-property-based-tests-for-complicated-inputs-786de23de8f0">Clojure: automated property-based tests for complicated inputs</a> was originally published in <a href="https://medium.com/appsflyerengineering">AppsFlyer Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>