Community
Halima Abdi
Halima AbdiGeneral
Oct 16

My first coding slip-up and the lesson I still use

When I first tried to write a simple script to track my M-Pesa sales I forgot to add a check for zero values. The program crashed when there were no sales for a day and I looked like a fool in front of my campus friends. Now I always test my code with a few fake numbers first and I keep a backup copy before I run anything. A simple tip that helped me: write the data to a text file first, then read it in your program, so you can see errors without needing the internet.

6

Replies

6
Collins Omondi
Collins OmondiOct 16

I usually just make them up myself - like 0, 100, 250, and a negative number if the logic needs it. Simple pen-and-paper stuff works fine when you're starting out, and you get to think through the edge cases as you pick each number. I have not tried a generator tool yet, but I am curious about what you'd recommend for someone who is still wrapping their head around basic loops.

Lydia Achieng
Lydia AchiengOct 17

Love this, it's such a relatable moment - we've all been there with that "crash in front of friends" feeling. Your tip about testing with fake numbers first is gold, and writing data to a text file is smart especially when you're on campus Wi-Fi that keeps dropping. Quick question - when you test with fake numbers, do you just make them up yourself or do you use a simple tool to generate them?

Sarah Njeri
Sarah NjeriOct 17

This hit home - I still remember my first "cannot divide by zero" crash too, right in the middle of a demo to my lecturer. What you said about testing with fake numbers first is solid. I do the same thing, but I keep a small exercise book where I write down the test cases (0, 50, 100, -20) and what the expected output should be. When something breaks, I flip through the pages and can usually spot where my logic went wrong. Plus it works offline, which is a lifesaver when campus Wi-Fi decides to take a siesta.

SA
Sharon AtienoOct 17

I totally get that crash feeling - it happened to me too when I was trying to calculate average sales for my sister's salon, and the computer said "cannot divide by zero" right in front of my classmates. Now I always start with simple numbers like 0, 50, 100 (just like the others said), and I test with my phone's hotspot when the campus Wi-Fi acts up - it's saved me during more group presentations than I can count. Quick tip that helped me: write down your fake numbers on a small book first, so you can see exactly what went wrong when something breaks.

AM
AmaniOct 18

Happened to me too, back when I was tracking my mum's kiosk sales - the first time I divided by zero during a "no sales" day, my laptop nearly hit the wall. I always make up the numbers myself (0, 50, 100, even negative values), keeps it simple and helps you think through the tricky cases. Have you tried testing on your phone's hotspot when campus Wi-Fi dies? It saved my bacon more than once during group projects.

Wanjiru Kamau
Wanjiru KamauOct 18

We've all had that moment where the screen just freezes and you want to disappear. I love the idea of using a notebook for test cases because it's so much easier to spot a mistake on paper than staring at a screen for hours. Since you mentioned the text file tip, do you find that it helps you keep your work organized when you're working with low-bandwidth or slow connections?