In the previous chapter, Quiz Application Development, we explored the engine behind the interactive quizzes. Before that, in Python Setup and R Setup, we built our coding environments.
Now that we have all our tools, we need a recipe for how to use them together. This chapter covers the Development Workflowβthe daily routine of opening the project, making a change, testing it, and saving it.
Imagine a busy restaurant kitchen. If every chef threw ingredients into the soup pot whenever they felt like it, the meal would be a disaster. Instead, chefs follow a strict process: Prep $\rightarrow$ Cook $\rightarrow$ Taste $\rightarrow$ Serve.
Software development is the same. You cannot just change a file and hope for the best. You need a workflow to ensure your changes are safe and correct.
Let's say you are studying the Regression lesson and notice two problems:
The Goal: You want to fix both errors on your computer and verify they work before sharing them with the world.
The Solution: We follow a cycle called the Edit-Test Loop. This chapter guides you through creating a safe workspace, making changes, and validating them locally.
To keep your work organized, we rely on three main concepts.
Imagine you are writing a draft of an important email. You don't type it directly into the "Send" box. You write it in a separate document first.
In Git (our version control system), this "separate document" is called a Branch. It is a copy of the project where you can make mistakes without breaking the real website.
Jupyter Notebooks remember things. If you define a variable x = 5 and then delete that cell, the computer still remembers x is 5. This can lead to bugs that only happen on other people's computers. We must learn to "Restart and Run All" to ensure the code truly works.
We don't edit the live website. We run a "fake" website on our own laptop (Localhost) to see how our changes look.
Let's walk through the steps to solve our "Weekend Fix" use case.
First, tell Git you are starting a new task. Open your terminal in the ML-For-Beginners folder.
# 1. Update your project to the latest version
git checkout main
git pull
# 2. Create a new branch named 'fix-regression'
git checkout -b fix-regression
Explanation: checkout -b means "Create a new branch and switch to it." You are now in a safe sandbox named fix-regression.
Open the lesson file (e.g., 2-Regression/1-Tools/notebook.ipynb) in Visual Studio Code or Jupyter.
In the Jupyter interface menu:
If the notebook runs all the way to the end without errors, your fix is good!
Now, let's fix that typo in the quiz. As we learned in Quiz Application Development, we need to run the quiz app to see the change.
# 1. Go to the quiz folder
cd quiz-app
# 2. Start the local preview
npm run serve
Explanation: This starts the web server. You can now open your browser to http://localhost:8080, navigate to the quiz, and verify that your typo is gone.
Once you have "tasted the soup" (tested the notebook and quiz), you are ready to save.
# 1. Add the changed files to the "staging area"
git add .
# 2. Save them with a message
git commit -m "Fixed regression bug and quiz typo"
Explanation: git commit saves a snapshot of your changes. The message helps others understand what you did.
What actually happens when you work through this flow? It is a conversation between your text editor, the runtime engines, and the version control system.
This is the most common mistake for beginners. Let's look at why it happens.
Imagine you write this code in a cell:
# Cell 1
secret_number = 42
print(secret_number)
Then you delete Cell 1 and write Cell 2:
# Cell 2
# I deleted Cell 1, but Python still remembers secret_number!
print(secret_number + 10)
The Trap: On your computer, this works because you ran Cell 1 five minutes ago.
The Crash: On my computer, I never ran Cell 1. When I run Cell 2, it crashes because secret_number doesn't exist.
The Fix: "Restart & Run All" clears the computer's memory and runs everything from scratch. This guarantees the code works for everyone, not just you.
If you are following the R track (setup in R Setup), the workflow is slightly different.
R Markdown files (.Rmd) are text files that compile into HTML. You cannot just save the file; you must "Knit" it.
In RStudio:
# Internal logic of the Knit button
rmarkdown::render("notebook.Rmd")
Explanation: This command runs every single line of code in a clean environment and produces a result file. If your code has a bug, the Knit will fail immediately, alerting you to the problem.
In this chapter, we established our Development Workflow:
git checkout -b).npm run serve to visually check changes.Now that you have fixed the bug and saved your work locally, how do you send it to the main project so everyone else can benefit? You need to follow the rules of the community.
Next Chapter: Contribution Guidelines
Generated by Code IQ