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.
- ShaunaTheDead ( @ShaunaTheDead@fedia.io ) 27•5 months ago
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.- Enoril ( @Enoril@jlai.lu ) 12•5 months 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 :-)
- morbidcactus ( @morbidcactus@lemmy.ca ) 7•5 months 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
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.
- ShaunaTheDead ( @ShaunaTheDead@fedia.io ) 4•5 months 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
- tobogganablaze ( @tobogganablaze@lemmus.org ) English24•5 months ago
You tried “everything” for over 2 hours but never tried the “*” selector?
- FizzyOrange ( @FizzyOrange@programming.dev ) 10•5 months ago
Real moral of the story: STATIC TYPING!
Seriously so many people think it’s a waste of time, and then stuff like this happens.
- BatmanAoD ( @BatmanAoD@programming.dev ) 5•5 months ago
If only there were a good statically typed database, as opposed to thin wrappers over SQL.
- QuazarOmega ( @QuazarOmega@lemy.lol ) English3•5 months ago
And better error messages than “bro, you got a syntax error on this line”
- 𝒍𝒆𝒎𝒂𝒏𝒏 ( @lemann@lemmy.dbzer0.com ) 10•5 months ago
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
My second pair of eyes was in an another country for business stuff so I had to solve it all by myself and because of the frustration, i wrote this post. Sorry about that
- leftzero ( @leftzero@lemmynsfw.com ) 2•5 months ago
That’s when rubber duck debugging comes in handy.
- SatouKazuma ( @SatouKazuma@programming.dev ) 10•5 months ago
You want to hate programming? Try using JS. It’s anarchy.
“Why is this the way to do things?”
“Because it just is.”
- treadful ( @treadful@lemmy.zip ) English4•5 months ago
Oh, and there’s at last 2 other ways to do it too.
- SatouKazuma ( @SatouKazuma@programming.dev ) 3•5 months ago
Sure, but they use ersatz methods that are so incredibly obscure and removed from the standard library that expecting one to know them is beyond foolhardy.
- treadful ( @treadful@lemmy.zip ) English1•5 months ago
No clue what that means. I was thinking more along the lines of how there’s 3+ techniques for async functions. Or that there’s a handful of syntax implementations, versions, and supersets of the language. Or that there are many interpreters all with different standard libraries and quirks.
It’s an annoyingly flexible language.
- SatouKazuma ( @SatouKazuma@programming.dev ) 3•5 months ago
It just feels like anarchy to me. Why is anything the way it is in JS? Maybe I’m learning it wrong, but starting from zero, I now feel like I understand less than nothing.
- ulkesh ( @ulkesh@beehaw.org ) English8•5 months ago
We’ve all done stupid stuff like this. The trick is to pad time into estimates to account for it :D
- tastysnacks ( @tastysnacks@programming.dev ) 2•5 months ago
The trick is to get project managers to automatically pad you time.
- ulkesh ( @ulkesh@beehaw.org ) English1•5 months ago
Yeah in my 25 years of experience, none of them have ever done that.
- RandomVideos ( @RandomVideos@programming.dev ) 7•5 months ago
At least its 2.5 hours and not 2 years because of writing h instead of H
- corsicanguppy ( @corsicanguppy@lemmy.ca ) 4•5 months ago
I suspect there’s a long tragedy about this, the likes that would give The Odyssey pause.
I do this, too. The only remedies I know are a walk or a colleague’s fresh perspective.
- RagnarokOnline ( @RagnarokOnline@programming.dev ) 5•5 months ago
Sucks bro. You’re in good company tho
- driving_crooner ( @driving_crooner@lemmy.eco.br ) 4•5 months ago
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 ( @spartanatreyu@programming.dev ) 5•5 months 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.
- tastysnacks ( @tastysnacks@programming.dev ) 4•5 months ago
Honestly I worry about the use of ChatGPT on programmers. Training your eyes and brain to see things takes time. I know the suits just want production but I’d rather have better programmers.
Of course, I could just be old.
I posted the entire function where the issue was occuring and it was trying to solve the function and not the query.
- lolcatnip ( @lolcatnip@reddthat.com ) English3•5 months ago
Programming: not even once!
- Elise ( @xilliah@beehaw.org ) 2•5 months ago
I’m a coder and I like my job. It just has to fit with you. You have to be zen and like fiddling around with stuff. How did you even learn to write all of that if you hate it so much?
There’s a book called what color is your parachute you might like.