<?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 Karen Trubovitz on Medium]]></title>
        <description><![CDATA[Stories by Karen Trubovitz on Medium]]></description>
        <link>https://medium.com/@karentru?source=rss-b871f38d276e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*h4pBVq3g8SMrKYAYgWe2bQ.jpeg</url>
            <title>Stories by Karen Trubovitz on Medium</title>
            <link>https://medium.com/@karentru?source=rss-b871f38d276e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 23:49:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@karentru/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[From Tedious to Effortless: How We Built an AI Agent to Do Our Job — And How You Can Too]]></title>
            <link>https://medium.com/@karentru/from-tedious-to-effortless-how-we-built-an-ai-agent-to-do-our-job-and-how-you-can-too-87f3c529fe3f?source=rss-b871f38d276e------2</link>
            <guid isPermaLink="false">https://medium.com/p/87f3c529fe3f</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Karen Trubovitz]]></dc:creator>
            <pubDate>Wed, 14 May 2025 06:08:02 GMT</pubDate>
            <atom:updated>2025-05-14T06:08:02.555Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Tedious to Effortless: How We Built an AI Agent to Do Our Job — And How You Can Too</h3><p><strong>TL;DR</strong> — Why spend hours making manual changes when the right automation tool can do it for you in minutes? 🚀</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BuGqLHvMtFGL4__HhtcBUg.jpeg" /></figure><p><strong>As a manager, I’ve always looked for ways to make code maintenance more efficient</strong> — <strong>especially for repetitive tasks like writing unit tests and refactoring code.</strong> When I saw how much time my team was spending on these manual processes, I knew there had to be a better way.</p><p>That’s what led me to create <strong><em>Torii Genie</em></strong>, an AI-powered tool designed to automate code maintenance tasks. It started as an idea after an AI hackathon at Torii but quickly became a game-changer in our efforts to improve our project’s quality metrics.</p><p>You might be wondering why we didn’t just use <em>Cursor</em>, <em>Bolt</em>, or <em>Aider</em>. Keep reading to find out 😇</p><p>In this article, I’ll share the challenges we faced, how I built <em>Torii Genie</em>, and the impact it had on our project — plus how AI can help other teams streamline their development process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X0PmwtDX_cIcZiNTK0iVHg.gif" /><figcaption><strong><em>Torii Genie in action</em></strong></figcaption></figure><h3>The Challenge: Why Torii Genie Was Built</h3><p>We aimed to improve the code quality metrics of a project, focusing on key aspects such as test coverage and TypeScript adoption. These metrics are crucial for ensuring reliability, maintainability, and scalability. Higher coverage helps catch issues early, reduces bugs, increases development velocity by giving developers confidence to make changes, and fosters better collaboration.</p><p>At the time, our project had 62% test coverage and 33% TypeScript coverage — leaving significant room for improvement. Traditionally, developers had to manually write tests or convert JavaScript code to TypeScript, which was time-consuming and tedious.</p><blockquote>I was frustrated that we were investing a significant amount of time and effort, yet the needle wasn’t moving much.</blockquote><h3>Bringing Torii Genie to Life</h3><p>During an AI hackathon at <em>Torii</em>, I was inspired to create an AI-powered solution to tackle these challenges. That’s how <em>Torii Genie</em> was born — an intelligent bot designed to assist with code refactoring by applying a GPT-based prompt across multiple code files simultaneously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*AOwxNdU3W1KCO1ZK8EziFw.jpeg" /><figcaption>Hackatorii</figcaption></figure><h4>Modular and Configurable Infrastructure</h4><p><em>Torii Genie</em> is a modular system that allows developers to easily add different bots for various tasks through configuration. Users can define the AI model they want to use and specify the bot’s tasks:</p><pre>{<br>  &quot;model&quot;: { // configure AI model<br>     &quot;name&quot;: &quot;openai&quot;,<br>     &quot;type&quot;: &quot;gpt-4o&quot;<br>  },<br>  &quot;geniesConfig&quot;: {<br>    &quot;HOW_TO_CONFIG&quot;: { // configure a bot<br>      &quot;description&quot;: &quot;Refactoring task details for clarity and readability&quot;,<br>      &quot;prompt&quot;: &quot;string | file path - User prompt for detailed instructions&quot;,<br>      &quot;instructions&quot;: &quot;string | file path - System instructions for AI guidance&quot;,<br>      &quot;handlerPath&quot;: &quot;file path - Path to AI output handler&quot;,<br>    }<br>  }<br>}</pre><p>Each bot consists of a user prompt, system instructions, and a handler function that processes AI-generated output and applies the refactoring.</p><h4>Example: Automating Unit Test Generation</h4><p>To increase test coverage, I developed a bot that automates unit test creation. This bot integrates with OpenAI’s models and generates nearly complete pull requests.</p><p>The bot is designed to add unit tests specifically for our integrations. I provided examples of good tests we already have and trained it to generate high-quality results without the need for back-and-forth, unlike other AI tools that aren’t designed for this specific task and usually require additional manual effort.</p><p>The bot’s configuration, prompt, instructions, and output handler are stored in Git, allowing multiple developers to use it consistently over time.</p><h4>Here’s the configuration for the unitTestGenerator bot:</h4><pre>&quot;unitTestGenerator&quot;: {<br>  &quot;description&quot;: &quot;Generates a Jest unit test with 100% coverage for a specific integration.&quot;,<br>  &quot;prompt&quot;: &quot;scripts/codeGenie/genies/unitTestGenerator/prompt.ts&quot;,<br>  &quot;instructions&quot;: &quot;scripts/codeGenie/genies/unitTestGenerator/instructions.txt&quot;,<br>  &quot;handlerPath&quot;: &quot;scripts/codeGenie/genies/unitTestGenerator/handler.ts&quot;,<br>  &quot;targetIntegrationType&quot;: &quot;&lt;Target integration type&gt;&quot;<br>}​</pre><h4>Example Prompt:</h4><pre>Write a 100% coverage unit test using Jest for this file: <br>{integrationCodeFileAsString}.<br><br>Additional context: <br>{additionalCodeFilesAsString}.<br><br>Return the response in the following JSON format:<br>{<br>  &quot;data&quot;: {<br>    &quot;testFile&quot;: &quot;Test content for ${testDirectoryPath} folder&quot;,<br>    &quot;fixtures/responses&quot;: { &quot;{fileName}&quot;: &quot;JSON with mock API response&quot; },<br>    &quot;fixtures/expected&quot;: { &quot;{fileName}&quot;: &quot;JSON with expected result&quot; }<br>  }<br>}​</pre><h4>Example Instructions:</h4><pre>You are a code assistant.<br>Your task is to write Jest unit tests with 100% coverage for integrations.<br>You will be provided with the following files: XXXX, and you will provide unit tests for YYY file.</pre><p><em>Torii Genie</em> sends the prompt and instructions to the AI model API, and the API response — the AI-generated test files — is then processed by the bot’s handler.</p><pre>export const handler = (<br>   genieConfig: { targetIntegrationType: string }, <br>   aiResponse: string<br> ): void =&gt; {<br>    // Parse the AI response<br>    // Add test and fixture files to the correct location in the project<br>}</pre><p>A developer then reviews the AI-generated code, fine-tunes it if needed, and opens a PR.</p><p><strong>Review, tweak, ship — done! 🚀😃</strong></p><h3>Results: The Impact of Torii Genie</h3><p>The development of <em>Torii Genie</em> and its <em>unitTestGenerator</em> bot led to:</p><ul><li><strong>Increased Test Coverage:</strong> The project’s test coverage improved from 62% to 84%, with most tests quickly added using the <em>unitTestGenerator</em> bot — a <strong>10% boost in just one day!</strong> Now that we have it and it has proven to do an awesome tool, we can aspire to reach 100%!</li><li><strong>Improved productivity</strong>: The bot accelerated the test generation process by 3–4x.</li><li><strong>Reduced manual effort</strong>: Developers could focus on strategic tasks rather than repetitive test writing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zLv28arevxTHT52C91CX8g.jpeg" /></figure><p>While test coverage alone doesn’t guarantee quality, it provides a strong foundation for making confident changes and encourages more ambitious improvements. As AI-generated code becomes more widely used, these tests and coverage will be crucial for verifying AI outputs.</p><h3>Broader Implications: Beyond Testing</h3><p>The applications of <em>Torii Genie</em> go beyond unit testing. It can also be used to automate other code maintenance tasks, such as:</p><ul><li><strong>Converting JavaScript to TypeScript</strong>, to enhance type safety, improve developer experience, and reduce runtime errors.</li><li><strong>Migrating from React class components to React hooks</strong>, to modernize the codebase, improve readability, and align with current best practices.</li><li><strong>Updating legacy libraries to newer versions</strong>, to ensure compatibility, security, and performance improvements.</li></ul><p>As software evolves, maintaining and modernizing codebases becomes crucial. AI-powered tools like <em>Torii Genie</em> can significantly reduce manual work, improve team morale, and keep projects up to date.</p><h3>Conclusion</h3><p>Investing in AI-driven tools can transform workflows and enhance efficiency. <strong>Sometimes, it’s better to invest in a tool that automates changes rather than manually implementing those changes one by one.</strong></p><h3>Final Note</h3><p>This project was developed before tools like <em>Cursor</em> — which now offer similar capabilities — became available. You can choose to build your own custom AI-powered solutions or use existing tools, depending on your specific needs.</p><p>For us, <em>Torii Genie</em> was the perfect fit. It’s <strong>tailored</strong> to our use cases, allows us to easily add more bots, and enables engineers to share useful prompts efficiently.</p><p><strong>The key takeaway:</strong> AI can significantly improve productivity. Consider how you can integrate it into your workflow to work smarter, not harder.</p><p><strong>Originally published on the </strong><a href="https://www.torii.engineering/From-Tedious-to-Effortless-How-We-Built-an-AI-Agent-to-Do-Our-Job-And-How-You-Can-Too-199ed7c9326580c3b687ed5e733ce1c4"><strong>Torii Engineering Blog</strong></a><strong> on February 13, 2025.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87f3c529fe3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kicking Off Complex Features: The Hackathon Approach]]></title>
            <link>https://medium.com/@karentru/kicking-off-complex-features-the-hackathon-approach-c83129644140?source=rss-b871f38d276e------2</link>
            <guid isPermaLink="false">https://medium.com/p/c83129644140</guid>
            <category><![CDATA[alignment]]></category>
            <category><![CDATA[collaboration]]></category>
            <category><![CDATA[feature-kickoff]]></category>
            <category><![CDATA[hackathonindia]]></category>
            <category><![CDATA[product]]></category>
            <dc:creator><![CDATA[Karen Trubovitz]]></dc:creator>
            <pubDate>Tue, 21 Jan 2025 14:19:00 GMT</pubDate>
            <atom:updated>2025-01-21T14:19:00.358Z</atom:updated>
            <content:encoded><![CDATA[<h4>Discover how a focused, collaborative sprint helped us test feasibility, inspire innovation, and align stakeholders for an ambitious Q1 launch.</h4><p>During our end-of-year planning, we identified a key initiative for our company’s strategy which we wanted to prioritize in 2025. To support this goal, we aim to release a significant feature in this area as early as possible — ideally putting it in our customers’ hands by early Q1. If this timeline proves unrealistic, we may need to reassess our approach or shift focus to other features in this area.</p><p>This article was co-written by <a href="https://www.linkedin.com/in/karen-trubovitz-88a901169">Karen Trubovitz</a>, Engineering Team Lead, and <a href="https://www.linkedin.com/in/uri-hershkovitz-017b8a92/">Uri Hershkovitz</a>, Product Manager, at Torii.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eqs3AzVy1nXRZCKEPOlXnA.png" /></figure><h3><strong>The Story Behind the Hackathon</strong></h3><p>With a Q1 release deadline and critical ongoing projects that demanded our team’s current attention, we needed a creative, focused approach to test feasibility without derailing our team.</p><p>Our vision was clear, but questions loomed large. Could we build something compelling within our timeframe? Would the core functionality excite stakeholders? Was the lift realistic given our resources?</p><p>Our solution? A hackathon.</p><blockquote><em>A </em><strong><em>Hackathon</em></strong><em> is a short, focused, sprint aimed to test a single specific idea, answer a specific question or create an innovative project. It is usually between several hours to several days long at most.</em></blockquote><p>A hackathon provided the perfect environment to tackle these unknowns — a focused, time-bound sprint to validate our vision and answer these critical questions while utilizing minimal development resources.</p><p>From this point forward, when reading roman text, you’ll read Karen’s perspective, and when you are reading <em>italicized text, you’ll read Uri’s perspective.</em></p><h3>Why a Hackathon?</h3><p><em>The hackathon was a critical step to validate the feasibility of our feature plan within an ambitious timeframe. It allowed us to test whether the bare-bones skeleton will work as intended, and the potential shown could excite stakeholders even when showing only basic functionality and using existing components.</em></p><p>The hackathon not only tested the technical side but also created a live, interactive version of the feature for stakeholders (PMs, designers, AEs, and CSMs) to try out, helping teams start working together effectively. This allowed us to provide a solid starting point for our planned feature while using only a small development team</p><p><em>This hands-on approach enabled us to answer fundamental questions early, ensuring we stayed aligned with timelines and stakeholder expectations</em></p><p>The process allowed us to test a data model, check if it could handle growth, and find challenges early while exploring solutions. Without this, technical issues might have been discovered later in development, wasting the entire team’s time while waiting for the product team to find a solution that fits the technical needs.</p><p><em>This helped shape the feature release order to help mitigate risk and maximize value to customers.</em></p><h3>The Hackathon Experience</h3><p>During the three-day hackathon, we formed a small, dedicated team to focus on this effort without disrupting the larger team’s ongoing project.</p><p><em>We sat in a dedicated space, and worked face-to-face, to make sure our efforts were focused on the most pressing questions, and providing the most bang for our limited buck. It also allowed us to easily collaborate and rapidly make micro decisions to reach our goal, that could slow down a more structured development process.</em></p><p>We worked on a dedicated git branch without formal code reviews, focusing on building a basic framework for future development. We skipped things like automated tests and detailed validations to concentrate on testing feasibility and identifying areas that would need more work later.</p><p><em>Having a hands-on product manager allowed us to QA each code push, and to craft a demo experience that matched to future product vision and strategy. I could then be</em> <em>an ambassador for the feature and its vision, and leverage the limited feature preview to gauge how the full feature might be received.</em></p><p>We started with a simple data model defined as constants in the code, planned a basic frontend structure, and focused on the most important tasks. By keeping the proof of concept simple and specific, we created a solid foundation for building a scalable feature in the future.</p><p><em>Additionally, we used the initial functionality to spark productive discussions amongst internal stakeholders about prioritizing feature capabilities and defining the minimal requirements for the MVP launch.</em></p><h3><strong>Why You Should, or Shouldn’t Try This Out</strong></h3><p><em>Hackathons come with challenges. For one, the initiation phase may not include the full team, leading to difficulty with onboarding them and potential disengagement later on when full development begins.</em></p><p>The fast-paced, unstructured nature of hackathons might not suit everyone, as it requires quick thinking, flexibility, and acceptance that the work and code may be temporary.</p><p><em>There’s also a risk of creating “sacred cows” in design or engineering — ideas that are difficult to discard — even if the hackathon code or approach ultimately proves unsuitable. There is definitely a world where you’ll need to discard all hackathon-generated code, which can raise concerns about wasted effort.</em></p><p>However, if you overcome these challenges, you will be able to quickly test features, see results quickly, and understand what’s possible early in the process.</p><p><em>This fast-paced environment fosters productive discussions with stakeholders, helping to identify technical hurdles and product or design questions that need to be addressed before full development begins. The results achieved can build confidence among stakeholders and crystalize potential hurdles and decision points that may lie ahead.</em></p><p>The hackathon can create a technical foundation to speed up future work while being a fun and rewarding experience for the team. It gives everyone a chance to brainstorm, innovate, and solve problems together in real time.</p><h3>Conclusion</h3><p>In just three days, our hackathon provided clarity, confidence, and a clear path forward. Whether we succeed long-term remains to be seen, but this was a critical first step in building something remarkable.</p><p>Have you used a hackathon to kickstart a complex project? How did it go, and what lessons did you learn? What other approaches have you tried, and how did they work? Share your thoughts in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c83129644140" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Would You Teach Programming to Beginners in Just 30 Minutes?]]></title>
            <link>https://medium.com/@karentru/how-would-you-teach-programming-to-beginners-in-just-30-minutes-d9f517eba185?source=rss-b871f38d276e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9f517eba185</guid>
            <dc:creator><![CDATA[Karen Trubovitz]]></dc:creator>
            <pubDate>Sun, 22 Dec 2024 06:01:35 GMT</pubDate>
            <atom:updated>2024-12-22T06:01:35.068Z</atom:updated>
            <content:encoded><![CDATA[<h4>In this blog, I’ll share how I managed to do exactly that.</h4><p>The activity was designed for a group of 15-year-old girls with no prior programming background.</p><h3><strong>Start with a Simple Analogy</strong></h3><p>To explain what code is, I used one of my favorite analogy — recipes.</p><p>Imagine you’re baking a birthday cake for a friend. You’d start by deciding on the kind of cake you want (my favorite is cheesecake 🍰) and then follow a recipe step by step. If you follow it correctly, the result will be a delicious cake.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*6VGRURfxWXc8GfPgkEX1tA.png" /><figcaption>Created with DALL·E</figcaption></figure><p>Programming works the same way. A programmer writes step-by-step instructions for a computer to create a specific feature with a specific user experience, just as a recipe guides a baker.</p><p>To make the idea more engaging, I shared the first minute of Josh Darnit’s “Exact Instructions Challenge” video (link provided in the footnotes).</p><p>In many ways, programmers are like master chefs in a limitless kitchen. They don’t just follow recipes — they experiment, combine unexpected elements, and create entirely new experiences. From crafting tools that keep people connected with loved ones to building systems that process data about distant galaxies, programming empowers you to create things that real people use and rely on every day, whether it’s apps, tools, or complete systems.</p><h3><strong>Hands-On Activity</strong></h3><p>I chose a wardrobe app, designed to help users assemble outfits for different events, as the concept for the activity..</p><p>To make the activity relatable, I explained to the girls that we would work on building a specific feature for this app. Drawing on the cake recipe analogy, I highlighted that we would follow a similar process: writing a “recipe” — a program — that gives the computer precise, step-by-step instructions to achieve the desired functionality.</p><h4><strong>The Goal</strong></h4><p>Build a feature in the app that suggests outfit ideas based on the type of event and the user’s request.</p><h4>Part 1: Building a Database</h4><p>To prepare for the session, I pre-created several outfit options for party, holiday, and school events (using ChatGPT). These were displayed on a board for the activity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RIvHETfh8IdZDvjCtg8mIQ.png" /><figcaption>Outfits created with DALL·E</figcaption></figure><p><strong>Classifying Looks</strong></p><p>For each outfit, I asked: <em>“Which event would you suggest this for: Party, School, or Holiday?”. </em>I invited the girls to participate by writing next to each outfit the event they thought it suited best.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ku_A2jt_XW6J4t5IKZyucw.png" /></figure><p>We started by assigning each look to a single category. Then, we explored outfits that could fit into multiple categories.</p><p><strong>Discussion</strong></p><p>I asked them: <em>“Why did you choose these categories for certain looks over others?”</em></p><p>The group shared their reasoning behind assigning specific outfits to categories, leading to a conversation about how our brains naturally classify outfits based on characteristics. For example, white outfits might feel suited for holidays, while dresses and sparkles are typically associated with parties.</p><p>To connect this to programming, I explained that computers also require someone to classify data for them — though in reality, this process can be much more complex. For simplicity, we focused on how classifications and user inputs allow an app to suggest relevant options.</p><p>Finally, I brought it all together by explaining that the group had essentially created a database — a collection of looks with their respective classifications — and that we could now see how the app uses this data to make outfit suggestions.</p><h4><strong>Part 2: </strong>Building User Stories Through Screens</h4><p>I handed out pages representing each step of the app, with the following text, and asked the group to arrange them in the correct order, based on the user’s journey through the app:</p><ol><li><em>Welcome to the chicest app around! Let’s pick a fabulous look :)</em></li><li><em>Party, holiday, or just another day at school? Choose, and we’ll pop up a stylish outfit for you.</em></li><li><em>We’ve picked the perfect look for the weather and the event you selected. How does it look? Do you love it?</em></li><li><em>Not a fan of the outfit? No worries! We’ve got plenty more inspiration for you. We’ll keep going until we find the perfect one.</em></li><li><em>So glad you chose to dress with us! We can’t wait to help you upgrade your look next time.</em></li></ol><p>The result should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CMTcI3hENyXMvjIYRcweXA.png" /></figure><h4><strong>Part 3: </strong>Behind the Scenes — Unpacking t<strong>he App’s Logic</strong></h4><p>I used two colors to represent the app’s flow — one for user input and another for the computer’s actions.</p><ol><li><strong>Opening Screen: </strong>I explained that the app starts by welcoming the user and asking for their name and age. I invited a participant to come up and write their name and age on the board, simulating the process where the computer receives and stores this information in a variable called “user.”</li><li><strong>Choosing an Event: </strong>Next, the app asks the user to select an event — party, holiday, or school. I asked another participant to write their chosen event on the board. Simulating the process where the computer receives and stores this information in a variable called “event”, to the user in the next step.</li><li><strong>Suggesting a Look: </strong>I described how the app accesses its database, finds outfits matching the chosen event, and suggests the first look that matches the chosen event.</li></ol><ul><li>I asked the group, <em>“Do you like this look? Yes or no?”</em></li><li>If the answer was <em>no,</em> I explained how the app would pull the next matching look from the database and suggest it.</li><li>If the answer was <em>yes,</em> the app would move to the final screen.</li></ul><p>4. <strong>Final Screen: </strong>Once the user accepted a look, I explained that the app thanks the user and wraps up the session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7jy3L5et8cUk1LDYIwv_iQ.png" /></figure><p>By the end of the activity, the group understood how the app’s process worked step by step, combining user input with the computer’s logic to deliver results.</p><h4>Part 4: Bridging the Gap — Visual Flow Meets Pseudo Code</h4><p>To connect what we did visually to code, I created pseudo code for the feature in advance, and we walked through it together, explaining step by step how it connects to the application’s screens that we discussed earlier.</p><pre>// Variables<br>const user = login();         <br>const event = chooseEvent();        <br>const looks = getLooksFromDatabase(user, event);  <br><br>// Loop<br>for (look in looks) {<br>  const isUserLoveLook = handleLook(look);<br>  if (isUserLoveLook) {<br>    break; // Exit the loop if the user loves the look<br>  } else {<br>    continue; // Move to the next look if they don&#39;t<br>  }<br>}<br>showEndPage();</pre><ol><li><strong>User Input:</strong></li></ol><ul><li>The user logs in by providing their details (name and age), which are stored in a variable called user.</li><li>They then choose an event, which is stored in another variable called event.</li></ul><p><strong>2. Database Query:</strong></p><ul><li>The app accesses its database and retrieves a list of looks that match the chosen event. This list is stored in the variable looks.</li></ul><p><strong>3. Loop:</strong></p><ul><li>The app goes through the looks one by one using a loop.</li><li>For each look, it asks the user if they like it. This is handled by the function handleLook(look).</li></ul><p><strong>4. Condition:</strong></p><ul><li>If the user likes the look (isUserLoveLook is true), the app exits the loop (break) and moves to the final screen.</li><li>If the user doesn’t like the look, the app moves to the next one (continue) until a suitable look is found.</li></ul><p><strong>5. Final Step:</strong></p><ul><li>Once the user selects a look they love, the app displays the final screen (showEndPage).</li></ul><p>This pseudo code mirrors the process we discussed — moving step by step through user input, database access, loops, and conditions to create the app’s functionality.</p><h4>Part 5: Wrapping It Up</h4><p>The activity concluded with a recap, emphasizing how we explored the creation of an organized “recipe,” or algorithm, that a computer can follow.</p><p>Throughout the session, three key programming concepts were covered:</p><ul><li><strong>Variables</strong></li><li><strong>Conditions</strong></li><li><strong>Loops</strong></li></ul><p>These building blocks allow us to design both simple and complex logic, forming the foundation for much more advanced programming.</p><p>Did you like the concept of this activity? If you’d like to try it out yourself, here’s a quick <strong>checklist</strong> to help you prepare:</p><ul><li>Print images of outfits and app sentences.</li><li>Set up a board and markers for classifying outfits.</li><li>Have a computer or screen ready to show a video or example code.</li></ul><p>With this simple and structured activity, you can make programming accessible, interactive, and fun for beginners in just 30 minutes.</p><p>Photos from the event:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ie94MICan2QYLeozozhDmA.png" /></figure><p>Thank you for reading! I hope this activity inspires and helps you.</p><p>A special shoutout to my amazing colleagues at <a href="https://www.toriihq.com/">Torii</a> for helping fine-tune this activity, making it both engaging and insightful. I’m fortunate to work with such incredible people in a workplace that values social impact — a privilege I do not take for granted.</p><ul><li><a href="https://www.youtube.com/watch?v=cDA3_5982h8">Josh Darnit’s Exact Instructions Challenge video</a></li><li><a href="https://cat-bounce.com/">Cat-bounce website</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9f517eba185" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Hours to Seconds: A Tale of SQL Query Optimization]]></title>
            <link>https://medium.com/better-programming/from-hours-to-seconds-a-tale-of-sql-query-optimization-e0d38066e043?source=rss-b871f38d276e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0d38066e043</guid>
            <category><![CDATA[query-optimization]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[sql-query-performance]]></category>
            <category><![CDATA[innodb]]></category>
            <category><![CDATA[index]]></category>
            <dc:creator><![CDATA[Karen Trubovitz]]></dc:creator>
            <pubDate>Sun, 13 Mar 2022 16:12:32 GMT</pubDate>
            <atom:updated>2022-03-16T21:13:14.577Z</atom:updated>
            <content:encoded><![CDATA[<h4>An example of a query optimization technique</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cGzAhzrpH_tx7FmNE0lWUw.jpeg" /><figcaption>Cartoon castle vector created by upklyak — <a href="http://www.freepik.com/">www.freepik.com</a></figcaption></figure><p>It was Monday noon. When a new feature was released to production, I knew it would result in a large number of new records being added to the table: movies. But I had no idea what was going to happen next.</p><h3>The problem</h3><p>I monitored one of our customer’s logs and waited for a major flow to complete before confirming that the release had not broken anything. As time passed, the flow failed to complete, and I realized something had gone wrong.</p><p>Because it was a critical process and a customer was waiting on the other side, I had to fix it right away. During a debugging session, I discovered that one of our database queries had gotten significantly slower. The operation took several hours to finish.</p><h4>The “Naughty” Query</h4><pre>SELECT   <br>  title,   <br>  director,  <br>  time <br>FROM movies <br>WHERE  <br>  idStudio= 10 AND   <br>  genre IN (&#39;Crime Thriller&#39;, &#39;Spy Thriller&#39;, &#39;Legal Thriller&#39;) AND   <br>  time &gt; &#39;1970-01-01&#39; <br>ORDER BY time ASC <br>LIMIT 10000</pre><p>It’s worth noting the following about the movies table:</p><ol><li>It’s an InnoDB table.</li><li>The primary key of the table is id, which is an Auto Increment column, that is used to give each row a unique identity.</li><li>Two of the table’s indexes are:<br>a. KEY `idx_time` (`time`)<br>b. KEY `idx_idStudio_genre_time` (`idStudio`,`genre `,`time`)</li></ol><p>Notice that:</p><ul><li>The index idx_idStudio_genre_time covers the columns used in the “naughty” query&#39;s WHERE clause.</li><li>There are 2 columns (title, director) in the SELECT clause that are <strong>not</strong> covered by any of the table’s indexes.</li></ul><h4>Disclaimer</h4><p>As you may have guessed, I’m not in the film industry, therefore the movies table is made up, but the table indexes and query structure are based on the original query.</p><h3>The Road Not Taken — Altering the Table</h3><p>Initially, my approach was to change the structure of the movies table (and therefore modifying the query).</p><p>I used the explain statement to gather information about how MySQL optimizer performs the query, and it appeared that the MySQL optimizer did not choose the index I expected. I anticipated the idx_idStudio_genre_time index to be chosen, but instead, the idx_time index was chosen.</p><p>In addition, we selected two columns (title and director) in the query’s SELECT clause, that were not covered by any index. In that scenario, MySQL iterates over the entire table to retrieve the values for the columns that aren&#39;t in the index. This could cause a performance issue.</p><p>Moreover, the query has two range conditions: genre IN (...) AND time &gt; &#39;1970-01-01&#39;. Once the first range condition is met, any subsequent conditions in the query will not use any further indexes. The query performance is unaffected by having both genre and time in our index. The index simply takes up additional storage space.</p><p>I meant to improve the table indexes and add columns to the table, to address these issues and others. For example, the genres “Crime Thriller,” “Spy Thriller,” and “Legal Thriller” all belong to the same category: “Thriller”. By adding a category column to the table and indexing it with INDEX(`idStudio`,`category`,`time`), we can update the query to use category instead of genre, to avoid using a second range condition.</p><p>My goal was to improve query performance, however, the approach I came up with had two main drawbacks:</p><ul><li>First, indexes have a significant overhead cost. Writing on the indexed table becomes slower as you add more indexes.</li><li>Second, the table was huge so it took hours to alter it. In order to test my theory, I duplicated our database (to mimic production size tables) and added <strong>one</strong> column to the test database’s movies table. Because the table was so large, the migration took 7 <strong>hours</strong>.</li></ul><p>At this time, it was clear that this was not the path we wanted to take. Changing the movies table had wider implications and took a long time, and we faced an urgent issue.</p><h3>The Road Taken — Rewriting the Query</h3><p>An “only code” solution is the quickest strategy. We can run it manually on the database to get an idea of the query’s performance right away, then merge it into production and test it for all of our customers. If it doesn’t work, we can rollback to the previous query with a single click.</p><p>Although it seemed like a long shot, we chose to update the query to leverage the table’s existing index, idx_idStudio_genre_time, and to reduce the dataset from which the query selects the title, director and time columns.</p><p>The effect of rewriting the query, to produce an identical result as the original query, was surprising. The query was no longer performed in <strong>hours </strong>but in <strong>seconds</strong>.</p><h4>The Rewritten Query</h4><pre>SELECT   <br>  title,   <br>  director,  <br>  time <br>FROM movies<br>JOIN (<br>  <strong>SELECT   <br>    id<br>  FROM movies<br>  WHERE  <br>    idStudio= 10 AND   <br>    genre IN (&#39;Crime Thriller&#39;, &#39;Spy Thriller&#39;, &#39;Legal Thriller&#39;)AND <br>    time &gt; &#39;1970-01-01&#39; <br>  ORDER BY time ASC <br>  LIMIT 10000</strong><br>) innerTable  <br>ON movies.id = innerTable.id</pre><p>Take note of the following:</p><ul><li>The JOIN clause query (the “subquery”) is identical to the “naughty” query. Except that the id column, which is the movies table primary key, is selected.</li><li>The table produced from the “subquery” is called innerTable.</li><li>Table movies is joined with table innerTable. The columns selected in the “naughty” query, are being selected from the joined tables in the rewritten query.</li></ul><h3>What’s the Magic?</h3><p>Hooray! The issue has been resolved. Now, the query returns a result in seconds, the flow is functional for our customer, and everyone is pleased.</p><p>But that bothered me… why is it that the query performs so much better? The two queries provide the same output, but their performance on large datasets is substantially different… what’s the trick?</p><p>You might be surprised to learn that <a href="https://dev.mysql.com/doc/refman/5.7/en/innodb-index-types.html">MySQL indexes the primary key automatically</a>. It means that all of the movies table indexes include the table&#39;s id column.</p><p>idx_idStudio_genre_time is now the <strong>covering index</strong> for the “subquery”. This is an index that provides all the necessary results for a query. Since the “subquery” only uses columns that are part of that index, the selected value (id) can be fetched from the index tree quickly. Unlike the &quot;naughty&quot; query, which required additional table lookup in order to retrieve all of the desired columns.</p><p>The PRIMARY KEY index is used to join the movies and theinnerTable tables. The tables are joined using the eq_ref join type, as described in the explain output. This is one of &quot;<a href="https://dev.mysql.com/doc/refman/5.7/en/explain-output.html">the best possible join types. It is used when all parts of an index are used by the join and the index is a </a><a href="https://dev.mysql.com/doc/refman/5.7/en/explain-output.html">PRIMARY KEY</a>&quot;.</p><p>Using (INNER) JOIN in the query resulted in a significant reduction in the size of the dataset from which we select values. When the dataset was smaller, selecting the title, director and time columns was relatively quick.</p><h3>Takeaways</h3><ol><li><strong>Make a “minimal viable change”.</strong> When we spot a problem, we may be tempted to fix all of the problematic aspects, but focusing on the smallest testable solution, that provides value to our customers, allows us to move faster and deliver quick solutions.</li><li><strong>Reduce the number of records in your query’s FROM clause.</strong> If you’re having trouble querying large tables, try making the dataset, you’re selecting values from, smaller. Use, for example, the trick I mentioned in this blog.</li><li><strong>Make the most of what you have.</strong> Use your current table indexes to your advantage, learn about your database’s “free” capabilities, and put them to creative use.</li><li><strong>Collaborate with your teammates to come up with solutions.</strong> Brainstorming is a valuable tool for creating new ideas. This is especially true when your team and you need to think of a new solution.</li><li><strong>Share what you’ve learned.</strong> Communicate your new knowledge and insights with others so they can benefit from it as well.</li></ol><p>Thanks for reading. I hope this was helpful!</p><p>Special thanks to Lital Weiss and Tal Bereznitskey, my colleagues in <a href="https://www.toriihq.com/">Torii</a>, for your thoughtful remarks and brainstorming sessions on this problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0d38066e043" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/from-hours-to-seconds-a-tale-of-sql-query-optimization-e0d38066e043">From Hours to Seconds: A Tale of SQL Query Optimization</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>