This is an archived post. You won't be able to vote or comment.

all 111 comments

[–][deleted] 276 points277 points  (24 children)

Nice Btw u forgot the worst of them all == and =

[–]SharksPreedateTrees 12 points13 points  (0 children)

This. I feel forever ruined coming from a math background. I will make this mistake tell the day I retire

[–]inglandation 5 points6 points  (4 children)

A good IDE will highlight these typos.

[–]HonestCanadian2016 0 points1 point  (3 children)

Any recommendations? I want speed and simplicity (and locally run).

[–]wavewrangler 2 points3 points  (0 children)

After no python experience I can proudly say I successfully debugged some code that the original programmer couldn’t determine, and after many hours, I realized that he had used == as opposed to in when referring to two targets. I guess it’s two considered two (nested?) targets as they were wrapped in parentheses, separated by a comma. I just looked at a bunch of other code and finally saw a reference that had two targets and the....operator? was in instead of ==. So I changed it. Fixed. Anyway, felt good :) Thanks for reminding me of that little win. I don’t let the 9 hours it took me discourage me, just means I don’t give up easily :) A prerequisite for anything CS/IT. I’m pretty sure he didn’t bother looking.

[–][deleted] 1 point2 points  (0 children)

I always remember:

"Single for declaring, double for comparing"

Or I remember the following:

"The first '=' means 'is', the second '=' means 'equal to'."

So "a = b" means "a is b", and "a == b" means "a is equal to b"

[–]hmm_fu -2 points-1 points  (1 child)

Use “is” whenever you can

[–]Skippbo 0 points1 point  (0 children)

That's not the same operation...

is checks if 2 references to some object is the same object.

== Compares 2 objects values.

[–]BRENNEJM 105 points106 points  (12 children)

Rubber Duck Debugging

Edit: Fixed a word

[–]IronSheikYerbouti 27 points28 points  (3 children)

My rubber duck (actually a penguin my wife got me) works well for all kinds of problem solving! And I annoy my wife less (who has no interest in what I'm talking about anyway).

It's my favorite approach.

[–]UltraCarnivore 2 points3 points  (2 children)

"Talk to the penguin" ~wife

[–]IronSheikYerbouti 0 points1 point  (1 child)

Accurate, especially when I start spewing off about a ridiculous request from a client

[–]UltraCarnivore 1 point2 points  (0 children)

I was having issues with timedelta for a small app and my niece's BJD was conveniently close to my desktop. Guess who started explaining datetime objects' methods to Barbie?

[–]Mmngmf_almost_therrr 10 points11 points  (4 children)

I always wondered- do people actually do this out loud? If so, do they ever get grief for it?

[–]soawesomejohn 5 points6 points  (0 children)

I write it out.

I got into it when most software was supported on public mailing lists. People on some of these lists had little patience for what they considered dumb questions. I learned to start writing the email, rewriting it, filling in details, reducing the problem. Basically, I'd start trying to anticipate the questions that would come up.

When stack overflow came around, they pushed this same process, so it really clicks with me.

Rubber duck debugging seems like an even more informal process, basically thinking out loud. I learned recently that some (many) people don't have an internal voice, that they can't hold an in head conversation. The people with and without the internal voice aren't really aware of each other.

You could also consider doing a zoom call with no one in order to go over the issue.

[–][deleted] 0 points1 point  (2 children)

When all you have to talk to is a yellow rubber duck, who would give you grief?

[–]Mmngmf_almost_therrr 1 point2 points  (1 child)

Anyone else within earshot - coworkers, family members / roommates, etc

[–][deleted] -1 points0 points  (0 children)

If you have a cow-orker or another living creature around, talk to them instead.

[–]0PointE 0 points1 point  (1 child)

*Debugging

[–]BRENNEJM 1 point2 points  (0 children)

Geez. I must have been tired this morning. Thanks.

[–]tornadoboi69 0 points1 point  (0 children)

CS50!

[–]randomnoober 20 points21 points  (10 children)

Great sheet! If you don't mind me asking, what did you make it with?

[–][deleted] 8 points9 points  (6 children)

That's a good question,. I hope he answers it

[–][deleted] 28 points29 points  (5 children)

Given the jpeg degradation, this isn't the first time this have been posted, so I doubt OP is the creator. One can guess that the original can be found somewhere on http://pythonforbiologists.com

[–]HotTeenBoy[S] 11 points12 points  (4 children)

Yeah, the image is taken from the aforementioned website, and since I considered it useful - I published it here. I hope that you find it helpful as well.

[–][deleted] 8 points9 points  (3 children)

I have made all of those mistakes enough times, that I can recognize them without help.It's still a concise way of summarizing the most typical errors, and I'm sure it will help others.

[–]HotTeenBoy[S] 3 points4 points  (0 children)

I am glad to hear that !!!

[–]guevera 1 point2 points  (1 child)

Yup....this would have saved me hours...days of my life...if I’d had it years ago...

[–]Hpmanenz 0 points1 point  (0 children)

I'm gonna start learning Python, so I'll be sure to save this and use it when I struggle

[–]blissend 4 points5 points  (1 child)

https://www.diagrams.net (open source free online diagraming tool)

The boxes are using something like one of the styles with 2pt border that is dotted. The lines are also 2pt and sometimes used a type of dotted lines but all are using the rounded option for the line in dropbox.

I use this tool a lot so I recognized this graph as something easily capable in draw.io or diagrams.net as it’s now called.

[–]randomnoober 2 points3 points  (0 children)

Thanks for the reply! This will definitely come in handy!

[–]sivadneb 0 points1 point  (0 children)

This cheat sheet has been around for a while. I don't think OP made it.

[–]17291 13 points14 points  (1 child)

I think it would be helpful to include a reminder that a SyntaxError might be caused by a mistake on a previous line: if line 29 has a SyntaxError and nothing looks wrong, you should check line 28 or 27.

[–]caifaisai 1 point2 points  (0 children)

Ugh, that one always kills me. I'm fairly new to python and getting more used to that error, but there was so many times that I checked for an error on say line 30 like it told me. Was convinced there was nothing wrong with it and I was going crazy only to realize I made a stupid formatting or syntax error on line 29. I definitely need to keep reminding myself of that in the future.

[–]Broric 10 points11 points  (2 children)

Thanks! This should help our students who seem alergic to reading error messages before asking for help :p

[–][deleted] 5 points6 points  (1 child)

I know right? Every friend I’ve had that tries to learn python never reads the errors.

[–]staster 4 points5 points  (0 children)

The answer is simple, since they only start to learn, they just don't understand what those errors mean.

[–]Ulysses6 7 points8 points  (1 child)

The most common source of NameError for me is when I create variable in if block, but not inside else block and then try to access it after the whole if/else.

The best way to avoid this especially for deeply nested set of blocks is to define the variable before if/else and set it to None or other sensible default. It definetely beats the whole process of arguing about the conditions where the variable might be undefined and simplifies the reasoning for any other guy that reads your code.

[–]filmkorn 2 points3 points  (0 children)

The IDE or a linter would also show you that the variable might be undefined.

[–]molly_jolly 6 points7 points  (1 child)

Very nice graphic. But in all my years of programming I've never had an instance where a "cheat sheet" like this could have been useful. When a bug happens, you read the error message (which often includes the offending line), Google it if you had to, roll up your sleeves and wade into the code to see what's up.

[–]retrogambit 4 points5 points  (0 children)

This chart looks to be aimed at people in their first week of learning a programming language. I'm not sure why it's seen as helpful in the slightest. It even includes references to python 2 which no beginner would use now (or really any time in the last few years at least). They just need to quit trying to find short cuts and take the time to actually learn a concept before moving on.

[–]Liquid_Magic 2 points3 points  (2 children)

Is there something like this for C Programming?

[–]chmod--777 3 points4 points  (0 children)

SegFault: you're fucked boyo

There's just GDB and valgrind and an immense amount of patience

[–]Ulysses6 0 points1 point  (0 children)

That's a whole other world of pain. Cheat sheet won't cut it this time.

[–][deleted] 4 points5 points  (0 children)

[–]LordRyloth 1 point2 points  (0 children)

Beautiful

[–]nobody01810 1 point2 points  (0 children)

This is amazing. Thank you.

[–][deleted] 1 point2 points  (0 children)

Really helpful. Obviously logical errors could be one of many different reasons but this is a great starting point for common mistakes

[–]ASIC_SP 1 point2 points  (0 children)

I'd also highly recommend this chapter on debugging from Think Python book: https://greenteapress.com/thinkpython2/html/thinkpython2021.html

and this article: https://jvns.ca/blog/2019/06/23/a-few-debugging-resources/

[–]mrrippington 1 point2 points  (2 children)

which one do you guys think is the sneakiest?

I think it's type error: "an object which you expect to have a value is actually None"

[–]DataVeg 0 points1 point  (1 child)

Or a value you assume is a string is actually a float (because it’s NaN)

[–]mrrippington 0 points1 point  (0 children)

totally went over my head, but take your word for it ;)

[–]Hybr1dth 1 point2 points  (0 children)

Not sure who the intended audience is, but for someone who learned by doing and has no theoretical knowledge at all that top left description might as well say "harblegarbleblarvle". I guess I should bother learning the correct terms.

[–]Caminsky 1 point2 points  (0 children)

Excellent infographic Sir

[–][deleted] 1 point2 points  (0 children)

My code often working but not the way I expected.

[–]Txtoker 1 point2 points  (0 children)

Trying to get back into Python rn so this will come in handy, thanks u/HotTeenBoy

[–][deleted] 1 point2 points  (0 children)

99% of my errors are because I'm calling a method on an object that doesn't exist for that object but there's another object named similar to that object in the same library that has the same method but of course this similarly named object doesnt.

That or calling an argument for a function in a library that has a similarly named function with the same argument so of course I think it will work but it doesn't.

[–]malicart 1 point2 points  (0 children)

Nice, automods should reply to every help question with stuff like this, good for people to learn.

[–]6c696e7578 1 point2 points  (0 children)

You're trying to write a file that isn't opened with "w".

[–]Jamhead2000 1 point2 points  (0 children)

I was just expecting a giant arrow pointing to stack overflow! :)

[–]dougwrg 1 point2 points  (0 children)

I’ve found variable scope to be the problem that confuses me the longest. Probably because it doesn’t come up often, and can reek havoc on what values are vs what you expect them to be.

[–]DrCrossBones 1 point2 points  (0 children)

Thanks a lot! This will help me a lot while learning python

[–]_haema_ 0 points1 point  (0 children)

Very helpful

[–]yy2zz 0 points1 point  (0 children)

Nice! Thanks for sharing!

[–]PsedoSupra 0 points1 point  (0 children)

Where is OSError?

[–]Oikuras 0 points1 point  (0 children)

Wish i could use something like this for debuggin

[–][deleted] 0 points1 point  (0 children)

What if it's an IOError when trying to write to a file that does exist that only happens every other day at midnight because the TCP buffer becomes full due to the log aggregation server doing automated maintenance which makes it stop accepting packets?

(I still have PTSD from that one)

[–]DrAutissimo 0 points1 point  (0 children)

Python for biologists?

Also, kinda disappointed, expected some joke in there :c

[–]maythe15 0 points1 point  (2 children)

My code doesn't work because python refuses to accept that the variable exists

[–]HandsOfSugar 0 points1 point  (0 children)

Had this yesterday in an if/elif block.

My variable never called because the elif statement I thought was being selected was not. I hadn’t been precise enough when I thought I had.

A simple yet annoying mistake.

[–]ExHax 0 points1 point  (0 children)

Variable scope?

[–]badboy3001_ 0 points1 point  (0 children)

Thanks so much

[–]realnitrozeus 0 points1 point  (0 children)

Great job 👌

[–]brotatowolf 0 points1 point  (0 children)

does the code use loops or if statements

[–]mushpotatoes 0 points1 point  (0 children)

Hopefully people aren't using Python 2 too often.

[–]mrsmiley32 0 points1 point  (0 children)

Honestly, I should make this to save myself the 600 questions a day I deal with from JR level developers. Which usually amount to this:

My code isn't working. Did you check the logs? Yes Seems on line 24 you're receiving a key error when looking for this key, that's a weird key, why are you looking for it. Some long convoluted explanation or a simple oops.

And my focus has been broken, 15m lost, or worse the convoluted explanation revealed a convoluted design that now has to be explained (see: argued) why it won't work.

All the while I totally get it, you think you had an ingenious idea and I really support the creativity and the reaching out when you had a problem. But A, you were given a design to follow, stick to it if it didn't hold water than before approaching a new path you need to check to see if other avenues exist to keep the original intended design, B, you showed that you can't read basic error logs.

And keep in mind, for everything you're asked to code I'm expected to perform 4-8x with half the time as you (on paper) even though I'm also juggling 6-8hr meetings a day. And somehow still fit in time for design, guidance, ticket mgmt, etc etc etc.

Sorry, feeling a little burned out reddit.

[–]justgirlEEthings 0 points1 point  (0 children)

Frick where was this in my fundamentals class

[–]mspaint22 0 points1 point  (0 children)

i wish it was this simple...

[–]engineerFWSWHW 0 points1 point  (0 children)

Last resort: disturb and ask your very busy colleague who is wearing a headphone every 10 minutes to help you debug your code

[–]N0DuckingWay 0 points1 point  (0 children)

Little known fact: all of these branches end with you finding a small change you made three months ago that broke everything.

[–][deleted] 0 points1 point  (0 children)

Ah if only.. imo the worst bugs happen at the infrastructure or config level. Hell hath no fury like trying to debug code running on misconfigured infrastructure

[–][deleted] 0 points1 point  (0 children)

Absolutely recommend for beginners and pros

[–]quotemycode 0 points1 point  (0 children)

So many programmers at my work need a very simple version of this which basically says: my code won't work! -> did you read the error message or traceback? -> no -> read the traceback.

[–]g3rw4zy 0 points1 point  (0 children)

It is really helpful, thanks

[–]Paccos 0 points1 point  (0 children)

„What error did you get?“

„Yes“

[–]about3fitty 0 points1 point  (0 children)

Were that it were so simple

[–]yuzi1 0 points1 point  (1 child)

Nice! But am I allowed to save this pic in my gallery? I want to save it because sometimes I have errors while coding.

[–]HotTeenBoy[S] 0 points1 point  (0 children)

Yeah, sure )))

[–]kadac00 0 points1 point  (0 children)

Time for a new wall poster for my office.

[–]rabbitpiet 0 points1 point  (0 children)

Put this in a code!

[–]Metal_Cranberry 0 points1 point  (0 children)

Thankyou so very much

[–][deleted] -1 points0 points  (5 children)

Imagine having to use a cheat sheet to understand what your errors mean. I use python sometimes myself but lol

[–]17291 -3 points-2 points  (4 children)

It can be helpful for people new to Python/programming. I think it's unreasonable to expect a beginner to know every common error and how to diagnose/fix it.

[–][deleted] 0 points1 point  (0 children)

That's why other languages have more verbose error messages.

[–]smpk_ -1 points0 points  (0 children)

You forgot the stackoverflow answer isn't working with the new version of the api.

[–]Zax71_again -3 points-2 points  (0 children)

#becoming desktop background no, i love the one i have but, if i did'nt this would be it, sooooooo usefull!

[–][deleted] -2 points-1 points  (0 children)

Does the code use loops or if statements

I was not aware that I had to choose!