r/learnprogramming • • Sep 12 '24

Debugging I DID IT!!!

1.3k Upvotes

I FINALLY GOT UNSTUCK. I WAS STUCK ON ONE OF THE STEPS IN MY TIC TAC TOE GAME. I WAS MISERABLE. BUT I FINALLY FIXED IT. I feel such a high right now. I feel so smart. I feel unstoppable

Edit: Usually I just copy and paste my code into chatgpt to let it solve it. But this time I decided to actually try and solve it myself. No code pasting, nothing. Chatgpt was ruining my problem solving skills so I decided to try and change that. I only asked a few basic indirect questions (with no reference to my project) and I found out that I had to use a global variable. Then I was stuck for some even more time since it seemed like the global variable wasn’t working, and the problem literally seemed like a wall. But I figured it out

r/learnprogramming • • Mar 21 '23

Debugging Coding in my dreams is disrupting my sleep?

956 Upvotes

Anytime I code 1-2 hours before bed, I fall asleep but feel half awake since in my dreams I still code but it’s code that makes no sense or I write the same line over and over. It drives me crazy so I force myself a wake to try to disrupt the cycle. It’s so disruptive. Anyone else? And how to stop other than not coding close to bedtime?

Flair is bc I’m debugging my brain.

r/learnprogramming • • May 27 '20

Debugging I wasted 3 days debugging

1.2k Upvotes

Hi everyone, if you're having a bad day listen here:

I wasted more than 50 hours trying to debug an Assembly code that was perfectly working, I had simply initialized the variables in the C block instead of doing it directly in the Assembly block.

I don't know if I'm happy or if I want to cry.

Edit: please focus on the fact it was assembly IA-32

r/learnprogramming • • Dec 20 '25

Debugging Finding out there is a lot more to tech than just "Frontend vs Backend"

403 Upvotes

I have been working with Python for about 5 years now, and for most of that time, I was stuck in a bit of a bubble. I assumed the career path was basically just moving from junior to senior backend roles, building APIs and scaling web services. It felt like the industry was 90% CRUD apps and centered around the same few "cliché" frontend and backend frameworks.

Recently, I started looking into Quant Finance, and it has been a total eye-opener. It is a completely different world where the problems aren't about HTTP requests or CSS; they are about high-frequency execution, mathematical modeling, and processing massive amounts of data in real-time. It made me realize how many deep technical niches we completely ignore because they aren't as "loud" as web development.

I wanted to share this because if you are starting to feel a bit burnt out or bored with standard web stacks, I really encourage you to look at these non-obvious fields. Whether it is Quant, Embedded Systems, or Bio-informatics, there are rabbit holes out there that are way more technically challenging than the standard paths. I spent years thinking I had seen most of what the industry had to offer, but I am finding out I was barely scratching the surface of what we can actually do with code.

r/learnprogramming • • Apr 08 '26

Debugging How do you actually understand programming?

73 Upvotes

How do you actually understand programming? 🤯

I’ve been studying computer science as a subject, but when it comes to solving programming exercises… I feel completely stuck. Like I don’t even know how to start.

Is it just me or did anyone else go through this phase? How did you overcome it?

Any tips, methods, or ways of thinking that helped you finally “get it”?

r/learnprogramming • • 1d ago

Debugging Why is the program showing invalid when the number is within the range?

14 Upvotes
int user_year; // input year

cout << "Enter a year: ";

cin >> user_year;

while(user_year > 2099 || user_year < 1900 ){
  cin.clear(); 
  cin.ignore(10000, '\n');
  cout << "Invalid Input, Enter a year: "; 
}

The user input needs to be greater than 1900 and less than 2099, so 1900 - 2099.

Whenever I input a value in between those numbers such as 2010, it gives invalid input.

What I want

if user_year is outside the specified range indicate "Invalid input" but loop back to user input.

I used an if statement but the problem was that it did not loop back to cin

EDIT: HERE IS MY ORIGINAL CODE

while (!(cin >> user_year) || user_year < 1900 || user_year > 2099) {
    cin.clear();
    cin.ignore(10000, '\n');
    cout << "Invalid Input, Enter a year: ";
}

FIXED:
I had a function in my program and it was causing it to return 0 as the year.
but the code above is correct

r/learnprogramming • • Aug 30 '26

Debugging Please. I need help learning how to debug existing code.

37 Upvotes

Im starting to resent the way programming is taught. It is seemingly taught in isolation the way mathematics is. You learn the functionality of code but they do not present the bigger picture where everything works together. It's frustrating because I want to learn programming through and through, every single bit.

Is there anything on Github meant for beginners to learn how to debug and have an intuitive understanding on how piece of functionality (functions, loops, arrays, strings) work together?

It's like yeah. I know how arrays work, I know about loops, sure, but everything works together. And none of the guides are showing me how bugs can occur due to the symbiotic nature if everything working together. Nothing exists in isolation.

r/learnprogramming • • Jun 22 '26

Debugging Advise

18 Upvotes

I'm 20 years old, from Egypt, I'm a self-taught Desktop Application Developer, I have 3 years of experience from freelancing. But I have no degree.

Now I must serve 3 years mandatory military service or I can go back to continue my education, but the problem is, here in my country I can't just get into college directly, I have to spend 4 years learning unrelated subjects before I can get into college. So I want your advice, if you were in my place, would you serve 3 years of military service and try to find a job without degree or would you choose option 2 and spend 8 years to finish your education?

I'm having hard time deciding, because both options are bad, but I think the 3 years military is the better option because it's the shortest path and I have experience in programming.

Thanks.

r/learnprogramming • • Jul 16 '26

Debugging How do i get my ball to stop bouncing after a while

13 Upvotes

My ball is able to bounce but it keeps bouncing when it gets closer to the ground how do I fix this issue.

This is not the full code only a snippet.

# SURFACE OBJECTS
surface1 = Ball_Surface(10, 10, 200, 200, "pink")

# BALL OBJECTS
ball1 = Ball_Object(surface1.rect.centerx - 10, 20, 10, "white")

# PLATFORM OBJECT
ground1 = Platform(20, 150, "black")

# SPEED
velocity1 = 7

# GRAVITY
gravity1 = 0.8 

# MOVEMENT FUNCTION
def movement1(ball, platform, velocity, gravity):
    if ball.center[1] < (platform.y_pos - (ball.radius - 5)):
        velocity += gravity
        ball.center[1] += velocity

    elif ball.center[1] >= (platform.y_pos - (ball.radius - 5)):
        ball.center[1] = platform.y_pos - ball.radius # reset the ball position after collision
        velocity = -velocity * gravity

        if abs(velocity) < 0.6: 
              velocity = 0

return velocity

r/learnprogramming • • May 19 '20

Debugging I was given a problem where I have to read a number between 1000 and 1 billion and prints it out with commas every 3 digits. I'm kinda confused on how to go about this problem.

637 Upvotes

not sure how to go about this. any help is appreciated :)

r/learnprogramming • • Jul 27 '23

Debugging How can you teach someone to debug/problem solve better?

222 Upvotes

My role currently is a lot of teaching and helping people become better at their dev work, one thing I struggle to teach though is debugging/problem solving issues. I learned by just getting stuck in and sitting for hours at stupid errors, but how do I teach people to learn this faster?

I ask as I get a lot of people asking for help as soon as they get an error and not having the confidence to look into it or not knowing how to debug it correctly, so I'll get them to screen share and I'll debug on their machine for them, but it doesn't seem to click for them for some reason. I'll get asked 2 days later to do the same thing. Am I being too lenient and should just tell them to figure it out? Debugging it probably the best skill a dev can learn, is there any good resources I can use to help teach this?

Do I create bugs in our training repo? Do I do presentations? Demos on debugging? What's the best here?

Edit: Thanks for the help everyone, got some very useful help, some I knew but neglected to implement and some I've never thought of before and I'll be sure to experiment to see how I get on.

r/learnprogramming • • Jun 01 '26

Debugging how it feels like to be a developer that doesn't use ai in 2026

30 Upvotes

i'm building something as a personal project. doing everything manually, no vibe code just writing my code. i want to actually understand what I'm building.

but I keep second guessing myself. everyone around me is shipping apps in 3 days with Claude and Cursor while I'm here spending a week trying to properly understand how to structure my user classes and objects before writing a single line.

like should a User object contain the scan history directly or should that be a separate class ? I'm spending real time thinking about this instead of just prompting my way through it.

is this a waste of time in 2026 ? or are the people who actually understand the fundamentals going to be the ones still employed in 5 years ?

r/learnprogramming • • Aug 31 '26

Debugging Anyone know how to fix the brackets in my program not being used correctly?

0 Upvotes

So I'm making a text based wordle clone thing in python and the way it shows the player details about the input letter (correct, wrong spot, incorrect) is with different kinds of brackets. The issue I'm having is that if a letter has appeared more times in the player's guess than is present in the word then it will only take the value of the first instance of that letter.

() = incorrect

{}= correct but wrong spot

[] = correct

This is the code that prints out the different letters:
while len(guess) != 5:

        while len(guess) != 5:
            guess = input(
                "Please input a five letter word: ")  # Input field for the user's guess
        buffer = answer
        for index in range(0, 5):
            if guess[index] == answer[index]:
                print(
                    "[" + guess[index] + "]"
                )  # adds square brackets to a letter indicate it is in the word and in the right spot
                answer = answer.replace(guess[index], "*", 1)
            elif guess[index] in answer:
                print(
                    "{" + guess[index] + "}"
                )  # adds a squigly bracket to indicate the letter is in the word but in the wrong spot
                answer = answer.replace(guess[index], "*", 1)
            elif guess[index] != answer[index]:
                print(
                    "(" + guess[index] + ")"
                )  # adds a curved bracket to indicate the letter is incorrect
                answer = answer.replace(guess[index], "*", 1)

and this is an example of the bug (the correct word is wally):

Please input a username: test
Please input a five letter word: lalal
{l}
{a}
{l}
(a)
(l)

r/learnprogramming • • Aug 18 '26

Debugging Difficulties with debugging

3 Upvotes

​

i am a beginner in C, i went through and have a basic understanding of fundamentals but whenever a problem arises in my code i cant find it for hell, even if its obvious, i need to turn to an ai agent for help, the habit i wanna rid of, but whenever i do try to find the cause of an error myself i find myself unable to do that, i also find it difficult writing more efficient code

an example:

```

int tokens(char* string, char (*argv)[MAXTOKEN], toks types[MAXTOKEN]) {

char temp[150];

int count = 0; int i = 0; int b = 0;

int tokens = 0;

while(count < MAXTOKENLENGHT) {

if (string[i] == ' ' || string[i] == '\0' || string[i] == '\n') {tokens++;temp[b] = '\0'; strcpy(argv[count], temp); count++; b = 0;} else if (string[i] == '\"') {

temp[b] = '\"';

b++;

i++;

while (string[i] != '\"' && string[i] != '\0') {

if (string[i] == '\"') {temp[b] = '\0';temp[b+1] = '\0'; strcpy(argv[count], temp);b = 0; count++;break;} else {temp[b] = string[i];i++;b++;}

}

if (string[i+1] == '\0' || string[i+1] == ' ') {temp[b] = string[i]; temp[b+1] = '\0'; strcpy(argv[count], temp); count++; b = 0; i++; tokens++;} else {fprintf(stderr, "unexpected stuff after string"); exit(1);}

} else {

temp[b] = string[i];

b++;

}

if(string[i] == '\0') {break;}

i++;

}

int k = 0;

while (k < count) {

if (strcmp(argv[k], "PRINT") == 0) {

types[k].type = 0;

int len = strlen(argv[k+1]);

printf("k=%d, argv[k+1]='%s', first='%c', last='%c'\n", k, argv[k+1], argv[k+1][0], argv[k+1][len-1]);

if (argv[k+1][0] == '\"' && argv[k+1][len-1] == '\"') {

types[k+1].type = 1;

memmove(&argv[k+1][0], &argv[k+1][1], len - 2);

argv[k+1][len - 2] = '\0';

strcpy(types[k+1].textvalue, argv[k+1]);

}

}

k++;

}

return count;

}

```

r/learnprogramming • • Jul 03 '26

Debugging OOP

1 Upvotes

hello i am a python beginner who has started learning OOP and ive been using resources like CS50p however i still find myself being confused over the concepts taught and i would like someone to teach me OOP or is there any other resource i can look at to learn OOP better? please recommend thanku

r/learnprogramming • • 21h ago

Debugging Adding a fourth item to the linked list causing a segfault, but fine otherwise?? (C++)

13 Upvotes

I am implementing a linked list that uses a tail pointer to add to the end of a linked list. For some reason the code works perfectly fine after adding three nodes to the list, but adding a fourth node to the list causing a seg fault. From testing it appears that the header node isn't pointing to the first node for whatever reason, but even then adding to the end of the list doesn't use the header pointer.

I am used to programming in C and am trying to learn C++ so I am not familiar with many of the differences between the two. Thanks in advance.

#include <iostream>
#include <cstdlib>
//linked list with a tail pointer,
struct cell_coord_node{
    int x;
    int y;
    cell_coord_node * next=nullptr;
};


using namespace std;
cell_coord_node * cell_add_end(cell_coord_node **header , cell_coord_node ** tail, int x , int y){
    cell_coord_node * new_node = (cell_coord_node*) malloc(sizeof(cell_coord_node));
    new_node->x=x;
    new_node->y=y;
    if (*header==nullptr){ // empty list case
        (*header) = new_node;
        (*tail) = (*header);


        return (*header);
    }
    else{
        // allocate memory at tail
        (*tail)->next = new_node; // last node points to new node
        (*tail)=new_node; // moving tail pointer down to new node
        return (*tail);
    }


}


int main(){
    cell_coord_node * head;


    cell_coord_node * tail=head;
    cell_coord_node * first_node = cell_add_end( &head, &tail,1,1);


    cout << first_node->x << "   " << first_node->y << endl;
    cell_coord_node * second_node  = cell_add_end(&head, &tail,2 ,2);


    cout << second_node->x << "   " << second_node->y << endl;


    cell_coord_node * third_node = cell_add_end(&head,&tail,3 ,3);


    cout << third_node->x << "   " << third_node->y << endl;
    cout << "reading from tail" << endl;
    cout << tail->x << "    " << tail->y << endl;


    cout << "reading from head" << endl;
    cout << head->x << "    " << head->y << endl;


    //Causing a seg fault
    /*cell_coord_node * fourth_node = cell_add_end(&head,&tail,4,4);
  
    cout << fourth_node->x << "   " << fourth_node->y << endl;*/


    
    return 0;
}

r/learnprogramming • • 26d ago

Debugging Newbie question

0 Upvotes

I'm struggling and can't do it even though I asked the AI ​​a lot. I want to create a function that highlights a part of a web page with some images and text, Copy to obsidian notes software with actual image not link. But when copying, the clipboard only has text. So what should we do?

r/learnprogramming • • Aug 06 '26

Debugging How to, not feel empty about programming, and not fear the future.

16 Upvotes

I have been programming since I was 14 years old, it started of very simple with discord bots, and now has spiraled into something completely different. Currently, as a 19 year old, I have the best future in my eyes, because I turned my hobby into my job. In the upcoming weeks I will start my so called "dualesstudium", where I will be studying at a University, whilst working for a company, and it is all about IT.

During these 5 years, I learned everything from programming websites, to apps, to learning registers, and assembly, to how to set up a server, how to hack into one, to learning C, and simple raspberrypi configurations, to camera modules, to low-level-architecture and yada yada. It is currently 3 AM, and this is the third time where I just stare blank at my laptop. I have finished numerous projects, working on other ones, but I am just feeling a little empty? I used to program up to 4 or even up to 8 hours a day, and in the last couple of days it feels as if I have a full block. I dont want to abandon my projects, because I love them, but I always find myself starting at those projects, changing 5 LoC, and then being confused on what to do. I am a Solo Developer, always have been one, mostly because I like to plan and manage myself (though that is gonna change anyway once the dualesstudium starts). But I really feel like advice from other programmers would do me REALLY good right now. Guessing that the most default answer here would be something like "Take a break", or "Find yourself", or "Stop fricking programming for 8 hours a day, that stuff is how you burnout the fastest", however, I am fearful of my future. I am 19 years old, and for me it already feels like time is running out. IT is a fast market, and it feels like if I am not moving fast enough, I am gonna miss the train that is gonna help me generate wealth. I love my parents, they did everything for me, and I really want to pay them back big, which is also why I put a lot of stress on me.

The older you are the wiser you get, is atleast what I would guess. Any old persons, or just people older than me, who have maybe had the same experience as me; Do you guys have any advice for me?

r/learnprogramming • • Jun 24 '26

Debugging New programmer here with some basic questions and im open to any suggestions

3 Upvotes

I set a goal for myself to do one little project a week to track my journey and build up a small library of files that I can throw at a company as a resume, my issue so far is likely me typing like a doofus, my code is this

#calculator

print("calculator, type first number, then hit enter, then enter your function, A is add, S is subtract, M is multiply, and D is divide, hit enter, last number, then enter to get your answer ")

a=int(input( ))

b=input( )

c=int(input( ))

if b=="A":

print(a+c)

elif:

b=="S"

print(a-c)

elif:

b=="M"

print(a\*c)

else:

b=="D"

print(a/c)

This code gives me a syntax error(though itll probably be unreadable because idk how to format on redit) on line 11, specifically the collon. If i cut everything elif and after, it runs addition flawlessly, it also says syntax error when its removed, i ask on here instead of Google for 1 reason, human input, people are smarter than (most) machines, and no Google search could ever give me responses that are as helpful as that from a person. Edit: thank you all so much for the feedback and the assistance, much appreciated

r/learnprogramming • • Jul 18 '26

Debugging I'm building a budgetting app

0 Upvotes

I need to create a chart that looks like this:

100|          
 90|          
 80|          
 70|          
 60| o        
 50| o        
 40| o        
 30| o        
 20| o  o     
 10| o  o  o  
  0| o  o  o  
    ----------
     F  C  A  
     o  l  u  
     o  o  t  
     d  t  o  
        h     
        i     
        n     
        g     

i need to calculate the percetages spent in each category and represent them in the chart.

so far, through SO much struggling ive gotten it to return only the first category and i got it to put all the categories in a dictionary correctly.

(c_w dictionary)

I seriously don't know where to get the answer, I've done a bunch of searching and asked on other forums for help and i jsut cant get it

im fed up.

import math
class Category:
    def __init__(self, name):
        self.name = name
        self.ledger = []


    def deposit(self, amount, description=""):
        self.ledger.append({"amount": amount, "description": description})


    def withdraw(self, amount, description=""):
        if self.check_funds(amount):
            self.ledger.append({"amount": -amount, "description": description})
            return True
        else:
            return False


    def get_balance(self):
        balance = 0
        for transaction in self.ledger:
            balance += transaction['amount']    
        return balance


    def check_funds(self, amount):
        return amount <= self.get_balance()


    def transfer(self, amount, destination_category):
        if self.check_funds(amount):
            self.withdraw(amount, f"Transfer to {destination_category.name}")
            destination_category.deposit(amount, f"Transfer from {self.name}")
            return True
        else:
            return False
    def __str__(self):
        method = '\n'.join(f"{transaction['description']:23.23}{transaction['amount']:>7.2f}" for transaction in self.ledger )
        return f"{self.name.center(30,'*')}\n{method}\nTotal: {self.get_balance()}"
    def __iter__(self):
        for item in self.ledger:
            return item
def create_spend_chart(categories):
    #create the header text
    header = 'Percentage spent by category'
    #create the percentages down the left side
    
    #a 
    total_withdraw = 0 
    #create a list for the category withdraws
    c_w = {} 
    amounts = [transaction['amount'] for category in categories for transaction in category.ledger]
    for amount in amounts:
        if amount < 0:
            total_withdraw += -amount
    # Calculate withdrawals for each category
    for category in categories:
        withdrawal = 0
        for transaction in category.ledger:
            amount = transaction['amount']
            if amount < 0:
                withdrawal += -amount  # Add the amount spent (negative for withdrawals)
        c_w[category.name] = withdrawal
        method = math.floor(( c_w[category.name]/total_withdraw)*100)
    
    return f'{header}\n{name}: {method}' for i in c_w
food = Category('Food')
auto = Category('Auto')
food.deposit(1000, 'initial deposit')
auto.deposit(1000, 'initial deposit')
food.withdraw(10.15, 'groceries')
food.withdraw(15.89, 'restaurant and more food for dessert')
clothing = Category('Clothing')
food.transfer(50, clothing)
food.withdraw(100.99)
clothing.withdraw(21.17)
auto.withdraw(200)

r/learnprogramming • • Aug 05 '26

Debugging Hey guys need a little help in JavaScript Fundamental

0 Upvotes

Actually I am learning JS

For long

But whenever I got stuck in function

I know how to write functions in JavaScript

But i won't understand that concept like

First class function

High order function

Closure (i know )

But these 3 concepts (Feels to Confusion for me)

How can I understand these

r/learnprogramming • • Aug 20 '26

Debugging I'm learning how to code c++ with sdl2

4 Upvotes

I'm trying to create a graybox but I can't even run my code because I keep encountering build issues and an error saying "the system can't find the path specified" and idk how to solve it. I'd appreciate it if anyone could help me deal with it so I can get to coding.

r/learnprogramming • • Jun 16 '26

Debugging Basic HTML is not working

0 Upvotes

When I typed in code in visual code and ran it through google it returned with the code I inputted.

<!DOCTYPE html>
<html>

    <body>
        <h1><i>MADE BY </i></h1>
         <title>OUR FIRST HTML SESSION</title>
    </body>
         
    
</html>

r/learnprogramming • • Aug 08 '26

Debugging code running error due to window defense

0 Upvotes

Program 'main.exe' failed to run: An Application Control policy has blocked this fileAt line:1 char:101

+ ... sa\patterns\" ; if ($?) { g++ main.cpp -o main } ; if ($?) { .\main }

+ ~~~~~~.

At line:1 char:101

+ ... sa\patterns\" ; if ($?) { g++ main.cpp -o main } ; if ($?) { .\main }

+ ~~~~~~

+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException

+ FullyQualifiedErrorId : NativeCommandFailed

--------------------------------------------------------------------------------------------

What is the solution of this , i have tried excluding the folder in window defense it doesn't work

r/learnprogramming • • Aug 10 '26

Debugging Weird Python Glitch

14 Upvotes

Hey, I'm pretty new to Python so sorry if this is something really obvious.

I'm trying to learn a bit of Python before I start university, and I've been having a really weird issue with my program. Sometimes when I use print(), instead of printing the word, it outputs numbers.

I took a screenshot of it here.

The weirdest part is that it doesn't happen every time. Sometimes everything works normally, and other times I get the weird output.

I've already tried reinstalling Python and restarting my computer. I'm also using VS Code, if that matters.

Has anyone seen this before or know what could cause it?

I'm honestly pretty confused by it, so any help would be appreciated.