开发者

Intentionally Buggy Code (Python)

开发者 https://www.devze.com 2023-01-10 17:43 出处:网络
This is a strange request but I\'m looking for buggy Python code. I want to learn more about bugs and debuggers 开发者_Python百科and I need some buggy code to work with. Unfortunately, all the code I\

This is a strange request but I'm looking for buggy Python code. I want to learn more about bugs and debuggers 开发者_Python百科and I need some buggy code to work with. Unfortunately, all the code I've written is short and bug-free (so far).

Preferably it's not GUI stuff (b/c I'm just starting to learn it) but anything's good.

Thanks in advance


Not sure how to scout "intentionally" for source code with bugs but you can look into the bug trackers of the main Python projects (and the less widespread ones, too), look for the bugs the reports refer to and debug them. It's a win-win situation. You win the skill to debug and they (hopefully) win a patch for the bug :-)


Debugging is 70% about finding and figuring out the bug from reports of anomalies before you can do anything about it, and 30% about figuring out how not to take the castle of cards down when fixing it. If you have it pointed out in the code for you, or are just given code and you're told it's buggy, you're in a worse place than where you started.

Lawrence's comment is spot on IMO, go hunt down something that's been tracked and logged and you have rero steps for in a project where you have realistic constraints and enough codebase to work with if you want this exercise to have any meaning. Will double as good exercise in learning to read too when you have to puzzle out an alien code base too.


Here's a nice example, spot the bug ;)

Just a bit of code that bit me a couple of years ago.

methods = []                       
for i in range(10):                        
    methods.append(lambda x: x + i)        

print methods[0](10)                       
0

精彩评论

暂无评论...
验证码 换一张
取 消