this post was submitted on 11 Jun 2024
134 points (82.5% liked)

Programming

16403 readers
46 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

Title before edit: I hate programming, why did i choose this field

TL;DR: Stupid mistake, made by hours waste.

Basically, I was extracting date from the SQL db, and it was not displaying. I tried everything, heck I even went to chatgpt, and copilot. Two and half hours of trying every single thing under the sun, you know what was the issue?

SELECT task, status, id FROM mainWorkSpace WHERE user_id = @user_id

I FUCKING FORGOT TO ADD 'date' TO THE DAMN QUERY. TWO AND HALF HOURS. I was like, "Ain't no way." as I scrolled up to the query and there it was, a slap in the face, and you know what was the fix?

SELECT task, status, date, id FROM mainWorkSpace WHERE user_id = @user_id

Moral of the story, don't become a programmer, become a professional cat herder instead.

top 50 comments
sorted by: hot top controversial new old
[–] [email protected] 56 points 1 month ago (3 children)

The best advice I can give to new developers is "question your assumptions".

"But I set that variable" - did you?

"It should default to 0" - is it?

Remember - if things were working as you think they are then your code would be working.

[–] [email protected] 7 points 1 month ago

Thanks will keep in mind next time it happens

[–] [email protected] 4 points 1 month ago

I have great colleagues who still bust out this kind of cross-examination when we're trying to figure out why my code is a bag of poo. I have some friends I've known 25 years who will do this, and it's every bit as annoying and infuriating as it's invaluable help.

load more comments (1 replies)
[–] [email protected] 54 points 1 month ago (4 children)

You didn't add the date field to your query and couldn't work out why it didn't return the missing field for over 2 hours?

Perhaps SQL isn't for you as things get waaaaay more finicky than that.

[–] [email protected] 82 points 1 month ago (22 children)

You’ve never made a silly mistake where you “can’t see the forest for the trees”?

It happens to the best of us

[–] [email protected] 5 points 1 month ago

One time I've been trying to force UE5 to let me edit TArray, an hour later I realized I could just use TMap

load more comments (21 replies)
[–] [email protected] 19 points 1 month ago (1 children)

Seriously. If this broke him it gets so much worse.. but honestly op, this is how you learn what to do and what not to.

[–] [email protected] 10 points 1 month ago (2 children)

I know that, my anger has manifested this post, and I shouldn't have criticized the entire field

load more comments (2 replies)
[–] [email protected] 10 points 1 month ago (1 children)

You don't know the circumstances. They might have only seen the query results after several processing steps...

load more comments (1 replies)
[–] [email protected] 8 points 1 month ago (2 children)

it's indeed a new language for me and I haven't developed that ability to know where the bug is happening but I am going to get there.

[–] [email protected] 5 points 1 month ago (1 children)

Assuming you're coming from a linear programming and OOP background, then data (incl. SQL) kinda sucks because it's not always clear how to apply existing concepts. But, doing so is absolutely critical to success, perhaps more so than in most OOP environments. Your post isn't funny to me because I'd be laughing at you, not with you.

If a variable is fucked, the first questions you should answer are, "Where'd it come from?" and "What's its value along the way?". That looks a lot different in Python than SQL. But, the troubleshooting concept is the same.

If object definitions were replaced by table/query definitions in planning then you'd probably not have made the initial error. Again, it looks different. But, the concept is the same.

load more comments (1 replies)
load more comments (1 replies)
[–] [email protected] 41 points 1 month ago (3 children)

In those kinds of situations you need to remember to try to break the problem down into simpler sections to identify where the problem lies. One of the first steps would be to run SELECT * FROM mainWorkSpace WHERE user_id = @user_id and see if that returns anything.

[–] [email protected] 15 points 1 month ago

Was going to say that.

@OP:

One of the main skill a developer must have is being able to troubleshoot properly how their code behave.

Break your code in small pieces, check all of them with unitary test (formal or not) to validate their behavior then move to the next step. Never test everything in one shot or you will be overwhelmed by side effect bugs whom will distract you from the real root cause.

Being a programmer is not just coding but also testing and deploying (even locally).

That won’t avoid you being blocked by a silly mistake for hours, everybody did that at some point in their career, but that will reduce your frustration against yourself when you discover why the bug existed.

Do a pause, go walk, change the topic and the next time you look at your code, you will spot the obvious bug :-)

[–] [email protected] 9 points 1 month ago

If you're not familiar with the table, use a select top 10 * from table if you're on sqlserver, postgresql uses limit and oracle has fetch.

Don't recommend select * without limits or conditions unless you absolutely know the table, you can very quickly make a DBA unhappy

[–] [email protected] 9 points 1 month ago (1 children)

In those kinds of situations you need to remember to try to break the problem down into simpler sections to identify where the problem lies.

Learned that the hard way.

One of the first steps would be to run SELECT * FROM mainWorkSpace WHERE user_id = @user_id and see if that returns anything.

It's one of those situations where if i write something, i forget it because it is doing its thing and about selecting everything, i should've done that and it's my mistake.

[–] [email protected] 5 points 1 month ago

You should read up on what's called "rubber ducky" debugging

Here's a link to a comic that summarizes the idea succinctly: https://www.smbc-comics.com/comic/the-rubber-duck-method Wikipedia article here: https://en.wikipedia.org/wiki/Rubber_duck_debugging

[–] [email protected] 27 points 1 month ago (1 children)

You tried "everything" for over 2 hours but never tried the "*" selector?

[–] [email protected] 24 points 1 month ago* (last edited 1 month ago)

User: I've tried everything

Support: Have you tried ?

[–] [email protected] 26 points 1 month ago (3 children)

The difference between experienced devs and non experienced devs is that we have hundreds of stories like that under our belt. Hundreds of "Ah I wasted all this time because of a typo", and now we know to check for it.

It never stops. And after a while, a dev will share this exact scenario and you'll look back and share the same bit to them.

[–] [email protected] 4 points 1 month ago

Thanks for sharing your experience, who knew a frustrating post written by me would give me lessons which i am going to take to heart.

[–] vrek 4 points 1 month ago (1 children)

I had that experience last week. I half blame the language though cause the way it works is you don't initialize a variable, first time you use it the language automatically makes the variable and default value is 0.

I had a variable countoot that I had a formula calculate. Then a simple if countoot > 0 do this else do that. The program kept doing that. I knew countoot should be 2. I manually did the formula ... The answer was two.

I did the same formula in 3 other programs and it worked correctly. I spent between 1.5 to 2 hours a day for like 3 days banging my head on the desk trying to figure out why it would work. Fourth day me and 2 other guys were trying to figure it out when I finally really looked closely. I realized the formula result was stored in ccountoot(notice 2 c) and the if statement was based on countoot(notice 1 c)...yeah I felt so stupid when correcting the typo fixed the problem.

load more comments (1 replies)
load more comments (1 replies)
[–] [email protected] 24 points 1 month ago

I’ve been a SQL dev for years. Last week I spent half an hour reading up on why wrapping a bunch of queries in a transaction was giving me incorrect results compared to when they were separate committed statements. I was investigating locking or what might be happening in the execution plan that was throwing it off.

Turns out I just fucked up the where clause. I didn’t even consider the schoolboy stuff. This kind of shit happens all the time.

[–] [email protected] 12 points 1 month ago (2 children)

This kind of stuff happens all the time IMO, we're human and not perfect 🤷‍♂️

I don't know how much of a help ChatGPT would be in this situation without access to your schema, at least with Copilot you can write a comment in the code explaining what you're trying to do and get some usable pointers in the generated suggestion (which takes your codebase into account).

I usually try to get a second pair of eyes on my code if something that seems relatively simple isn't working as expected... As you gain more experience these mistakes will become less common, and easier to spot

load more comments (2 replies)
[–] [email protected] 11 points 1 month ago (1 children)

No worries. I’ve wasted more time on lesser mistakes than this. I also once made everyone an admin by forgetting a single ampersand. That was a fun eight hours.

load more comments (1 replies)
[–] FizzyOrange 10 points 1 month ago (4 children)

Real moral of the story: STATIC TYPING!

Seriously so many people think it's a waste of time, and then stuff like this happens.

load more comments (4 replies)
[–] SatouKazuma 10 points 1 month ago (1 children)

You want to hate programming? Try using JS. It's anarchy.

"Why is this the way to do things?"

"Because it just is."

[–] [email protected] 5 points 1 month ago (5 children)

Oh, and there's at last 2 other ways to do it too.

load more comments (5 replies)
[–] RandomVideos 9 points 1 month ago (1 children)

At least its 2.5 hours and not 2 years because of writing h instead of H

[–] [email protected] 5 points 1 month ago

I suspect there's a long tragedy about this, the likes that would give The Odyssey pause.

[–] [email protected] 9 points 1 month ago (5 children)

Get yourself a debug rubber ducky mate, talk to it when you are troubleshooting might fire off a coupe more pathways to identify the problem sooner.

[–] [email protected] 5 points 1 month ago (1 children)

I would like mine blue with an army's helmet.

[–] [email protected] 6 points 1 month ago (1 children)

You can dress it up however you like.

Holiday duck

Professor Duck

Tech support duck

load more comments (1 replies)
load more comments (4 replies)
[–] [email protected] 8 points 1 month ago (2 children)

We’ve all done stupid stuff like this. The trick is to pad time into estimates to account for it :D

load more comments (2 replies)
[–] zero_spelled_with_an_ecks 7 points 1 month ago (1 children)

I do this, too. The only remedies I know are a walk or a colleague's fresh perspective.

[–] [email protected] 7 points 1 month ago (1 children)

For me rubber ducking a coworker solves a lot of these things instantly, but walking just gets me further entrenched in my own stupid ideas.

load more comments (1 replies)
[–] RagnarokOnline 6 points 1 month ago

Sucks bro. You’re in good company tho

[–] [email protected] 5 points 1 month ago

One of the hardest issues to troubleshoot is a bad assumption. Be glad you only spent 2 hours on this.

[–] [email protected] 5 points 1 month ago (3 children)

What did you asked ChatGPT? I tried it and straightforward said that the date field wasn't included on the select statement

https://chatgpt.com/share/80918db9-5284-4a9b-b971-dde78b00497a

[–] spartanatreyu 9 points 1 month ago

Better to ask a rubber duck than an LLM.

It has better results, is cheaper, and makes has a positive compounding effect on your own abilities.

load more comments (2 replies)
[–] [email protected] 5 points 1 month ago (4 children)

https://m.youtube.com/watch?v=CFRhGnuXG-4

Watch this. I have found that this makes it way easier to debug shit, is more readable, and cuts down on mistakes.

load more comments (4 replies)
[–] [email protected] 4 points 1 month ago (2 children)

Every bug is an opportunity to learn. Learn about the language, the code base or about yourself. Today you learned about yourself.

load more comments (2 replies)
[–] [email protected] 4 points 1 month ago

I'm pretty sure chatgpt caught mistakes like these for me recently and in the past. Just always slap in all your code into the prompt and tell it what you want the code to do step by step. Like with rubber ducky debugging.

load more comments
view more: next ›