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.

→ More replies (2)
→ More replies (1)

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.

→ More replies (2)

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")
→ More replies (2)

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?

→ More replies (1)

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

3

u/Astrokiwi May 06 '21

And before that: to actually use a proper IDE rather than a text editor with syntax formatting.

→ More replies (2)

6

u/Vietname May 06 '21

Id add learning pdb to this as well

3

u/[deleted] May 06 '21

Who needs pdb when you can be a printy boi?

→ More replies (2)

4

u/TheFrogWhoHatesFlies May 06 '21

pdb?

9

u/PinkFlyingElephant May 06 '21

The python debugger, Google for 'python pdb'

→ More replies (1)

13

u/vectorpropio May 06 '21

Prolapse data base

6

u/synthphreak May 06 '21

Now I'm afraid to ask what ipdb stands for...

→ More replies (1)
→ More replies (1)
→ More replies (3)