How to make a solution that has been given to you yours again?


It’s an odd one but I am curious to know everybody’s opinion on this:

I have been working on a pet project using python. I have been stuck on one particular place for days. Then I finally gave up solving it alone and decided to ask the question on Stack overflow where someone really nice, not only did solve my problem but also made my code much more readable and clearer…
I feel like the very project is no longer mine and it would be like cheating if I were to re-use the entirety of the code even if the solution is there.

Given the nature of coding and the “don’t reinvent the wheel” approach, such circumstances must happen fairly often so my question is:

How do you make that code “yours” again?



I think, that you need to understand how the solution given to you works. And there is nothing wrong in asking for help.

Just use the solution and your old code and keep the clean code for future reference of how it should be done :slight_smile:

Just try to understand why that code is better instead of just copy pasting so the next time you can do it yourself and you do yourself a favor by learning something! I assume you tried really hard to find a solution yourself, still got stuck and then went to Stackoverflow to ask the question, so there is nothing wrong with using the code that was given to you :slight_smile: You are using it to create something new! Just like what Pablo Picasso would have said: good artists copy, great arists steal :sunglasses:

I think that it’s still your project, but things like that will always happen after contact with someone more experienced.

What do you mean by readability? Are you concerned about the code logic or was it more about ‘visual’ layout? If it’s the latter I can wholeheartedly recommend going through PEP-8 Code Guidelines to understand how all of that should be composed. Maybe look for a PEP-8 plugin for your IDE or editor that would apply some style correction for you. If it’s the former however… practice! Read code of other, more experienced, developers and try to grok how and why they made certain choices or decisions.

I hope that I helped you in at least some manner. :slight_smile:

1 Like

Classical Not Invented Here syndrom :slight_smile:

Let’s say you are using jQuery or Bootstrap for your project. Is it still your project or not?
You’ll often be using some amount of external code, so just embrace it. You can’t make everything from scratch.

Or can you?


An external solution can be taken as a base for one’s own development, rather than being used as-is.

I think this line from your link sums up the solution to copy and paste code. Like everyone says, you’ve got to learn it from somewhere and modifying other code is a good way to understand it.

As everyone said here before make sure you deeply understand the code. Don’t just blindly copy and paste. Something I have done in the past is find a solution on stack overflow. Use it in my own code ,but print out some logs in key places get a deep understanding of it. Then delete the solution entirely, and re do it on your own. Can you reproduce the solution?

Also, I don’t think anyone mentioned it before make sure you credit the answer in your code.

Good luck :grinning:

all great answers here. Even just retyping it rather than copy/paste can be helpful. Try making a mini version of your problem using the new solution, then try to re-implement. Lots of code gets reused…as long as you understand why the new solution works and why it improves yours use it if it helps move you forward. I’ll often add a comment in my source code with a link to the stack overflow page where I got the help, even if I have since modified it.

autopep8 for life!

Wish there was something similar (and commonly used) in JS-world.

You said it. It’s really baffling to go from the world of pretty formalised languages like Python, C++, Rust, C# or Java to a language like JavaScript. Browser code is compressed by removing all whitespaces aside from the ones within literal strings; if not then the indentation can very well be mixed tabs and spaces and the only constant seems to be the use of camel case over snake case. Most people don’t comment the code, at least the one compressed for browsers, but even some Git repositories seem to have abandoned the practice. Not that it’s something unique to JS. :wink:

Don’t get me wrong, I’m not criticising the language. It’s just going to require some adjusting to the lack of a widely accepted standard, Fortunately, most IDE or text editors have either some sort of default setting when dealing with JS or allow you to make your own standard to keep it consistent.

Thanks all, much clearer now :wink:

@dandevac : I meant that the code itself is more understandable.

I will need to tweak the code i think after review

FYI, I found prettier which while not necessarily an agreed upon standard, can at least reformat your code into something sensible and consistent.

Being new to coding too I totally know that feeling. It’s a hard one for me, I ALWAYS want to do something myself, that goes for everything in my life, not just coding. Ask anyone I know. :slight_smile: I think the most important thing is to understand the code solution so you can do it yourself next time. And to echo the above comment, make sure you credit the code if you use it. During the JSON section on FCC I spent days trying to figure it out, initially I ended up mostly using someone else’s solution, but I kept at it and read all the docs for JSON and APIs and now I have a much better grasp of it.

Keep it up, someday you’ll be the one giving the advice!