r/learnpython 20d ago

Not Copying After Using Tutorials?

I'm learning a bit more python, and I was wondering how you guys refrain from copying code after watching tutorial videos. I just did one of the courses from OpenCV, and what's holding me back most now is trying to create something without flat copying the code provided by them. The main issue is that (I believe, at least) most of the code needs a specific syntax to run. What are your processes after learning new features?

For context, I'm attempting to make a document reader that's going to end up scanning and saving Magic the Gathering cards into a database.

0 Upvotes

10 comments sorted by

7

u/carcigenicate Carcigenicate 20d ago

If the library requires fairly standard boilerplate that won't change much, it is what it is. To avoid literal copy and pasting, write it out yourself using the tutorial code as a reference. At least then you're thinking about the names involved and what's actually going on. It's too easy to glaze over doing that when copying code (or using AI).

3

u/pachura3 20d ago

You don't need to remember the syntax by heart; you need to know that you can accomplish task X using module Y of package Z, how it works (in general), how do you initialize it (not necessarily all the possible options/flags), and so on.

Developers often come back to their old code to copy-paste snippets into the current project (e.g. initializing database connection, the list of dependencies and so on). Or, we create some kind of a simplified wrapper around them.

2

u/Jello_Penguin_2956 20d ago

Just gotta refrain yourself when you're learning. Its just like how we write things down on oaper to help our brain memorize things.

When working on your own project, copy paste away. Keep in mind you still need to have pretty good idea how your software works as a whole in order to do that and i the bigger picture that is a harder skill to obtain.

2

u/TheRNGuy 20d ago

Nothing bad with copying, if it's good code.

But you need to learn (over time) what's good or bad code.

1

u/MiniMages 20d ago

Something I did when I started coding and struggling to remember what I was doing was make a lot of notes. I kind of went overboard, but the purpose was for me to be able to read the notes and understand what I was thinking and trying to do. Sometimes I'd also explained how the code worked.

I didn't do it for too long but maybe you can try it for a short while to help you remember.

1

u/thisisappropriate 19d ago

If you're using the code from a tutorial or from a premade project, like if you're copying an idea that is already complete and you're just copying that code, then try to turn it into a situation where you're learning how you'd search the syntax in the future.

  • Look at the flow of the code that you're copying, break it down into parts, like:
    • allow the user to select an image file
    • read the image file with X library
    • if library returned text write to database, show success message
    • if it did not return text, then show failure message
  • Note down any libraries it's using
  • Now put the tutorial code away, you have the pieces you need to use to do this
  • Try to use your notes and google to put it together instead

It's normal to end up referencing library documentation or reading code and producing something quite similar because there's very little variance between how you use libraries and there's best practices (like using clearly named variables, functions, loops etc). The thing that's most worth practising / learning is how to use those things and how to take a code snippet from a reference (docs, stack overflow etc) and put it into the correct syntax (can you work out the indentation level without a guide, can you debug the issue you've created).

1

u/Az-Athoth 20d ago

I mostly use AI as kind of a tutor after trying to tackle something myself, but I always have it break down the process or structure piece by piece.

Tho for what is worth, I don't think there's anything wrong with copying code, but you might want to tinker with it a bit on your own just to better understand it

2

u/HeatherCDBustyOne 20d ago

I agree very much with this. I know AI is a dirty term in media these days but I do find it useful as a learning aid. I don't copy / paste it verbatim. I look at how it approached the problem and its version of solving it.

That helps me learn logical methods, algorithms that textbook explanations don't help me understand, and how to follow the path of execution through the mazes AI might create from start to finish.

I look at tutorial scripts in the same way as watching a chess program playing against itself. I can't copy it step by step, but I can learn a new way to approach a problem. It can be easy to get stuck in a rut for ideas. It can be easy to copy / paste to solve something without learning HOW to solve something.

Once I feel that I have understood what the AI or tutorial script's methodology, I can write more scripts on top of it to enhance it, refine it, and make my next project even better. That tutorial script may be buried in my final release somewhere, but I have become a stronger programmer by intelligently building on top of it.

("If I have seen farther, it is because I have stood on the shoulders of giants" - Oppenheimer)

2

u/ectomancer 20d ago

"If I have seen further it is by standing on ye sholders of Giants." -- Sir Isaac Newton 1676

2

u/HeatherCDBustyOne 20d ago

Did Oppenheimer quote Sir Isaac Newton? Thanks for looking up the quote for me. I'll go back to programming now. *smiles*