Answers.Body: <p>If you mean by "debugging" teaching students to use a debugger, I wouldn't do that. However, having students finish or repair a program that you create is a useful early exercise. In particular, you can give them a program larger than they would be expected to write themselves. It needs to have excellent design/coding. But you have either removed or carefully broken a few parts before you give it to them. The errors introduced can be quite simple (missing punctuation) or more complex. </p>
  
  <p>The students get to (a) read code (b) see good design (c) interpret compiler diagnostics (d) grapple with structure - assuming the program has some length. </p>
  
  <p>This idea is discussed in the book <a href="https://smile.amazon.com/Pedagogical-Patterns-Educators-Joseph-Bergin/dp/1479171824/" rel="nofollow noreferrer">Pedagogical Patterns: Advice for Educators</a>, where it is called "Fixer Upper". </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T18:34:03.983Z
Answers.Text: I just looked up that book. That was quite a fun little rabbit hole! Welcome to [cseducators.SE]. I hope we hear more from you in the future!
Answers.UserDisplayName: Ben I.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T12:52:23.877Z
Answers.LastActivityDate: 2017-09-04T18:35:05.443Z
Answers.LastEditDate: 2017-09-04T18:35:05.443Z
Answers.UserDisplayName: Buffy
Answers.Body: <p>I give students targeted debugging exercises to make them aware of common <em>traps</em> that they can fall into while coding, and I believe that this is beneficial to them.  Certain errors come up all of the time, and pointing them out can be a real time-saver for students when they code their own labs.</p>
  
  <p>I also give out small bits of badly-formatted code, with poor variable names, indentation, etc.  But these are always to call attention to the importance of good coding practice.</p>
  
  <p>However, I do not emphasize either of these activities heavily; the ability to conceive of algorithms is still of the utmost importance, and I don't want to halt students' growth along this more important axis.  And switching entirely into debugging might (perversely) not help them learn the most important skill of debugging, which is to test with extreme regularity as you work, since you are providing them with fully implemented (bad) code.</p>
  
  <p>So, <em>yes</em>, by all means, give students limited, carefully targeted debugging exercises.  But don't switch completely over to this activity.  Finding bugs is important, but it is only one skill that a budding developer needs.  </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T12:19:14.663Z
Answers.LastActivityDate: 2017-06-22T12:19:14.663Z
Answers.UserDisplayName: Ben I.
Answers.Body: <p>In the engineering world, being able to read, understand, debug and add on to existing code is MUCH more valuable skill than writing code from scratch.  Too often, programmers will opt to rewrite a block of code from scratch rather than (or being intimidated by) spending the time to understand the existing code.  This leads to re-introducing bugs that have already been fixed before - not in the code itself, but in the understanding of ALL of the requirements of the code.</p>
  
  <p>Here's a tip for those programmers - if your code seems much simpler, there is a good chance you left out something important.</p>
  
  <p>So, I would vote for putting the emphasis on students learning to read, understand and then debug or augment existing code.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T20:33:02.440Z
Answers.Text: Nice answer. Welcome to CSE!
Answers.UserDisplayName: Ben I.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T06:39:13.930Z
Answers.Text: I came to this HNQ to find an answer like that. In the industry, you often have contexts where it is 90% debugging and rewriting existing code, and only 10% writing your own. So from the "real world" perspective, debugging existing code, usually written by others, is much more prevalent than writing from scratch, but being very good at writing from scratch of course provides the knowledge and capability to know how the debugged code should look like, what's wrong with it.
Answers.UserDisplayName: hiergiltdiestfu
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T19:44:04.863Z
Answers.LastActivityDate: 2017-06-22T19:44:04.863Z
Answers.UserDisplayName: Ross Heitkamp
Answers.Body: <p>I tend to think that CS education should be done in multiple stages (to be repeated as the students progress in skill):</p>
  
  <ol>
  <li>teach them theory</li>
  <li>show them good code
  
  <ul>
  <li>as an example</li>
  </ul></li>
  <li>have them write code
  
  <ul>
  <li>it's implied that they will need to do SOME debugging to "evolve" their code to a working state</li>
  </ul></li>
  <li>have them debug others' not-so-good code</li>
  </ol>
  
  <p>Start with the theory.  Once they start to understand that, show them good examples.  Many folks learn well by example; this helps them "solidify" their understanding of the theory and gives them some idea of how it SHOULD look / work.  Then, get them writing code; no amount of theory and example can replace this.  After all that, start showing them some not-so-good code to debug and clean up.</p>
  
  <p>Remember the famous quote by Brian Kernighan:</p>
  
  <blockquote>
    <p>Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?</p>
  </blockquote>
  
  <p>Tackling complex debugging, when they haven't developed enough skill yet, will be overly-challenging.  Let them build some proficiency THEN start building the debugging skills.</p>
  
  <p>I would agree that good debugging skills are critical.  A quote from Maurice Wilkes:</p>
  
  <blockquote>
    <p>By June 1949 people had begun to realize that it was not so easy to get programs right as at one time appeared. I well remember when this realization first came on me with full force.
    The EDSAC was on the top floor of the building and the tape-punching and editing equipment one floor below. [...] It was on one of my journeys between the EDSAC room and the punching equipment that "hesitating at the angles of stairs" the realization came over me with full force that a good part of the remainder of my life was going to be spent in finding errors in my own programs.</p>
  </blockquote>
  
  <p>I wish I could say that my career was different.  The only difference is that much of the code I maintain is written by others.  A good part of the remainder of MY life will be spent finding errors in my own programs AND those of others.</p>
  
  <p>Once they've developed good debugging skills on one "level" of programming complexity, repeat the cycle for the next level.  Consider debugging skills the "boss challenge" before they've "leveled up" and are ready for the next skill level.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T22:04:21.437Z
Answers.Text: Nice insights from seasoned developer. Welcome to CSE!
Answers.UserDisplayName: Ben I.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-08T07:48:12.540Z
Answers.Text: I love these stages and their order, showing students good code before having them write their own is a better way to build a foundation of coding skills necessary to tackle more advanced material.
Answers.UserDisplayName: Josh Rumbut
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T20:40:46.930Z
Answers.LastActivityDate: 2017-06-23T20:01:27.650Z
Answers.LastEditDate: 2017-06-23T20:01:27.650Z
Answers.UserDisplayName: Meower68
Answers.Body: <p>I've been a software engineer for over 25 years and in my opinion, the two skills are just different.  What you need to know and how you spend your time is very different when conceiving of a new design or code, or fixing something that exists. The two are both required to some extent on most projects but are very different activities.</p>
  
  <p>One of the things about software is that there are usually 2, 3, or maybe 10 different ways to do the same thing.  Inevitably opinions will vary about what is "best" and there is often no single "best" because there are trade-offs and questions of style, and often several similar technologies that can achieve the same result.</p>
  
  <p>Most people prefer to write new code because it's more "fun" and they get to learn and do the things the way they think is best.  It is kind of like building an electric train set.</p>
  
  <p>However, I would wager that on an actual software project, code is read or changed 10 time as often as it is written, so about 90% of the time spent is on understanding and debugging.  Debugging is often easier since it does not require as comprehensive knowledge of the technology or code.  Debugging an existing system is often a good way of learning a new technology and is where new team members are usually started.</p>
  
  <p>I have worked with very smart engineers who just could not stand to fix existing code and every time they were asked to fix something they rewrote it, because their opinions about what was "best" were so strong and rigid.  This in my opinion is self-indulgent and on an actual project where time and money are limited resources it can be very inefficient and wasteful.  Good engineers write good code but good team members know when you just have to fix something and move on vs. when a major overhaul is really needed.</p>
  
  <p>With all this in mind I think it is important to put existing code in front of students and require them to understand and debug it, not only to get it working correctly but to see how other people do things and what choices other engineers make, and also to understand that on an actual job they'll be expected to fix things fairly efficiently.  They will probably find that they agree with some approaches and disagree with others.</p>
  
  <p>At the same time students should be in a situation where they must "debug a blank sheet of paper" where they get to do the fun stuff, but then also find that it is very hard to make choices that end up being the right choices for the project long term.</p>
  
  <p>One way of achieving both goals would be to have all of the students write their own code for part of the project, and then exchange code and problems so that they are then debugging someone else's code, and having their own code debugged.  On a real project this is often done with team code reviews which, if done right, can provide valuable feedback to everyone, both the coder and reviewer.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T16:47:50.353Z
Answers.Text: Welcome to CSEducators.SE! Thanks for the thorough response. Looking forward to hearing more from you!
Answers.UserDisplayName: Peter
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T16:22:41.613Z
Answers.LastActivityDate: 2017-06-23T16:22:41.613Z
Answers.UserDisplayName: Uncle Long Hair
Answers.Body: <p>I would say that it is helpful to have them write their own code in the beginning to better understand the processes that go into writing for an application. It gives them a strong basis and practice with finding errors in the code they're most aware of: their own. Think about it; if they already know their thought process and procedure as to what needs to be done, then they can try as many times as is needed to get that code working perfectly.</p>
  
  <p>However, it is also a fact of life in CS that if you work for anything but a start-up or SaaS company you are almost certainly going to be doing more <em>maintaining</em> of legacy code than actually creating of new stuff. By showing the students how to look through the code of others and find the issues in it, you are giving them practical experience for what will more than likely end up being the majority of their career.</p>
  
  <p>I would suggest having students both write new and debug others' code, starting with writing their own and after a semester shifting gears to maintenance/debugging of faulty code.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T05:48:36.780Z
Answers.Text: Welcome to Computer Science Educators Stack Exchange! This is a great answer! I hope We'll be seeing more answers from you.
Answers.UserDisplayName: ItamarG3
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T05:57:12.997Z
Answers.Text: Thank you for the warm welcome! :) I am admittedly not an educator (past helping some of the kids from the class below me in my programming course during high school) and am in fact enrolled in a CS program starting this fall. However I have been coding for a few years and found this post through the sister site Stack Overflow.
Answers.UserDisplayName: cMcNerlin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T06:00:13.920Z
Answers.Text: Welcome to CSE @cMcNerlin. Don't feel anything coz of not being an educator. Me too not a professional educator. I usally teach coding for my friends and relatives. I am a Developerby profession. and Please note Stackoverflow is actually the father. First they started Stackoverflow and later moved to SE.
Answers.UserDisplayName: i--
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T06:04:20.617Z
Answers.Text: @cMcNerlin It's quite alright. Most are not professional educators here, but they do have insight. I am not a professional teacher, but I have my fair share of teaching, mentoring (see [my question](https://cseducators.stackexchange.com/questions/396/teaching-coding-paradigms-and-concepts-with-specific-context) in that context) and tutoring.
Answers.UserDisplayName: ItamarG3
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T06:07:06.980Z
Answers.Text: @Sagar V Thank you for the encouraging words and fun fact! It seems that SE (or at least the CS educators section) is very welcoming and happy to have new contributors. Also, I have found that every developer or even a novice coder has something to offer for somebody.
Answers.UserDisplayName: cMcNerlin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T05:41:19.060Z
Answers.LastActivityDate: 2017-06-24T05:41:19.060Z
Answers.UserDisplayName: cMcNerlin
Answers.Body: <p>Writing code is essential, and a part of that is debugging (your own) code. If you can't debug your own code, you won't get very far, unless you write perfect code the first time, every time.</p>
  
  <p>Debugging someone else's code introduces students to things that debugging their own can't - different styles, and different approaches to problem solving, that perhaps they would not come up with on their own. So debugging someone else's code helps you write better code for yourself. You learn what is good, what works, and what is bad, and doesn't work. </p>
  
  <p>Just as for learning another natural language (written), you can get fairly far writing and correcting your own words, but at some point, you'll benefit from reading (and possibly correcting) someone else's words. </p>
  
  <p>So to answer your question, yes, I see no problem in having students debug code (that isn't theirs). In fact, I would almost go as far as to say you should. But I wouldn't say that debugging code is more important than writing code. I would say it is part of writing code.  </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T11:57:25.220Z
Answers.LastActivityDate: 2017-06-22T11:57:25.220Z
Answers.UserDisplayName: Brett Becker
Answers.Body: <p>I agree that learning to debug code written by someone else is a critical skill, but I do not think it can replace having to write and debug your own code.  </p>
  
  <p>Writing your own code is a critical design exercise and students need to continue to develop their design skills.  Debugging is a critical skill, but if students cannot create and debug efficient code on their own, they will not be able to code independently.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T15:23:23.470Z
Answers.Text: Hi John! Welcome to CS Educators! As it currently stands I don't really see anything different between your answer and the one given by @BrettBecker. Would you mind elaborating so that the difference becomes clear?
Answers.UserDisplayName: thesecretmaster
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T15:23:35.653Z
Answers.Text: If you look at it from a perspective of teaching debugging to someone who has zero knowledge on the subject, though, targeted debugging exercises written by an instructor can focus on specific skills and strategies in a far more structured fashion than simply relying on whatever luck-of-the-draw situation comes from student-generated code.  By all means, this shouldn't be an either-or proposition.  Both skills are critical.
Answers.UserDisplayName: Tristan
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T14:58:10.963Z
Answers.LastActivityDate: 2017-06-22T14:58:10.963Z
Answers.UserDisplayName: John McManus
Answers.Body: <p>During my 4 years of school debugging was never taught to us. We were only quickly shown that if we get an error, set a break point, see where it breaks and you know 
  where the error is. Looking back, I can understand why we didn't cover debugging and it was because there was so much material to teach that there just was not any time to cover it. 
  As a student, struggling to learn all the new concepts provided, I appreciated the fact that I did not have to learn another concept, especially one that required one to understand
  the IDE I was using. I agree that debugging is a necessary skill for programming but I don't think it should be a requirement. I think the teacher should drill debugging into the
  student’s heads by making it a part of their own routine. When teaching a lecture, as an example, if you declare all your class properties before typing out the methods, this is a habit 
  that students notice and will copy. Once you are done typing your class, instead of creating another class, why not set a few break points, and run the app. Show your students how you
  are stepping through the methods and making sure you are getting the correct output. This workflow will teach the students that the debugger is not only for errors but it is
  a common practice for a programmer to write piece by piece.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T22:05:56.403Z
Answers.Text: We don't get a ton of time to cover debugging. Partly because they will *have* to pick this up later, so we try to focus in on the things that will be harder to pick up naturally. Nice answer, welcome to CSE!
Answers.UserDisplayName: Ben I.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-22T20:40:28.983Z
Answers.LastActivityDate: 2017-06-22T20:40:28.983Z
Answers.UserDisplayName: MIKE
Answers.Body: <p>Neither is "better" or "worse" - just different. Writing your own code and understanding someone else's code well enough to debug and improve it are definitely distinct skills, both of which are necessary to be successful in industry.</p>
  
  <p>It seems like people are rarely given a lot of experience in the latter skill in college, and some curricula don't teach debugging techniques very well (especially to students that are just starting out). (I actually think that Eric Lippert's <a href="https://ericlippert.com/2014/03/05/how-to-debug-small-programs/" rel="nofollow noreferrer">article</a> on debugging should be mandatory reading in college curricula).</p>
  
  <p>So, really, it can't be either/or - both are necessary, especially if debugging assignments are accompanied by instruction in debugging techniques.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-24T18:31:19.973Z
Answers.Text: That's an interesting article. Welcome to [cseducators.SE]. I hope we hear more from you in the future!
Answers.UserDisplayName: Ben I.
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T18:02:26.867Z
Answers.LastActivityDate: 2017-06-23T18:02:26.867Z
Answers.UserDisplayName: EJoshuaS - Stand with Ukraine
Answers.Body: <p>There's a lot of discussion about how people who work in industry spend a lot of time working with other people's code. That's true, but in my opinion, the key skill for dealing with other people's code is skill at refactoring. If you're going to teach new developers how to work with code developed by others, a class on refactoring would be invaluable.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T17:23:07.130Z
Answers.Text: Hi Geoff! Welcome to [cseducators.se]!  Thanks for choosing to contribute your knowledge here. Would you mind fleshing out your answer a bit more? It's already good as is, but that might make it a bit better.
Answers.UserDisplayName: thesecretmaster
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T17:20:12.930Z
Answers.LastActivityDate: 2017-06-23T17:20:12.930Z
Answers.UserDisplayName: Geoff Snowman
Answers.Body: <p>Even though I'm not an educator, I work with programming and personally I don't think that you should teach your students on how to debug (don't curse me!).
  What I'd do is to present them the debugger and say what it is for, followed by a practical example. Then I'd give them code with bug(s) and tell them that they should use a debugger help them find the error (maybe a code with integer overflow problem). Probably I'd do that in one class, like 50 minutes of duration tops. </p>
  
  <p>In my point of view, teaching how to debug is as useless as having a whole class on how to compile a program (on introductory courses). </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T20:53:27.260Z
Answers.Text: Hi Luizfzs! Welcome to [cseducators.se]! Don't worry about not being a salaried teacher -- I'm not either. Anyone who had experience or is interested in CS Education is welcome here, and I'm sure you've taught someone else some CS at some point. This is an interesting take on the question, and I hope to hear more from you!
Answers.UserDisplayName: thesecretmaster
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-23T19:58:02.863Z
Answers.LastActivityDate: 2017-06-23T20:58:12.270Z
Answers.LastEditDate: 2017-06-23T20:58:12.270Z
Answers.UserDisplayName: luizfzs
Body: <p>Is asking students to debug code better than asking them to write code, if the goal is to give students a strong basis in creating error-free code?</p>
  
  <p>In my point of view, when we ask them to write a program by giving some scenario, they will write some code.  Most probably, this code will contain errors. Then they will correct them after debugging.</p>
  
  <p>When we ask them to debug other's code, they will be more careful, they have to pass through various scenarios and they will become very strong in syntax while correcting mistakes and so on.</p>
  
  <p>So, my question is:</p>
  
  <p><strong>While teaching coding, after some point, can I ask them to debug code rather than continue writing code?</strong></p>
  
  <p>Which will make them stronger at coding?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-22T14:16:36.097Z
Comments.Text: Why not both? Give them group project with full code-review and proper testing.
Comments.UserDisplayName: PTwr
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-22T14:55:39.360Z
Comments.Text: Introduce them to TDD early.  It's good for both breaking down tasks to develop algorithms, and for producing quality code in the first place.  Not to mention that it's a very good habit to have.
Comments.UserDisplayName: Baldrickk
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-22T14:58:01.870Z
Comments.Text: Maybe write code, pass it to your neighbour and have them debug it.
Comments.UserDisplayName: Darren Bartrup-Cook
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-22T19:48:04.660Z
Comments.Text: What age group? In my undergrad work our faculty had all "come from the industry" so our work included large projects that were broke and required fixing before augmenting, creation work, and larger group projects where you had to collaborate, integrate and debug. All I'd say made me a better developer when I graduated.
Comments.UserDisplayName: AlG
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-23T03:36:05.520Z
Comments.Text: what makes you believe that any practical application can actually be error free?
Comments.UserDisplayName: atk
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-23T14:01:58.863Z
Comments.Text: In my opinion it's not so much about the debugging (they'll do that anyhow on their own applications as well, although certainly it's different) but just the simple act of **reading other people's code**. In my opinion that's taught way too little if at all in university, but it is oh so very, very, very essential.
Comments.UserDisplayName: Voo
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-23T19:33:38.557Z
Comments.Text: Incidentally, as someone who's done both CS and French teaching-related work, I think there's an analogy with "Should I have students write their own French or edit and translate others'?" The answer is simply **yes** :) The more methods you can throw at a student for interacting with the material, the better it will stick, and also the more likely they'll discover what they love most. Similarly, in the CS courses I was helping with, there were lectures, guided labs, unguided labs, larger assignments, tiny Q&As , mutual code reviews, puzzles, etc. — every possible tool. I thought it was great.
Comments.UserDisplayName: Luke Sawczak
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-24T23:53:01.757Z
Comments.Text: I am currently experimenting with getting pupils to modify existing code — I have not been teaching long, but believe that this will have a better outcome that having struggle to start from zero.
Comments.UserDisplayName: ctrl-alt-delor
Tags: <debugging>
Title: Is asking students to debug existing code better than having them write new code?
ThreadText: # Is asking students to debug existing code better than having them write new code?
  
  (Asked by: username_0 on 2017-06-22)
  
  Is asking students to debug code better than asking them to write code, if the goal is to give students a strong basis in creating error-free code?
  
  In my point of view, when we ask them to write a program by giving some scenario, they will write some code. Most probably, this code will contain errors. Then they will correct them after debugging.
  
  When we ask them to debug other's code, they will be more careful, they have to pass through various scenarios and they will become very strong in syntax while correcting mistakes and so on.
  
  So, my question is:
  
  **While teaching coding, after some point, can I ask them to debug code rather than continue writing code?**
  
  Which will make them stronger at coding?
  
  **Tags:** debugging
  
  > **Comments:**
  > **username_1**: Why not both? Give them group project with full code-review and proper testing.  
  > **username_2**: Introduce them to TDD early.  It's good for both breaking down tasks to develop algorithms, and for producing quality code in the first place.  Not to mention that it's a very good habit to have.  
  > **username_3**: Maybe write code, pass it to your neighbour and have them debug it.  
  > **username_4**: What age group? In my undergrad work our faculty had all "come from the industry" so our work included large projects that were broke and required fixing before augmenting, creation work, and larger group projects where you had to collaborate, integrate and debug. All I'd say made me a better developer when I graduated.  
  > **username_5**: what makes you believe that any practical application can actually be error free?  
  > **username_6**: In my opinion it's not so much about the debugging (they'll do that anyhow on their own applications as well, although certainly it's different) but just the simple act of **reading other people's code**. In my opinion that's taught way too little if at all in university, but it is oh so very, very, very essential.  
  > **username_7**: Incidentally, as someone who's done both CS and French teaching-related work, I think there's an analogy with "Should I have students write their own French or edit and translate others'?" The answer is simply **yes** :) The more methods you can throw at a student for interacting with the material, the better it will stick, and also the more likely they'll discover what they love most. Similarly, in the CS courses I was helping with, there were lectures, guided labs, unguided labs, larger assignments, tiny Q&As , mutual code reviews, puzzles, etc. — every possible tool. I thought it was great.  
  > **username_8**: I am currently experimenting with getting pupils to modify existing code — I have not been teaching long, but believe that this will have a better outcome that having struggle to start from zero.  
  
  ---
  
  ## 12 answers
  
  ### Answer by username_10 on 2017-06-22. Score: 15
  
  I give students targeted debugging exercises to make them aware of common *traps* that they can fall into while coding, and I believe that this is beneficial to them. Certain errors come up all of the time, and pointing them out can be a real time-saver for students when they code their own labs.
  
  I also give out small bits of badly-formatted code, with poor variable names, indentation, etc. But these are always to call attention to the importance of good coding practice.
  
  However, I do not emphasize either of these activities heavily; the ability to conceive of algorithms is still of the utmost importance, and I don't want to halt students' growth along this more important axis. And switching entirely into debugging might (perversely) not help them learn the most important skill of debugging, which is to test with extreme regularity as you work, since you are providing them with fully implemented (bad) code.
  
  So, *yes*, by all means, give students limited, carefully targeted debugging exercises. But don't switch completely over to this activity. Finding bugs is important, but it is only one skill that a budding developer needs.
  
  
  ---
  
  ### Answer by username_11 on 2017-06-22. Score: 15
  
  In the engineering world, being able to read, understand, debug and add on to existing code is MUCH more valuable skill than writing code from scratch. Too often, programmers will opt to rewrite a block of code from scratch rather than (or being intimidated by) spending the time to understand the existing code. This leads to re-introducing bugs that have already been fixed before - not in the code itself, but in the understanding of ALL of the requirements of the code.
  
  Here's a tip for those programmers - if your code seems much simpler, there is a good chance you left out something important.
  
  So, I would vote for putting the emphasis on students learning to read, understand and then debug or augment existing code.
  
  > **Comments:**
  > **username_10**: Nice answer. Welcome to CSE!  
  > **username_12**: I came to this HNQ to find an answer like that. In the industry, you often have contexts where it is 90% debugging and rewriting existing code, and only 10% writing your own. So from the "real world" perspective, debugging existing code, usually written by others, is much more prevalent than writing from scratch, but being very good at writing from scratch of course provides the knowledge and capability to know how the debugged code should look like, what's wrong with it.  
  
  ---
  
  ### Answer by username_13 on 2017-06-22. Score: 8
  
  I tend to think that CS education should be done in multiple stages (to be repeated as the students progress in skill):
  
  1. teach them theory
  2. show them good code
     * as an example
  3. have them write code
     * it's implied that they will need to do SOME debugging to "evolve" their code to a working state
  4. have them debug others' not-so-good code
  
  Start with the theory. Once they start to understand that, show them good examples. Many folks learn well by example; this helps them "solidify" their understanding of the theory and gives them some idea of how it SHOULD look / work. Then, get them writing code; no amount of theory and example can replace this. After all that, start showing them some not-so-good code to debug and clean up.
  
  Remember the famous quote by Brian Kernighan:
  
  > Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?
  
  Tackling complex debugging, when they haven't developed enough skill yet, will be overly-challenging. Let them build some proficiency THEN start building the debugging skills.
  
  I would agree that good debugging skills are critical. A quote from Maurice Wilkes:
  
  > By June 1949 people had begun to realize that it was not so easy to get programs right as at one time appeared. I well remember when this realization first came on me with full force.
  > The EDSAC was on the top floor of the building and the tape-punching and editing equipment one floor below. [...] It was on one of my journeys between the EDSAC room and the punching equipment that "hesitating at the angles of stairs" the realization came over me with full force that a good part of the remainder of my life was going to be spent in finding errors in my own programs.
  
  I wish I could say that my career was different. The only difference is that much of the code I maintain is written by others. A good part of the remainder of MY life will be spent finding errors in my own programs AND those of others.
  
  Once they've developed good debugging skills on one "level" of programming complexity, repeat the cycle for the next level. Consider debugging skills the "boss challenge" before they've "leveled up" and are ready for the next skill level.
  
  > **Comments:**
  > **username_10**: Nice insights from seasoned developer. Welcome to CSE!  
  > **username_14**: I love these stages and their order, showing students good code before having them write their own is a better way to build a foundation of coding skills necessary to tackle more advanced material.  
  
  ---
  
  ### Answer by username_20 on 2017-06-22. Score: 4
  
  I agree that learning to debug code written by someone else is a critical skill, but I do not think it can replace having to write and debug your own code.
  
  Writing your own code is a critical design exercise and students need to continue to develop their design skills. Debugging is a critical skill, but if students cannot create and debug efficient code on their own, they will not be able to code independently.
  
  > **Comments:**
  > **username_21**: Hi username_20! Welcome to CS Educators! As it currently stands I don't really see anything different between your answer and the one given by @username_19. Would you mind elaborating so that the difference becomes clear?  
  > **username_22**: If you look at it from a perspective of teaching debugging to someone who has zero knowledge on the subject, though, targeted debugging exercises written by an instructor can focus on specific skills and strategies in a far more structured fashion than simply relying on whatever luck-of-the-draw situation comes from student-generated code.  By all means, this shouldn't be an either-or proposition.  Both skills are critical.  
  
  ---
  
  ### Answer by username_15 on 2017-06-23. Score: 3
  
  I've been a software engineer for over 25 years and in my opinion, the two skills are just different. What you need to know and how you spend your time is very different when conceiving of a new design or code, or fixing something that exists. The two are both required to some extent on most projects but are very different activities.
  
  One of the things about software is that there are usually 2, 3, or maybe 10 different ways to do the same thing. Inevitably opinions will vary about what is "best" and there is often no single "best" because there are trade-offs and questions of style, and often several similar technologies that can achieve the same result.
  
  Most people prefer to write new code because it's more "fun" and they get to learn and do the things the way they think is best. It is kind of like building an electric train set.
  
  However, I would wager that on an actual software project, code is read or changed 10 time as often as it is written, so about 90% of the time spent is on understanding and debugging. Debugging is often easier since it does not require as comprehensive knowledge of the technology or code. Debugging an existing system is often a good way of learning a new technology and is where new team members are usually started.
  
  I have worked with very smart engineers who just could not stand to fix existing code and every time they were asked to fix something they rewrote it, because their opinions about what was "best" were so strong and rigid. This in my opinion is self-indulgent and on an actual project where time and money are limited resources it can be very inefficient and wasteful. Good engineers write good code but good team members know when you just have to fix something and move on vs. when a major overhaul is really needed.
  
  With all this in mind I think it is important to put existing code in front of students and require them to understand and debug it, not only to get it working correctly but to see how other people do things and what choices other engineers make, and also to understand that on an actual job they'll be expected to fix things fairly efficiently. They will probably find that they agree with some approaches and disagree with others.
  
  At the same time students should be in a situation where they must "debug a blank sheet of paper" where they get to do the fun stuff, but then also find that it is very hard to make choices that end up being the right choices for the project long term.
  
  One way of achieving both goals would be to have all of the students write their own code for part of the project, and then exchange code and problems so that they are then debugging someone else's code, and having their own code debugged. On a real project this is often done with team code reviews which, if done right, can provide valuable feedback to everyone, both the coder and reviewer.
  
  > **Comments:**
  > **username_16**: Welcome to CSEducators.SE! Thanks for the thorough response. Looking forward to hearing more from you!  
  
  ---
  
  ### Answer by username_17 on 2017-06-24. Score: 3
  
  I would say that it is helpful to have them write their own code in the beginning to better understand the processes that go into writing for an application. It gives them a strong basis and practice with finding errors in the code they're most aware of: their own. Think about it; if they already know their thought process and procedure as to what needs to be done, then they can try as many times as is needed to get that code working perfectly.
  
  However, it is also a fact of life in CS that if you work for anything but a start-up or SaaS company you are almost certainly going to be doing more *maintaining* of legacy code than actually creating of new stuff. By showing the students how to look through the code of others and find the issues in it, you are giving them practical experience for what will more than likely end up being the majority of their career.
  
  I would suggest having students both write new and debug others' code, starting with writing their own and after a semester shifting gears to maintenance/debugging of faulty code.
  
  > **Comments:**
  > **username_18**: Welcome to Computer Science Educators Stack Exchange! This is a great answer! I hope We'll be seeing more answers from you.  
  > **username_17**: Thank you for the warm welcome! :) I am admittedly not an educator (past helping some of the kids from the class below me in my programming course during high school) and am in fact enrolled in a CS program starting this fall. However I have been coding for a few years and found this post through the sister site Stack Overflow.  
  > **username_0**: Welcome to CSE @username_17. Don't feel anything coz of not being an educator. Me too not a professional educator. I usally teach coding for my friends and relatives. I am a Developerby profession. and Please note Stackoverflow is actually the father. First they started Stackoverflow and later moved to SE.  
  > **username_18**: @username_17 It's quite alright. Most are not professional educators here, but they do have insight. I am not a professional teacher, but I have my fair share of teaching, mentoring (see [my question](https://cseducators.stackexchange.com/questions/396/teaching-coding-paradigms-and-concepts-with-specific-context) in that context) and tutoring.  
  > **username_17**: @Sagar V Thank you for the encouraging words and fun fact! It seems that SE (or at least the CS educators section) is very welcoming and happy to have new contributors. Also, I have found that every developer or even a novice coder has something to offer for somebody.  
  
  ---
  
  ### Answer by username_19 on 2017-06-22. Score: 3
  
  Writing code is essential, and a part of that is debugging (your own) code. If you can't debug your own code, you won't get very far, unless you write perfect code the first time, every time.
  
  Debugging someone else's code introduces students to things that debugging their own can't - different styles, and different approaches to problem solving, that perhaps they would not come up with on their own. So debugging someone else's code helps you write better code for yourself. You learn what is good, what works, and what is bad, and doesn't work.
  
  Just as for learning another natural language (written), you can get fairly far writing and correcting your own words, but at some point, you'll benefit from reading (and possibly correcting) someone else's words.
  
  So to answer your question, yes, I see no problem in having students debug code (that isn't theirs). In fact, I would almost go as far as to say you should. But I wouldn't say that debugging code is more important than writing code. I would say it is part of writing code.
  
  
  ---
  
  ### Answer by username_23 on 2017-06-22. Score: 2
  
  During my 4 years of school debugging was never taught to us. We were only quickly shown that if we get an error, set a break point, see where it breaks and you know
  where the error is. Looking back, I can understand why we didn't cover debugging and it was because there was so much material to teach that there just was not any time to cover it.
  As a student, struggling to learn all the new concepts provided, I appreciated the fact that I did not have to learn another concept, especially one that required one to understand
  the IDE I was using. I agree that debugging is a necessary skill for programming but I don't think it should be a requirement. I think the teacher should drill debugging into the
  student’s heads by making it a part of their own routine. When teaching a lecture, as an example, if you declare all your class properties before typing out the methods, this is a habit
  that students notice and will copy. Once you are done typing your class, instead of creating another class, why not set a few break points, and run the app. Show your students how you
  are stepping through the methods and making sure you are getting the correct output. This workflow will teach the students that the debugger is not only for errors but it is
  a common practice for a programmer to write piece by piece.
  
  > **Comments:**
  > **username_10**: We don't get a ton of time to cover debugging. Partly because they will *have* to pick this up later, so we try to focus in on the things that will be harder to pick up naturally. Nice answer, welcome to CSE!  
  
  ---
  
  ### Answer by username_24 on 2017-06-23. Score: 2
  
  Neither is "better" or "worse" - just different. Writing your own code and understanding someone else's code well enough to debug and improve it are definitely distinct skills, both of which are necessary to be successful in industry.
  
  It seems like people are rarely given a lot of experience in the latter skill in college, and some curricula don't teach debugging techniques very well (especially to students that are just starting out). (I actually think that Eric Lippert's [article](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) on debugging should be mandatory reading in college curricula).
  
  So, really, it can't be either/or - both are necessary, especially if debugging assignments are accompanied by instruction in debugging techniques.
  
  > **Comments:**
  > **username_10**: That's an interesting article. Welcome to [cseducators.SE]. I hope we hear more from you in the future!  
  
  ---
  
  ### Answer by username_25 on 2017-06-23. Score: 2
  
  There's a lot of discussion about how people who work in industry spend a lot of time working with other people's code. That's true, but in my opinion, the key skill for dealing with other people's code is skill at refactoring. If you're going to teach new developers how to work with code developed by others, a class on refactoring would be invaluable.
  
  > **Comments:**
  > **username_21**: Hi username_25! Welcome to [cseducators.se]!  Thanks for choosing to contribute your knowledge here. Would you mind fleshing out your answer a bit more? It's already good as is, but that might make it a bit better.  
  
  ---
  
  ### Answer by username_26 on 2017-06-23. Score: 2
  
  Even though I'm not an educator, I work with programming and personally I don't think that you should teach your students on how to debug (don't curse me!).
  What I'd do is to present them the debugger and say what it is for, followed by a practical example. Then I'd give them code with bug(s) and tell them that they should use a debugger help them find the error (maybe a code with integer overflow problem). Probably I'd do that in one class, like 50 minutes of duration tops.
  
  In my point of view, teaching how to debug is as useless as having a whole class on how to compile a program (on introductory courses).
  
  > **Comments:**
  > **username_21**: Hi username_26! Welcome to [cseducators.se]! Don't worry about not being a salaried teacher -- I'm not either. Anyone who had experience or is interested in CS Education is welcome here, and I'm sure you've taught someone else some CS at some point. This is an interesting take on the question, and I hope to hear more from you!  
  
  ---
  
  ### Answer by username_9 on 2017-06-24. Score: 1
  
  If you mean by "debugging" teaching students to use a debugger, I wouldn't do that. However, having students finish or repair a program that you create is a useful early exercise. In particular, you can give them a program larger than they would be expected to write themselves. It needs to have excellent design/coding. But you have either removed or carefully broken a few parts before you give it to them. The errors introduced can be quite simple (missing punctuation) or more complex.
  
  The students get to (a) read code (b) see good design (c) interpret compiler diagnostics (d) grapple with structure - assuming the program has some length.
  
  This idea is discussed in the book [Pedagogical Patterns: Advice for Educators](https://smile.amazon.com/Pedagogical-Patterns-Educators-Joseph-Bergin/dp/1479171824/), where it is called "Fixer Upper".
  
  > **Comments:**
  > **username_10**: I just looked up that book. That was quite a fun little rabbit hole! Welcome to [cseducators.SE]. I hope we hear more from you in the future!  
  
  ---
  
  