<?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 Dario Di Pasquale on Medium]]></title>
        <description><![CDATA[Stories by Dario Di Pasquale on Medium]]></description>
        <link>https://medium.com/@dariodip?source=rss-a22f7d80066c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fdRzW7EbrmzrYGQTdik98Q.jpeg</url>
            <title>Stories by Dario Di Pasquale on Medium</title>
            <link>https://medium.com/@dariodip?source=rss-a22f7d80066c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 20:43:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dariodip/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[Stop building everything, start building this: the power of the MVP]]></title>
            <link>https://dariodip.medium.com/stop-building-everything-start-building-this-the-power-of-the-mvp-980e0a917b43?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/980e0a917b43</guid>
            <category><![CDATA[lean-startup]]></category>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[mvp]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Mon, 02 Mar 2026 16:10:23 GMT</pubDate>
            <atom:updated>2026-04-16T14:42:27.449Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>This post is also available on <a href="https://dariodip.com/posts/product/stop-building-everything-start-building-this-the-power-of-the-mvp/?utm_source=medium">my personal website</a>.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YufYM3Zmg0zwucc1" /><figcaption>Photo by <a href="https://unsplash.com/@chatelp?utm_source=medium&amp;utm_medium=referral">Pierre Châtel-Innocenti</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Most teams don’t fail because they ship too slowly. Speed is rarely the real villain. In fact, many teams move fast, hit deadlines, close sprints, and still end up nowhere meaningful.</p><p>They fail because they ship the wrong thing with high confidence.</p><p>That’s the dangerous part. Not ignorance, but confident ignorance. Polished features. Clean architecture. Well-run ceremonies. And underneath it all, an assumption that was never truly tested.</p><p>An MVP is not “version 0.1 of your full product.” It’s not a lighter UI. It’s not fewer features. It’s not your roadmap, compressed.</p><blockquote>An MVP (Minimum Viable Product) is the cheapest test that can validate or kill your riskiest assumption. It is the earliest version of a new product with just enough features to satisfy early adopters and validate a product concept.</blockquote><p>Notice the word kill. If your “MVP” can only confirm your idea but cannot clearly invalidate it, then it’s not an experiment. It’s a performance. You’re acting like you’re learning, but you’re actually protecting the idea.</p><p>A real MVP creates tension. It forces a binary moment. Did we get the signal we defined in advance, or not?</p><p>If your MVP cannot produce a clear decision (build, pivot, or stop), then it isn’t an MVP.</p><p>It’s just a smaller backlog wearing experimental clothing.</p><h3>The only definition that matters</h3><p>Use this sentence as your quality gate:</p><blockquote><strong><em>An MVP is the minimum effort needed to trigger a high-signal learning event.</em></strong></blockquote><p>It is like playing <a href="https://en.wikipedia.org/wiki/Marco_Polo_(game)">Marco Polo</a>: you want to catch the other team as fast as possible with closed eyes and only shouting “Marco!” (your high signal). As soon as you hear them shouting back “Polo!” (your decision metric), you can understand how far you are from the goal.</p><p>High-signal means you can clearly decide what to do next:</p><ul><li><strong>Persevere</strong> (Double Down): The hypothesis is validated. Focus on reducing friction in the core loop, improving retention, and preparing for the next stage of growth or complexity. You are getting closer to the goal, and you need to move in that direction.</li><li><strong>Pivot</strong> (Change Direction): The core value is there, but the delivery or target is off. This could be a <em>Customer Segment Pivot</em> (right product, wrong user) or a <em>Value Prop Pivot</em> (right user, wrong problem). You are getting further from the goal, so you need to change direction.</li><li><strong>Stop</strong> (Kill the Bet): The signal is clear: the market doesn’t need this, or the economics don’t work. Celebrate the “fail-fast” and redirect resources to a more promising hypothesis.</li></ul><p>You can use the following 5-step execution loop to validate your MVP:</p><ol><li><strong>Name the single riskiest assumption</strong><br> Example: “Ops managers will pay €99/month to cut weekly reporting time by 30%.”</li><li><strong>Pick the cheapest credible experiment</strong><br> Don’t code by default. Start with the lightest test that can prove behavior.</li><li><strong>Define one decision metric</strong><br> Not pageviews. Use behavior tied to value: activation, retention intent, willingness to pay.</li><li><strong>Set a threshold before running</strong><br> Example: “If &lt;25% of qualified users complete the core action, we pivot.”</li><li><strong>Make the call fast</strong><br> No post-rationalization. Data beats opinion.</li></ol><h3>Types of MVP (and when to use each)</h3><p>There are different types of MVPs, each with its own characteristics and use cases. Here are the most common types:</p><h3>Smoke Test MVP (landing page + CTA)</h3><p>A smoke test for an MVP is a pre-development validation technique used to measure market demand before building a product. It involves creating a landing page with a clear value proposition, ad campaign, or prototype that simulates a product’s value proposition to gauge user interest through clicks, sign-ups, or “buy now” button interactions.</p><h3>Concierge MVP</h3><p>A Concierge MVP is a strategy where you deliver a service manually to a small group of users, simulating an automated, high-tech solution to validate a business idea without upfront software development. By providing a highly personalized, hands-on experience, you learn directly from customer feedback and prove demand before investing in automation.</p><p>You deliver value manually behind the scenes.</p><p>An example can be <a href="https://www.youtube.com/watch?v=czNgFW9rzAQ">Food on the Table</a>: The founder manually created grocery lists and meal plans based on user preferences before building a system.</p><h3>Wizard of Oz MVP</h3><p>A Wizard of Oz MVP is a product strategy where a functional, user-facing interface is presented, but all backend processes are performed manually by humans, not software. This allows startups to test, validate, and gather data on new ideas without investing in expensive, full-scale automation.</p><p>Looks automated, but part of the system is manual.</p><p>An example can be <a href="https://medium.com/nikhilvarshneypandb/zappos-and-the-wizard-of-oz-a-relentless-customer-success-story-everyone-should-learn-3c7dd99fc97">Zappos</a>: Founder Nick Swinmurn took pictures of shoes in local stores, posted them online, and bought/shipped them manually when orders arrived.</p><h3>Single-Feature MVP</h3><p>A single-feature MVP consists of launching with only one core, high-impact feature to solve a specific problem, allowing startups to validate business ideas, reduce initial development costs by up to 60%, and gather targeted user feedback. It focuses on testing viability and desirability by delivering immediate value to early adopters, rather than building a complex, fully-featured app.</p><p>One painful job-to-be-done solved end-to-end.</p><p>An example can be <a href="https://en.wikipedia.org/wiki/Foursquare_(company)">Foursquare</a>: Began solely as a check-in application.</p><h3>Pre-sale MVP</h3><p>A pre-sale MVP (Minimum Viable Product) is a strategy to validate market demand by selling a product, or the promise of one, before it is fully built. Using techniques like crowdfunding, landing pages, or demo-based sales, it tests willingness to pay, minimizes financial risk, and gathers crucial feedback to guide development.</p><p>Sell before building fully (paid pilot, LOI, deposit).</p><p>While both are low-fidelity validation techniques used before building a full product, a Pre-sale MVP is a “high-commitment” version of a Smoke Test MVP. A Pre-sale MVP takes the validation a step further by actually collecting money. It proves that customers don’t just like the idea, they are willing to pay for it now to get it later.</p><p>The Smoke Test MVP acts like a “lure” to see if anyone is interested. You might run an ad to a landing page for a non-existent product. If they click “Buy Now,” they get a message saying, “We’re not launched yet, join the waitlist!”</p><h3>No-Code / Prototype MVP</h3><p>No-code MVPs allow entrepreneurs to rapidly build and launch functional prototypes-often in days rather than months-to validate business ideas without writing code. By using drag-and-drop tools like Bubble, Adalo, or Softr/Airtable, you can create cost-effective, iterative MVPs, significantly reducing the risk of failure and allowing for quick user feedback.</p><p>Figma, no-code stack, or scripted backend for fast iteration.</p><p>Steps to Build a No-Code MVP</p><ol><li>Define the Core Value: Identify the single most important problem your product solves.</li><li>Map User Journey: Sketch the essential screens and actions.</li><li>Select Tools: Choose tools that match your technical comfort level and functional needs (e.g., Airtable for data, Bubble for logic).</li><li>Build &amp; Launch: Assemble the MVP, focusing on functionality over design.</li><li>Iterate: Gather user data, test, and improve the product continuously.</li></ol><h3>Content MVP</h3><p>A Content Minimum Viable Product (MVP) is the simplest, most essential version of a content strategy or asset designed to test audience engagement with minimum effort and investment. It helps creators validate topics, formats, and value propositions through quick, iterative feedback loops before investing heavily in production.</p><p>Teach the solution before building it (article, demo video, teardown, webinar).</p><h3>Quick selector: choose the MVP type by risk</h3><p>This table can be very useful to decide which type of MVP to build, based on the risk you are willing to take, the question you want to answer, and the signal you want to receive.</p><p>“Do they care?” -&gt; Smoke test / Content MVP [Qualified inbound, replies, discovery calls. Engagement vanity if the audience is too broad]</p><p>“Will they pay?” -&gt; Concierge / Pre-sale MVP [Money, signed commitment, pilot start date. Requires clear scoping and trust]</p><p>“Can they use it?” -&gt; Prototype / Wizard of Oz [Task completion and friction points. Can mask real performance constraints]</p><p>“Will they come back?” -&gt; Single-feature thin slice [Activation + repeated use of that one feature. Teams sneak in “just one more feature”]</p><h3>Anti-patterns to avoid</h3><p>Everything can be done wrong, even MVP. Here are some common anti-patterns:</p><ul><li>“MVP” that includes half the roadmap</li><li>Success criteria defined after seeing results</li><li>Vanity metrics (impressions, generic traffic)</li><li>No explicit kill criteria</li><li>Team is emotionally attached to the solution, not the problem</li></ul><h3>Practical example</h3><p>Let’s make this less <strong>abstract</strong> and more <strong>real</strong>.</p><p>Imagine you wake up with the idea: “ <em>I want to build an AI reporting assistant for e-commerce operators.</em> “ In your head, it’s beautiful. Clean dashboards. Smart insights. Maybe even predictive suggestions. It feels like a SaaS already.</p><p>Now, there are two very different roads you can take.</p><p>The seductive one — the “ <em>I am building a real company</em> “ path — looks like this:</p><p>You start by setting up authentication. Then a proper dashboard. Then Stripe billing. Then user roles. Then the admin panels. Then integrations with Shopify, WooCommerce, Meta Ads, and Google Ads. You spend weeks polishing infrastructure. It feels productive. It looks serious.</p><p>But here’s the uncomfortable truth: <strong>none of that proves anyone actually wants the thing.</strong></p><p>You’ve bought complexity before buying certainty.</p><p>The alternative path is humbler. Almost embarrassingly simple.</p><p>Recruit some (~10) qualified e-commerce operators. Not random people. Real operators with real revenue, real reporting pain.</p><p>For two weeks, don’t build the product. Run a concierge workflow. You manually pull their data. You manually generate insights. You may be using AI tools behind the scenes. But to them, it feels like a service.</p><p>At the end of the two weeks, you ask a brutally clear question:</p><blockquote><em>“Would you continue next month on a paid plan?”</em></blockquote><p>You define a threshold in advance. For example, at least 4 out of 10 must commit to paying.</p><p>If the answer is <strong>yes</strong>, you don’t automate everything. You automate the single highest-friction step first — the one that consumes most of your manual time.</p><p>Notice what happened here.</p><p>You didn’t start by building a product. You started by <strong>testing a market</strong>.</p><p>You didn’t optimize the code. You optimized for <strong>signal</strong>.</p><p>The goal isn’t to look like a startup. It’s to reduce uncertainty. Every early decision should be judged by one question: “Does this increase my confidence that people will pay?”</p><p>This is how you earn the right to build complexity. Not by faith. Not by vibes. By evidence.</p><p>And there’s something almost philosophical here: complexity is cheap for engineers. Certainty is expensive. So the disciplined move is to buy certainty first.</p><p>Once someone is willing to pull out a credit card, architecture suddenly becomes a very good problem to have.</p><h3>Final pre-build checklist</h3><p>Before you open your editor. Before you sketch the system diagram. Before you convince yourself that “this time it’s different.”</p><p><strong>Pause.</strong></p><p>Most early-stage mistakes don’t come from bad code. They come from unexamined assumptions. We fall in love with an idea, then we quietly start protecting it. We replace questions with features. We replace doubt with architecture.</p><p>An MVP isn’t a smaller product. It’s a <strong>structured experiment</strong>.</p><p>So before building anything, run through this checklist with almost uncomfortable honesty:</p><ul><li>What assumption are we testing right now?</li><li>What metric decides the outcome?</li><li>What threshold triggers pivot/kill?</li><li>What is the cheapest valid test?</li><li>How fast can we run the next loop?</li></ul><p>If these answers are fuzzy, you’re not doing MVP. You’re doing hope-driven development.</p><p><strong>And hope, while emotionally satisfying, has a terrible conversion rate.</strong> <strong>References:</strong></p><ul><li>Eric Ries, <em>The Lean Startup</em></li><li>Don McGreal, Ralph Jocham, <em>The Professional Product Owner</em></li></ul><p><em>Originally published at </em><a href="https://dariodip.com/posts/product/stop-building-everything-start-building-this-the-power-of-the-mvp/?utm_source=medium"><em>https://dariodip.com </em></a><em>on March 2, 2026.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=980e0a917b43" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Prepare for the PSM I using Scrum]]></title>
            <link>https://dariodip.medium.com/prepare-for-the-psm-i-using-scrum-f51b67f1a07e?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f51b67f1a07e</guid>
            <category><![CDATA[scrum-master]]></category>
            <category><![CDATA[engineering-mangement]]></category>
            <category><![CDATA[scrum]]></category>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[agile]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Sat, 21 Oct 2023 15:40:39 GMT</pubDate>
            <atom:updated>2023-10-25T07:44:34.931Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F52k5oj9VMHEpxaZ" /><figcaption>Photo by <a href="https://unsplash.com/@designer4u?utm_source=medium&amp;utm_medium=referral">Olga Guryanova</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>In the fast-paced world of project management and software development, staying relevant and competitive requires continuous learning and adaptation.</p><p>Since September 2021, I have been working at <a href="https://www.helloprima.com/">Prima</a>, a company that utilizes the <strong>Scrum framework</strong> to manage projects efficiently.</p><p>In January 2023, I was promoted to the role of Engineering Manager, overseeing a dedicated team. As I took on this new leadership position, I felt the pressing need to deepen my knowledge of Scrum, not just as a project management methodology but also as a valuable tool for personal and professional growth.</p><p>In this article, I will share my journey of using Scrum as a methodology to obtain the Scrum <strong>PSM I</strong> certification from <a href="https://www.scrum.org/assessments/professional-scrum-master-i-certification">scrum.org</a>.</p><h3>What is Scrum?</h3><p>Scrum is an agile project management framework that emphasizes collaboration, adaptability, and iterative progress. It has become a standard in the software development industry and is widely recognized for its effectiveness in managing complex projects. Scrum principles include transparency, inspection, and adaptation, making it a versatile tool for problem-solving and continuous improvement.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FGH8TXXnWgM5Q73Vzjf%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FGH8TXXnWgM5Q73Vzjf%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FGH8TXXnWgM5Q73Vzjf%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/538dc3e337d3d6b4fcc37fdf4142211f/href">https://medium.com/media/538dc3e337d3d6b4fcc37fdf4142211f/href</a></iframe><h3>Why Scrum for Certification Preparation?</h3><p>Scrum is deeply rooted in the principles of empiricism, emphasizing transparency, inspection, and adaptation as its core tenets. This empirical approach to problem-solving has proven to be exceptionally effective in project management, and it seamlessly translates to the realm of learning and certification preparation.</p><p>The empiricism at the heart of Scrum means that it acknowledges that knowledge and understanding are not static, but rather dynamic and subject to change. This acknowledgment aligns perfectly with the journey of studying a subject in certification preparation, where one’s understanding may evolve and grow over time.</p><p>Let’s break down how Scrum’s empiricism supports effective learning:</p><ol><li><strong>Transparency</strong>: In Scrum, transparency involves making all aspects of the work visible. Similarly, when preparing for a certification, being transparent with yourself about your current level of understanding, what you need to learn, and your progress is essential. Keep clear records of your study plans, materials, and achievements.</li><li><strong>Inspection</strong>: Scrum encourages regular inspection and adaptation. As you study, it’s crucial to regularly assess your comprehension of the material. Are you grasping the core concepts? Are there areas where you’re struggling? This inspection process allows you to identify knowledge gaps and areas for improvement.</li><li><strong>Adaptation</strong>: Scrum is all about adapting to changing circumstances. Likewise, when studying for a certification, adapting your study methods and priorities based on your inspection results is key. If you find that you need more time on a particular topic, adjust your study plan accordingly. This flexibility ensures that you are continually improving your understanding.</li><li><strong>Incremental</strong> Progress: Scrum promotes incremental progress towards a goal. By breaking down the certification material into smaller, manageable sprints, you create a structure that allows you to steadily build your knowledge, mastering one concept before moving to the next. This incremental learning mirrors Scrum’s iterative development process.</li><li><strong>Continuous Improvement</strong>: Scrum values continuous improvement, and this concept is directly applicable to your certification preparation. Regularly reviewing your progress, making adjustments, and striving to enhance your understanding can lead to more effective learning.</li></ol><p>In essence, Scrum’s empiricism makes it an ideal framework for certification preparation. It embraces the dynamic nature of knowledge acquisition and encourages adaptability and transparency, all of which can significantly enhance your learning journey. Just as Scrum has revolutionized project management, it can also transform the way you approach your professional development and certification attainment.</p><h3>Utilizing Notion as a Scrum Board for Certification Preparation</h3><p>To embark on my journey to Scrum PSM I certification, I needed a tool to facilitate this, and that’s where Notion, a versatile note-taking and organization platform, played a crucial role.</p><p>I established a <a href="https://smiling-meteorite-e5b.notion.site/baecf375424346d5a53e8fe7ab2d91b7?v=a954cca0746b412888404cec93b005c1&amp;pvs=4">Notion template</a> (feel free to duplicate it as a template) as my virtual Scrum board for this endeavor. Just as Scrum boards are the focal point for tracking progress in projects, my Notion database became the hub for my certification preparation. It allowed me to create a visual representation of my progress and tasks, making it easy to apply Scrum’s principles of transparency, inspection, and adaptation to my study plan.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FtTc43DeTm2kkJTrI2G%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FtTc43DeTm2kkJTrI2G%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FtTc43DeTm2kkJTrI2G%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="362" frameborder="0" scrolling="no"><a href="https://medium.com/media/895c1b0be094ce923e3808fe3cfb08bb/href">https://medium.com/media/895c1b0be094ce923e3808fe3cfb08bb/href</a></iframe><h4>Starting with the Scrum Guide</h4><p>In Scrum, there is no Sprint 0. So my journey began with a deep dive into the <a href="https://www.scrum.org/resources/scrum-guide">Scrum Guide</a>. It served as the foundational text for understanding Scrum principles, roles, events, and artifacts.</p><p>The Scrum Guide is to Scrum what a textbook is to a subject, and I treated it as such. By thoroughly studying the guide, I ensured a robust understanding of the framework’s core concepts.</p><h4>Tracking Progress with scrum.org’s Open Assessments</h4><p>As I delved into the Scrum Guide, I supplemented my learning with scrum.org’s <a href="https://www.scrum.org/open-assessments/">open assessments</a>, especially <a href="https://www.scrum.org/open-assessments/scrum-open">Scrum Open</a>, <a href="https://www.scrum.org/open-assessments/product-owner-open">Product Owner Open</a>, and<a href="https://www.scrum.org/open-assessments/scrum-developer-open"> Scrum Developer Open</a>. These assessments provide a valuable opportunity to evaluate one’s understanding and knowledge of Scrum principles. They are akin to practice exams and mirror the iterative approach that is fundamental to Scrum.</p><p>For each open assessment, I meticulously recorded my scores and the areas where I struggled. These notes became the basis for my Notion database. Using Scrum’s iterative approach, I organized my database with tasks related to the specific areas I needed to improve. Each task represented a learning item, and, similar to how a Scrum backlog evolves, my database grew organically as I identified new topics that required further exploration.</p><p>My Notion Scrum board evolved as I progressed. It wasn’t a static plan but a living document. With each review, I adapted my study plan, focusing on areas where I had gaps in my knowledge. The transparency of this approach kept me motivated and allowed me to visualize my improvement over time.</p><h4>Successful Certification Achievement</h4><p>Once I was confident in my knowledge and skills, I decided it was time to put my learning to the test. I registered for the Scrum PSM I certification exam from scrum.org, and thanks to the disciplined, Scrum-inspired approach I had taken, I was well-prepared. When I received my results and learned that I had passed the exam successfully, it was not just a certification achieved; it was a testament to the power of Scrum applied to learning.</p><h4>Conclusion</h4><p>In conclusion, the journey to obtaining the Scrum PSM I certification has been a rewarding and enlightening experience. By applying Scrum’s principles to my study approach and leveraging tools like Notion, I’ve not only achieved my certification but also developed a deep understanding of the Scrum framework.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fa0h7sAqON67nO%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fa0h7sAqON67nO%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2Fa0h7sAqON67nO%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab38f4d6331ea3d9fbc2f1d6919794f0/href">https://medium.com/media/ab38f4d6331ea3d9fbc2f1d6919794f0/href</a></iframe><p>It is my hope that this article can serve as a source of inspiration and guidance for others on their certification journey. May it help more individuals successfully conquer the PSM I exam and further embrace the power of Scrum in their professional endeavors.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f51b67f1a07e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Entity or Value Object: that is the question]]></title>
            <link>https://dariodip.medium.com/entity-or-value-object-that-is-the-question-fa1dc5d58406?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa1dc5d58406</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-design]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Tue, 03 Oct 2023 17:37:14 GMT</pubDate>
            <atom:updated>2023-10-03T17:37:14.092Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gnpLeGKKFpdUZmIW" /><figcaption>Photo by <a href="https://unsplash.com/@io_exception?utm_source=medium&amp;utm_medium=referral">Antonio Feregrino</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In Domain-Driven Design (DDD), one of the key decisions you’ll encounter is whether a particular concept should be modeled as an <a href="https://www.domainlanguage.com/wp-content/uploads/2016/05/DDD_Reference_2015-03.pdf"><strong>Entity</strong> or a <strong>Value Object</strong></a>. This decision can significantly impact the design and behavior of your software.</p><p>In this blog post, we’ll explore the distinction between Entities and Value Objects and provide a method to help you determine which is the right choice for a given domain concept.</p><h3>Understanding Entities and Value Objects</h3><p>Before diving into the decision-making process, let’s clarify what Entities and Value Objects are in the context of DDD.</p><h4>Entities</h4><p>Entities represent objects with a distinct identity that runs throughout their entire lifecycle. They are characterized by their unique identifiers, such as an ID or a combination of attributes that make them distinguishable.</p><p><strong>An Entity’s equality is based on its identity, not its attributes.</strong> In other words, two entities with the same attributes are still considered different if they have different identities.</p><blockquote>When an object is distinguished by its identity, rather than its attributes, make this primary to its definition in the model. Keep the class definition simple and focused on life cycle continuity and identity.</blockquote><p>Entities often correspond to real-world objects that you want to track and reference independently. For example, a “Customer” in an e-commerce system is typically an Entity because each customer has a unique ID, and you need to distinguish them even if their attributes (name, email, etc.) are the same.</p><h4>Value Objects</h4><p>Value Objects, on the other hand, are objects without distinct identities. They are defined solely by their attributes, and their equality is based on the equality of those attributes. Value Objects represent concepts that are immutable, and any change results in a new Value Object instance.</p><blockquote>When you care only about the attributes and logic of an element of the model, classify it as a value object. Make it express the meaning of the attributes it conveys and give it related functionality.</blockquote><p>Value Objects are often used to represent things like dates, money, addresses, or measurements. For instance, a “DateOfBirth” object is a Value Object because it’s defined by its date value, and two DateOfBirth objects with the same date are considered equal, regardless of where or how they are used.</p><h3>The Decision-Making Method</h3><p>Now that we have a clear understanding of Entities and Value Objects, let’s explore a method for making the right choice when modeling concepts in your domain.</p><h4>Step 1: Identify the Concept</h4><p>Start by identifying the concept you want to model. Ask yourself whether it has a distinct identity or if it’s solely defined by its attributes.</p><h4>Step 2: Determine Identity</h4><p>If the concept has a distinct identity that remains consistent throughout its lifecycle, it’s likely an Entity. Consider whether you need to track, reference, or relate this concept individually. If so, an Entity is the right choice.</p><h4>Step 3: Consider Mutability</h4><p>Think about whether the concept is immutable or can change over time. If it’s immutable and its equality is based solely on its attributes, it’s a strong indicator that it should be a Value Object.</p><h4>Step 4: Analyze Use Cases</h4><p>Consider how the concept will be used in your domain. If you often need to perform operations or comparisons based on its identity, it’s likely an Entity. If it’s frequently used as a set of attributes and equality comparisons are attribute-based, it’s a Value Object.</p><h4>Step 5: Consult Domain Experts</h4><p>Always involve domain experts and stakeholders in the decision-making process. Their insights can help clarify the nature of the concept and guide your modeling choices.</p><h4>Step 6: Refine as Needed</h4><p>It’s essential to iterate and refine your modeling decisions as your understanding of the domain evolves. Don’t be afraid to adjust your model based on real-world usage and feedback.</p><h3>Conclusion</h3><p>The distinction between Entities and Value Objects in DDD is crucial for building a domain model that accurately represents your problem space.</p><p>By following the decision-making method outlined above, you can make informed choices when modeling concepts and ensure that your software aligns with the domain’s inherent structure. Remember that the ultimate goal is to create a domain model that is both expressive and robust, enabling you to build more maintainable and effective software.</p><p>If you need more details about this topic, useful resources can be found <a href="https://github.com/ddd-crew/free-ddd-learning-resources">here</a>.</p><p>I hope that this article was useful for you! 👋</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa1dc5d58406" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Domain-Driven Design pt. 2: Understanding Complex Domains]]></title>
            <link>https://dariodip.medium.com/introduction-to-domain-driven-design-pt-2-understanding-complex-domains-119de97befcb?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/119de97befcb</guid>
            <category><![CDATA[ddd]]></category>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 20:36:40 GMT</pubDate>
            <atom:updated>2023-03-02T20:36:40.392Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ODal3-E_-2qSb98e" /><figcaption>Photo by <a href="https://unsplash.com/@michalmatlon?utm_source=medium&amp;utm_medium=referral">Michal Matlon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Domain-Driven Design (DDD) is a software development approach that focuses on understanding and modeling the problem domain. In his book “Domain-Driven Design: Tackling Complexity in the Heart of Software,” Eric Evans argues that a good model of the domain is essential for building high-quality software that meets the needs of users and stakeholders.</p><p>In <a href="https://medium.com/@dariodip/introduction-to-domain-driven-design-ddd-24a62cb6472d">the first part of this series</a>, we discussed the fundamentals and key concepts of DDD. In this article, we will go a little deeper into what a model is and how to think about it, using the blue book as the main source of knowledge.</p><h3>The model</h3><p>The first chapter of the book provides an overview of DDD and explains why it is important to focus on the domain when developing software. According to Evans, many software projects fail because developers do not have a clear understanding of the problem they are trying to solve. He argues that to build successful software, developers must have a deep understanding of the domain and be able to communicate effectively with domain experts.</p><p>One of the key concepts in DDD is the model, which is a representation of the problem domain. The model is not just a set of classes and objects, but a shared understanding of the domain that can be used to guide software design and implementation. Evans stresses the importance of creating a model that accurately reflects the domain and is understood by all stakeholders.</p><p>In DDD, three basic uses determine the choice of a model:</p><ol><li><em>The model and the heart of the design shape each other: </em>the link between the model and the implementation helps during maintenance and continuous development because the code can be interpreted via model understanding<em>;</em></li><li><em>The model is the backbone of a language used by all team members: </em>with that assumption, developers can communicate with domain experts and with other developers in a language that is close to the domain<em>;</em></li><li><em>The model is distilled knowledge:</em> a model allows developers and domain experts to collaborate effectively as they wrestle information in this form<em>.</em></li></ol><blockquote>A domain model is not a particular diagram; it is the idea the the diagram is intended to convey.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*ds7I8iv-CyhcKCeTIme_Xg.jpeg" /><figcaption>The famous pipe. How people reproached me for it! And yet, could you stuff my pipe? No, it’s just a representation, is it not? So if I had written on my picture “This is a pipe”, I’d have been lying!</figcaption></figure><p>The scope of knowledge encapsulated in a model surpasses the mere identification of entities through the “find the nouns” approach. The activities and rules that govern a business are just as essential to the domain as the entities themselves, and a domain will typically contain multiple categories of concepts. Developers simultaneously refactor the implementation of an application to align it with model changes, allowing the application to incorporate and leverage the knowledge encapsulated in the model.</p><h4>Ingredients of Effective Modeling</h4><p>Here are the ingredients that lead to success while modeling:</p><ol><li><em>Binding the model and the implementation;</em></li><li><em>Cultivating a language based on the model;</em></li><li><em>Developing a knowledge-rich model;</em></li><li><em>Distilling the model;</em></li><li><em>Brainstorming and experimenting.</em></li></ol><h3>Ubiquitous Language</h3><p>Another important concept in DDD is the ubiquitous language, which is a language that is shared by all stakeholders in the domain. The ubiquitous language includes domain-specific terminology and concepts that are used to describe the problem domain. By using a ubiquitous language, developers and domain experts can communicate effectively and avoid misunderstandings.</p><p>The Ubiquitous Language will be detailed in the next posts of this series.</p><h3>A model for a barbershop scheduling application</h3><p>Let’s see an example of modeling for a barbershop scheduling application. We can imagine that our stakeholders are managers of barbershops, and we can do a bit of practice in modeling by defining the model of an application used by clients of the barbershops to schedule appointments.</p><p>A scheduling application for barbershops might have the following domain model:</p><ul><li><strong>Barber</strong>: An individual who cuts hair for clients.</li><li><strong>Client</strong>: An individual who receives haircuts from barbers.</li><li><strong>Appointment</strong>: A scheduled time slot during which a client receives a haircut from a barber.</li><li><strong>Service</strong>: A specific type of haircut that a barber can provide, which has a duration and a price.</li><li><strong>Availability</strong>: A specific period of time during which a barber is available to provide haircuts.</li></ul><p>However, after analyzing this model, it easily comes out that something is missing: the <strong>service </strong>should be an archetype and a single barber should be able to either provide it or not. So we will introduce a new concept:</p><ul><li><strong>Service instance</strong>: A specific service provided by a single barber.</li></ul><p>The model that comes out (over-simplified) is the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xIY3ijNvPeyVV1oZwZ7Vzw.png" /></figure><p>In addition to these core concepts, the domain model might include the following domain services:</p><ul><li><strong>Booking</strong>: A service that allows clients to schedule appointments with barbers.</li><li><strong>Availability Checker</strong>: A service that allows clients to check the availability of barbers for specific time slots.</li><li><strong>Payment</strong>: A service that allows clients to pay for appointments and services.</li></ul><p>The ubiquitous language for this domain might include terms such as “<em>haircut</em>,” “<em>appointment</em>,” “<em>barber</em>,” and “<em>client</em>.” The model might be organized into bounded contexts based on different areas of functionality, such as booking appointments, managing barbers and services, and processing payments.</p><p>Overall, the domain model provides a shared understanding of the key concepts and relationships in the scheduling application for barbershops and guides the development of the application’s design and implementation.</p><p>It is important to notice that the process of modeling is an iterative process and can take a lot of time brainstorming and experimenting to find the right model that best fits our domain.</p><h3>Conclusions</h3><p>In summary, a model is a representation of the problem domain that captures the essential aspects of the domain and can be used to guide software design and implementation. The model includes entities, value objects, domain services, and bounded contexts, and is described using a ubiquitous language that is understood by all stakeholders. These topics will be discussed in the other articles of this series that will come (hopefully) soon.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=119de97befcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Domain-Driven Design (DDD)]]></title>
            <link>https://dariodip.medium.com/introduction-to-domain-driven-design-ddd-24a62cb6472d?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/24a62cb6472d</guid>
            <category><![CDATA[domain-driven-design]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[software-design]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Thu, 19 Jan 2023 19:15:46 GMT</pubDate>
            <atom:updated>2023-01-19T19:15:46.660Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*RIPYLxocOZg3esan" /><figcaption>Photo by <a href="https://unsplash.com/@firmbee?utm_source=medium&amp;utm_medium=referral">Firmbee.com</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Designing software nowadays can be such a tough job, we know. Software complexity has raised and it is still raising reaching summits above the havoc. All this wave of fear and destruction and fire and chaos can be stopped with a proper software design strategy.</p><p>Designing and developing software is something that must have to do with <em>solving problems </em>that customers have. However, sometimes the domain of the problem we are trying to solve is very complex and this can lead to difficulty in communication between developers and stakeholders.</p><p>I believe that Domain-Driven design can be part of the solution.</p><p>In this post, I will introduce the basics of Domain-Driven design. It will look like a roundup of definitions, but don’t worry: other posts of this series will follow with detailed explanations about other concepts from Domain-driven design.</p><h3>Key concepts of DDD</h3><p>Domain-driven design (DDD) is an approach to software development that focuses on understanding and modeling the complex business domain in which a system operates. It was introduced by Eric Evans in his book “<a href="https://www.amazon.it/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215">Domain-Driven Design: Tackling Complexity in the Heart of Software</a>”, and has since become a popular methodology for designing and building software systems that are scalable, maintainable, and aligned with business goals. The key point of DDD is that the code structures (i.e. objects, classes) should match the business domain.</p><p>The starting point for understanding DDD is the <strong>model</strong>. In Domain-Driven Design (DDD), a <strong>model</strong> refers to a conceptual representation of a specific area of the business domain, such as a customer, an order, or a product. It is a way of understanding and describing the problem space, and it is used to guide the development of software that supports the business processes and rules that operate within that domain. A model is typically composed of entities, value objects, services, and domain events. The goal of a model is to encapsulate the complex business rules and logic that govern the behavior of the system, making it easier to understand and reason about.</p><p>One of the core principles of DDD is the idea of a “<strong>ubiquitous language</strong>”, which is a shared language used by domain experts and software developers to communicate about the domain and its requirements across the model. This helps to ensure that the software system accurately reflects the needs and processes of the business domain, and allows for more effective collaboration between developers and domain experts.</p><blockquote>With a ubiquitous language, the model is not just a design artifact. It becomes integral to everything the developers and domain experts do together.</blockquote><p>It constitutes a <strong>Shared Language </strong>that is understood by both developers and domain experts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ObQH8YdRz4bETQUnWBNqmg.png" /></figure><p>Another key concept in DDD is the idea of a “<strong>bounded context</strong>”, which refers to a specific area of the business domain that has well-defined boundaries and a distinct set of terms and meanings. By dividing the domain into bounded contexts, it becomes possible to design software systems that are more focused and modular, which can lead to improved maintainability and scalability. A <strong>Bounded Context</strong> is a central pattern for managing complexity in large software systems. It refers to the boundary or scope within which a certain domain model applies. By isolating the model within this boundary, it helps to reduce complexity and improve clarity by ensuring that the model is not unnecessarily impacted or influenced by other areas of the system. This allows teams to work independently on different parts of the system while still being able to integrate them together seamlessly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nAPxA9RBFGNemW6xch4bIg.png" /></figure><h3>Benefits of DDD</h3><p>One of the main benefits of using DDD is that it helps to ensure that the software system being built is aligned with the business goals and needs of the organization. This is achieved by creating a deep understanding of the domain through collaboration with domain experts, and by using that understanding to inform the design and implementation of the software system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VR2AY1AuBUswOPSwkRjeSg.png" /></figure><p>DDD also emphasizes the importance of iterative and incremental development, with a focus on delivering value early and continuously. This allows for a more flexible and responsive approach to software development and helps to ensure that the software system stays aligned with the changing needs of the business.</p><p>Overall, DDD is a powerful approach to software development that can help organizations to build scalable and maintainable systems that are well-aligned with business goals. By focusing on understanding and modeling the complex domain in which the system operates, DDD can help organizations to build software systems that are more effective, efficient, and responsive to the needs of the business.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24a62cb6472d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[For comprehension in Elixir]]></title>
            <link>https://dariodip.medium.com/for-comprehension-in-elixir-e376e94bd29c?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/e376e94bd29c</guid>
            <category><![CDATA[elixir]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Wed, 21 Dec 2022 19:11:24 GMT</pubDate>
            <atom:updated>2022-12-21T19:11:24.443Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_Vv88Am_hBgPg2P9" /><figcaption>Photo by <a href="https://unsplash.com/@wolfgang_hasselmann?utm_source=medium&amp;utm_medium=referral">Wolfgang Hasselmann</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The <strong>for comprehension</strong> is a powerful language construct in Elixir that allows developers to express complex iterations and conditional logic in a declarative way. It is quite similar to the for loop of other programming languages, but with more functionality and more concise syntax. It is used to filter and transform collections of data and can be used as an alternative to recursive functions or nested Enum functions. Personally, I find it very interesting and readable given its declarative nature.</p><p>At a high level, a <strong>for comprehension</strong> consists of a sequence of <em>generators</em>, <em>filters</em>, and <em>collectors</em>. Each generator represents a sequence of values, and the comprehension iterates over these sequences in a nested way. Filters allow you to specify conditions that must be met for a value to be included in the final result. If the condition of the filter evaluates to true, the value is passed to the collector. Lastly, collectors specify how the values should be combined and transformed.</p><p>Here is the basic pipeline that shows that a value gets generated from the <em>generator, </em>filtered by the <em>filter</em> and, eventually, collected by the <em>collector.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dXTIKmH3T-AtzhrylcEWeg.jpeg" /></figure><p>Here is a basic example of a <strong>for comprehension</strong> that filters a list of numbers to only include even numbers:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*PsSl4vFGQOMzdPs93UP9sg.jpeg" /><figcaption>For Comprehension</figcaption></figure><p>In this example, the <em>generator</em> is n &lt;- numbers, which specifies that the for comprehension will iterate over the numbers list. The <em>filter</em> is n rem 2 == 0, which specifies that the comprehension will only include elements n for which the remainder when n is divided by 2 is equal to 0. The do: keyword specifies the transformation that should be applied to each element that satisfies the filter. In this case, the transformation is the <a href="https://en.wikipedia.org/wiki/Identity_function">identity function</a>, so the element is returned unchanged.</p><p>It’s also possible to specify multiple generators in a single <strong>for comprehension</strong>. In this case, the comprehension will iterate over the <a href="https://en.wikipedia.org/wiki/Cartesian_product">Cartesian product</a> of the generators. In the following example we use two generators:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*9wigQO-Ys_Tlq8EnW6XNMA.jpeg" /><figcaption>For Comprehension — 2</figcaption></figure><p><em>Filters</em> can also be specified for each generator. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*pUW4ve0NjPhOQZqdewxb7Q.jpeg" /><figcaption>For Comprehension — 3</figcaption></figure><p>In addition to filtering and transforming elements, for comprehensions can also be used to perform <em>side effects</em>. For example, the following code snippet will print each element of the numbers list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*EEStUlMFd7ExtmG_uOdTnA.jpeg" /><figcaption>For Comprehension — 4</figcaption></figure><p>It’s also possible to bind the result of a for comprehension to a variable using the into keyword. For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*BqBBpEq4uPdbBSiCp14lyg.jpeg" /><figcaption>For Comprehension — 5</figcaption></figure><p>Passing uniq: true can guarantee that the results are only added to the collection if they were not returned before. Here is an example of the uniq keyword:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/599/1*d6BS44T7gIeVeF5ixWsLgQ.jpeg" /><figcaption>For Comprehension — 6</figcaption></figure><p>The :reduce option, instead, allows us to implement a <a href="https://en.wikipedia.org/wiki/MapReduce#Reduce_function"><strong>reduce step</strong></a>. It takes an accumulator and the do block that uses -&gt; clauses:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*VDkmtEPAe3J7-KxDY_8oHw.jpeg" /><figcaption>For Comprehension — 7</figcaption></figure><p>When the :reduce keyword is given , its value is used as the initial accumulator and the do block must be changed to use -&gt; clauses, where the left side of -&gt; receives the accumulated value of the previous iteration and the expression on the right side must return the new accumulator value. Once there are no more elements, the final accumulated value is returned. If there are no elements at all, the initial accumulator value is returned.</p><p>In conclusion, for comprehensions are a convenient and expressive way to iterate over and transform collections of data in Elixir. They can be used as an alternative to recursive functions or nested Enum functions, and offer a clear and concise syntax for specifying complex iterations and conditional logic.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e376e94bd29c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rust: fear => love => hate => love => disillusion]]></title>
            <link>https://dariodip.medium.com/rust-fear-love-hate-love-disillusion-fa9f6f05b54e?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa9f6f05b54e</guid>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Mon, 31 Jan 2022 18:02:32 GMT</pubDate>
            <atom:updated>2022-01-31T18:02:32.143Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rRxmAI9amLkqfMHz" /><figcaption>Photo by <a href="https://unsplash.com/@brandomol?utm_source=medium&amp;utm_medium=referral">Brandon Molitwenik</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>My journey through <a href="https://www.rust-lang.org/">Rust</a> was very tortuous and tormented. During this article, I want to retrace my steps towards the discovery of that amazing programming language.</p><h4>First encounter: fear</h4><p>When I was at the university, a colleague of mine and I have been started working on a <a href="https://github.com/dariodip/prefix-search">project for the course of Data Compression</a>. That was something very low-level and bitwise. We already knew a bit of <strong>C</strong>, <strong>Java</strong>, <strong>Python</strong>, and <strong>JavaScript</strong>. Every of those, except C, were not suitable at all to work with bits, and since we don’t want to work with C anymore, we decided to pick a brand new programming language (the worst idea <strong>ever</strong> when you have to finish your project as soon as possible).</p><p>We then started looking for a programming language with the following characteristic:</p><ul><li>Fast</li><li>Compiled</li><li>Easy to learn</li></ul><p>We already heard about both Go and Rust and we were excited to learn Rust because the <a href="https://insights.stackoverflow.com/survey/2018">Stackoverflow Survey</a> said that Rust was the most loved programming language for developers and, of course, we were developers and we wanted to love it too.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*apAgtGjMEGNzYYuR" /><figcaption>My friend and I trying to love Rust</figcaption></figure><p>The first impression was: <strong>FEAR!</strong></p><p>WTF were those :: , i32 , println!(&quot;{}&quot;, something)? WTF is this “Ownership”?</p><p>After this first impression, we quickly decided to go for something more similar to the stuff that we already knew and there comes <a href="https://go.dev/">Go</a>. It was love at first sight as you may deduce reading <a href="https://dariodip.medium.com/">my other stories on Medium</a>. We developed the whole project in Go and everything went well.</p><p>Happy ending.</p><h4>Second (almost) encounter: love</h4><p>University was over and I started working for a software company in Rome. My first task was to fix a bug on a system written in Go. No problem!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FVgT9bySXhoucgkgNOf%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FVgT9bySXhoucgkgNOf%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FVgT9bySXhoucgkgNOf%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/67f93474b2bb27e74e5413a253c44b8f/href">https://medium.com/media/67f93474b2bb27e74e5413a253c44b8f/href</a></iframe><p>When I had to pick a language for a brand new system for manipulating images I was determined to pick Rust. I started reading the <a href="https://doc.rust-lang.org/book/">Rust book</a> and I found different aspects of the language that would have been killer features for my application:</p><ul><li><strong>memory safety</strong>: if there is a memory problem, your code does not compile <a href="https://arxiv.org/pdf/2003.03296.pdf">(almost) always</a>;</li><li><strong>performance</strong>: Rust is very <a href="https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust.html">fast</a>!</li><li><strong>fearless concurrency</strong>: manipulating images is something like manipulating matrices. Parallelism is the key to scaling up with no fear. Rust has great support for concurrency;</li><li><strong>that taste of functiona</strong>l: I love functional programming and I wanted to love Rust too.</li></ul><p>That was the first time that I fell in love with Rust ⚙️.</p><p>However, given that the company already had software written in Go, I eventually had to pick Go. I started feeling frustrated sometimes because of the lack of control over some features (thread locality etc), but, in the end, everything has gone ok.</p><p>Happy ending 2.</p><h4>Third encounter: hate</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F17839161&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fhate-hatred-emperor-palpatine-emperor-palpatine-gif-17839161&amp;image=https%3A%2F%2Fc.tenor.com%2F3NN4e_vQ0SwAAAAd%2Fhate-hatred.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/235ea1dfd62f35bac5f02299cf73463a/href">https://medium.com/media/235ea1dfd62f35bac5f02299cf73463a/href</a></iframe><p>After changing different jobs, I started working for another company and they use mainly Elixir <strong>💧</strong>, Elm 🌳, and, of course, Rust ⚙️.</p><p>I was very happy to join that company and still, I am! Very excited to work on Rust, finally. I can love Rust as <a href="https://insights.stackoverflow.com/survey/2021#technology-most-loved-dreaded-and-wanted">86.98%</a> of the developers in 2021 does.</p><p>I started doing something using Elixir (one of my favorite programming languages) and I finally had to work on a CRUD microservice using Rust and it was… frustrating.</p><p>I hated Rust. It sucks!</p><p>I want to be focused on the domain of my application, reducing time-to-market, releasing it as soon as possible and I want to write as many tests I can but it is not quite straightforward in Rust.</p><p>I spent so much time finding out why I cannot return that variable, writing stupid impls that could be implicit and hating Rust.</p><p>I had to duplicate pieces of code because the returned value of that function that could have been reused is something opaque and internal to some library which is changed almost every week.</p><p>Sad ending for now.</p><h4>Forth encounter: love</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F5832506&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fin-love-gif-5832506&amp;image=https%3A%2F%2Fc.tenor.com%2FkojCruAztd8AAAAC%2Fin-love.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ab7ef590161eec5b7c86e4d5d5af7f6/href">https://medium.com/media/4ab7ef590161eec5b7c86e4d5d5af7f6/href</a></iframe><p>I come to an end that, at the moment, Rust is not the best choice for a CRUD microservice. It is too young. Its libraries are still limited and it lacks a consolidated framework for the web (that I like).</p><p>But I cannot rest and my struggle was to understand why so many developers love it. So I decided to solve <a href="https://adventofcode.com/">Advent of Code</a> 2021 puzzles using <a href="https://github.com/dariodip/advent-of-code-2021">Rust</a>.</p><p>Ok. Now I understand why they love it. I love it too.</p><p>It is fun and pleasant to write Rust code. It is fun to solve algorithms using it and I like to run benchmarks to see it performing very fast.</p><p>My doubts about the hype of love for Rust are finally resolved.</p><h4>What I like about Rust</h4><p>There are some features that I really like aboutRust from the developer&#39;s point of view (that’s why I jump over performance, single binary, and so on). Here are some:</p><ul><li>The ecosystem: the standard library is very complete. It has great support for different types and data structures that help the developer write clear code;</li><li><a href="https://doc.rust-lang.org/std/result/">Result&lt;T,E&gt;</a> and <a href="https://doc.rust-lang.org/std/option/index.html">Option&lt;T&gt;</a> : yeah! They rock! Result&lt;T,E&gt; is very useful to handle errors and Option&lt;T&gt; to handle <em>null values</em>. They are inspired by <a href="https://en.wikibooks.org/wiki/Haskell/Classes_and_types">Haskell’s type classes</a> and it should be enough to appreciate it. Using type classes makes your code clear and safe. This was a clever move. Kudos Rust!</li><li>Ownership: at the first glance it may look scary but I can assure you that after spending different hours looking (and yelling) at the output of the compiler, trying to understand what is wrong in your code, you’ll appreciate it;</li><li>Compiler errors: errors printed by the compiler are very clear and concise. It will bring you to the solution, explaining why you did something wrong;</li><li>The debugger: <a href="https://lldb.llvm.org/">LLDB</a> rocks and it is well integrated with <a href="https://code.visualstudio.com/">VSC</a>;</li><li>Macros: Rust’s macros are very powerful. They are the icing on the cake of Rust.</li></ul><h4>What I dislike about Rust</h4><p>Here are some features that I don’t like about Rust from the developer’s point of view:</p><ul><li>Steep learning curve: come on guys! It is clear that learning Rust is not easy at all. You fail so many times before being confident in writing Rust code;</li><li>Primitive types: I don’t like the fact that primitive numbers have explicit size annotation. I’m sure there are many reasons behind this decision but I don’t like that;</li><li>Unsafe: unsafe is treated as a magic power of the language. If you use it, you feel a lot of responsibilities;</li><li>mod.rs : I don’t like the need for explicit export modules through mod.rs . When you change something (i.e. the name of the module), you have to change it in different points;</li><li>Lack of reflection: I know that reflection<a href="https://stackoverflow.com/questions/36416773/how-does-rust-implement-reflection"> implies the knowledge of type details at runtime</a>, but it feels like a missing feature and sometimes you end up <a href="https://github.com/dariodip/advent-of-code-2021/blob/master/src/lib.rs#L36">copy-pasting code in a huge </a><a href="https://github.com/dariodip/advent-of-code-2021/blob/master/src/lib.rs#L36">match</a>.</li></ul><h4>I would pick it for…</h4><p>However, at the time of writing, I am reading tons of books and articles about programming in Rust for microservices, system programming and videogames and I think that Rust will be best suitable for the following use-cases:</p><ul><li>CPU bound microservice: when you have to deal with something that requires a lot of computation, Rust may be the answer;</li><li>Command-line tools: Rust is <a href="https://www.zdnet.com/article/rust-takes-a-major-step-forward-as-linuxs-second-official-language/">taking steps in the Linux kernel</a> and its adoption for developing command-line tools is straightforward;</li><li>Ass-kicking solvers: it is both fast and safe and provides a good level of abstraction, so it would be a good choice for developing solvers.</li></ul><h4>Conclusions</h4><p>I don’t know what will be next, but I am enjoying programming in Rust and I hope you will too.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa9f6f05b54e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Find duplicates using Python]]></title>
            <link>https://dariodip.medium.com/find-duplicates-like-a-boss-f46422f54dd1?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f46422f54dd1</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Wed, 19 Jan 2022 17:01:13 GMT</pubDate>
            <atom:updated>2022-01-21T16:08:38.762Z</atom:updated>
            <content:encoded><![CDATA[<p>The exercise of <strong>finding duplicates</strong> in a list is a classical example of a didactic problem that you may find during your journey through learning algorithms. During this post, we will try solving this problem using different algorithms, showing the differences between each one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*En5P2P4hLRyXG7Ti" /><figcaption>Photo by <a href="https://unsplash.com/@miracleday?utm_source=medium&amp;utm_medium=referral">Elena Mozhvilo</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>This article has been mainly written for fun and as a writing exercise. Its main purpose is to show different solutions to a single problem, explaining the reasoning behind certain decisions.</blockquote><p>Finding duplicates in a list is a trivial problem for an experienced Software Engineer. Maybe it is one of the first algorithms you developed at the University and you should not push yourself so hard on this.</p><p>The statement for this problem is the following:</p><blockquote>Given an array of n elements that contains elements from 0 to n-1, with any of these numbers appearing any number of times. Find this repeating number and return it.</blockquote><p>For the lack of simplicity, we will consider only lists of integers. Some of the algorithms shown, however, can be used also for other types.</p><p>In this post, we will see different solutions for this problem. Every solution has some requirements and uses a given amount of space and time (and a degree of coolness). We will use Python to implement them.</p><p>To generate our random lists we can use the following functions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd074f8d982883a49c2245f98cd53653/href">https://medium.com/media/cd074f8d982883a49c2245f98cd53653/href</a></iframe><p>The first one generate_random_list(n,k)generates an unsorted list of n random integers from 0 to k .</p><p>Instead, the second one generate_random_list_pigeon(n) generates a list of n random elements from 1 to n-1 . It is named after the <a href="https://artofproblemsolving.com/wiki/index.php/Pigeonhole_Principle">Pigeonhole principle</a> so that we can ensure that only one element is duplicated. This function will come in handy at some point.</p><h3>Dummy solution</h3><p>The <strong>dummy solution </strong>has no special prerequisites and does not require a detailed explanation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b7a53696882bb3f1d4d7113f2b12c46/href">https://medium.com/media/2b7a53696882bb3f1d4d7113f2b12c46/href</a></iframe><p>It iterates over the elements in the list from the first element in the list and checks if there is a duplicate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*zEFthbVWbah5PSJXn_I08A.png" /><figcaption>i=0</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*8ct-2tYn11qh9iuj-30p8g.png" /><figcaption>i=1</figcaption></figure><p>When the outer for is at its first iteration, the inner one will iterate over the other elements, comparing the element pointed by <em>i </em>and the element pointed by <em>j</em>. When both the elements at index <em>i</em> and <em>j</em> are the same, it will return this element. Then the index <em>i</em> will be moved to the next element and so on so forth. Easy!</p><h4>Analysis</h4><p><strong>Constraints:</strong> The algorithm works for every list of elements that are comparable in which there is at least a duplicate. The input list will not be modified.</p><p><strong>Space complexity: </strong>O(1). We only allocated two variables <em>i</em> and <em>j.</em></p><p><strong>Time complexity:</strong> in the worst case, the algorithm compares every pair of elements that can be obtained only once. So, <em>i </em>can assume values from <em>0</em> to <em>n-2, </em>and for each value of <em>i, j</em> can assume <em>n-2-i </em>values. Indeed, the first time j iterates from 1 to n-1 (n-2 times), the second time from 2 to n-2 (n-3 times), etc. So, the time complexity is approximately <a href="https://cseweb.ucsd.edu/groups/tatami/handdemos/sum/#:~:text=Sum%20of%20the%20First%20n,inductive%20proof%20of%20this%20result."><em>O(n²)</em></a>.</p><h3>Sort and find</h3><p>The <strong>sort and find </strong>algorithm is based on a simple principle. If we sort our list, duplicated elements will be adjacent, so we don’t need to look for every pair, we just need to inspect every adjacent pair of elements.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49d1690ec6fff7b23337baa4d82e9402/href">https://medium.com/media/49d1690ec6fff7b23337baa4d82e9402/href</a></iframe><p>The first iteration is in-place sorting. This can be achieved using the method <a href="https://docs.python.org/3/howto/sorting.html">sort</a> of Python. After the sorting, elements can be compared two-by-two, checking for adjacent ones. This is straightforward because once the list is sorted, equal elements are adjacent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*_yqSzRNYUVdtaL0kUYt8cg.png" /><figcaption>An initial list</figcaption></figure><p>The following animation shows the algorithm on our example list:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*GEC56FEkCsnWlwhS4hZ9gw.gif" /></figure><h4>Analysis</h4><p><strong>Constraints: </strong>the input list <em>must</em> be modifiable for the algorithm to be correct. The method sort() of Python does in-place sorting. We could have used the sorted method to return a brand new sorted list, but this would have required O(n) additional space to a new list;</p><p><strong>Space complexity: </strong><em>O(1)</em> if sorting is in-place, <em>O(n)</em> if we use a new sorted list;</p><p><strong>Time complexity: </strong><em>O(n log n) </em>because we require at least <a href="https://www.bowdoin.edu/~ltoma/teaching/cs231/fall07/Lectures/sortLB.pdf"><em>O(n log n) </em>to sort our list</a> and <em>O(n)</em> to traverse it since every element is checked at most twice.</p><h3>Using a HashMap</h3><p>Another cool solution for finding a duplicate in a list would require the use of a <a href="https://en.wikipedia.org/wiki/Hash_table">HashMap</a>.</p><p>A <strong>hash map</strong> is a data structure that can map keys to values. The average cost for inserting, searching, or deleting a key is constant.</p><p>Using this structure, we can mark elements that have been seen during our traversal and, if an element is already present in the <em>seen map, </em>it is a duplicated element.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9113936a7f76a4a05db2834bd600230/href">https://medium.com/media/f9113936a7f76a4a05db2834bd600230/href</a></iframe><p>Also in that case, the implementation is pretty straightforward: a <a href="https://docs.python.org/3/tutorial/datastructures.html#dictionaries">dictionary</a> is used as the map of the <em>seen values</em>. For each element of the list, we check out if it is already present in our map. If so, it is the duplicated we were looking for, otherwise, we insert it on the map.</p><h4>Analysis</h4><p><strong>Constraints: </strong>elements in the list have to be <a href="https://docs.python.org/3/reference/datamodel.html#object.__hash__">hashable</a> to be used as keys in the map;</p><p><strong>Space complexity: </strong><em>O(n)</em>. The extra space is for the hash map.</p><p><strong>Time complexity: </strong><em>O(n)</em> since we check every element once and for each element we do a lookup and an insert in the map (that costs <em>O(1)</em> in the average case).</p><h3>Using Math</h3><p>Math is almost always the key for solving algorithmic problems. Every software engineer should be skilled on math.</p><p>The following code shows a very simple implementation of the algorithm to solve our problem. However, this has many limitations, but is a good starting point and works well in some cases.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dfec01631a58ace6f709817107a9ff5f/href">https://medium.com/media/dfec01631a58ace6f709817107a9ff5f/href</a></iframe><p>We know that the sum of the first <em>n </em>natural number can be achieved using the <a href="https://cseweb.ucsd.edu/groups/tatami/handdemos/sum/#:~:text=Sum%20of%20the%20First%20n,inductive%20proof%20of%20this%20result.">following equation</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/128/1*wujj3Rza3bNDMWyXed9gtQ.gif" /><figcaption>Sum of the first n natural numbers</figcaption></figure><p>We can apply another step and find the sum of consecutive natural numbers from <em>k</em> to <em>n</em> that equals to:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/338/1*Y4h-y-lkN6YvAyFbsBXDng.gif" /><figcaption>Sum of the natural numbers from k to n</figcaption></figure><p>In our code we define a <a href="https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions">lambda function</a> to get this formula, then we apply it to the first interval composed of numbers less than our minimum (numbers before our interval), eventually, we do the same for natural numbers from 1 to our maximum.</p><p>By subtracting the sum outside our interval from our complete sum, we would obtain the expected sum of natural numbers from our minimum to our maximum.</p><p>After getting the real sum of the elements inside our list, we can subtract the above mentioned value to this one, obtaining the element that is present twice in our list.</p><p>It can be easily proven that this algorithm has many constraints and does perform correctly in a single condition. Let’s analyze this.</p><h4>Analysis</h4><p><strong>Constraints: </strong>the algorithm performs correctly when the list contains integers and only a single value is repeated a single time. It is strict enough, isn’t it?</p><p><strong>Space complexity: </strong><em>O(1)</em>. We only need to keep 3 values in memory.</p><p><strong>Time complexity: </strong><em>O(n). </em>The two sums for obtaining the expected sum in the interval would require constant time, the sum of all the elements in the list would require <em>O(n).</em></p><blockquote>I hope you enjoyed reading this article as much as I enjoyed writing it.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f46422f54dd1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Linux Containers: explore User Space, cgroups and Namespaces]]></title>
            <link>https://dariodip.medium.com/understanding-linux-containers-a-simple-recipe-7c24cc1137b4?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c24cc1137b4</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Sat, 10 Apr 2021 09:57:49 GMT</pubDate>
            <atom:updated>2021-04-10T10:01:56.994Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qh-wxHsdm83uXgXX" /><figcaption>Photo by <a href="https://unsplash.com/@guibolduc?utm_source=medium&amp;utm_medium=referral">Guillaume Bolduc</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>What is a container? Actually, it is not a real thing.</blockquote><p>In this post, I will try to explain what containers are and how they work, decomposing them and understanding their components, without going too deep in some concepts which require a way long explanation than the one I could give in a single post.</p><p>Currently, there are many technologies for containers (e.g. Docker, containerd, runC and so on), but this post is not going to talk about them and therefore, will be (almost) technology agnostic. This does not mean that you should take this information for implementing your own containers in production (this is totally insane, even if you are a nerd 😃).</p><h4>What is a container?</h4><p>A container is a form of OS virtualization that might be used to run an application. Inside a container, there should be all the necessary executables, binary code, libraries and configuration files to run the application.</p><p>Containers are often confused with VMs. However, compared to them, containers do not contain operating system images (aka Kernel Space), making them more lightweight and portable, having significantly less overhead. On the other hand, virtual machines run in a hypervisor environment so that each virtual machine must include its own guest OS inside it, along with its related binaries, libraries, and application files. This is expensive because requires a large amount of system resources and overhead, especially when multiple VMs are running on the same physical server.</p><p>Basically, using a container we are moving the <em>abstraction layer</em> upper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*b-FIq7y6sFvBGdCE-DXOrQ.png" /><figcaption>Virtual Machine vs Container</figcaption></figure><h4>Ingredients</h4><p>Containers are actually made of:</p><ol><li>User Space code;</li><li>Control groups;</li><li>Namespaces.</li></ol><p>Let’s dive into these pieces one by one, gathering them together to create our container.</p><h4>User Space vs Kernel Space</h4><p>In order to start with our exploration, it is important to note that, in Linux, the kernel is the only layer of abstraction between programs and the resources they need to access.</p><p>Each process makes system calls:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*nz0ivldTbmWZn4NYv7rrVw.png" /></figure><p>Since containers are processes, they also make system calls:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*U3fPz84zUqqGeX3Ys8sUgg.png" /></figure><p>As we agreed, a container is a process and now we could ask: what about files and programs that are inside a container image? That bunch of files and programs are the container’s <strong>User Space.</strong></p><p>The User Space is composed of all the code in an operating system that lives outside the kernel. The User Space can include programs that are written in C, Java, Python, Go and other programming languages. When we talk about containers, the User Space is what is delivered in a container image.</p><p>A good way to get and explore a container’s User Space is by pulling one, running it and, eventually, exporting it:</p><pre>$  docker run -it --name alpine_us alpine:latest true</pre><pre>$  docker ps -a<br>CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                     PORTS               NAMES<br>bf1d7fd847ca        alpine:latest       &quot;true&quot;              6 seconds ago       Exited (0) 6 seconds ago                       alpine_us</pre><pre>$  docker container export alpine_us | tar -xf -</pre><pre>$  ls<br>bin   dev   etc   home  lib   media mnt   opt   proc  root  run   sbin  srv   sys   tmp   usr   var</pre><p>Here is our <strong>User Space</strong>. This contains utilities such as <em>sh</em>, <em>gzip</em> and so on, and libraries:</p><pre>$  ls bin<br>arch          chmod         dnsdomainname fdflush       hostname      linux32       mkdir         mv            printenv      run-parts     stty          uname<br>ash           chown         dumpkmap      fgrep         ionice        linux64       mknod         netstat       ps            sed           su            usleep<br>base64        cp            echo          fsync         iostat        ln            mktemp        nice          pwd           setpriv       sync          watch<br>bbconfig      date          ed            getopt        ipcalc        login         more          pidof         reformime     setserial     tar           zcat<br>busybox       dd            egrep         grep          kbd_mode      ls            mount         ping          rev           sh            touch<br>cat           df            false         gunzip        kill          lzop          mountpoint    ping6         rm            sleep         true<br>chgrp         dmesg         fatattr       gzip          link          makemime      mpstat        pipe_progress rmdir         stat          umount<br><br>$  ls usr/lib<br>engines-1.1                libcrypto.so.1.1           libssl.so.1.1              libtls-standalone.so.1     libtls-standalone.so.1.0.0 modules-load.d</pre><p>All those programs work by manipulating data that come from registers in the CPU, external devices, memory or disk. In order to do that, they get access to data by making <a href="http://man7.org/linux/man-pages/man2/syscalls.2.html">system calls</a> to the kernel.</p><p>The <strong>kernel </strong>provides an abstraction for security, hardware and internal data structures. For example, the <a href="https://man7.org/linux/man-pages/man2/open.2.html"><em>open(2)</em></a><em> </em>system call is commonly used to get a file handler and abstract the manipulation of files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/182/1*KKCdCtbug20Pv9qSV4oxQQ.png" /><figcaption>Abstraction layers</figcaption></figure><p>Now that we have our User Space, let’s explore the next ingredient.</p><h4>Control Groups</h4><p><a href="https://lwn.net/Articles/236038/"><strong>cgroups</strong></a> (abbreviated from <strong>control groups</strong>) is a Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes. The control groups functionality was merged into the Linux kernel mainline in kernel version 2.6.24, which was released in January 2008.</p><p>Cgroups is a feature that enables:</p><ul><li><strong><em>Resource limiting</em></strong>:<em> </em>groups can be set to not exceed a given memory limit;</li><li><strong><em>Prioritization</em></strong>:<em> </em>some groups may have a larger share of CPU utilization<em>;</em></li><li><strong><em>Accounting</em></strong>: group’s resource consumption can be measured;</li><li><strong><em>Control</em></strong>: groups can be frozen and restarted.</li></ul><p>Groups are materialized in the pseudo-filesystem mounted in <em>/sys/fs/cgroup </em>and are created by <em>mkdir </em>in the abovementioned pseudo-filesystem. To move a process from a cgroup to another, it should be added in the <em>task</em> file under that cgroup (for example, echo $PID &gt; /sys/fs/cgroup/&lt;SUBSYSTEM&gt;/&lt;SUBGROUP&gt;/tasks).</p><p>In terms of cgroups, a “<strong>container</strong>” is a group of processes that share a set of parameters used by one or more <em>subsystems</em> (also called <em>controllers</em>); then all processes within the container inherit that same set. Other (not yet existing) subsystems could use containers to enforce limits on CPU time, I/O bandwidth usage, memory usage, filesystem visibility, and so on. Containers are hierarchical in form of trees.</p><p>The container mechanism is not limited to a single hierarchy; instead, the administrator can create as many hierarchies as desired. For example, you can create a different hierarchy for the control of network bandwidth usage and for the control of memory usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*CLfRbzk6R02tj-YF_mc73A.png" /><figcaption>An example of cgroup hierarchy</figcaption></figure><p>Different container hierarchies need not resemble each other in any way and a subsystem can only be attached to a single hierarchy. As soon as a machine boots, there is a tree of one node with the first process in the first node. This means that your whole machine is a container with no limits.</p><p>The administration of containers is performed through a special virtual filesystem. By default, all known subsystems are associated with a hierarchy, so a command like:</p><pre>mount -t cgroup none /cgroups</pre><p>would create a single container hierarchy with all known subsystems on <em>/cgroups</em>. A setup with different subsystems for CPU and network, instead, could be created with something like:</p><pre>mount -t cgroup none -o cpu /cgroup<br>mount -t cgroup none -o net /cgroup</pre><p>So, in order to create our group for example for <em>blkio</em>, for a process $PIDwe should proceed with the following steps:</p><pre>$ sleep 3000 &amp; PID=$!</pre><pre>$ mount -t cgroup none /cgroup -o blkio</pre><pre>$ mkdir /cgroup/mygroup</pre><pre>$ echo $PID &gt; /cgroup/mygroup/tasks</pre><p>And to check that our process is actually under our desired cgroup, we could check under /proc/$PID/cgroup :</p><pre># cat /proc/$PID/cgroup<br>9:freezer:/<br>8:pids:/user.slice/user-1001.slice/session-25.scope<br>7:net_cls,net_prio:/<br>6:cpuset:/<br>5:cpu,cpuacct:/user.slice<br><strong>4:blkio:/mygroup</strong><br>3:perf_event:/<br>2:devices:/user.slice<br>1:name=systemd:/user.slice/user-1001.slice/session-25.scope<br>0::/user.slice/user-1001.slice/session-25.scope</pre><p>There we are! We made our cgroup working, let’s explore the next ingredient.</p><h4>Namespaces</h4><p><a href="https://man7.org/linux/man-pages/man7/namespaces.7.html"><strong>Namespaces</strong></a> are a feature of the <a href="https://www.kernel.org/doc/html/latest/admin-guide/namespaces/resource-control.html">Linux kernel</a> that partitions kernel resources such that one set of processes sees one set of resources while another set of processes sees a different set of resources. A namespace wraps a global system resource in an abstraction that makes it appear to the processes within the namespace that they have their own isolated instance of the global resource. Changes to the global resource are visible to other processes that are members of the namespace but are invisible to other processes. One use of namespaces is to implement containers.</p><p>There are different type of namespaces available in Linux:</p><ul><li><strong>cgroup</strong>: isolates cgroup root directory;</li><li><strong>IPC</strong>: isolates System V IPC and POSIX message queues;</li><li><strong>Network</strong>: isolates network devices, stacks, ports, etc.;</li><li><strong>Mount</strong>: isolates mount points;</li><li><strong>PID</strong>: isolates process IDs;</li><li><strong>Time</strong>: isolates boot and monotonic clocks;</li><li><strong>User</strong>: isolates users and groups IDs;</li><li><strong>UTS</strong>: isolates hostname and NIS domain name.</li></ul><p>The kernel assigns each process a symbolic link per namespace kind in /proc/&lt;PID&gt;/ns/. The inode number pointed to by this symlink is the same for each process in this namespace. This uniquely identifies each namespace by the inode number pointed to by one of its symlinks.</p><p>Reading the symlink via readlink returns a string containing the namespace kind name and the inode number of the namespace. Here is an example of this:</p><pre>$ sleep 3000 &amp; PID1=$!<br>[1] 3261</pre><pre>$ sleep 3000 &amp; PID2=$!<br>[2] 3262</pre><pre>$ ls -l /proc/$PID1/ns/ | awk &#39;{print $1, $9, $10, $11}&#39;<br>total<br>lrwxrwxrwx cgroup -&gt; cgroup:[<strong>4026531835</strong>]<br>lrwxrwxrwx ipc -&gt; ipc:[<strong>4026531839</strong>]<br>lrwxrwxrwx mnt -&gt; mnt:[<strong>4026531840</strong>]<br>lrwxrwxrwx net -&gt; net:[<strong>4026533321</strong>]<br>lrwxrwxrwx pid -&gt; pid:[<strong>4026531836</strong>]<br>lrwxrwxrwx pid_for_children -&gt; pid:[<strong>4026531836</strong>]<br>lrwxrwxrwx user -&gt; user:[<strong>4026531837</strong>]<br>lrwxrwxrwx uts -&gt; uts:[<strong>4026531838</strong>]</pre><pre>$ ls -l /proc/$PID2/ns/ | awk &#39;{print $1, $9, $10, $11}&#39;<br>total<br>lrwxrwxrwx cgroup -&gt; cgroup:[<strong>4026531835</strong>]<br>lrwxrwxrwx ipc -&gt; ipc:[<strong>4026531839</strong>]<br>lrwxrwxrwx mnt -&gt; mnt:[<strong>4026531840</strong>]<br>lrwxrwxrwx net -&gt; net:[<strong>4026533321</strong>]<br>lrwxrwxrwx pid -&gt; pid:[<strong>4026531836</strong>]<br>lrwxrwxrwx pid_for_children -&gt; pid:[<strong>4026531836</strong>]<br>lrwxrwxrwx user -&gt; user:[<strong>4026531837</strong>]<br>lrwxrwxrwx uts -&gt; uts:[<strong>4026531838</strong>]</pre><p>In the above, it looks clear that the inode number is the same for both $PID1 and $PID2.</p><p>The namespaces API includes the following system calls:</p><ol><li>clone(2) : the <em>clone</em> system call creates a new process;</li><li>setns(2) : the <em>setns</em> system call allows the calling process to<br> join an existing namespace;</li><li>unshare(2) : the <em>unshare</em> system call moves the calling process to a<br> new namespace.</li></ol><p>Let’s see that in action. Starting from the container we’ve exported in the section about User Space, let’s create a new namespace using <em>unshare.</em></p><pre>$ ls<br>bin  dev  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var</pre><pre>$ sudo SHELL=/bin/sh unshare --fork --pid --ipc --net chroot $(pwd) &quot;$@&quot;</pre><pre>/ # ls<br>bin    dev    etc    home   lib    media  mnt    opt    proc   root   run    sbin   srv    sys    tmp    usr    var</pre><pre>/ # cat /etc/os-release<br>NAME=&quot;Alpine Linux&quot;<br>ID=alpine<br>VERSION_ID=3.13.4<br>PRETTY_NAME=&quot;Alpine Linux v3.13&quot;<br>HOME_URL=&quot;<a href="https://alpinelinux.org/">https://alpinelinux.org/</a>&quot;<br>BUG_REPORT_URL=&quot;<a href="https://bugs.alpinelinux.org/">https://bugs.alpinelinux.org/</a>&quot;<br></pre><p>As you can see, we are inside the new namespace, running our container as the root. Don’t you believe it? Let’s open another shell and let’s check it out:</p><pre>$ ps -a<br>  PID TTY          TIME CMD<br>  786 pts/0    00:00:00 sudo<br>  787 pts/0    00:00:00 unshare<br>  788 pts/0    00:00:00 sh<br>  809 pts/1    00:00:00 ps</pre><pre>$ sudo ls -l /proc/4038/ns<br>total 0<br>lrwxrwxrwx 1 root root 0 Apr  6 15:47 cgroup -&gt; &#39;cgroup:[4026531835]&#39;<br>lrwxrwxrwx 1 root root 0 Apr  6 15:47 ipc -&gt; &#39;ipc:[<strong>4026533573</strong>]&#39;<br>lrwxrwxrwx 1 root root 0 Apr  6 15:47 mnt -&gt; &#39;mnt:[4026531840]&#39;<br>lrwxrwxrwx 1 root root 0 Apr  6 15:47 net -&gt; &#39;net:[<strong>4026533576</strong>]&#39;<br>lrwxrwxrwx 1 root root 0 Apr  6 15:47 pid -&gt; &#39;pid:[4026531836]&#39;<br>lrwxrwxrwx 1 root root 0 Apr  6 15:47 pid_for_children -&gt; &#39;pid:[<strong>4026533574</strong>]&#39;<br>lrwxrwxrwx 1 root root 0 Apr  6 15:47 user -&gt; &#39;user:[4026531837]&#39;<br>lrwxrwxrwx 1 root root 0 Apr  6 15:47 uts -&gt; &#39;uts:[4026531838]&#39;</pre><pre>$ sudo ls -l /proc/3100/ns<br>total 0<br>lrwxrwxrwx 1 dario dario 0 Apr  6 15:37 cgroup -&gt; &#39;cgroup:[4026531835]&#39;<br>lrwxrwxrwx 1 dario dario 0 Apr  6 15:10 ipc -&gt; &#39;ipc:[<strong>4026531839</strong>]&#39;<br>lrwxrwxrwx 1 dario dario 0 Apr  6 15:37 mnt -&gt; &#39;mnt:[4026531840]&#39;<br>lrwxrwxrwx 1 dario dario 0 Apr  6 15:37 net -&gt; &#39;net:[<strong>4026533321</strong>]&#39;<br>lrwxrwxrwx 1 dario dario 0 Apr  6 15:37 pid -&gt; &#39;pid:[4026531836]&#39;<br>lrwxrwxrwx 1 dario dario 0 Apr  6 15:37 pid_for_children -&gt; &#39;pid:[<strong>4026531836</strong>]&#39;<br>lrwxrwxrwx 1 dario dario 0 Apr  6 15:37 user -&gt; &#39;user:[4026531837]&#39;<br>lrwxrwxrwx 1 dario dario 0 Apr  6 15:37 uts -&gt; &#39;uts:[4026531838]&#39;</pre><p>As you can see, the process <em>bash</em> (aka 3100) and <em>unshare </em>(aka 4038) have different inode numbers, meaning that they are under two different namespaces.</p><h4>Conclusions</h4><p>Now that you know how containers work, you could use them better, being more aware of what’s behind them (and you could stop confusing them with VMs). You could go over experimenting network, bind mounts and so on, or you could just pick Docker or containerd and go deeper with them.</p><h4>References</h4><ol><li><a href="https://www.youtube.com/watch?v=7mzbIOtcIaQ">Keynote: Containers aka crazy user space fun</a></li><li><a href="https://www.redhat.com/en/blog/architecting-containers-part-1-why-understanding-user-space-vs-kernel-space-matters">Why User Space vs Kernel Space matters</a></li><li><a href="https://www.youtube.com/watch?v=sK5i-N34im8">Cgroups, namespaces, and beyond: what are containers made from?</a></li><li><a href="https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt">Control Groups</a></li><li><a href="https://man7.org/linux/man-pages/man7/namespaces.7.html">man page of namespace</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c24cc1137b4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[//go:embed unleashed]]></title>
            <link>https://dariodip.medium.com/go-embed-unleashed-1eab8b4b1ba6?source=rss-a22f7d80066c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1eab8b4b1ba6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Dario Di Pasquale]]></dc:creator>
            <pubDate>Sat, 03 Apr 2021 08:38:00 GMT</pubDate>
            <atom:updated>2021-04-03T08:43:36.670Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YgUAtSspU-C_F_EI" /><figcaption>Photo by <a href="https://unsplash.com/@marekokon?utm_source=medium&amp;utm_medium=referral">Marek Okon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One of the reasons why I love Go is that Go compiler creates static binaries by default unless you use <a href="https://golang.org/pkg/cmd/cgo/"><em>cgo</em></a> to call <em>C</em> code, in which case it will create a dynamically linked library.</p><p>It makes it easy to ship Go programs, create very lightweight Docker images and exploit cross-compiling and plugins.</p><p>Starting from Go 1.16, it also gives you the opportunity to ship your own “batteries” using the <a href="https://golang.org/pkg/embed/">package embed</a>.</p><p>Package embed provides access to files <em>embedded</em> in the running Go program.</p><p>Importing the library embed you can use the //go:embed directive to initialize a variable of type string, []byte, or embed.FS<em> </em>with the content of files read from the package directory or subdirectories at compile time. In other words, //go:embed directive allows you to include the contents of arbitrary files and directories in your Go application.</p><p>Using the //go:embed comment to your code, the compiler will know to include files to the static binary. The base form of the comment is the following:</p><pre>//go:embed FILENAMES<br>var &lt;VARIABLE NAME&gt; &lt;string, []byte or embed.FS&gt; </pre><p>So, your “embedded” variable can be of type string , []byte or embed.FS for a group of files.</p><p>The go:embed directive understands <a href="https://pkg.go.dev/path#Match">Go file globs</a>, so patterns like files/*.txt will also work (but not **/*.txt recursive globbing).</p><p>For a complete technical explanation, you can read<a href="https://golang.org/pkg/embed/"> the official documentation</a>.</p><p>Let’s see a simple example using //go:embed to embed a file into a variable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2e7c21dce41350ac32e3b82413e3656/href">https://medium.com/media/a2e7c21dce41350ac32e3b82413e3656/href</a></iframe><pre>➜  ls       <br>hello.txt         hello_embedded.go<br>➜  cat hello.txt <br>Hello from embedded!<br>➜  go run hello_embedded.go<br>Hello from embedded!</pre><p>The same result can be achieved using []byte :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/309930236c7486e8fc79d5d9209e177e/href">https://medium.com/media/309930236c7486e8fc79d5d9209e177e/href</a></iframe><p>And still, we can embed an entire directory as it is shown in the following snippet:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75435cb87211ffdfb8aa0462dc8ccf7e/href">https://medium.com/media/75435cb87211ffdfb8aa0462dc8ccf7e/href</a></iframe><p>Doing that, we can also iterate over the embedded filesystem. This makes us able to include several files and folders, creating a kind of <a href="https://en.wikipedia.org/wiki/OverlayFS">overlay filesystem</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f04ec9880616d06c2e9746ac6d555e66/href">https://medium.com/media/f04ec9880616d06c2e9746ac6d555e66/href</a></iframe><p>The method ReadDir returns a list of DirEntry , an interface that declares the following methods:</p><ul><li>Name() : returns the name of the file (or subdirectory) described by the entry;</li><li>IsDir() : reports whether the entry describes a directory;</li><li>Type() : returns the type bits for the entry;</li><li>Info() : returns the FileInfo for the file or subdirectory described by the entry.</li></ul><h3>A practical example: caching complex structures</h3><p>A very useful use case for //go:embed can be caching complex structures.</p><p>Imagine we have a program that handles structures that are expensive to be created but that will be kept into memory for all the life of the program. We may take advantage of //go:embed to embed them into memory at the start time.</p><p>In our example, we will use a ComplexStruct structure, that stores a value and its MD5 and SHA256 ingests. Here the code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0ed9852df6a670952d1a9fd8d8aae800/href">https://medium.com/media/0ed9852df6a670952d1a9fd8d8aae800/href</a></iframe><p>It is clear that the method NewComplexStruct is expensive since it has to compute both MD5 and SHA256 ingests of the value.</p><p>Supposing we know that some values are going to be used, we could create an encoder to store a cached version of our values, embedding it into our program to take advantage of precomputed values. Here the code for the encoder:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27208a6b47d10099f43a9a8b93970510/href">https://medium.com/media/27208a6b47d10099f43a9a8b93970510/href</a></iframe><p>Running this function with a precomputed list of ComplexStruct writes a file called complex_structures.gob in the current directory. Running this code I have created a <em>gob </em>file. Examining that file we will know that it is a binary file of 396 bytes:</p><pre>➜  file complex_structures.gob <br>complex_structures.gob: data<br>➜  wc -c complex_structures.gob <br>     3422 complex_structures.gob</pre><p>Now let’s write our piece of code to decode it into our program:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d91e5e5ad5b1616415b354ea1261fd9/href">https://medium.com/media/5d91e5e5ad5b1616415b354ea1261fd9/href</a></iframe><p>Running the program will give us the following result:</p><pre>➜ go run hello_embedded.go    <br>v=ciao,md5=6e6bc4e49dd477ebc98ef4046c067b5f,sha256=b133a0c0e9bee3be20163d2ad31d6248db292aa6dcb1ee087a2aa50e0fc75ae2<br>v=dario,md5=8a49317e060e23bb86f9225ca581e0a9,sha256=2dbe33913ae5d6b16a801119f5fa1c419620c26d1a456e01490d697eb9b12589<br>v=golang,md5=21cc28409729565fc1a4d2dd92db269f,sha256=d754ed9f64ac293b10268157f283ee23256fb32a4f8dedb25c8446ca5bcb0bb3<br>v=complex,md5=4b8bafdec076f25030c303049f4e6586,sha256=ea4b35e8f83279eab1e670e389d71201b360f291a0dc30c659ed708ac9c67d76<br>v=structure,md5=07414f4e15ca943e6cde032dec85d92f,sha256=520cdb563bf80b193aab6aad62781a9647c75dbf76748117299c7dac0ae63a87<br>...</pre><p>Not that easy to read but efficient 😄.</p><p>Let’s see how the size of our Go binary changes including an embedded file:</p><pre>➜  go build -o embedded .<br>➜  wc -c embedded <br> 2468752 embedded<br>➜  go build -o notembedded .<br>➜  wc -c notembedded        <br> 2464624 notembedded</pre><p>So our binary with an embedded file of 396 bytes will be 4128 bytes bigger. Trying with a bigger file the result is the following:</p><pre>➜  wc -c complex_structures.gob <br>    3422 complex_structures_bigger.gob<br>➜  wc -c embedded <br> 2464592 embedded</pre><p>And it is 4160 bytes bigger. So don’t panic, it won’t waste your binary.</p><p>After a few analysis, I tried to understand where and how the embedded file is actually embedded. Inspections have been made on the binaries from the first example, the one with the text file having “<em>Hello from embedded!</em>”, because text value is easier to find into a binary.</p><pre>➜  strings embedded_test | grep -i hello<br> to unallocated span/usr/share/zoneinfo/37252902984619140625EMULTIHOP (Reserved)Egyptian_HieroglyphsIDS_Trinary_OperatorMeroitic_HieroglyphsSIGALRM: alarm clockSIGTERM: terminationSTREAM ioctl timeoutSeek: invalid offsetSeek: invalid whenceTerminal_Punctuationauthentication errorbad defer size classbad system page sizebad use of bucket.bpbad use of bucket.mpchan send (nil chan)close of nil channeldodeltimer0: wrong Pfloating point errorforcegc: phase errorgc_trigger underflowgo of nil func valuegopark: bad g statusinconsistent lockedminvalid write resultmalloc during signalnotetsleep not on g0p mcache not flushedpacer: assist ratio=preempt off reason: reflect.makeFuncStubruntime: double waitruntime: pipe failedruntime: unknown pc semaRoot rotateRighttime: invalid numbertrace: out of memorywirep: already in goworkbuf is not emptywrite of Go pointer  of unexported method previous allocCount=, levelBits[level] = 186264514923095703125931322574615478515625Anatolian_Hieroglyphs<strong>Hello from embedded!</strong></pre><p>There it is. Let’s understand where it is stored inside the binary file:</p><pre>➜  xxd embedded_test | grep -B 2 -A 2 &quot;from&quot;<br>--<br>000c9d10  35 34 37 38 35 31 35 36  32 35 41 6e 61 74 6f 6c  |5478515625Anatol|<br><strong><em>000c9d20</em></strong>  69 61 6e 5f 48 69 65 72  6f 67 6c 79 70 68 73 48  |ian_Hieroglyphs<strong>H</strong>|<br><strong><em>000c9d30</em></strong>  65 6c 6c 6f 20 66 72 6f  6d 20 65 6d 62 65 64 64  |<strong>ello from embedd</strong>|<br><strong><em>000c9d40</em></strong>  65 64 21 0a 49 6e 73 63  72 69 70 74 69 6f 6e 61  |<strong>ed!</strong>.Inscriptiona|<br>000c9d50  6c 5f 50 61 68 6c 61 76  69 4f 74 68 65 72 5f 47  |l_PahlaviOther_G|<br>--<br>...</pre><p>Finally, we know where our string is. It is embedded from the offset <strong><em>000c9d20 </em></strong>to<strong><em> 000c9d40 </em></strong>in our binary.</p><h4>Warning</h4><p>Never forget to include embed in your code to avoid compiler errors like:</p><pre>➜  go build -o notembedded .   <br>./hello_embedded.go:42:3: //go:embed only allowed in Go files that import &quot;embed&quot;</pre><p>Have a nice embedding.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1eab8b4b1ba6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>