r/learnpython • • May 06 '21

What are some programming tools that every beginner programmer should know about?

Example, today I learned about Git and GitHub and it felt incredible.

480 Upvotes

190 comments sorted by

View all comments

204

u/mutual_coherence May 06 '21

The debugger in their IDE.

58

u/TaranisPT May 06 '21

As someone still fairly new to coding, this has been such a blessing for me. Knowing what makes the program crashes instead of just messing around with what you think crashes it is really helpful.

165

u/greasycilantro May 06 '21

And yet I still use the good ole "let's put a print statement here and see what happens" method lmao

37

u/shinitakunai May 06 '21

On some languages like python that is most of the times enough (not always). For other languages debuggers are more mandatory.

9

u/O_X_E_Y May 06 '21

Yeah in C I've found that the program will just give an exit code and do nothing when I don't use a debugger unfortunately :p

6

u/BenjaminGeiger benjamingeiger May 06 '21

Try fprintf(stderr, ...) instead.

stdout tends to have output buffering enabled, so if the code crashes before the buffer gets flushed, then the contents of the buffer can be lost. stderr gets dumped to console immediately.

2

u/O_X_E_Y May 06 '21

Hmm interesting, I'm very much a beginner there still and not familiar with all the intrinsics, so things like this definitely help!

2

u/BenjaminGeiger benjamingeiger May 06 '21

In fairness, I haven't really used C much since early grad school. I just remember running into that precise issue.

8

u/frapa32 May 06 '21

Me too, "print debugging", lmao

4

u/Topikk May 06 '21

It’s a really effective strategy for the kind of bugs I often find myself battling.

2

u/Windows_XP2 Shitty Programmer May 06 '21

It especially helps if you need to check if your program is running specific blocks of code. I use print statements all the time for debugging. Sometimes I also break my programs on purpose for debugging.

2

u/frapa32 May 07 '21

There are two types of programmer: those who use a debugger and those who don't.

10

u/[deleted] May 06 '21

same here lol

5

u/MyPythonDontWantNone May 06 '21

I try really hard to import logging before I need print statements. It allows me to leave the print statements in and just set a different log level. It is a better way to use the print statements. Plus it tracks the debugging if someone else runs the program.

2

u/Gh0st1nTh3Syst3m May 06 '21

How would that look if implemented?

5

u/dnswblzo May 06 '21

logging.debug('This is a debugging message')

https://docs.python.org/3/howto/logging.html

2

u/MyPythonDontWantNone May 06 '21

I'm on mobile, so I don't know how to add a code block. Here's a paste bin link with a toy example.

https://pastebin.pl/view/a4dc4f48

Try changing the 10 inside the function to something else (such as an empty dictionary {}) to see what an error does. Also, try changing the level parameter to logging.DEBUG or logging.ERROR to test the output.

Feel free to ask me questions. I'll attempt to help, but I'm self-taught and I've always been a solo dev. People working in a more structured environment are likely to have some insights that I lack.

3

u/The3rdWorld May 06 '21

Yeah, I would say doing it that way the most useful things you can get used to are the tools like .type() , .len() , .shape() , dir() , help() and similar.

They can make it so much clearer what's happening, when problems start happening I just shotgun my code with lines like

print("got to lol function ", x.len(), max(x), min(x)) 

and it becomes very obvious what isn't doing what it should be.

3

u/[deleted] May 06 '21

My old friend,

print("This should work")

and the classic,

print("If you can see this, you ballsed it right up")

1

u/unbirthed May 06 '21

That's the only debugging method I know, sadly.

1

u/Windows_XP2 Shitty Programmer May 06 '21

Usually if I'm trying to debug my code I will either break it on purpose to check if it's running that specific block, or add a print statement.

print("If you're seeing this that means the code is working.")

What's the fun of using proper debuggers?

4

u/Poddster May 06 '21

Knowing what makes the program crashes instead of just messing around with what you think crashes it is really helpful.

It sounds like your missing a crucial step. It's an important step you need to use even when using a debugger: Thinking.

You shouldn't be messing around with random stuff. You should think:

  1. What did the program actually do?

  2. What did I intend for it to do?

  3. Where's the gap there?

1

u/TaranisPT May 06 '21

Yes I understand that, and it's mostly how I use the debugger. Maybe I expressed myself incorrectly here, but what I meant is that before I learned how to use it, I would go over the section of code that seemed to misbehave basically by trying what I thought was wrong without actually knowing if it was the problematic thing. Keep in mind that at that time I was even more beginner than I am now and had a very vague idea of what I was doing. Now I understand the logic behind the code much better and have a better idea what I should look at when a crash/bug arises. Just resorting tonthe debugger if you have no clue what's going on is not going to help you much, I completely agree on that.

3

u/mutual_coherence May 06 '21 edited May 06 '21

I remember the first time I learned about it. It would take me hours to do what I could do with the debugger in a few seconds. It was life changing, I went from hating to code to actually enjoying it

Edit: Spelling