13 Replies - 1100 Views - Last Post: 09 April 2016 - 11:40 PM Rate Topic: -----

#1 Hype  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 12-December 15

Learning vs Copying

Posted 08 April 2016 - 07:19 AM

Recently I've noticed that I don't think I'm actually learning anything, I'm mostly copying and don't truly understand what's going on. I just know that I need to type a certain piece of code to make a certain thing happen, is this normal?

Is it common for people to type code that they don't really understand, they just know that it does what they need it to do? Or do all programmers actually understand the code they're typing and exactly how it works?

Is This A Good Question/Topic? 0
  • +

Replies To: Learning vs Copying

#2 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 615
  • Posts: 2,596
  • Joined: 13-June 14

Re: Learning vs Copying

Posted 08 April 2016 - 07:28 AM

At the beginning, you should be typing things and understanding what you're doing. Eventually, when you've gotten that understanding, you'll be able to do it without thinking.

As an example, recently I saw someone basically google how to solve a particular problem and the solution they found involved list comprehensions and other things they didn't really understand. So, when I asked them to explain to me how it worked, they couldn't. What they should have done was to think about how to use what they already knew to solve the problem (which definitely was possible and yes, it would have taken longer).

So really, take time to solve the problems yourself, again by thinking about how you can use what you've learnt. I think that's the main test of your understanding.
Was This Post Helpful? 2
  • +
  • -

#3 astonecipher  Icon User is offline

  • Too busy for this
  • member icon

Reputation: 2343
  • View blog
  • Posts: 9,400
  • Joined: 03-December 12

Re: Learning vs Copying

Posted 08 April 2016 - 08:25 AM

If you don't understand the code you are copying and pasting over, what happens when you need to modify it to get different results? Do you search for other code to copy and paste that does the other thing?

The key to learning, is understanding. If you don't understand what is being done, you are wasting your time.
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12189
  • View blog
  • Posts: 45,251
  • Joined: 27-December 08

Re: Learning vs Copying

Posted 08 April 2016 - 08:37 AM

If your assignment is to check if a string is a palindrome and you copy code to do this, then that's not learning. If you look up how to write a loop or access a character at a specific index, that's totally okay. Everyone looks up syntax and library usage at some point.

Try to use that as your metric for gauging what to Google moving forward.
Was This Post Helpful? 0
  • +
  • -

#5 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10735
  • View blog
  • Posts: 18,363
  • Joined: 19-March 11

Re: Learning vs Copying

Posted 08 April 2016 - 10:24 AM

View PostHype, on 08 April 2016 - 09:19 AM, said:

Is it common for people to type code that they don't really understand, they just know that it does what they need it to do?


Yes, it's called "using a library". I have no idea how the reader and writer in python's csv library are implemented, and I don't care. Since it's a library, someone else is in charge of making sure it works and it stays working.
In a sense, you could put most of your toolset in this category. I don't know about you, but I've never looked into the guts of the python implementation that I'm using.

That's not what you're asking, though. You're asking about copying lines of code that someone else wrote, and dropping them into a different context, and hoping they work. This is a very dangerous practice, and it's likely to bite you hard at some point - and the real problem is, you'll never know when it's going to fail, because you don't understand the lines that you're using. Do people do this? Yes, all the time. Do they do this in production code? I'm sure they do, in some shops. Good code review should ensure that this sort of thing doesn't get merged to master very often unless SOMEONE in the shop understands it (if I'm reviewing your code, and I don't understand it, I'm supposed to ask you about it... and then we find out that you don't understand it either, and we go and figure it out, and then two people understand it)

To riff on the title of the thread a little, the difference between learning and copying is really about what you do with the code you copy. If you're reading a book on python, and you see an example, the right thing to do is to analyze that example and make sure you understand what it's doing and how the individual pieces fit together, and what each piece is doing as a part of the whole. You don't have to understand what print means - that's an atom, it just is what it is - but you should be able to see how something like print ("%s and %b" % ("foo", "bar")).capitalize() fits together to produce - well, you tell me. Can you see what that should produce, and why? If not, here's a good chance to practice.
You can do the same thing with a sample of code you get from StackOverflow or some other source. It takes a little more work, but once you have understood the pieces and how they fit together, then you are a few steps closer to being capable of maintaining that code in the future.
To my mind, the ability to learn from examples rather than simply dropping them in is a key milestone for becoming a programmer, and the willingness to simply drop in lines without understanding them is a serious no-hire mark.

I don't care if it takes you a little while to learn how the code works. I care very much if things start going wrong later and we have to re-work your solution because the stuff you borrowed didn't really fit our needs correctly.
Was This Post Helpful? 2
  • +
  • -

#6 Hype  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 12-December 15

Re: Learning vs Copying

Posted 08 April 2016 - 10:39 AM

Thanks for the posts.

An example of the sort of copying that I mean is if you have your program but you just can't figure out how to do a certain thing, so you google it, find the solution and then use that solution. Then the next time you need to do that task in a different program, you just copy the code from your previous program. What you end up with are lots of code chunks in your program that you have no idea how they work you just know they do.

So you essentially just remember that it works rather than how it works.
Was This Post Helpful? 0
  • +
  • -

#7 baavgai  Icon User is online

  • Dreaming Coder
  • member icon


Reputation: 6997
  • View blog
  • Posts: 14,637
  • Joined: 16-October 07

Re: Learning vs Copying

Posted 08 April 2016 - 10:53 AM

View PostHype, on 08 April 2016 - 09:19 AM, said:

Is it common for people to type code that they don't really understand


Well, typing is kind of unusual; it tends to be copied and pasted in giant swaths. ;)

Like any modern programmer, I often start by asking the interwebs how to solve a problem. I find bits wisdom than I then must cobble together to make something happen. However, I have to admit, I don't generally like other people's code, even when it works, so I "fix" it.

You learn a lot from taking code you don't understand and breaking it. You often learn what the parts you didn't understand actually do. I very rarely end up using other peoples code, in the sense that by the time I'm done messing with it the original writer wouldn't recognize their contribution to my final version.

You cannot learn by throwing lines of code in and walking away. However, you can learn a lot by taking code you're actually interested in and trying to make it work just a little differently. Make other people's code your own and you'll always be learning.
Was This Post Helpful? 2
  • +
  • -

#8 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10735
  • View blog
  • Posts: 18,363
  • Joined: 19-March 11

Re: Learning vs Copying

Posted 08 April 2016 - 11:08 AM

Quote

So you essentially just remember that it works rather than how it works.


Yes, this is what we call an "antipattern" - it feels like the right thing to do when you're doing it, but over time it leads you into an unmaintainable state.
Like most antipatterns, there's never a point where doing it is obviously worse than not doing it - the marginal cost of just dropping this line in here is low relative to the harm that it does - so it's always tempting. (Notice the parallel with bad habits like smoking - there's never a point where this next cigarette is the one that's going to kill him, so the smoker can always have "just this one") Also like most antipatterns, the long-term cost of undoing the damage far outweighs the aggregated short-term benefit. Therefore, the correct solution is to simply impose a rule on yourself: don't allow code into your codebase that you don't understand, unless it's in a library that you have reason to believe will be well-maintained for the life of the project, or at least will fail slowly enough for you to find an alternative.

Note that this doesn't mean you can't use code from the web! In fact, you should look at how other people solve problems, and learn from what you find. However, you should make sure that you first learn from it, and only then deploy what you've learned.
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13567
  • View blog
  • Posts: 54,133
  • Joined: 12-June 08

Re: Learning vs Copying

Posted 08 April 2016 - 11:15 AM

Quote

An example of the sort of copying that I mean is if you have your program but you just can't figure out how to do a certain thing, so you google it, find the solution and then use that solution. Then the next time you need to do that task in a different program, you just copy the code from your previous program.

.. and what, you never go back to inspect/learn/pick apart what you copied? That's awfully lazy and showing a deficit of caring to be better.

The fun really hits when you've been "totes coding for 3+ years" and still stymied with problems and pine "oh where do I start?!". As I have mentioned to a few folk in the last two weeks you _will_ encounter problem spaces that have no tutorial, that have no hand holding, and that have no tutor to fall back on. If you have been just copying shit for all those three-plus years you will not be able to actually synthesis a solution because it is new. Your three-plus years of being a "coder" actually means you have spent three-plus years being a parasite that masquerade as a person who creates (aka - a programmer).

How do you avoid being a parasite - simple: do work. Apply what you know and spend time doing a project. Take a look at our project lists. Pick something, plan it out, and make it happen.

Project Ideas
Martyr2 Mega Project List

If you find yourself slipping into just 'googling for answers' to your own self assigned projects because of time, wanting the false sense of pride for a hollow completion, or what ever I would politely ask you to fudge off and find another profession to muck around in.
Was This Post Helpful? 2
  • +
  • -

#10 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10735
  • View blog
  • Posts: 18,363
  • Joined: 19-March 11

Re: Learning vs Copying

Posted 08 April 2016 - 11:18 AM

That's another way to put it, yes.
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13567
  • View blog
  • Posts: 54,133
  • Joined: 12-June 08

Re: Learning vs Copying

Posted 08 April 2016 - 11:26 AM

It's Tough Love Fridays, jon. Sometimes the world needs a few extra dunks for good measure.

Spoiler

Was This Post Helpful? 0
  • +
  • -

#12 Hype  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 12-December 15

Re: Learning vs Copying

Posted 08 April 2016 - 01:24 PM

mod: please use the 'reply' button instead of quoting the post above yours.
---

It's ok, I can accept straight up replies.

I'm actually programming for fun, as a hobby so I'm not trying to "make it easy" to complete assignments or anything of that nature. I'm doing this purely for my own interest.

I'll take onboard what you've said and try to spend more time figuring out the solution rather than just googling it. If I have to google for the solution I'll make sure I fully understand it before using it so next time I have the same problem, I will have learnt how to solve it, rather than remembered how to solve it.

Thanks.

This post has been edited by modi123_1: 08 April 2016 - 01:29 PM
Reason for edit:: removed giant quote. Just use the 'reply' button.

Was This Post Helpful? 0
  • +
  • -

#13 MentalFloss  Icon User is offline

  • .
  • member icon

Reputation: 577
  • View blog
  • Posts: 1,500
  • Joined: 02-September 09

Re: Learning vs Copying

Posted 08 April 2016 - 09:43 PM

Quote

I'll take onboard what you've said and try to spend more time figuring out the solution rather than just googling it. If I have to google for the solution I'll make sure I fully understand it before using it so next time I have the same problem, I will have learnt how to solve it, rather than remembered how to solve it.


Yeah, these are all good ideas. You know what I do too? I manually type out the code that I'm interested in. Not only that, I write it in the way that the author probably wrote it, and continually compile along the way to make sure it works. What I mean by this is write the skeleton, compile, fill in a method and write the calling code to that method, compile, repeat until their work has been transcribed.

You might argue "I don't want to reinvent the wheel. It's a waste of time. I just want it done.", but I say that if you have to write it yourself -- you will really understand it. If you just copy/paste, or write the whole thing in one fell swoop, you don't really learn anything about the code, nor do you better yourself as a programmer.
Was This Post Helpful? 1
  • +
  • -

#14 DK3250  Icon User is online

  • Pythonian
  • member icon

Reputation: 326
  • View blog
  • Posts: 1,110
  • Joined: 27-December 13

Re: Learning vs Copying

Posted 09 April 2016 - 11:40 PM

In the help forum, people sometimes ask for code. It is generally always rejected and we ask of OP "Show us what you have done - then we will help troubleshooting".

The philosophy behind this approach is not that we (the DIC community) wants to be evil. It is because people learn much more from working/thinking themselves; code that are handed out are seldom scrutinized in the same way as code made by oneself.

For the last 3 years I have, on volunteer basis, educated kids (age 10-16) in Python (and HTML/Javascript). It is my experience that understanding is paramount.
It happens that a kid has been absent for on or two sessions; in order for the group to progress, I have tried to hand out code covering what has been taught during the absence.
It works, in the sense that I can continue on a common platform - but in most cases, it later becomes clear that very little understanding is associated with handed-out code.

It's fine to give or receive small code snippets, explaining some aspect. I learn a lot from other peoples code samples; but only if I spend enough time to really understand. It happens that I receive a code snippet that I don't understand - such code I don't use; I can't maintain it and I can't be sure how it works in all situations.

This post has been edited by DK3250: 10 April 2016 - 12:51 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1