So convoluted... Now I don't understand my own code

tl/dr : I am just venting my frustration with my code and myself…

I started working on a challenge (never mind what it is.) Then I wondered, is this the right question I am trying to answer? Then I went back to the problem statement seeing that I didn’t really understand what was it about but by that moment I had already written around 100 lines of code that had a dozen of functions to do A, B, C, D… It was horrible… Then I said, “Alright, I can do this…” and erased all of my code…

I made a drawing of the process I needed to follow… But, is it the right process? Am I overcomplicating things? Self-doubt… Procrastination… Time wasting… Tutorial hell… Maybe I should grab a sandwich…

My brand new editor vscode was looking fantastic and I was able to set up a nice workflow… Let’s tweak the editor (yeah, I was avoiding!) When I was done playing with the theme, the fonts, yada, yada, yada, for two or three hours, I coded againg… I was seeing the problem under a new perspective and comenced again to code… Errors poped where I didn´t expect… I couldn’t understand why… Frustration set… I restarted everything… Now it works… Sort of… Nah! It doesn’t work!

From this session of coding, I created a function to verify the format of the values entered… It runs!.. Then, upon reading carefully, the function was not needed because the challenge states that “assume that the data entered is correct.” It was too late because I started wondering about things like what is the output of print(int("09") in python? Would it produce 9? (luckily it did…) I was proud of a function I coded that is meaningless for the task at hand… OK, time to stop and have quality time with my family… Though, in my head I was still thinking about that silly code…

The next morning I woke up refreshed at 5:00 AM, had black coffee to become fully alive and functional (pun not intended… sorry.) “Any idiot could have written that piece of $h17!” (Thankfully my present self is compassionate with my old self…) “Have you made some sort of pseudocode yet or a drawing?” No… I haven’t… And the pseudocode thing brings me bad, bad memories from back at highschool trying to program in MS BASIC… I wish I could code like the dude Dade Murphy in Hackers… Wait, wasn’t Angelina Jolie in that movie? Can you guess what happened? I am now doing “reserach” about that Hackers movie…

Then I think: “How about taking a hint about how to solve the problem?” Easy way out… No! I have got to solve the problem myself! OK, what about posting at the forums to see the light? What am I goning to post? I don’t even know what to ask and torturing users and moderators and anyone reading here with sense-less code is a crime… Maybe I should see what’s on TV…

1 Like

Hello. I understand how you feel, not just about coding, but your attitude, in general. So, I felt compelled to respond to this dumpster fire of a post.

  1. If you’re having trouble working with complicated tasks, maybe try working on easier problems to build up your confidence and reinforce the fundamentals. Leetcode offers thousands of problems, all ranked Easy, Medium, or Hard.

  2. Kinda weird that you’re choosing not to use pseudocode as a learning tool because of something that happened years ago. It kinda sounds like an excuse to play the victim and honestly, nobody wants to be around that. Galvanize / Hack Reactor offers a free prep course that has a great section on code skeletons. This will help immensely if and when you’re ready to end the pity party and start improving your skills.

  3. Take a breath. Be patient and kind with yourself. You sound incredibly stressed and overwhelmed, and that is not a state of mind that is conducive to growth and learning. Take breaks. Find ways to improve in little ways, and let that empower you to take the next step.

  4. It’s okay to look at the hints. Just make sure you spend time fully understanding why it works, and it can be a great learning experience.

I hope your day improves. Life can suck sometimes, but that makes it even more important that we reach out and connect with others.

3 Likes

HI @daacosta !

I think this is part of the problem which is leading to your frustration.
Asking for help is a good thing.

There will always be issues in programming that you won’t be able to solve.
It doesn’t matter if you have been programming for 2 years or 20 years.
There will always be moments when you will need to ask for help.

I would suggest, when you get into these situations and not sure where to turn, reach out and ask for help.
Another pair of eyes can help you see the issue or provide tips on how to refactor your code.

I disagree with this.

Programming is a very collaborative effort.

I think it is good to reach out and ask for help or different opinions on how to refactor your code.
Often you will learn about how to do things better and grow as a developer.

Well, if it is a large project, then posting a github repo and maybe a live link would be a good start.
Along with that, a short description of what the problem is or better yet what you are trying to achieve.

That’s fine.

You could start your post with, “I am not sure how to word this but I am trying to create X but running into issues with Y. Here is my code.”
That will start a dialog where the community can engage with you and ask follow up questions as necessary.

the forum exists to help all developers at all stages.

I have been on the forum for a few years now and I have seen a lot of code in a variety of conditions.

The forum won’t judge you for your code. So you wouldn’t be wasting anyone’s time.

We are here to help each other out and grow :+1:

5 Likes

First of all: Thanks… I needed that :face_holding_back_tears: I am cool with this now and I was just venting out frustration and what happens when anyone tries too hard to solve a problem (rest asured that I will ask concrete questions…)

  1. Indeed I broke the problem into small chunks and it all started making sense. For instance: If I code for a function f(x) maybe I should code for the inverse function f_inv(x) Then all the little functions that fed the big function started to settle.
  2. The pseudocode is a very important tool and is a good habit. Of course, the inner teenager comes out and groans and complains whenever you have to use a tool that wasn’t properly explained back in those days… Yet, you are right: I used the pseudocode.
  3. I did take a break, played with my kiddos, talked to my wife, forgot about coding for a long while and the next day I was able to progress in baby steps. Now, I have the m07h3rf…er at the ropes and I ain’t quiting!
  4. Hints you say… I am gathering concepts that I need but I am not peeking into the solution nor anyone’s solution… That’s what I meant. I am going to try to solve this hard so that when I am done I’ll be able to say that I did it and that I learned the concepts myself.

“I hope your day improves.” Believe me, my day has improved a lot and I have been able to learn by messing up and recovering, and then gathering pieces… It’s been awesome! And, my friend, thanks for your valued opinion. Means the world to me.

1 Like

Wow! I have read so many of your articles and it is such a priviledge to get a swift kick in my a$$ from a person as famous and bright as you that I can only thank you. I am a big fan of yours. Truly a big fan (and literally a big fan because I weigh around 230 lbs and that’s big…) :rofl:

Indeed, asking for hints can be helpful and I intend to do so when the vein at my forehead quits sticking out :laughing: The problem is that sometimes taking a hint prematurely would deprive me from walking the road to learning new concepts or seeing what is it that I need to work on… My post was a reflection of my challenge.

In solving a programming problem one has to come up with a set of steps to solve the problem, implement the solution, test the solution and go back to the drawing board. In the problem I am solving right now, conceptualizing what’s going on is what I need to do. Why is that? Because if I borrow yours or anybody elses approach, I am not learning my approach to the problem and that’s a shame.

By the way, my post was a way of reaching out, but having no concrete questions to ask, and having no idea of what I was doing, was a sign that I hadn’t worked on the problem enough. All those lines of code were erased eventually because I was thinking of a better way to solve the problem and I had the chance to write, test, redo…

The last part of your response is absolutely true and everybody has been nice to me here. It is such a fine community! Thanks Jessica for your perspective. I feel safe reaching out and when I get really, really stuck I will knock everybody’s door.

OK, here it goes:

image

  1. I need to implement a day calculator for this challenge (I can do it!, I don’t know how yet but I will figure it out)
  2. My third test is failed so I need to see what’s going on there…
  3. The rest of the tests passed but I don’t know yet why…

My code is not rock solid yet… I need to work on it but I am feeling such a rush…

BTW: If one mixes Python with JS, one ends up using let x = 10 in Python… I also used push() in Python instead of apend()… Not even funny…

:slight_smile: relax, take deep breath

Watch this video min. 5 times and take notes Secret to Learning To Code | JavaScript Mentor Session #learntocode - YouTube

This video has given best advice to any new learner and I found it super duper useful during my learning journey and even today.

Other suggestion start following pomodoro technique and practice box breathing technique to relax and focus well.

Cheers & all the very best,
Vikram

After reading through the whole thing.
I’d like to say that you gained a lot than losing anything precious. And they’re as follows:

  1. You realized that you’ve developed the ability to solve problems.

  2. You learned how to think logically to come up with a solution.

  3. By thinking hard for a solution you created new neurons in your brain that are required to be a problem solver. And with more repetitions. Your problem solving skill become second in nature to you.

  4. You also have recognized that your efforts towards learning software development were not in vain.

  5. And also that you should understand your problem well before you start writing a solution for it.

There doesn’t seem to be anything that you lost in the process.
Congratulations.

1 Like

Wonderfull video. Thanks! I have used pomodoro before and I believe in the methodology to avoid procrastinating. This time the methodology is called for. The perspective you bring to the table is most valuable. I am now at the point of getting some things done and moving forward. Since I have no deadline I have relaxed a bit.

I am all into breathing exercises and walking. This has helped me a lot. One of the things that surprised me was that code, all of the sudden, would pop in my head and I would immediately start coding at my phone with QPython and draft the idea of what I came up with…

Unfortunately I have the bad habit of not commenting my code and my future self I always unhappy with my present/past self.

You are right. I have gathered some cool tools that I didn’t have before. Truly, it has been a rush of adrenaline and I am now seeing things under a new light.

By the way: It was after reading your post that I was able to see the small bug that was messing my code and now I believe I can say that I am 95% there.

image

I need now to come up with the days thing. If I can succeed in gettig that small part I will be done…

The challenge has been solved… Sort of… When running the code in REPL it still misses some tests (5 of 12). I don’t see the problem as the output is identical to the tests! Why isn’t my code passing the tests? I have no idea… The more I try the less I see it… Time to ask for help… And I did ask… And I got the answer…

The guy that helped me @camperextraordinaire figured it out right away by examining the output… My answer had an extra space at the end of the returned value by the function (a string.) Then it hit me, how could he figure out the problem so fast? Then I saw it… I wasn’t examining the output of the tests! The solution was there at the logs… Then I fixed it:

    if day == "":
        new_time = f"{hours}:{minutes} {am_pm.rstrip()} {string_days}"
        new_time = new_time.rstrip()
    else:
        day = day.lower().capitalize()
        ind = key_day_calc(val_list.index(day) + days)
        new_time = f"{hours}:{minutes} {am_pm.strip()}, {Days_of_Week.get(ind).strip()} {string_days}"
        new_time = new_time.rstrip()
    return new_time

That’s just the piece of code that I needed to fix… I just removed blank spaces at the end of the string… Horrible? Oh yeah! My code is nothing to be proud of but it solves the problem and I made it… Perhaps it is suboptimal but I figured out how to solve the problem… Can I come up with another method? Yes, I am thinking of alternative approaches… Now that I have solved the problem, I will give myself license to peek at others solutions… And here’s my REPL:

We (the mods) are used to seeing issues with tests and formatting. It is very often people forget to look at the string they are building. Missing/extra spaces and so on are very common.

Next, it is a very common mistake when debugging code to look for logic issues before checking for more simple errors. Always start with the simple things, you would be surprised just how often the code you have written works but you made a simple mistake that isn’t at all related to the actual code logic.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.