<?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 Faruk Mustafic on Medium]]></title>
        <description><![CDATA[Stories by Faruk Mustafic on Medium]]></description>
        <link>https://medium.com/@tms1337?source=rss-fb953933de60------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*g16pDrGIy7bKPzWy8Q5ffQ.png</url>
            <title>Stories by Faruk Mustafic on Medium</title>
            <link>https://medium.com/@tms1337?source=rss-fb953933de60------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 17:29:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tms1337/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[The Real Cost of “I Will Learn AI Later”]]></title>
            <link>https://medium.com/upstart-services/the-real-cost-of-i-will-learn-ai-later-be6f26e146ce?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/be6f26e146ce</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[ai-tools]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[education]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Thu, 16 Jan 2025 18:09:23 GMT</pubDate>
            <atom:updated>2025-01-16T18:09:23.392Z</atom:updated>
            <content:encoded><![CDATA[<p>Turning Complex Decisions into Measurable Outcomes: An AI-Enhanced Framework for Strategic Problem-Solving</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*z4rn6qmDI-Dq9Jvd.png" /></figure><h3>Navigating Life’s Perpetual Decision Points: A Personal ROI Analysis</h3><p>In today’s rapidly evolving landscape, we face critical decision points at every turn. Each choice carries weight, each pause has implications.</p><p>Consider these pivotal questions about your professional trajectory:</p><ul><li>How will market forces reshape the value of your expertise by mid-year? By year’s end? Is your skill portfolio due for strategic enhancement?</li><li>That premium certification program with its $2000 price tag — is timing critical, or could delayed investment serve you better?</li></ul><p>But this framework extends beyond career decisions. Take relationships, for instance. Have you evaluated the correlation between your current investments — time, emotional bandwidth, shared economic responsibilities — and the direction this connection is heading?</p><h3>Breaking Through Decision Paralysis: A Quantifiable Approach</h3><p>At first glance, these life-altering choices can seem overwhelming. How do we create a reliable decision-making framework when faced with so many variables? The good news: there’s a method to the madness.</p><p>What many don’t realize is that even the most complex career and skill-based decisions share an underlying pattern. Each can be deconstructed into quantifiable elements, making the seemingly impossible… manageable.</p><p>Think of it as financial modeling for life choices: we’re not seeking perfect predictions, but rather informed estimates. The magic happens when we dissolve towering uncertainties into smaller, assessable components. Even approximate calculations, when properly structured, provide significantly more insight than pure intuition.</p><p>Editor’s Note: Throughout this article, you’ll find interactive elements designed to both reinforce key concepts and build a deeper understanding of our readers’ experiences. Through polls and checkpoints, we’ll create a collaborative learning environment that benefits everyone. Let’s embark on this analytical journey together.</p><h3>Why read this post? Map of the post</h3><p>While our case study focuses on quantifying the true impact of postponing AI skill development, the implications reach far beyond. This methodology serves as your blueprint for tackling any pivotal life decision where timing and resource allocation play critical roles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p-qUVC1RRNdRlx5kAbDONQ.png" /></figure><p>Throughout our analysis, we’ll use the “AI learning delay” scenario as our practical example. However, the framework we’re developing transcends this single use case. You’ll gain a versatile decision-making toolkit applicable to any significant choice involving investment — whether that’s time, money, or energy — and timing considerations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/0*hcI5fopi7bJhQUTY.png" /></figure><p><a href="https://tms1337.substack.com/p/the-real-cost-of-i-will-learn-ai">The Real Cost of &quot;I Will Learn AI Later&quot;</a></p><p>To ensure thorough coverage and digestible insights, we’ve structured this comprehensive guide into three strategic installments:</p><p>Series Overview: In This Article (Part 1): Foundational Framework We’ll introduce our decision-making methodology, walking through practical examples that transform abstract choices into concrete action plans.</p><p>Coming Soon: Part 2: Mastering Uncertainty Learn techniques for quantifying seemingly intangible factors and making reliable estimates when faced with ambiguous variables.</p><p>Part 3: Leveraging AI for Decision Intelligence Discover how to amplify your decision-making capabilities using cutting-edge AI tools and frameworks.</p><p>What to Expect From This Series:</p><ul><li>Deep dive into a real-world decision scenario with complete analysis</li><li>Systematic approach to converting intuition into measurable insights</li><li>Practical AI integration guide with ready-to-implement prompts</li><li>Hands-on exercises to apply these principles to your own decisions</li></ul><h4>🔍 Quick Visual Recap: Breaking Down Decisions</h4><p>The power of our methodology lies in its ability to convert abstract considerations into concrete metrics. Let’s examine how this transformation unfolds, moving from nebulous thoughts to quantifiable decision points.</p><p>This systematic deconstruction serves two crucial purposes:</p><ol><li>It illuminates the hidden assumptions that often cloud our judgment</li><li>It reveals critical gaps in our reasoning that might otherwise go unnoticed</li></ol><p>Below, we’ll demonstrate this metamorphosis, showing how fuzzy thinking crystallizes into actionable insights through our structured approach.</p><h3>Step 1: Preparing the question</h3><p>Let’s break this down step by step. We’ll start with a basic framework that works for any big decision.</p><p>We’ll use “The Real Cost of I Will Learn AI Later” to demonstrate the method</p><p>It’s too vague to answer in its current form. Let’s fix that.</p><h4>There are always two aspects of every decision:</h4><ol><li>Investment/Risk:</li></ol><ul><li>What you need to put in</li><li>Can be time, money, or any measurable resource</li></ul><p>2. Gain/Reward:</p><ul><li>What you get back</li><li>Also needs to be measurable</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EUtuz-JvwS5zblr_.png" /></figure><h4>Making Vague Questions Measurable</h4><p>Let’s rephrase our AI learning question:</p><ul><li>“What $ amount will my salary increase per hour invested in learning?”</li><li>“How much time will I save long-term by starting now?”</li></ul><p>Establishing Your Decision Metric: Finding Common Ground</p><p>Every choice we make creates ripple effects across multiple dimensions. The key to clarity? Identifying a single, dominant metric that cuts through the noise. Let’s explore how to distill complex decisions into measurable outcomes.</p><h3>Converting Complexity into Clarity</h3><p>The foundation of effective decision-making lies in establishing what we call a “decision currency” — a unified metric that enables direct comparison between options. Here’s how various decision elements transform into actionable metrics:</p><p>Time-Value Analysis From: “Time is money” (vague concept) Through: Standardized time-return measurement To: “Productivity ROI: Hours gained per hour invested”</p><p>Financial Impact Assessment From: Multiple financial indicators Through: Unified return calculation To: “Investment efficiency: Revenue generated per dollar spent”</p><p>Career Progression Metrics From: Various career objectives Through: Focused outcome measurement To: “Monthly compensation growth rate”</p><p>Operational Efficiency From: Multiple impact points Through: Prioritized efficiency metric To: “Weekly time reclaimed from streamlined processes”</p><p>This convergence from scattered metrics to a single, powerful measure provides the clarity needed for confident decision-making. By establishing your decision currency, you create a reliable compass for navigating complex choices.</p><h3>Step 2: Choose Your Decision Currency</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/0*v2Mk3Xu5KNJqUjo2.png" /></figure><p>At the heart of effective decision analysis lies a fundamental concept: your investment metrics must align with your return metrics. This alignment enables precise calculation of returns per unit invested, creating a clear decision pathway.</p><p>Practical Applications in Action: Temporal Return Analysis Calculate the future time savings relative to your current time investment in learning or implementation.</p><p>Financial Impact Evaluation Measure salary enhancement potential against specific training duration commitments.</p><p>Productivity Enhancement Metrics Quantify reduced meeting time relative to initial automation implementation effort.</p><p>Focus Case: AI Skill Investment Analysis For our detailed examination, we’ll focus on a specific metric: “Projected income increase per training day invested in AI skills.”</p><p>This metric proves particularly effective because it:</p><ul><li>Provides a clear dollar value for your time investment</li><li>Offers measurable learning units (training days)</li><li>Creates directly quantifiable outcomes (salary differentials)</li></ul><p>With our measurement framework established, we’ve laid the groundwork for detailed numerical analysis. Moving forward, we’ll break down these numbers into actionable insights.</p><h3>Step 3: Define Your Scope and Outcomes</h3><p>You have your metrics. Now you need concrete numbers for both sides of the equation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*regpOPYgPxFk_R4gyPPrmg.png" /></figure><h4>Investment Side</h4><p>Your time investment isn’t a single number. It depends on your starting knowledge, learning method, and required proficiency level.</p><p>Without defining scope, you’re just guessing in the dark.</p><h4>Example Scope:</h4><p>“Learn GPT and Claude for programming tasks, reaching job-proficient level.”</p><p>This works because it’s specific:</p><ul><li>Tools: GPT and Claude</li><li>Purpose: Programming</li><li>Level: Job proficiency</li></ul><p>Of course, your scope will be different. That’s the point — it should match your situation, goals, and circumstances.</p><p>The beauty of AI? It adapts to how you learn best.</p><h4>Reward Side</h4><p>In our case, we’re measuring additional yearly salary from AI skills.</p><p>Simple to understand, tricky to estimate. But don’t worry — we’ll tackle this step by step, leaving no gaps in understanding.</p><h3>📍 Status check: Where We Are Now</h3><p>Now instead of quiz, let’s recap a bit, so we don’t overwhelm ourselves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*maFk5A3l4V93Cf54.png" /></figure><p>Every now and then let’s review where are we now, so w don’t get lost in too much content at once.</p><p>Let’s pause and see what we’ve built step by step. Let’s check our abstract the map again.</p><h4>What’s Next?</h4><p>We’re ready to tackle the actual numbers. But first, solid foundation check:</p><ul><li>Your question is measurable ✓</li><li>Your units are defined ✓</li><li>Your scope is clear ✓</li></ul><p>Now we can start continue with confidence to the next post in series, where we tackle the “estimate problem”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be6f26e146ce" width="1" height="1" alt=""><hr><p><a href="https://medium.com/upstart-services/the-real-cost-of-i-will-learn-ai-later-be6f26e146ce">The Real Cost of “I Will Learn AI Later”</a> was originally published in <a href="https://medium.com/upstart-services">The Upstart blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[We are GenerationGPT: Summarizing and Transferring GPT Conversations, A Practical Guide]]></title>
            <link>https://tms1337.medium.com/we-are-generationgpt-summarizing-and-transferring-gpt-conversations-a-practical-guide-4f6740071d87?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f6740071d87</guid>
            <category><![CDATA[content-generation]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[gpt]]></category>
            <category><![CDATA[prompt-engineering]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Tue, 09 Apr 2024 04:46:38 GMT</pubDate>
            <atom:updated>2024-04-09T06:02:51.904Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MobkHMNG4EO-fHo6K1KvVQ.jpeg" /><figcaption>All rights: Google gemin <a href="https://g.co/gemini/share/0795711afa5c">https://g.co/gemini/share/0795711afa5c</a></figcaption></figure><blockquote>btw: entire blog post except this comment generated via prompt as well, check url <a href="https://chat.openai.com/share/231fa823-4bc9-44b7-9dbf-9b38e5c14065">https://chat.openai.com/share/231fa823-4bc9-44b7-9dbf-9b38e5c14065</a></blockquote><blockquote><strong>Need for feedback</strong>: (!!) This is draft of the series “We are GenerationGPT” containing: problems, prompt solutions, iterating on prompt to improve, final thought and generated deliverables.</blockquote><blockquote><a href="https://x.com/faruk_mustafic/status/1777570036472742325">https://x.com/faruk_mustafic/status/1777570036472742325</a></blockquote><blockquote>Also here on twitter thread, to see more work that we plan to convert to blog posts</blockquote><blockquote>If you would like this format to continue feedback by clap and/or comment, we have a lot of prompts we use but need to make sure worth the effort to convert to posts.</blockquote><blockquote>init solution mentioned in blogpost generated at <a href="https://chat.openai.com/share/85cd6751-7274-4ee0-b6fa-eb071f9f94cd">https://chat.openai.com/share/85cd6751-7274-4ee0-b6fa-eb071f9f94cd</a></blockquote><h3>Introduction: “Exporting a GPT Conversation”</h3><p>Have you ever wished you could take a snapshot of your brainwaves during those moments of brilliance? Imagine capturing the essence of a deep, insightful conversation with GPT, bottling it up like a genie, and sharing it with the world — or just revisiting it for a personal hit of nostalgia. In this digital age, where fleeting thoughts are immortalized with a click, exporting a GPT conversation is our bridge from ephemeral genius to lasting legacy. Let’s dive into the why and how of preserving these digital dialogues, and maybe, just maybe, we’ll uncover the secret to bottling up that genie for good.</p><h3>Problem Statement</h3><p>In the realm of artificial intelligence, where conversations can range from the mundane to the profoundly insightful, there exists a conundrum that many of us face yet few of us tackle: how do we immortalize these ephemeral exchanges? Just as one would capture a photograph to preserve a moment in time, the digital conservation of a GPT dialogue holds a mirror to the intellectual adventures embarked upon within these chats. This chapter ventures into the essence of the challenge, illuminating the why’s and what’s of exporting a GPT conversation as we peel back the curtain on this modern-day quest for digital preservation.</p><h3>Initial Solution via Prompt</h3><p>In the journey of encapsulating our GPT conversations, our first station is a prompt designed to distill these exchanges into a more portable form. Imagine a magic formula that takes the sprawling, winding paths of our dialogue and compresses them into a neat summary, ready to be understood at a glance or shared with ease. This initial prompt is our attempt at alchemy, turning the lead of our extended conversations into gold:</p><pre>Context: This prompt is designed to accurately summarize the ongoing chat session.<br><br>Instructions: Copy and paste this prompt into another GPT-3.5 chat to generate a summary of the conversation.<br><br>Desired Output Format: Please provide a summarized chat with all relevant information that can be transferred to another GPT-3.5 model with no loss of context. The summary can be presented in bullet points or paragraphs, whichever is more suitable.</pre><p>This initial foray into summarization seeks to harness the power of GPT itself to encapsulate its conversations, promising a bridge from the detailed to the digestible. But how well does it fare? Let’s examine the output it produces and the journey it takes us on.</p><h3>Running the Initial Prompt: A Detailed Look</h3><p>In the spirit of distilling the essence of our digital dialogues, we employed the crafted prompt to summarize a specific conversation, which you can find <a href="https://chat.openai.com/share/1c452d21-3f84-4142-8e29-84d70d3ea228">here</a>. The conversation revolved around troubleshooting PostgreSQL connection issues on macOS, focusing on persistent problems with port 5432. Despite various attempts to resolve the issue, including verifying service status and tweaking configuration files, the stubborn problem remained unsolved. The summary aimed to accurately capture this troubleshooting saga, emphasizing the user’s determination to find a resolution.</p><p>Response:</p><pre>**Conversation Summary:**<br>- User encountered connection issues with PostgreSQL on macOS, specifically on port `5432`.<br>- Despite attempting various fixes, including verifying PostgreSQL service status and checking configuration files, the issue persisted.<br>- Suggestions were provided, such as ensuring correct port settings and inspecting firewall settings, but the problem remained unresolved.<br>- Further investigation into potential causes was discussed, emphasizing the user&#39;s persistence in resolving the issue.<br><br>**Instructions for GPT-3.5:**<br>- Summarize the conversation accurately, focusing on the user&#39;s struggle to troubleshoot PostgreSQL connection issues on macOS.<br>- Include details about attempted fixes, such as verifying service status and checking configuration files.<br>- Highlight the user&#39;s persistence in trying to resolve the issue despite encountering continued connection refusal on port `5432`.<br>- Provide the summary in a format suitable for transfer to another GPT-3.5 model without loss of context.</pre><p>The quality of the summary is commendable, providing a concise yet comprehensive overview of the problem at hand. It captures the critical points of the dialogue, ensuring that the essence of the troubleshooting effort is preserved. However, the real test of this summary lies in its ability to convey the complexity and frustration of the issue while still being digestible to someone new to the conversation. The effectiveness of this initial attempt opens the door to further refinement, exploring the balance between brevity and depth in our quest to encapsulate the richness of GPT conversations.</p><blockquote>… will finish if feedback positive…</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f6740071d87" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[In just 5 mins: Write sales email that people will actually read]]></title>
            <link>https://medium.com/upstart-services/in-just-5-mins-write-sales-email-that-people-will-actually-read-db765f258b0c?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/db765f258b0c</guid>
            <category><![CDATA[copywriting]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[sales]]></category>
            <category><![CDATA[marketing]]></category>
            <category><![CDATA[gpt-3]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Tue, 30 May 2023 01:40:59 GMT</pubDate>
            <atom:updated>2023-05-30T01:40:59.063Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*4Y2ogrH68eux6kOB" /><figcaption>Easy peasy (source <a href="https://unsplash.com/photos/Ak5c5VTch5E">https://unsplash.com/photos/Ak5c5VTch5E</a>)</figcaption></figure><p>Writing sales emails can be a minefield of pitfalls. They can end up too spammy, leaving your prospects hitting that dreaded “delete” button. Or maybe they ramble on forever, putting your recipients to sleep. And let’s not forget the ones that sound as stiff as a robot reciting Shakespeare. If your emails don’t resonate or feel natural, it’s time to hit the brakes and give them a friendly, concise, and genuine makeover. Your prospects will thank you, and your sales will soar!</p><h3>Why even write</h3><p>Hold on to your hats, folks, because GPT is changing the content game like a boss! This magical AI can whip up emails that make customers drool, sales copies that have them reaching for their wallets, and more! It’s like having a creative genius on speed dial, ready to crank out killer content with a friendly touch. Get ready to ride the GPT revolution and watch your business soar!</p><h3>GPT or not GPT — find the middleground</h3><p>Here goes the usual pitch:</p><blockquote>Say goodbye to boring sales emails! With GPT, you’ve got the ultimate secret weapon for crafting killer messages. This genius model whips up personalized and persuasive content that grabs attention, makes people smile, and boosts those conversion rates. It’s like having a smooth-talking salesperson in your inbox, but without the fancy suit. Trust me, GPT will have your customers clicking that “Buy Now” button faster than you can say “cha-ching”!</blockquote><p>Generated by GPT by the way.</p><p>Sounds magical, <strong>but there’s always a catch</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*bf_dGEVqDRPGiTei" /><figcaption>Beware of chaos! (source <a href="https://unsplash.com/photos/yuv1FPyZdR0">https://unsplash.com/photos/yuv1FPyZdR0</a>)</figcaption></figure><p>When you let GPT loose on email generation, things can get a little wacky. It’s like letting a mischievous monkey loose on your keyboard! Without enough context or information, you might end up with emails that leave your customers scratching their heads. So, be sure to give GPT some guidance, or else prepare for some hilariously confusing messages!</p><p>This is why we will give examples of prompts that give proper contextual information.</p><h3>Writing prompt</h3><p>Always try to tell GPT a story about the context. For example, read the prompt below and see if you understand what the mail should be about and who is it directed to:</p><pre>Write a sales email according to the following points:<br>- email is directed to an early stage startup<br>- email should start by mentioning some event that resonates with founders<br>- email is directed to startup that might or might not be collecting <br>    certain numerical metrics<br>- email must tell a story about startup that collects data <br>    but does not detect trends<br>- email must tell a story about startup that collects data <br>    but does not do risk management<br>- email must explain that if you fail to risk manage, you fail overall</pre><p>Now, if we want to tell GPT to include some styling, phrasing and other info we can do it by appending this to the prompt:</p><pre>Additional requirements:<br>- email MUST sound informal<br>- email MUST NOT be longer than 100 words !<br>- email MUST split points in paragraphs</pre><p>Of course, you can have your own requirements, but for this quick 5 minutes email this was sufficient for us.</p><p>Feel free to play around with additional constraints.</p><h3>First results</h3><p>Now when we run a query we get something like this:</p><pre>Subject: Hey [Startup Name], let&#39;s unlock your data&#39;s true potential!<br><br>Hey [Startup Name] team,<br><br>I hope you had a blast at [event name]! <br>    It&#39;s incredible to witness your entrepreneurial spirit firsthand.<br><br>Let me share a quick story. <br>    There was a startup just like yours, <br>    collecting heaps of valuable data. <br>    However, they struggled to detect trends <br>    that could skyrocket their growth. <br>    And you know what they say, understanding trends is key to success!<br><br>On the flip side, there was another startup <br>    that collected data but neglected risk management. <br>    Unfortunately, this oversight led to unforeseen challenges, <br>    putting their overall success at stake. <br>    Remember, managing risks is vital for thriving.<br><br>To help you minimize risks and maximize growth, <br>    I&#39;d love to offer you a free exploratory call. <br>    Let&#39;s chat about how we can unlock the true potential <br>    of your data and navigate the path to success together.<br><br>Looking forward to connecting soon!<br><br>Cheers,<br>[Your Name]</pre><p>This already looks like something. What you can do now is add some nice figures if needed, add your calendly link and you are done.</p><p>You can also run your prompt multiple times and A/B test which version of the email gives you the best results.</p><p>Enjoy connecting to those clients waiting for you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db765f258b0c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/upstart-services/in-just-5-mins-write-sales-email-that-people-will-actually-read-db765f258b0c">In just 5 mins: Write sales email that people will actually read</a> was originally published in <a href="https://medium.com/upstart-services">The Upstart blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to: Monte Carlo financial simulations [Part 1]]]></title>
            <link>https://medium.com/upstart-services/how-to-monte-carlo-financial-simulations-dd6f32d830f1?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd6f32d830f1</guid>
            <category><![CDATA[randomness]]></category>
            <category><![CDATA[investing]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[risk-management]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Mon, 29 May 2023 23:20:28 GMT</pubDate>
            <atom:updated>2023-05-29T23:24:19.359Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*xZMcn7F6VNgLvnmt" /></figure><p>For some context, take a look at the previous post where we do brief introduction to both risk management and simulations.</p><p><a href="https://blog.upstart.services/risk-management-5-minute-pitch-cce4ef599766">Risk management 5 minute pitch</a></p><h3>Numerical data</h3><p>Numerical data is like a treasure trove of numbers that hold valuable information. It’s all about quantifying things, like temperatures, prices, or even the number of times you accidentally hit your funny bone (ouch!). These numbers help us make sense of the world and unravel its mysteries, like a secret code that only statisticians can crack. So, let’s grab our calculators and embark on a numerical adventure!</p><pre>import numpy as np<br><br># Assuming the numerical data is stored in a CSV file called &quot;data.csv&quot;<br>data = np.genfromtxt(&#39;data.csv&#39;, delimiter=&#39;,&#39;)<br><br># Printing the loaded data<br>print(data)p</pre><p>Above we can see python example of loading a data from a csv file to a numpy array. This is usually the first step to starting our explorations, simulations and other adventurous stuff.</p><h3>Data as time series</h3><p>Now, let’s take a look at numerical time series. It’s like having a front-row seat to witness the evolution of numbers over time. Imagine tracking the stock market prices or monitoring the monthly sales of your favorite ice cream shop. That’s a numerical time series! It’s like watching a fascinating dance of digits that moves to its own rhythm. So, let’s put on our statistical dancing shoes and dive into the world of time series!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*J1S3cVYi5szyHSek" /><figcaption>Time series in natural environment.</figcaption></figure><p>When it comes to representing numerical time series graphically, we turn to the trusty line graph. Picture this: time takes the spotlight on the x-axis, while the corresponding values gracefully dance along the y-axis. It’s like connecting the dots of a captivating story, revealing the rise and fall, the peaks and valleys of the data’s journey through time. So, get ready to draw some lines and let the data unfold before your eyes!</p><pre>import matplotlib.pyplot as plt<br>from matplotlib.pyplot import figure<br>import numpy as np<br><br># Assuming you have a NumPy array called <br># &#39;time&#39; for the time values and &#39;values&#39; for the <br># corresponding numerical values<br># Here we will just fill values with random data<br><br>time = list(range(0,1000))<br>values = np.random.normal(0, 1, 1000)<br><br># Plotting the time series<br>figure(figsize=(16, 8), dpi=80)<br>plt.plot(time, np.cumsum(values))<br><br># Adding labels and title<br>plt.xlabel(&#39;Time&#39;)<br>plt.ylabel(&#39;Values&#39;)<br>plt.title(&#39;Time Series Plot&#39;)<br><br># Displaying the plot<br>plt.show()</pre><p>Above you can see example how would you usually plot the time series in python for the first look and to get some ideas.</p><p>You should get result similar to the figure below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9y1nclCct5Rnn89zyUzuYQ.png" /><figcaption>Yaay, our first time series!</figcaption></figure><h3>How to convert our data to time series</h3><p>To represent real-life phenomena as time series, we become like curious observers, capturing snapshots of data at regular intervals. Whether it’s measuring temperatures, counting people at a concert, or tracking daily sales, we arrange these observations in chronological order. It’s like creating a time-lapse video that reveals hidden patterns, uncovers trends, and even helps us predict the future (if only we could predict the weather as accurately!).</p><p>Just to do some practice, here’s an example Python script that converts a numerical CSV file into a time series using the pandas library:</p><pre>import pandas as pd<br><br># Assuming the numerical data is stored in a CSV file called &quot;data.csv&quot;<br>data = pd.read_csv(&#39;data.csv&#39;)<br><br># Assuming the CSV file has columns named &#39;time&#39; and &#39;value&#39;<br>time_series = pd.Series(data[&#39;value&#39;].values, index=pd.to_datetime(data[&#39;time&#39;]))<br><br># Printing the time series<br>print(time_series)</pre><p>Brief explainer:</p><p>In this script, we start by importing the pandas library using the import statement.</p><p>Next, we use the pd.read_csv() function to read the numerical data from a CSV file named &quot;data.csv&quot;. The resulting data is stored in a pandas DataFrame called data.</p><p>Assuming that the CSV file has columns named ‘time’ and ‘value’, we create a pandas Series called time_series using pd.Series(). We pass the numerical values from the &#39;value&#39; column of the DataFrame as the first argument. The second argument is the index, which we create by converting the &#39;time&#39; column to datetime format using pd.to_datetime().</p><p>Finally, we print the resulting time series using the print() function.</p><p>Remember to replace “data.csv” with the actual file path and name of your data file. Make sure the file is in the same directory as your Python script or provide the full file path if it’s located elsewhere.</p><p>You now have a pandas Series representing the time series, which provides powerful functionality for analyzing and manipulating time-based data in Python.</p><h3>Randomization — life is a casino</h3><p>Why do we need randomized simulations, you ask? Well, life loves throwing surprises at us, and randomness is its favorite tool. Randomized simulations help us prepare for the unexpected, explore different possibilities, and understand the range of outcomes that could occur. It’s like playing a game with the universe, where the rules are unknown, and the results keep us on the edge of our seats. Get ready for a wild ride!</p><p>In Monte Carlo simulations, we take randomness to a whole new level. By incorporating randomized events, we can mimic the uncertainties of the real world. It’s like spinning a roulette wheel or flipping a coin to simulate a wide range of possible outcomes. We let chance and probability guide us, giving our simulations a touch of excitement and unpredictability. Let’s roll the dice and see where the winds of randomness take us!</p><p>In Monte Carlo simulations, we encounter different types of randomized events. Continuous events are like a smooth roulette wheel spinning, where any value within a range is possible. On the other hand, discrete events are more like flipping a coin, where only two outcomes are possible. It’s like having a mixed bag of surprises, each with its own set of rules and possibilities. Time to embrace the randomness and let the simulations surprise us!</p><p>Again, some code. Here’s an example Python script that generates a randomized time series with a uniform delta between each step:</p><pre>import numpy as np<br>import pandas as pd<br><br># Set the number of steps and the uniform delta value<br>num_steps = 100<br>delta = 0.5<br><br># Generate the time series with randomized values<br>random_values = np.random.rand(num_steps)<br>time_series = pd.Series(random_values)<br><br># Add a uniform delta between each step<br>time_series = time_series * delta<br><br># Generate the time index<br>time_index = pd.date_range(start=&#39;2023-05-30&#39;, periods=num_steps, freq=&#39;D&#39;)<br><br># Assign the time index to the time series<br>time_series.index = time_index<br><br># Printing the randomized time series<br>print(time_series)</pre><p>Brief explainer:</p><p>In this script, we start by importing the necessary libraries: numpy and pandas.</p><p>Next, we define the number of steps (num_steps) and the uniform delta value (delta). You can adjust these values according to your requirements.</p><p>We then use np.random.rand() to generate an array of random values with the same length as the number of steps.</p><p>After that, we create a pandas Series (time_series) from the random values array.</p><p>To incorporate the uniform delta between each step, we multiply the random values by the delta value.</p><p>To create a time index, we use pd.date_range() and specify the start date as &#39;2023-05-30&#39;, the number of periods as num_steps, and the frequency as &#39;D&#39; (which represents daily steps).</p><p>Finally, we assign the time index to the time series using time_series.index = time_index. This ensures that each value in the time series corresponds to the respective time step.</p><p>The randomized time series with a uniform delta between each step is then printed using the print() function.</p><p>Feel free to modify the script to suit your needs, such as changing the start date, adjusting the frequency, or using a different method to generate random values.</p><h3>Picking the right randomness</h3><p>When using past observations to simulate potential future evolutions in Monte Carlo, we become time travelers armed with data. We analyze the patterns and trends hidden within historical time series, and then we use that knowledge to generate new series that reflect possible futures. It’s like peering into a crystal ball, except the ball is made of numbers, and we rely on statistical magic instead of magic spells!</p><p>Here are some of the randomness you can pick from when using numpy . You will find similar stuff in the other packages of choice as well.</p><pre>import numpy as np<br><br># Generating random integers<br>random_int = np.random.randint(low=0, high=10, size=5)<br>print(&quot;Random integers:&quot;, random_int)<br><br># Generating random floats between 0 and 1<br>random_float = np.random.random(size=5)<br>print(&quot;Random floats:&quot;, random_float)<br><br># Generating random floats from a normal distribution<br>random_normal = np.random.normal(loc=0, scale=1, size=5)<br>print(&quot;Random normal distribution:&quot;, random_normal)<br><br># Generating random boolean values<br>random_bool = np.random.choice([True, False], size=5)<br>print(&quot;Random boolean values:&quot;, random_bool)<br><br># Shuffling an array randomly<br>array = np.arange(1, 6)<br>np.random.shuffle(array)<br>print(&quot;Shuffled array:&quot;, array)</pre><h3>Setting up simulation</h3><p>In setting up a Monte Carlo simulation, we need to define a few basic modeling parameters. First, we choose the time period we want to simulate, determining how far into the future we want to gaze. Then, we decide on the statistical distribution that best represents our data, like a bell curve or a uniform distribution. Lastly, we select the number of simulations to run, like deciding how many lottery tickets to buy. Let the modeling begin!</p><h3>Defining objectives</h3><p>When running Monte Carlo simulations, it’s important to pick the objectives we want to keep track of. Whether it’s predicting stock market returns, estimating the likelihood of a heatwave, or forecasting the demand for avocado toast (crucial stuff!), we choose the specific outcomes we’re interested in. It’s like having a personal shopping list of objectives, guiding our simulation adventures and helping us focus on what really matters. Happy hunting for objectives!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd6f32d830f1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/upstart-services/how-to-monte-carlo-financial-simulations-dd6f32d830f1">How to: Monte Carlo financial simulations [Part 1]</a> was originally published in <a href="https://medium.com/upstart-services">The Upstart blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Writer Hybrid — Guided GPT]]></title>
            <link>https://medium.com/upstart-services/the-writer-hybrid-guided-gpt-16d64f37068c?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/16d64f37068c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[gpt-3]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Mon, 29 May 2023 21:11:01 GMT</pubDate>
            <atom:updated>2023-05-30T04:39:45.530Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Hybrid Writer — Guided GPT [001]</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*QXiauWWP3QBzOFRl" /></figure><p>Note that this is just the beginning of the journey where I explore how to work in sync with new tech but still be unique and add value. Will keep you posted with progress.</p><p>Recently, I generated a blog post via GPT. The issue is, if you don’t guide it well, it will just write general stuff and won’t have any personal touch.</p><p>In the end I will give you the prompt and the resulting blog post, so you can judge if it has any value or is just random rambling of the facts.</p><h3>Am I writer at all?</h3><p>But first let me state my position on the topic of using generators:</p><blockquote>For me it is okay to use generators, as long as you define the outline and the style of writing, that’s what you are contributing. The more details you define, the more value you added, and less value is some general generated stuff.</blockquote><h3>My first try</h3><p>The first blog post I tried to write with the help of GPT generator is one of these (try to guess which):</p><ul><li><a href="https://blog.upstart.services/risk-management-5-minute-pitch-cce4ef599766">Risk management 5 minute pitch</a></li><li><a href="https://blog.upstart.services/road-to-building-your-crypto-token-0x1-whythefck-we-need-a-blockchain-a1d10895e351">Road to building your crypto token 0x1: WhyTheFck we need a blockchain?</a></li></ul><p>Guessed which?</p><p>The risk management one was generated, the other one was hand written. Which one is better btw?</p><h3>Prompt</h3><p>The propmpt I used to generate and guide GPT in the direction I want is this one.</p><blockquote>Feel free to comment and discuss how to improve this!</blockquote><pre>For each of the following points write a paragraph:<br>- what is risk management<br>- how to numerically quantify risk<br>- how to model real world as numerical quantities<br>- why it is important to use numerical quantities when assessing risk<br>- what is the objective of risk management<br>- what questions risk management process tries to answer<br>- in which cases it is not possible to empirically get data for risk management procedure<br>- how can simulations can help risk management?<br>- what are monte carlo simulations in this context?<br>- what are the usual outputs of monte carlo simulations?<br>- an example of monte carlo simulation being used in risk management<br>- an example of actions proposed based on probabilities of certain risk events<br><br><br>Additional requirements:<br>- Each paragraph MUST NOT contain more than 60 words<br>- Text MUST use simple language<br>- Text MUST avoid expert terminology whenever possible<br>- Text MUST BE engaging<br>- Text MUST BE easy for casual readers to understand<br>- Text MUST BE in a style of a blog post<br>- Text SHOULD OCCASIONALLY make jokes<br>- Text SHOULD OCCASIONALLY be witty</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16d64f37068c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/upstart-services/the-writer-hybrid-guided-gpt-16d64f37068c">The Writer Hybrid — Guided GPT</a> was originally published in <a href="https://medium.com/upstart-services">The Upstart blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Risk management? The 5 minute pitch]]></title>
            <link>https://medium.com/upstart-services/risk-management-5-minute-pitch-cce4ef599766?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/cce4ef599766</guid>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[finance]]></category>
            <category><![CDATA[risk-management]]></category>
            <category><![CDATA[investment]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Mon, 29 May 2023 19:48:19 GMT</pubDate>
            <atom:updated>2023-05-30T04:41:21.870Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*U7Kj_49d_09U-6vx" /><figcaption>Let’s roll</figcaption></figure><h3>What is risk management?</h3><p>It’s like being a superhero for your business. Risk management involves identifying, assessing, and handling potential threats or uncertainties that could harm your company. Think of it as your trusty shield against danger!</p><p>The objective of risk management is simple: to protect your business from harm. It’s like building a fortress that guards against risks like a medieval knight defending the kingdom. We want to minimize potential losses, keep things running smoothly, and ensure our business survives any unexpected surprises.</p><blockquote>It’s like playing chess with the universe and making sure we don’t get checkmated!</blockquote><h3>Why use numerical quantities?</h3><p>Well, numbers don’t lie (unless they’re secretly plotting against us). Using numbers helps us objectively assess and compare risks. It’s like having a universal language for risk assessment. Plus, it makes us feel fancy with our spreadsheets and charts. Who doesn’t love a good graph? It’s like a rollercoaster ride for statisticians!</p><p>The risk management process is all about answering important questions. Are there any potential risks we should be aware of? What is the likelihood and impact of these risks? How can we reduce or eliminate them? It’s like being Sherlock Holmes and unraveling the mysteries of uncertainty. Elementary, my dear risk manager!</p><h3>How to numerically quantify risk?</h3><p>It’s all about crunching numbers. We assign values to risks based on their probability and potential impact. It’s like giving them a “risk score.” The higher the score, the scarier the risk. Think of it as turning risk into a math problem, but without the math teacher scolding you for using a calculator!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*P4rZdo7lHIM_jUiV" /><figcaption>Example of “numerifying” real life</figcaption></figure><p>Modeling the real world as numerical quantities might sound complicated, but it’s actually a way to make sense of chaos. We break down real-world situations into measurable factors and parameters. It’s like putting the world on a scale, weighing the risks and rewards. Just don’t forget to take the “real” out of reality when you’re done!</p><h3>So I should wait for disaster then analyze?</h3><p>Sometimes, getting empirical data for risk management is as likely as finding a unicorn playing the banjo. In cases where data is scarce or unreliable, we have to rely on alternative methods. It’s like being a magician and conjuring up creative ways to estimate risks. After all, we can’t let a lack of data rain on our risk management parade!</p><p>Here is where simulations come into play. We will cover the basics here but more on that in the next post.</p><h3>Simulations</h3><p>Simulations are like playing a video game, but with higher stakes. They help us model different scenarios and see how risks unfold in a virtual world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*k-UCh3qdC8wRzxEm" /><figcaption>Just like Matrix</figcaption></figure><p>It’s like a risk playground where we can experiment and learn without real-world consequences. Just remember to save your game before taking any daring risks. No respawns in real life!</p><h3>Randomized / Monte Carlo simulations</h3><p>Monte Carlo simulations are like Vegas for risk managers. They’re a fancy way of using random numbers to analyze risks. We simulate various possible outcomes and calculate the probabilities of different events. It’s like rolling the dice and predicting the future (minus the fortune-telling crystal ball). Maybe we’ll discover the secret to winning the lottery while we’re at it!</p><p>In risk management, Monte Carlo simulations can be a game-changer. For example, let’s say you’re launching a new product. By running simulations, you can estimate the probabilities of different sales figures, costs, and market trends. It’s like playing a “what-if” game with your business. Armed with this knowledge, you can make informed decisions and plan strategies. Who needs a crystal ball when you have Monte Carlo?</p><h3>Simulation results</h3><p>The outputs of Monte Carlo simulations can be as thrilling as a grand finale. They provide probabilities and distributions of different outcomes. It’s like having a crystal ball that shows us the likelihood of various scenarios.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dpeblpoUQyJjbcFjvip3uQ.png" /><figcaption>Example of simulation results in finance sector. Each line is potential scenario.</figcaption></figure><p>Armed with this knowledge, we can make informed decisions and plan strategies. Who needs a fortune teller when you have Monte Carlo?</p><h3>Simple example</h3><p>Based on the probabilities of certain risk events, actions proposed can be as exciting as a high-stakes action movie. Let’s say you’re an astronaut and there’s a 90% chance of a meteor shower during your mission. You might decide to postpone the launch or add extra shielding to your spacecraft. It’s like navigating through the cosmos with probabilities as your guide. Take that, gravity!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cce4ef599766" width="1" height="1" alt=""><hr><p><a href="https://medium.com/upstart-services/risk-management-5-minute-pitch-cce4ef599766">Risk management? The 5 minute pitch</a> was originally published in <a href="https://medium.com/upstart-services">The Upstart blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Road to building your crypto token 0x1: WhyTheFck we need a blockchain?]]></title>
            <link>https://medium.com/upstart-services/road-to-building-your-crypto-token-0x1-whythefck-we-need-a-blockchain-a1d10895e351?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1d10895e351</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[token]]></category>
            <category><![CDATA[banking]]></category>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Tue, 18 Oct 2022 02:08:27 GMT</pubDate>
            <atom:updated>2022-10-18T02:08:27.236Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_WyCx-GB3eVVFl5tdrA4Xg.png" /><figcaption>And then there was light (source <a href="https://unsplash.com/photos/7e2pe9wjL9M">unsplash</a>)</figcaption></figure><h3>The current state of affair</h3><p>Now whenever you do any type of exchange or a transaction, be it monetary or any other we achieve agreement (consensus in blockchain slang, get used to it) on the its validity by having a centralized entity we trust.</p><p>The most basic example is a bank. When you send some $$ to somebody you trust the bank and that it will honestly (hh) process everything and update your balances correctly.</p><p>Ignoring the fact that then banks use that money multiple times to offer other people credit with some interest rate without you having too much benefit, this works fine most of the time (except 1921, 1984, 2008… except).</p><p>But the issue is that we still believe the centralized entity does not have its goals aligned with ours at some point.</p><p>Did you ever ask yourself what was the cause of the last Big Recession? When we remove all the banking jargon, we can simply summarize it as:</p><blockquote>Banks were betting on house prices like it is horse racing knowing the state needs to bail them out. Imagine gambling but knowing when you lose, you get more.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YLrzUvRRCKDd_U1tw0OB4Q.png" /><figcaption>Thanks and Cheers! (<a href="https://media.vanityfair.com/photos/54caa7beb624d6910575ccb2/master/w_2560%2Cc_limit/image.jpg">source</a>)</figcaption></figure><p>Since boils down to a transaction of some type, this generalized to other situations as well. So the right question to ask, which is the answer to the title of this post is:</p><blockquote><strong>How to transact so that we all agree but don’t need a centralized entity with questionable motives?</strong></blockquote><h3>We don’t trust each other, but in a good way</h3><p>In the next blog post, since we save what is the current state of affairs, we will see how the blockchain is the after-affair we need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*JlRhwWQF_Y80-TyuC8TIFw.jpeg" /><figcaption>(Photo by <a href="https://unsplash.com/@bernardhermant?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Bernard Hermant</a> on <a href="https://unsplash.com/s/photos/trust?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>)</figcaption></figure><p>It is not necessarily bad not to fully trust every1, let alone the vast waters of the interwebs. The phrase that you might hear from time to time in this space is:</p><blockquote>Trust, but verify.</blockquote><p>Every1 who does not feel accountable will eventually come into temptation to game the system (yes you as well, don’t pretend it’s not like that).</p><p>In the next episode: Math comes to the rescue. Yes you heard it right, but don’t run away now, they just want you to think it’s complicated…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3ef9pfymPRlZtduIPtxyzQ.jpeg" /><figcaption>So long, bankers (and other questionable centralized entities, so they are not offended for being left out haha) (<a href="https://unsplash.com/@raghavmodi?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">source</a>)</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1d10895e351" width="1" height="1" alt=""><hr><p><a href="https://medium.com/upstart-services/road-to-building-your-crypto-token-0x1-whythefck-we-need-a-blockchain-a1d10895e351">Road to building your crypto token 0x1: WhyTheFck we need a blockchain?</a> was originally published in <a href="https://medium.com/upstart-services">The Upstart blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visual Bayes’ Theorem For Second Graders]]></title>
            <link>https://medium.com/upstart-services/bayes-theorem-for-second-graders-554b0165ccf4?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/554b0165ccf4</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[probability]]></category>
            <category><![CDATA[bayes-theorem]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Thu, 29 Sep 2022 02:42:55 GMT</pubDate>
            <atom:updated>2022-12-26T10:59:23.279Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fw7pBAlCro28lqWp.jpg" /><figcaption>Figure 1: Bayes’ Theorem real world application🤣 (<a href="https://tocsindata.com/wp-content/uploads/2020/12/Bayes_Theorem_MMB_01.jpg">source</a>)</figcaption></figure><p>If you take a look at the image above, you have probably heard something along the lines of</p><blockquote>… one of the most influential equations in history.</blockquote><p>The equation above is called Bayes’ theorem, and has wide variety of applications in probability theory. It allows us to sum up evidence and use that to calculate probability of certain things, conditional probabilities etc.</p><p>If you are thinking <em>“condition.. what?” </em>don’t leave the post just yet, it’s intended to explain the equation so that even the second grader could understand what it is.</p><p>Even if you know the equation and have used it, perhaps you see the novel way of looking at it.</p><h3>Probability in simple terms</h3><p>Even thought probability theory might seem complex at a first glance, a lot of concepts, formulas and theorems can be intuitively understood if you start looking at probabilities the certain way. At least it worked for me.</p><p>In probability theory, we have the concept of <strong>events</strong>, and event is basically anything that has probability of happening. Usually we use uppercase letters like A, B, C to denote events.</p><p>Then P(A) represents probability of event A happening. What probability of an event means?</p><p>Let there be N possible world states, and #A is number of those states where event A happened. Then we say:</p><p>P(A) = #A / N</p><p>So in a nutshell , <strong>the percentage of possible world states in which A happened</strong>.</p><p>We usually do not use percentages 0% to 100% but rather a number from 0 to 1 in math. So if probability of event A happening is 70%, we write that as P(A) = 0.7. So far so good.</p><p><em>(I know it’s a bit more complex formally, but trying to explain stuff simply here).</em></p><h3>Probability as area</h3><p>Now, the fun part. How I imagine this to be represented.</p><p>As we did before, let’s say we have a world with N possible states. Let us graphically represent that with rectangle.</p><p>Our rectangle contains points. Now each point will represent a possible state of the world for us, so the total rectangle represents all the possible world states, points being the specific states.</p><blockquote>And from now on, whenever we say a <strong>point</strong>, what we mean is a possible world state within this rectangle of all possibilities that can happen.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/1*wzxvla4ekEC02BvjZpiAFw.png" /><figcaption>Diagram 2: Our view of probability world</figcaption></figure><p>If you take a look at the diagram above, we denote it with T, and T=1 means it has area 1.</p><p>Each event is just a subset of points. For example, in the diagram, event A is covering a subset of points contained within a circle (remember each point is possible world state).</p><p>Now in the diagram event A has certain area, which is certainly less than 1, since it is contained within the rectangle of the area 1.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fslidetosubscribe.com%2Fembed%2Fme&amp;dntp=1&amp;display_name=Slide+to+Subscribe&amp;url=https%3A%2F%2Fslidetosubscribe.com%2Fme%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slidetosubscribe" width="450" height="152" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f49754ae9fcb9cf63e6be256dabe02e/href">https://medium.com/media/9f49754ae9fcb9cf63e6be256dabe02e/href</a></iframe><p>We will use notation P(A) to mean the area of A. For example if the area of A is say 0.1 then we write</p><p>P(A) = 0.1</p><p>But look what happened, now the area is the same thing as probability. We could have used another symbol to denote the area, but if we use P then it’s obvious.</p><p>The above statement then can be interpreted or read as:</p><ul><li>the probability of event A happening is 10%</li><li>the percentage of subset of points of a rectangle that A contains is 10%</li><li>the percentage of subset of world states where A occurs is 10%</li></ul><p>It is obvious that P(A) ≤ 1 since A is contained within a rectangle of the total area 1. This is one of the basic truths for probability theory, but now in our mental model it makes perfect sense without much thinking.</p><p><em>(Ignore the fact there are infinite points, just imagine them as having really small area. There is a mathy way to properly formalize this, but this is exactly what we are trying to avoid.)</em></p><p>Voila, and this is the way you can represent probability as area in your head. Our brains are hardwired to think in terms of natural things, so area is much more intuitive to our minds. This makes reasoning about certain concepts and formulas easier for us. We will see how.</p><h3>Multiple events</h3><p>Now of course, in most of the cases there is no single event that we keep track of. Usually there are more and we want to know probabilities of certain combination of these events.</p><p>For example, we want to know the probability of two events happening at the same time? Let’s call them A and B.</p><blockquote>This is the same as asking, if we pick the state of the state of the world at random, what is the percentage of times both events will have happened in that state.</blockquote><p>To get back to our area intuition, what is the percentage of times we will end up in a point that is in both A and B?</p><p>We denote the probability of both events happening with P(A, B).</p><h3>Dependent events</h3><p>If the events are happening in the same world, they depend and have effect on one another. We call this dependent events.</p><p>When this is the case, if we want to use our geometric representation, we draw the events as shapes in a single rectangle representing the world they live in and have effect on one another.</p><p>You can see the example of two dependent events geometrically represented in the Diagram 3 below.</p><h3>Mutually exclusive events</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*qrVjulPQ14jCkgiwgx_xhw.png" /><figcaption>Diagram 3: Mutually exclusive, but dependent events A and B</figcaption></figure><p>Let’s try to draw some conclusions from Diagram 3.</p><p>Since area of event B is larger, we can conclude P(B) &gt; P(A).</p><p>Also, specifically in the diagram above there are no points that belong to both A and B, meaning there is no overlap between them in the diagram. This means events are mutually exclusive in this world.</p><p>If we know event B happened, then A did not. Notation for the probability of A given B happened is P(A | B).</p><p>In this case</p><blockquote>P(A | B) = 0</blockquote><blockquote>P(B | A) = 0</blockquote><blockquote>P(A, B) = 0</blockquote><h3>Conditioning, what if…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*TdroN0PmVn6fQ3uIpHbu3A.png" /><figcaption>Diagram 4: Conditioned events A and B which overlap</figcaption></figure><p>What if there is some overlap between event? In the Diagram 4 above, we can see that there is certain set of points denoted with C, which is belonging to both A and B.</p><p>Now when we are picking point random, if we pick any point from C, we automatically can conclude that A happened, but also that B happened as well.</p><p>This is called conditioning, and it means events have some relationship such that for certain subset of world states they both happen.</p><p>If we think in terms of area, the area of C is the probability of both events happening. Equivalently, percentage of times we will pick any point from C in either pick.</p><p>Just to get familiar with some notation, area C is probability of both events happening, we denote it with P(A, B). So</p><blockquote>P(C) = P(A, B)</blockquote><h3>Bayes out of nowhere</h3><p>Now with our geometric representation and intuition about probabilities as areas, let’s think a bit about the case represented in Diagram 3.</p><p>There are events A and B and there is an overlap between events called C. Note that C is subset of both A and B.</p><p>But only in points that are in C, we know event A also happened. If we know B happened, then since A only happened in C where both events happened, we want to calculate what percentage of B is C.</p><p>This is easily calculated as C / B (remember sometimes we avoid writing P(C) and P(A) for brevity when working with areas)</p><p>We write this down as</p><blockquote>P(A | B) = C / B</blockquote><p>In the same way we conclude that:</p><blockquote>P(B | A) = C / A</blockquote><p>Okay now some math: we can multiply anything by 1 and still have the same thing. wow right. Using this we can do some simple arithmetics to get</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*SL30yp4Lj4ENe17UM_moyg.gif" /></figure><p>If we rewrite this in probability notation and use the P(B | A) = C / A, then</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*JYqMHk6XbeV8rO9FBB62Cg.gif" /></figure><p>Doesn’t this look familiar… If we leave out the middle part we have</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*mx6HUuLSkoRxGeGt-B6eEQ.gif" /></figure><p>We got the exact form of Bayes’ theorem by just calculating some areas. Hope this got you some more insight and intuition into both this specific equation but also probability theory in general.</p><h3>Independent events</h3><p>There is a simple case we forgot to mention where events A and B are not even in the same worlds.</p><p>For example, if we ask <strong>“What is the probability that it’s snowing in Sweden?”</strong> and <strong>“javascript is an elegant language”</strong>, these questions are totally separate in a sense that answers to them do not depend on one another (at least I hope so).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-lduWnmIIpXr9Smj_dk7Kw.png" /><figcaption>Diagram 2: Independent events</figcaption></figure><p>We call this case independent events. In the Diagram 2 above, we represent this graphically by having two rectangles. Each of them represents a separate world with separate potential states.</p><p>In the diagram, events A and B take up half the area of their worlds, so</p><blockquote>P(A) = 0.5 and P(B) = 0.5</blockquote><p>Since they are in the separate worlds, if we choose the state of each randomly, the other world can be in any of its own states. If both worlds have N as the number of possible states, then the total number of states of the world in its entirety is N*N = N².</p><p>The number of states within world 1 where A is happening is #A = 0.5 * N. But since we need to take into consideration combination with every state from world 2, then when looking the entire picture A is happening in 0.5 * N * N of the states.</p><p>If we want to know #(A, B), meaning number of states where both events are happening, then we only take into consideration 0.5 * N of the N states of world 2.</p><p>Then #(A, B) is 0.5 * N for A in world 1 and multiplied by each of the 0.5 * N states for B in world 2. Then total #(A, B) = 0.5 * N * 0.5. * N = 0.25 * N².</p><p>Since total number of states when both worlds considered is N², the percentage of times both events happen is</p><blockquote>#(A,B) / N² = 0.25</blockquote><p>In general we can conclude</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/1*3OFLErYrYIJjybENngkxiA.gif" /></figure><p>when considering separate worlds, or independent random variables.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=554b0165ccf4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/upstart-services/bayes-theorem-for-second-graders-554b0165ccf4">Visual Bayes’ Theorem For Second Graders</a> was originally published in <a href="https://medium.com/upstart-services">The Upstart blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting it right: Why and how to structure your tests [part 00]]]></title>
            <link>https://medium.com/upstart-services/getting-it-right-why-and-how-to-structure-your-tests-part-00-bfe972726a3d?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfe972726a3d</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[quality-assurance]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[software-testing]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Tue, 15 Jun 2021 03:14:31 GMT</pubDate>
            <atom:updated>2021-06-15T03:14:31.010Z</atom:updated>
            <content:encoded><![CDATA[<p>Avoid the trap of feeling the false sense of security provided by the tests that test the wrong stuff at the wrong places.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*7zvQsxX64jvEILZD" /><figcaption>You should have multi-level testing strategy, but be careful not to have too much redundancy (source <a href="https://unsplash.com/photos/xn1Jsu2ox4c">David Jorre</a>)</figcaption></figure><p>Let me start with a brief story. As a young developer, whenever I made any change to the code base, be it at work or for my own project, I always had this fear. The fear that I forgot some sequence of connections to some unrelated part of the code and that I will break some previous functionality.</p><p>Then, the revelation came. I discovered the beauty of tests. They make sure you can make changes without the fear of breaking something totally unrelated. Or do they?</p><blockquote>On more than one occasion I thought I had well tested code, but the obvious bugs happened <strong>in production</strong> at the worst points in time.</blockquote><p>So it’s not only sufficient to have tests, it is also important how and what you test.</p><p>Today, I have a testing system that works well for me in most of the situations. This does not mean you need to use that specific system, but you definitely should think about your testing strategy.</p><p>Besides giving you the sense of security, even though initially it takes longer to write the code <strong>and</strong> tests, getting this structure right can still <a href="https://tms1337.medium.com/but-dude-tdd-is-so-slow-and-besides-it-all-boils-down-to-the-same-sh-t-78ea3e8afe6d">save you time and money</a> long-term.</p><h3>QA? You mean questions and answers?</h3><p>Yes, let’s say I mean that. In that case, I will ask and answer a few questions first.</p><p><strong>Isn’t testing only for QA people?</strong> One common misconception is that testing is reserved for QA people. I am a developer too, and I write tests. But I write them for myself and I feel the benefits<strong>.</strong>.</p><p><strong>What are the benefits of testing?</strong> There are multiple benefits:</p><ul><li>you document what your code should do</li><li>you have a safety net and a sense of security when refactoring/making changes/adding new features</li><li>you get to see a lot of green passing tests every now and then, think this is a sufficient reason on its own</li></ul><p>I use the test while coding (and even test before coding = TDD) approach for years now, and since then I have much better night sleep and certainty that my code behaves as I intended it to.</p><p>And okay, I believe most of you agree with me and I do not need to sell you testing in this article, we are all mature enough to know that it is required. But even after we made a decision we will have tests in our codebase, some new questions open up. First and foremost:</p><blockquote>How to structure your tests, what to test and where?</blockquote><p>We will explore my specific approach through a practical example. But remember, the idea is important, the implementation may vary depending on the language, technology and mindset you use.</p><h3>The end is near</h3><p>And it should be. You should always start from the end. This means, let us first imagine we have everything already done for us in a best way possible. What would be the desirable properties of the solution we are given?</p><p>I could think of the following main general things, but there might be some other that are relevant specifically to you or your project:</p><ul><li>(P1) Be sure that new changes don’t break any previous functionality.</li><li>(P2) Be sure code works under various edge cases.</li><li>(P3) Do not have testing redundancy, where we test the same thing multiple times.</li><li>(P4) Avoid white box tests and focus on functionality. The closer the tests emulate the way user will use the system, the more safety and reliability they give us.</li><li>(P5) Tests should not take too long to run so that we get immediate feedback while coding.</li></ul><p>We will call these <strong>desirable properties</strong> or simply <strong>properties</strong> from now on.</p><p>Ok, all of these seem logical. But how to accomplish them, given that for example (1), (2) are at odds with (4). We should find a structure that does not over-test at each level, but still covers all of our needs. Well, let’s have a look.</p><h3>Example: Filtering bank transactions</h3><p>Imagine you are working in a bank and are given a following task:</p><blockquote>Make a system that when triggered gets the daily list of transactions from REST API and filters only those with amounts larger than 100$. Save these to the the database.</blockquote><p>As mentioned, I will explain the system that works for my style of coding. I hope that you take the general conclusions away and apply them to your own coding style.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*2eNRZKiIbux4d2nOxK7dQA.png" /><figcaption>Figure 1: My usual code structure</figcaption></figure><p>In <em>Figure 1</em> you can see what my usual code structure looks like. The entire system is made up of multiple functionalities. Each functionality is basically a function that does the following things:</p><ul><li>Obtains the input in some way. This can be simply via parameters, or connecting to REST API, blockchain node etc. In the latter case it uses a set of services that abstract this connection to the outside world.</li><li>Applies a series of <strong>pure functions</strong> that transform the input according to business logic. Pure means that functions are stateless and for the same input always give the same output.</li><li>Returns the output or emits/writes it somewhere else via the services.</li></ul><p>Bonus info: Notice that I never mentioned where and how are these functionalities deployed. This is because I think the code should be structured in such a way that a functionality can be packed up for any deployment environment and not concerned with that. This way we separate the concerns!</p><p>For the case of filtering the bank transactions:</p><ul><li>input = getting the list of transactions from the REST API</li><li>transformations = filtering the transactions based on the condition</li><li>output = writing to the database</li></ul><h3>Make yourself feel safe</h3><p>I always ask the following questions:</p><blockquote>What I need to be sure the code does right things in order for me to feel safe to deploy it?</blockquote><p>It’s best explained through an example, so let’s write down the things I would like to know are working for the transaction filtering system:</p><ul><li>(R1) Getting the list of transactions via the REST API works</li><li>(R2) Filtering functions chooses the right transactions</li><li>(R3) Writing to the database works</li><li>(R4) The entire functionality works and the parts are well connected together.</li><li>(R5) The entire functionality reacts well to the errors that occur in connectivity and/or core business logic</li></ul><p>We can see that the list contains items from the various levels of code hierarchy. For example:</p><ul><li>REST API and database tests are integration test at the level of connecting to the outside world.</li><li>Filtering functions are what defines business logic.</li><li>(R4) is the wholistic requirement that checks that the entire functionality works when all parts are connected together.</li></ul><h3>Solutions</h3><p>One potential solution that tries to satisfy all the desirable properties while testing these features is:</p><blockquote>- Think of as many edge main and cases as possible. For each one write the test that gets the data from the API, filters and writes the result to the database. Then read from the database and check that the results are correct.<br>- Write unit tests for each of the pure functions that are part of the business logic to document it.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*Tm5jNY8TzyEVUls7xgg8ZA.png" /><figcaption>Figure 2: Solution 1 for testing the system</figcaption></figure><p>This solution is depicted in <em>Figure 2</em><strong><em>. </em></strong>We have multiple tests each of which tests the entire functionality for the case while calling all the relevant services and connectors.</p><p>Testing code would look something along these lines of (I use javascript and jest, but it would probably look something similar in your language of choice):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aba40b3be144d42f79843a3c8b821739/href">https://medium.com/media/aba40b3be144d42f79843a3c8b821739/href</a></iframe><p>Although it seems simple and nice, this solution has multiple downsides:</p><ul><li>Since we can’t control the external REST API, we can’t simulate errors occurring. This violates (P2) (code works under various edge cases) as we can’t test those edge cases.</li><li>Since it is calling external services, test suite might (and probably will) be slow.</li><li>The testing itself will be non-deterministic as it depends on the external factors.</li><li>This solution violates property (P3) (no redundancy) as we test the same logic in unit tests and feature tests.</li><li>Since it’s calling outside services, this solution is slow and violates (P5).</li><li>We do not explicitly tests if the services work correctly. This means tests might fail either due to our logic/connectivity code being buggy or services simply not responding in time for example.</li><li>Too many repetitions in code since all full tests look pretty similar, just with changed input data and expected results.</li></ul><p>Additionally, this solution does not take into consideration that we have multiple levels of hierarchy. Whenever there is certain structure like this present, there is probably a way to use that fact to our advantage. This is a general and far reaching concept, not specific to software testing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*FAR7A6NVY3kC-Q_j2zHrcQ.png" /><figcaption>Figure 3: Solution 2 that takes hierarchical structure into consideration.</figcaption></figure><p>Then let’s try that. The structure is hierarchical, so let’s not having only single level of tests. If we group tests by levels (see <em>Figure 3</em>) we get:</p><ul><li><strong>integration tests</strong>: we test that REST API and DB service work as expected. Since these tests are slow we will not call them each time while developing, only once while coding the service, and before the deployment to check if there were breaking changes.</li><li><strong>business logic tests</strong>: we test each function that encodes the business logic separately with as many edge cases as possible.</li><li><strong>full test</strong>: we check that everything works when connected together. We don’t need to test as many cases as possible here because if the “glue” code that combines everything together works <strong>and </strong>business logic code works under various edge cases, we can assume full tests work under various edge cases as well. Except for, when the exceptions happen…</li></ul><p>In code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/70d349ac991eeb61f70debc13b522b99/href">https://medium.com/media/70d349ac991eeb61f70debc13b522b99/href</a></iframe><p>We avoided most of the pitfalls of the previous approach. Two remaining issues are that we are unable to test for the failures in connections and that the tests will be slow since they are calling real connectors to the outside world. Woohoo, making progress. Let’s tackle these remaining issues and live a happy and long life.</p><p>If you think about it, we already did test that services work well with our integration tests. No need to call them in all the other tests as well. This means that we can make fake versions of them that work locally. We make fakes in such a way that we can define responses, check latest requests etc. Here is the example of the <a href="https://gist.github.com/tms1337/a0225b4c0030dd73faf0b4926e982a2c">possible minimal implementation</a> (by no means production ready, but you can use it as an inspiration, feel free to comment improvements).</p><p>Note that we are not losing any certainty and safety by using fakes, since if the interface, data format or something else regarding the real services we use changes, the integration test will catch that.</p><p>What fakes enable us to achieve is that non-integration tests are much faster since fakes run locally in memory and do not really connect to the outside world. Additionally, we can simulate scenarios that we are not able to control with real services, i.e. when service connection fails. This way we check that the functionality as a whole handles these cases gracefully, or at least in a way we expect it to do.</p><p>We can visually see this solution in <em>Figure 4</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*QMDI3KicbbczG4wsuJYYWQ.png" /><figcaption>Figure 4: Solution 3 but with faster tests and development time.</figcaption></figure><p>This solution has all the desired properties that we wanted. In essence, it tests all the levels:</p><ul><li>✓ low level connectors to the outside world work = tested by <strong>integration tests</strong></li><li>✓ business logic works under many edge cases = tested by <strong>unit tests</strong></li><li>✓ the connector code that glues all together works well, and works well even on service failures = tested by full tests, but is fast since using fakes</li></ul><p>Even though it tests all the levels correctly, it does not run too slow and does not have redundant tests. Nice! We are using fakes, so we also have the freedom of specifying the response we want to simulate. This enables us to test multiple full tests to check if all goes okay in case of service failure for example.</p><p>Not sure about you, but with this test suite I am pretty confident my code does what I intend it to do.</p><p>To demonstrate the benefit of this approach, imagine your manager comes and tells you that you need to filter transactions that are based in the US, besides having value larger than 100$.</p><p>What we would do is change the basic full test <strong>C1</strong>, add and implement function <strong>f5</strong> that does the filtering and unit test it. Unit testing would check it works normal and under edge cases (country code not present, wrong country code etc), while the full test would change the feature definition. And that’s about it. We added a functionality, but are sure we did not break the rest of the system since there are other levels of tests in place.</p><h3>Conclusion</h3><p>The approach shown in the article is specific for my style of coding and structuring. Feel free to adapt it or make up a totally new approach for your specific use case.</p><p>Still, there are some general takeaways that I hope you remember and take with you:</p><ul><li>Testing is important for a longer term and larger projects, see <a href="https://tms1337.medium.com/but-dude-tdd-is-so-slow-and-besides-it-all-boils-down-to-the-same-sh-t-78ea3e8afe6d">this article</a> for simulation that tries to prove that.</li><li>Even though testing is important, it is important to plan the test structure as well. Otherwise you will have a false sense of security.</li><li>When creating and evaluating a testing structure and a system, define the <strong>desirable properties</strong> first. Then craft your system according to that. You can use the properties we mentioned as important, but you might have a totally different set of metrics that are relevant for you.</li></ul><p>And that’s all for now. In the future, I will write a followup article that follows this methodology but with specific code examples so that you can get a feel of the real stuff. Currently it’s all a bit abstract, and even though you probably understand the concept, we could use some good old code to understand exactly what’s happening.</p><h3>Heey heey</h3><p>Wanna connect via Twitter or spiritually?<br><strong>My Handle: </strong><a href="https://twitter.com/faruk_mustafic">https://twitter.com/faruk_mustafic</a><strong><br>My mantra</strong>: <em>If the code comes last, it lasts. Think more, code less.</em></p><blockquote>Thanks for reading this chunk of text, not a small thing at all.<br>I am Faruk Mustafic, the author of the blogpost,<br>or sometimes I go by <strong>tms1337</strong>, the <strong>Gradual Simplifier</strong> .<br>All feedback welcome, especially the negative one, since that way you improve.</blockquote><p>{<br> <strong>const</strong> { Passionate educator and visualizations lover }<br> <strong>const</strong> { Senior Javascript software engineer with 6y of experience in love with functional pipes and TDD }<br>}</p><p><strong>Swipe me right, the Medium way:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fslidetosubscribe.com%2Fembed%2Fme&amp;dntp=1&amp;display_name=Slide+to+Subscribe&amp;url=https%3A%2F%2Fslidetosubscribe.com%2Fme%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slidetosubscribe" width="450" height="152" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f49754ae9fcb9cf63e6be256dabe02e/href">https://medium.com/media/9f49754ae9fcb9cf63e6be256dabe02e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfe972726a3d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/upstart-services/getting-it-right-why-and-how-to-structure-your-tests-part-00-bfe972726a3d">Getting it right: Why and how to structure your tests [part 00]</a> was originally published in <a href="https://medium.com/upstart-services">The Upstart blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The identity crisis: “Testing costs me too much time for nothing?”]]></title>
            <link>https://medium.com/upstart-services/but-dude-tdd-is-so-slow-and-besides-it-all-boils-down-to-the-same-sh-t-78ea3e8afe6d?source=rss-fb953933de60------2</link>
            <guid isPermaLink="false">https://medium.com/p/78ea3e8afe6d</guid>
            <category><![CDATA[startup-lessons]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[test-driven-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[simulation]]></category>
            <dc:creator><![CDATA[Faruk Mustafic]]></dc:creator>
            <pubDate>Mon, 14 Dec 2020 04:24:14 GMT</pubDate>
            <atom:updated>2021-06-13T21:48:19.193Z</atom:updated>
            <content:encoded><![CDATA[<h4>Is short term pain of testing for long term gain worth it? Is there even a long term gain in the first place? Simulation time!!!</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*QyfpL6BlZKrv87fc" /><figcaption>Don’t burn what you earn by not investing additional time now for the better tomorrow (image source <a href="https://unsplash.com/@jpvalery">Jp Valery</a>)</figcaption></figure><p>Tradeoffs… We are the software crew, so this is our daily routine. Picking the coding methods, frameworks, cloud providers and anything in between.</p><p>I am using TDD (or at least I like to think I am) when writing code. Don’t worry, it’s not one of those <em>TDD or TDDie posts</em>.</p><p>This is a story about how I questioned some of the premises I have taken for granted for so long, and wanted them answered using hard solid data. The question is:</p><blockquote>Under which conditions is method X profitable in the long-run even though it takes more time short-term?</blockquote><p>For me X = TDD, but for you it can be something else.</p><p>It can be a controversial topic, but what I know for sure is that every day at least I have a method for approaching the problems I face. This is a sufficient benefit for me on its own. Though, is it worth the price? Let me guide us through the process of trying to find out.</p><p>The story begins with the my first green passing test suite.</p><p><strong>At first, it all seemed simple</strong>: It is true that with tests, some things take longer to implement initially. On the other hand, by first writing tests, I wrap my head around a problem. Besides, I am counting on the long-term savings I am making by introducing less technical debt and preventing regressions from occurring when refactoring or otherwise changing code. And dem gainzzz are real long-term, right? … Right? Anybody?</p><p>The other day, I asked myself if this was really true. There are those moments when you start questioning even the most elementary premise you go by. I mean, I do believe it is, but can I somehow quantify it? Or at least show to myself that it makes some sense? Once I started thinking about it, I felt more and more uncomfortable not having the answer and blindly following the method without evert trying to analyze it a bit deeper. At least in this way.</p><p>So finally one afternoon, I came up with an <strong>idea</strong>:</p><blockquote>Can I make a simple mathematical model that simulates what would happen with and without using some method that initially takes longer, but reduces technical debt in the long run.</blockquote><p>This is not TDD specific, and is applicable to any method with such characteristics. I personally would use this simulation to justify my use of TDD of course.</p><blockquote>Please take a note that this model is really crude, the numbers and assumptions are best guesstimates off top of my head. So consider this post as a conversation starter of sort.</blockquote><p>If it really does get the conversation started, you can contact me directly via my <a href="https://twitter.com/faruk_mustafic">Twitter handle</a> or in the comments down below.</p><p>Sorry to say this, but I have a disclaimer to make: don’t use the data shown here to go to your naggy friend to notify him that <em>you told him so. </em>Do your own research, play with the model and make your own conclusions.</p><p>Or even make a new shinny fancy statistical model that will take a lot more factors into consideration. I would be glad in that case, because inspiring somebody to do something has a merit of its own.</p><h3>Our goal</h3><p>It is always good to clearly state what you want, not just when running simulations. Repeat after me… We… Want…</p><blockquote>We want to measure if it is profitable to invest additional effort in TDD or similar approaches given the potential reductions in cost and time.</blockquote><h3>Model assumptions</h3><p>First let’s agree to this: we will examine the assumptions and results and only then go into the mathy meat of the model. Also spaces &gt; tabs if we are on the streak 🤭.</p><p>So let’s open up the question that each modeler meditates on:</p><blockquote>What does our model assume?</blockquote><p>Before dwelling on that, we should briefly introduce some naming.</p><p>Let’s call coding methods:</p><ul><li><strong>TESTED: </strong>i.e.<strong> </strong>TDD and other methods that involve testing or other practices that improve reliability</li><li><strong>QUICK: </strong>i.e. non-tested OOP code with bad patters sprinkled on top</li></ul><p>Below, in <em>Table 1</em>, is a list of our estimates for method attributes. Of course you still don’t know what these attributes means, but you if you kept track so far, you know that the next step is explain each one of them.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf3d91097cb427a52a8d2e804b3d80b6/href">https://medium.com/media/cf3d91097cb427a52a8d2e804b3d80b6/href</a></iframe><p>The meanings of the factors are as follows:</p><ul><li>factor = Measures how many times longer the method takes to implement the same code compared to the QUICK<strong> </strong>method. Or in a nutshell, this factor measures how much additional work is added <strong>while coding</strong>. We assume that each feature takes the same amount of time to build (unrealistic I know, but let’s go one step at a time 👶).</li><li>debt = This one might seem complex, but it is entirely natural and logical. Just follow along. It measures how much more time each new feature or a change takes just because of the effect of <strong>technical debt</strong>. So for example, if debt=0.01 this means even if we add a new feature of the sample complexity as the previous one, it will still take <strong>1%</strong> more time to implement. This happens for various reasons, and one of the best known ones is the so called spaghetti code. The more you add to it, the more time you need to spend locating the place where the new feature or change should reside.</li><li>old_bugs = The percentage of time spent on fixing the <em>old bugs</em>. These are bugs that were introduced into the system with some of the previous features and not the ones being added at the moment. Or even the bugs re-introduced again because we didn’t have tests covering those cases.</li><li>new_bugs = We all know the feeling, we spend some of our time chasing bugs caused by edge cases we forgot to cover when hastily trying to bring a new feature closer to production. There is a saying <em>Festina lente </em>in Latin meaning <em>Make haste slowly</em>. Sometimes, by trying to be faster, you end up being slower. With this attribute, we measure the percentage of time spent fixing this type of bugs and glitches.</li></ul><p>Estimates in <em>Table 1</em> roughly assume that TESTED halves the number of both old and new bugs, reduces technical debt by a factor of 3 when it’s really small, but lasts 50% longer. These estimates are near the ones outlined in <a href="https://medium.com/free-code-camp/8-observations-on-test-driven-development-a9b5144f868">this article</a>. Initially we assume a small amount of technical debt to be reduced in the first place (0.3% debt variable), but later on we will see that the larger the debt, the more the effect of TESTED is felt.</p><p>You might have noticed while reading the attributes that we are already making some bold assumptions here, exponential growth due to technical debt, roughly the same complexity of each feature… What’s next, constant array search time?</p><p>Now you are starting to see why I said this is a <strong>simple,</strong> <strong>rough,</strong> <strong>model</strong>. I already hear the suggestions flowing, all valid and fair points, but I only wanted to get some initial numbers to play with, model can be improved for sure. Besides, you haven’t yet read the entire post yet. Maybe I have some niceties down the road 🔽</p><p>Given we know what the attributes mean, here they come, the long awaited assumptions of our model that can be read out from the factors, but let’s explicitly state them:</p><ul><li>TESTED takes more time. This is what we started with, if it took same time, here would be nothing to discuss.</li><li>TESTED reduces the accumulation and the effect of technical debt.</li><li>TESTED reduces the rate of bug introduction since it tests more cases than QUICK. Also impossible to re-introduce the bug or break the tested case that worked before.</li><li>Part of time is spent debugging new code (new_bugs). Since TESTED includes writing down the tests and edge cases first, this reduces the percentage of time spend debugging. Or at least speeds up debugging process by telling us where the code fails (in which tests).</li></ul><h3>Results</h3><p>Aaand lift off 🚀. We start our simulations with initial parameters as shown in <em>Table 1</em> so we get some rough ideas and get this baby rollin’.</p><p>We use feature count F as our x variable rather than time. It is purely for convenience. This way it was simpler to write down the model.</p><p>We assume all features take roughly the same, about a week, or 5 working days with 8 working hours with QUICK method (hah the POs eternal dream).</p><p>Remember, we compare TESTED to the QUICK that has bad practices. But we still assume reasonably small variable that measures technical debt accumulation.This is intentional — our goal is to compare the different approaches, even in case of low potential for improvement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QewDRq-xy-NggV1AR0pJTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QF89lx5ek9cYMhV2KjyQTg.png" /><figcaption>Figure 1: <strong>left</strong>: Simulation result for F = 20 run with parameters from Table 1. <strong>right</strong>: Same simulation with F = 500.</figcaption></figure><p>If we run simulation for onlyF = 20 features, even after only 20 features built, the <strong>QUICK</strong> method takes double the time to build the same number of features as <strong>TESTED </strong>as per <em>Figure 1</em>. Not so quick after all.</p><p>But if we crank it up to F = 500, we start to notice the even larger difference. And it is growing exponentially it seems!</p><p>Okay, we kind of understand what’s happening. The technical debt slows down the <strong>QUICK</strong> method more and more.</p><p>If we convert developer hours to dollars by a fixed rate of 40$/hour, we get result as shown in <em>Figure 2</em>. Means rough loss of <strong>1,350,000$</strong> on <strong>~500</strong> features each taking a week to implement. Ouch. Considering we are just a startup, the results we got is not happy news. But then again, perhaps our assumptions are way off.</p><p>From now on we will only show this final graph, because <strong>money talks</strong> after all.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aLu01LW1JKkNBFnH6xp92Q.png" /><figcaption>Figure 2: Simulation result for F = 500 run with initial parameters.</figcaption></figure><h3>Real world is non-deterministic</h3><p>By fixing the values to some constants or by calculating some deterministic transformation of the value, we do gain some insight, but we only see one possible scenario. That’s why we are going to add something to our model that we have all been waiting for: raNDoMnEsS. That’s right, let us get our hands dirty with some real-world like data and see what happens. I am starting to get that feeling, are you? You know the one… You must know the one. Some people are using stims, we are using sims. And we sure do like it.</p><p>Before the goodies, Clap Clap to you for reading this far! Here is the <a href="https://colab.research.google.com/drive/1T54zmGCaivrHgg85hXqeP9djt-VRMH1X?usp=sharing">notebook link</a> as promised so you can play around if you want to. I will leave it at the bottom as well.</p><p>Since it is randomized simulation, we run each one <strong>20</strong> times and pick the most representative sample. We will do 4 simulations:</p><ul><li>The same old: Parameters from <em>Table 1</em></li><li>Methods closer together: debt = 0.015 for QUICK</li><li>We are really slow: factor = 3 for TESTED</li><li>A lot of debt to reduce: debt = 0.005 for QUICK</li></ul><p>The results are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KtM5EazBcy3NOq5BEphy3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MHNYnaEabCFce7JLBsMPvg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8f0dcz6P6FnHDJIal2ycw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HW2kpUJwCh4rxluUIppemg.png" /><figcaption>Figure 3: Results. First three assume small percentage of technical debt already progressively make TESTED method worse. The last one assumes larger percentage of technical debt.</figcaption></figure><p>If we take a look <em>Figure 3 </em>and a first graph which is simulation with our default parameters, we can see that by running the randomized version we save up to <strong>$2,400,000</strong>. That’s a full funding round!</p><h3>Conclusion</h3><p>Recall that we wanted to</p><blockquote>Under which conditions is method X profitable in the long-run even though it takes more time short-term?</blockquote><p>To sum the results up, after these experiment runs, we see data that roughly shows (in order of graphs shown in <em>Figure 3</em>)</p><blockquote><strong>Simulation 1</strong>: Even with small values for technical debt factor, where there is little margin for improvement,.it is almost twice as profitable to use the TESTED approach (if done right).</blockquote><blockquote><strong>Simulation 2</strong>: If the approach TESTED takes even more time compared to QUICK than assumed by default parameters, but still reliefs an existing non-trivial debt burden, it is profitable. Catch is that it will take some time to show the improvements.</blockquote><blockquote><strong>Simulation 3</strong>: When TESTED takes too much extra time and there is no real technical burden to relief, only then using TESTED makes no sense as it only makes the development process longer.</blockquote><blockquote><strong>Simulation 4</strong>: When technical debt accumulation variable for QUICK is high, TESTED is a no brainer to use.</blockquote><p>We now see that debt is the dominating variable. Variable factor can play a role for some time if large enough, so it should not be ignored. We should always strive to have a simple actionable conclusion. Preferably measurable. So, to simplify even more, the question is</p><blockquote>How low can you go?</blockquote><p>Meaning, how low can you reduce the debt factor relative to the other method. And also, how much do you perfect and become proficient at your method so that you reduce your factor.</p><p>You can’t control how bad the other method is. But you can control how good your method is. Because of this, it pays off to research various options until you find the sweet spot which enables you develop at the right multiple compared to other method so that you are saving time and money.</p><p>The variables you do control by your skill and hard work are your debt and factor. For example, testing strategy is of uttermost importance, since if we have redundant tests, we are directly impacting our factor in a negative way. So we must find a good one. Also if we don’t test the right things, we increase our debt since bugs will slip under our radars.</p><p>And this is where consuming quality content from people that have already went through that journey comes in. This is my initial post to get the ball rolling with something quick and dirty I had in my back pocket. But I do plan on publishing more higher quality content in areas such as teaching coding without code, adaptable code via good software architecture and structure, software development techniques, TDD and more.</p><p>If interested, swipe that thunder and let’s get this party started. Following the COVID restrictions of course.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fslidetosubscribe.com%2Fembed%2Fme&amp;dntp=1&amp;display_name=Slide+to+Subscribe&amp;url=https%3A%2F%2Fslidetosubscribe.com%2Fme%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slidetosubscribe" width="450" height="152" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f49754ae9fcb9cf63e6be256dabe02e/href">https://medium.com/media/9f49754ae9fcb9cf63e6be256dabe02e/href</a></iframe><p>Based on the points listed, there are some actionable conclusions as well:</p><ul><li>If the current method is good enough, i.e. using tests but not TDD, it might not be worth switching since there is not sufficient technical debt to be reduced.</li><li>Avoid actions that increase the development time without decreasing the technical debt levels. For example, we should not write redundant tests. This is why you should plan your testing strategy really well. But given good sources and readings, you should be good to go.</li></ul><h3>Caveats</h3><p>Even though this model is far from a fully accurate one, I do feel more assured that I tend to gain time and money long-term by using TDD. I also hope to spark somebody’s passion to make an even better and more accurate model.</p><p>Better model with more variables would perhaps spit out different numbers, but I am now pretty certain that <strong>if</strong> the current method is accumulating technical debt and/or not testing code, there is more than enough room to introduce TDD as an approach.</p><p>Once again (getting boring) be my guest and fiddle with the model and prove the point in one or the other direction. There are many variables I didn’t consider or assumptions that I could have modeled differently. Maybe I am totally wrong and am living in delusions 😕 You know where to <a href="https://twitter.com/faruk_mustafic">find me</a> if urgent information pops up.</p><h3>The Math Part</h3><p>If you are one of those people that are not into it, sorry, it had to come to this at one point. But we just can’t go any further without knowing the model. Heck, we got pretty far without knowing it anyways.</p><p>As per The Great Math Modeling Guide, let’s go to <em>Step 1</em> (that we do as Step 100): Explicitly write the mathematical equation of the model</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/0*6ZPZ7N1h9PZJUXvm" /><figcaption>Equation 1: And then there was light</figcaption></figure><p>All clear? Nice, we shall continue with simulations then.</p><p>Okay, fine, I <strong>can</strong> tell you which symbol stands for what:</p><ul><li>T_0 is average feature/change time</li><li>M is method factor</li><li>debt is technical debt factor that makes each new feature last longer</li><li>new and old are percent of time spent fixing new and old bugs respectively</li><li>f_i is the time it takes to code the i-th feature/change</li><li>Then total time cost F is just a sum it takes time to code each new feature/change. We sum as many features as we want to make the comparison on.</li><li>a(duration), b(factor), and c(debt, i) are functions that allow us to control and scale duration in hours of each feature. For initial experiments a and b are identity functions lambda x: x , while c is exponential c = lambda debt, i: (1 + debt) ** i</li></ul><h3>Resources</h3><p>Notebook: <a href="https://colab.research.google.com/drive/1T54zmGCaivrHgg85hXqeP9djt-VRMH1X?usp=sharing">here</a></p><h3>References</h3><p>[x] Not this time, I have put them in links directly</p><h3>Heey heey</h3><p>Wanna connect via Twitter or spiritually?<br><strong>My Handle: </strong><a href="https://twitter.com/faruk_mustafic">https://twitter.com/faruk_mustafic</a><strong><br>My mantra</strong>: <em>If the code comes last, it lasts. Think more, code less.</em></p><blockquote>Thanks for reading this chunk of text, not a small thing at all.<br>I am Faruk Mustafic, the author of the blogpost,<br>or sometimes I go by <strong>tms1337</strong>, the <strong>Gradual Simplifier</strong> .<br>All feedback welcome, especially the negative one, since that way you improve.</blockquote><p>{<br> <strong>const</strong> { Passionate educator and visualizations lover }<br> <strong>const</strong> { Senior Javascript software engineer with 6y of experience in love with functional pipes and TDD }<br>}</p><p><strong>Swipe me right, the Medium way:</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fslidetosubscribe.com%2Fembed%2Fme&amp;dntp=1&amp;display_name=Slide+to+Subscribe&amp;url=https%3A%2F%2Fslidetosubscribe.com%2Fme%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slidetosubscribe" width="450" height="152" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f49754ae9fcb9cf63e6be256dabe02e/href">https://medium.com/media/9f49754ae9fcb9cf63e6be256dabe02e/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78ea3e8afe6d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/upstart-services/but-dude-tdd-is-so-slow-and-besides-it-all-boils-down-to-the-same-sh-t-78ea3e8afe6d">The identity crisis: “Testing costs me too much time for nothing?”</a> was originally published in <a href="https://medium.com/upstart-services">The Upstart blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>