Stack OverflowToo "careless" in programming?
[+39] [41] Charles Khunt
[2009-06-09 06:47:29]
[ coding ]

I just feel so frustrated right now as I just finished one task.

Seems like every time I program (homework or other stuff), I make stupid mistakes that take me hours and hours to fix, sometimes it takes me the whole night just to finish a fairly small homework. Even if I do debug, still need lots of time to finish.

I love writing code and I'm constantly learning but there are a lot of those nights that I feel that maybe I'm just too "dumb" or careless to be good at it especially when I'm at the workplace in the future.

Any advice on this? Is this normal?

(53) Completely normal... - Arnis L.
Only way around it is experence and age. The older and more experenced I get, the moer time I am willing to put into a problem. I have noticed that I am much more likly to spend serious time on projects now that I am in my 30's. - Russ
(9) Oh, yea, one more thing. I personally believe that because you have noticed this limitation in yourself that you will strive to resolve it. This in itself makes you much more likely to grow into an intelligent, resourceful, and thoughtful programmer. - Russ
Do you often find that you code first or you write out the algorithm to solve it first? Planning can save you a lot of hassle down the road. - EureMir
(6) These little mistakes...those are called 'Bugs'. Welcome to the REAL WORLD, Charles...your red pill worked. - jrista
(1) Hang in there're doing fine. Keep moving forward with your education and you'll be alright. - Boydski
It's like learning to drive a car - at first it's frustrating to have to remember all the motions. Later you'll forget where the last few hours have gone while busy doing it. - rein
Biggest thing for me to get over what the feelimg that I should always be able to answer every question and find every bug. But now I realize sometimes you just need to toss it to a friend. - Matthew Whited
(2) Closed. You're supposed to feel that way. If it ever stops, worry... - Shog9
Does it make sense to have a closed community wiki??? - sheepsimulator
in the early days it helps immensely to ask yourself, after each line of code, what should be changed, and what should be the same. Then step through it in the debugger and see if your assertions are correct. This will help you find a lot of these little bugs much faster than running the thing and wondering where and why it blew up. Especially in lower-level languages like C and Assembly. Also, for each little bug that you find, think about how you can prevent yourself from making the same mistake the next time, and you will improve exponentially. - Steven A. Lowe
One thing to consider is that diffrent programming langauges can point out errors more easily then others. Making a mistake when programming ActionScript 2.0, for example, can be far more difficult to see then one made when writing Java or something like Scala. - Chad Okere
(1) Totally normal, and it will get worse when/if you do homework in assembly, for example. Don't let the SO people get you down, we aren't all super geniuses - it just takes time and persistent effort (so I'm told). I'm in the same boat you are. - nullArray
The fact that you care enough to even ask the question puts you miles ahead of 90% of the programmers out there. - Rory MacLeod
[+117] [2009-06-09 06:52:13] Copas

If learning to program doesn't make you feel dumb you're doing it wrong.

You will get used to it. I know - I feel the same way.

(2) I'm with Copas on this! Seems like the more things I learn the bigger the programming world gets, the more I realize how little I knew. - Akers
(1) I am proud to be the 101st upvoter of this answer. w00t! - Maxim Zaslavsky
Thanks! Got my first gold badge w00t! - Copas
this would be my accepted answer! - Derek B.
I've been programming professionally for about 10 years, but that doesn't stop me working past midnight sometimes on some stupid mistake. Keep at it, and try to be slightly less stupid tomorrow. - Rory MacLeod
[+50] [2009-06-09 07:06:13] Daniel Daranas

It would be better if you gave some examples of stupid mistakes, but still I have some suggestions:

  • Read Code Complete [1] and Object Oriented Software Construction, 2nd Edition [2]. You have more complete suggestions of (mostly) language-neutral books here [3], here [4] and here [5].
  • Do code reviews systematically.
  • Use Design by Contract.
  • Write some unit tests for your classes.
  • By the way, write everything in classes (in OO languages).
  • Keep track of your mistakes (not every mistake, but those that escape your first verification, and hence become bugs). e.g. in an Excel file. Start adding columns such as "Cause" or a long, descriptive column "Preventive actions that would have avoided the problem or spotted it much earlier". This can actually be a personal bug tracking system.
  • It's useful to use a source control system.
  • Learn that mistakes are part of being human. I make mistakes, you make mistakes, we make mistakes. That's why we invent processes to spot them, fix them and minimize their impact. We test, we write assumptions in code (Design by Contract), etc.
  • Don't do "just enough", try to do it really well. Be as clear as you can. e.g. Your question title begins with a lowercase, which is not standard; it would be better understood if it was a full sentence; etc. Fixing this costs nothing and makes your "code" easier to understand for those who come later and read it. Code as if someone else was going to continue your work.

(4) + 1 for source control - jens
(19) After your suggestion the author will feel even dumber. - User
(3) @Mastermind: He's studying something related to software construction, no? I think my suggestions were pretty basic. If he feels dumb about anything, he should look it up or just ask for clarification or more information. - Daniel Daranas
(2) Some useful suggestions, however writing down your mistakes seems a bit OTT for me! I think mistakes usually burn you enough to remember not to do them again without the need for writing them down. - RichardOD
(3) The advice about writing classes depends on the programming language, for example in Lisp you wouldn't write classes. - boutta
@RichardOD: OTT? Mmm... odd... (You probably mean, but still ;-)) - peSHIr
@boutta: You're right, of course. I'm talking from my OO perspective. I've mostly worked in C++ and C# and of course this shows in my advice. - Daniel Daranas
@peSHIr: More in the lines of, probably the third match :) - Daniel Daranas
(2) :D I always "Code as if someone else was going to continue [my] work." That's why the code is so crappy :D ;P - Peter Perháč
[+23] [2009-06-09 06:57:16] Damovisa

Even the most experienced developers have those moments/days. I call them the "Damn I'm an idiot" family of errors.

It's where you spend hours going over your code trying to work out what the hell is wrong with it only to find it's something ridiculous you took for granted.


  • You're actually looking at a different page/form/button
  • You had < instead of > or vice versa
  • You forgot to recompile before you ran it


(9) "Damn" is rather gentle for this class of errors - Matthew Whited
Self-censored :) - Damovisa
I thought, I'm the only one who has that kind of thoughts :) - hgulyan
[+13] [2009-06-09 06:58:55] ammoQ

This is a good time to learn best practices... write small, testable pieces of code, write unit tests. Write comments in your code so when debugging, you can immedately see what it should do (not just what it actually does...), etc.

Can I please add: "Write pseudocode" and most of all "Write worked examples"... For instance... comment a piece of code which writes XML with a "typical instance" of the XML produced... so you can see what you're trying to achieve... that's the real challenge... being clear about exactly (more or less;-) what you're trying to do BEFORE you start hacking code... and that applies at every level... system/application/program/class/method/line and verse ;-) - corlettk
Yeah, when I get stuck writing up a pseudocode list of tasks becomes a great starting point. And it also gives a good starting point for comments as well. - Matthew Whited
[+10] [2009-06-09 06:55:12] sharptooth

Even developers with years of experience often spend hours resolving problems that turn out quite simple in the end. Feeling frustration is normal - software development is very hard by its nature. As you practice and gain experience simple tasks will take much less time but you will shift to harder tasks and they will consume their share of your time.

[+8] [2009-06-09 07:00:59] Michael Borgwardt

Sounds like you might want to look into Test-Driven Development [1] - it can significantly reduce that kind of frustration.

But never eliminate. There's a very revealing quote from one of the guys working on the first computers (unfortunately, I don't remember the name) about how it was harder than expected and the moment he realized that he would spend much of the rest of his life finding errors in his own programs.


This makes sense as long as you know how to program and as long as you know how to define conditions for a piece of code. I guess it may not be helpful for a person learning how to program (and all the accompanying logic). It's a bit like saying "Drive a smaller car" if someone tells you that he has problems driving at all :-D - Thorsten Dittmar
That quote was from Maurice Wilkes. See - ajanicij
Thanks for the attribtuon! - Michael Borgwardt
[+7] [2009-06-09 07:02:04] Eduard - Gabriel Munteanu

It might happen because you write unmaintainable/unreadable code. Many students (I am a student as well) I know do this.

Try to adhere to standard coding practices and try to make things reasonably generic and well-separated. Have a look at open-source projects and see how nice code looks. Trust me, it's better and easier to write 500 lines of nicely-formatted code instead of a lump of 250 lines of unreadable, hard to extend and hard to debug code.

Here's a list of things you should be doing and which can be a time-saver later:

  • Check library calls return values, don't silently ignore errors.
  • Learn how to split your code into multiple files and group it by function.
  • Don't write huge, bulky functions. Split up your stuff until each and every function is reasonably small and easy to understand. If you're having difficulties understanding code 15 minutes after you wrote it, it's bad code.
  • Don't intertwine unrelated code and don't copy & paste all over the place. Try to reuse code.
  • Pay attention to small details, like indenting and formatting the code.
  • Make interfaces sufficiently generic and don't give in to ugly hacks or quick solutions, unless you're really, really in a hurry. Let there be a little flexibility.
  • Try to plan what you're about to do ahead of time. With experience, you should be able to work independently on different parts even when dependencies haven't been written yet.
  • Try to mimic how professional developers write good code, especially those from the open-source world. It may seem like overkill to you, but it is probably easier to write more lines of code than chasing strange bugs.

With time, you'll get better at debugging code and spotting mistakes. But I believe it's best to prevent exposure to such problems whenever possible. And no matter how good a programmer is, obfuscated or badly-written code will still slow him down a lot.

++on the "study GOOD code"... I've often thought that's what was missing from my university education... about 10,000,000 lines of GOOD code to learn from ;-) - corlettk
Very good advice indeed, except for the last one (mimic others) Perhaps you can clarify it a little, otherwise it sounds like you are promoting cargo cult programming :) - DR
[+6] [2009-06-09 07:02:29] chrmue

It's much better to be aware of the fact that you are making errors (even "stupid" errors!) than to believe that you are perfect! Everebody makes mistakes...

If you know your limits and take care you'll be a much better programmer than another person that believes it is a genius.

[+4] [2009-06-09 06:54:05] Vicky

Hey don't worry about these. I am a similar guy like you and am working in a software company now. These often happens. Just try to keep a track of silly mistakes you do and at a point you will avoid most of your mistakes. Just keep going... don't waste your time worrying about these because you can learn better than others if you make a mistake.

[+3] [2009-06-09 07:05:46] Joset

Programming is not programming that you've seen in the movies such as Die Hard 4. Every programmer makes mistakes. The more you discover it, the lesser chance for you to make the same in the future.

The biggest mistake you'll ever make in programming is the fear of committing one.

(2) Saw once in a movie that difficulty of hacking pr0n site is related with icon arrangement on desktop. :D - Arnis L.
(1) Or like Edgar in 24... "Ill just read the binary" - Egg
[+2] [2009-06-09 06:50:38] alex

This is normal - although as time goes on and you persist at your craft, you'll become more efficient.

[+2] [2009-06-09 06:57:13] Steve Crane

I think we all go through periods like this. If you persevere, things should get better. If your problems stem from lack of experience, the only way to get better is to keep on trying.

To try and minimise time-consuming errors, it is worthwhile to design your solution fully, on paper perhaps, before you actually start writing code. Not thinking through all aspects is a common reason for finding errors that cause you to backtrack and recode sections of your solution.

[+2] [2009-06-09 06:58:36] Thorsten Dittmar

This is normal. In the beginning you have to get used to a certain way of thinking: What steps must I take to accomplish my task. As you refine these steps, you get closer and closer to a solution that can be put into code. The smaller the steps, the easier the coding.

The most important thing is to try and not feel too frustrated, instead try to learn as much as possible from the mistakes you make. Next time you start a new programming task, concentrate also on identifying situations where you've made mistakes before and the ask yourself what you need to do differently this time.

[+2] [2009-06-09 07:53:04] Eric Anastas

Remember programing is very much an art form. There are always an infinite number of solutions to any problem, some which are much better then other depending on the problem.

So even when you no longer think you are "dumb" and doing everything right, someone is still going to come along and show you a better way to do something you thought you had nailed.

[+2] [2009-06-09 08:22:45] pd

There are two big things that will help tremendously with this. The main one is experience, and it will come naturally.

The other thing is learning to troubleshoot problems in a logical manner, which is something that will also come naturally as you gain experience, but you can save yourself a lot of effort by thinking about how you approach your problems now instead of learning what works by trial and error. Whenever you find a difficult bug, think about the things you tried before you arrived at the correct solution and figure out how you could have known they were less likely to be the correct answer. This will help you learn to analyze problems and try the most likely solutions first, and you won't waste as much time on things that don't work.

Some general tips:

  • Have a plan. Before you even write any code, think about what you need to do and how you're going to accomplish it. Identify the major steps in your solution and then figure out what needs to be done first.
  • Start simple. Get basic things working and then add additional functionality.
  • Work in small steps. Write your code in little pieces, and test each piece as you go. Don't write code for everything and then try to make it all work or you'll need Hair Club for Men in no time.
  • Fix problems, not symptoms. Always identify the cause of an issue before you try to fix it. Use your debugger, comment out code, or change conditions until you know exactly where the problem originates. Don't "fix" the behavior by fudging the code where the problem manifests.

Learning to code isn't easy, even though there will always be a few people that make you feel like it should be. Hang in there.

Great advice here. Especially +1 Fix problems, not symptoms. - Daniel Daranas
[+2] [2009-06-09 18:19:27] lorin

Debugging is one of the most difficult skills to learn when you're first starting out. I've found that the hardest part of debugging is when there's something that I assume to be true that turns out actually to be false. I'm convinced that the program should behave in a particular way, and it doesn't. What I basically have to do is:

  1. State explicitly (write down) the assumptions I have about why the code is behaving the way it is. (e.g., I know that function foo succeeds, I think it fails somewhere in function bar).
  2. Test these assumptions in the most simplified way possible.

The second step also takes experience in learning how to simplify your code and inputs so that you're testing only the particular assumption.

[+1] [2009-06-13 15:10:13] ojblass

If you are not struggling you are not challenging yourself. One good thing to do is look over your code from a few weeks, months, or years ago. This is very common and don't let it discourage you.

[+1] [2009-06-09 17:48:04] Nicolas Irisarri

The Software Engineering Institute [1] has a methodology to help you become a better developer. It's Called PSP [2]: Personal Software Process.

It should help you with these issues, however, on a more general view, I would say that following ANY methodology will help you produce less errors and be more productive.


[+1] [2009-06-09 10:27:42] Brad

Lots of great advice! All I can add is that only once I became disciplined to follow the guidelines I set for myself, did I start to become comfortable. And only just! Oh, and don't fuxx with working code the night before a demo unless you can EASILY redact it.

[+1] [2009-06-09 10:39:54] Mark Ellul

When you start feeling like this, go outside, take a quick walk, stretch your eyes, take some deep breaths. You need to rest your mind, with alot of stress or distractions its easy to make silly mistakes. A quick break can make these mistakes more visible.

You can do it! Just don't be hard on yourself, keep at it, and take regular breaks!

[+1] [2009-06-09 07:02:05] McAden

For a new person learning to program it usually involves changing to an entirely different method of thought. An entirely different way of wrapping your head around problems that you've never faced before and learning to deal with them in a manner appropriate to the world of computers and technology. When you start to understand data structures, how computers/electronics work, and get used to it, you'll find it's much easier.

[0] [2009-06-09 07:07:06] Matt Smith

It is frustrating, we all understand. and we are all still going through it.

There are good tools out there that help you build a library of reliable code snippets. Snippely [1] is a nice little example, but there are others.

If it makes you feel better, there are also many articles on line about how long it actually takes to become an overnight success;


[0] [2009-06-09 06:53:59] the_ajp

I know the feeling but you'll learn to look for abvious failing points and you'll also get better at debugging for sure.

Persist! :)

[0] [2009-06-09 11:18:47] Billy
  • divide any project you're doing into small chunks, that will be easier to handle

  • write short methods, that perform one precise bit of functionality

  • write unit tests. This is very important !

  • write the unit tests before you write the code that will be under test.

  • once you're done with a tasks, take a step back and look from a larger perspective at what you've just done : have you done similar things in other parts of the project ? Can you improve/refactor any of the code in order to make it clearer/simpler/etc ? Can you reuse any of that code somewhere else ? Are ther things that you haven't covered with the unit tests ? Are there any things that you've done in a quicky & dirty manner that you should clean up ?

  • log things using the framework that's available for your language ( log4j or similar )

  • read some good books ( Refactoring, Code Complete, Writing Solid Code )

Cheer up and do your best, you'll get the T-shirt ! :-)

[0] [2009-06-09 12:17:04] Jim C

First, debugging is harder then writing code. It take more practice and also takes longer. So it is how we spend most of our time.

Because debugging is harder then writing code, write simpler code. The simpler and clearer your code is the easier it is to debug. There is a famous programmer quote, to paraphrase, "debugging is twice has hard as programming. If I write code at the limit of my ability, then by definition I am not able to debug it".

[0] [2009-06-09 13:29:13] NekoJoe

To avoid careless programming follow the best practices mentioned here. But also make sure you're of sound mind when coding.

Don't force yourself to code. Remember to take a break. Sleep [1] is good too.

It's possible that you can spend 3 hours solving a problem that would take half an hour in the right mindset. Also if you walk away and come back you'll see the code with fresh eyes, or notice something you've overlooked before.


[0] [2009-06-09 16:31:33] JulianR

What sometimes helps me when I get stuck on something is to write a new StackOverflow question, detailing everything you're trying to do and where it goes wrong. Often, I realize what the problem is halfway through writing the question and it's usually a real case of "ooooh of course, stupid stupid stupid". I guess the reason this works for me is that you're forcing yourself to look at the problem from a different perspective as you're writing it for others to read and they need to be able to understand what you're doing. And if you're done writing the question and still haven't found the problem yourself, post the question ;)

[0] [2009-06-09 17:12:31] Rajesh Ramamirtham

I think it is completely normal and it is good in a way that you have identfied it.

The most important thing here is that you dont lose hope. Instead you should strive to get the solution. Implementing the solution would give you a lot of satisifaction. You can then go one step further and write a blog about it. Blogs are a good way to keep track of your ideas/thougts/stumbling blocks, etc. This is also a means to make sure that you dont repeat the same mistake twice. Suppose you encounter the same issue years later and you have no idea what you did previously, you can go back to your blog post/ community post and get the answer!

As beginners, most programmers/students are interested in short term solutions. However, when you become a pro, it is super important that you look for long-term/stable solutions.

Some things that can be kept in mind are:

  1. Write Unit Test Cases
  2. Proper naming convention
  3. Peer review and feedback
  4. Maintaining code in source control
  5. Versioning
  6. Think about performance from the start, instead of thinking about it in the later stages of SDLC.
  7. Follow consisted coding patterns
  9. Most important of all, be self-critical and be open to new ideas.

Why is everybody so concerned with performance? Sometimes you have to be, but usually it's a distraction. Use good habits and good algorithms, and if you still need performance (as measured by tests), profile the code and work on the hot spots. - David Thornley
[0] [2009-06-09 17:20:11] Paul Nathan

Write code small piece by small piece. I've helped beginning programmers for a few years now, and the #1 problem they have is they write too big pieces of code. Try to write code in 5-line increments. Test each 5 lines for correct compiling AND correct running.

[0] [2009-06-09 17:24:40] wcm

Don't worry. You'll find that you make the same mistakes less often. If you can learn from these mistakes, you will only get stronger and better. Some of these mistakes will be your best teacher.

it may not seem like it but you are getting better and better but you're moving to fast to notice. Hang in there an it will all work itself out.

Best 'o luck :)

[0] [2009-06-09 17:34:47] David Thornley

One thing I learned is that having larger building blocks helps, as in relatively self-contained sections of code that fit together. Try to keep code chunks self-contained and with limited functionality.

Another thing I sometimes use is formal proofs, which can go pretty fast if you're practiced with them. Of course, these only work on simple things; if you've got complex code, a formal proof will be a lot more complex than the code, and you don't gain anything. It's not that code I've proved correct actually is, but that the remaining mistakes are typically big dumb ones that show up well with even limited testing.

Test-driven development is good. With luck, you'll find out about stupid mistakes immediately. I like to find mine when the logic is still fresh in my mind.

Other people can help find mistakes in code. Sometimes just explaining the code will bring out mistaken assumptions you hadn't thought of before. Heck, I had a friend who'd talk about bugs in his code with a large cardboard cutout of Captain Kirk (from the original Star Trek).

And, of course, remember that you're not alone in this. There are very few programs of any size that will go through a thorough examination that doesn't find bugs.

[0] [2009-06-09 09:13:24] Ralpharama

There has been a lot of good advice here. I don't think 'too dumb' is correct but some people are undoubtedly better at coding than others. I often get people to write small scripts during job interviews. You can tell a lot about a person's coding skills etc by this - if the code is laid out neatly, consistently, with good var and function names, with lots of comments, then I know this is going to be a good person with good attention to detail. I find that with a structured, logical approach you make less mistakes. The clearer your code, the less silly mistakes you'll make, and the easier they are to spot. This approach can be learnt, but is easier for some than others. Also, learn how to debug your code - there are simple techniques that can spot tricky problems quickly. Saying that, sometimes we all need second eyes to spot a persistent bug that we can't fix...

[0] [2009-06-09 09:19:05] Ionuț G. Stan

You should try pair programming [1] if you have the chance. Another pair of eyes too look after you would make a real difference.


[0] [2009-06-09 09:19:19] Wedge

Nobody's perfect. The ratio of defects created per checkin is pretty close to 1:1 for the median developer. Experience, maturity, and improving your personal practice will help you get the better end of that ratio, but it'll be a long (never ending, in fact) hard-fought battle.

Consider: again, nobody is perfect. If you never acknowledge your own ignorance and your own fallibility then rather than retaining perfection you are instead merely missing out on opportunities to improve yourself. Only through accepting, eagerly seeking out, and remedying your own deficiencies can you possibly improve.

P.S. You could do worse, starting out, than to go through the highest voted Stack Overflow questions tagged best-practices [1].


[0] [2009-06-09 07:55:54] Mongoose

Everyone does this at first. It takes a long time to cut out certain stupid mistakes, and you can never get rid of them completely. Just think, after you spend 4 hours fixing a stupid bug, you're way more likely not to make that mistake again ;)

[0] [2009-06-09 07:57:24] Avram

I think that it is normal beginning. As people mention, even very experienced programmers can stuck to long time, on debugging process.
At this point what helps me when i start to programming, is writing logs(very important to make this logs readable). on time when i start i didnt know about TDD :) .

[0] [2009-06-09 08:02:56] Silvercode

Blaming others for errors when your code is broken is maybe even worse than making errors. But many people do that too. So making pretty sure your code works is very important. But when an error occurs, better check your code first.

One rule of thumb is that check the most obvious things first. For example maybe your code does work, but you have some parameter or setting wrong. Your module should throw an exception if possible, when input is wrong kind or not supported.

I think that defining and documenting the features of a program helps. If you find it hard to even describe what and how your program works, then there might be some hard to think of problems in some execution paths. In large systems this becomes more important, when some part of a system might have an effect to some other part, but if you are not aware of that, you might implement a new feature that breaks the first hard to notice functionality. So features should be clear and traceable.

[0] [2009-06-09 08:17:00] Seymour Cakes

It means you have to scale down your attention scope and span -- break things into smaller pieces and name them properly.

Don't use vague variable names or methods that will cause you to spend a few more previous seconds wondering what these variables or methods are about. Clear and concise.

[0] [2009-09-14 03:36:44] Gnatz

I've felt the same way. Just stick in there, keep pounding away at the code and eventually it gets easier.

[0] [2011-03-18 04:56:10] Winthan Aung

If you are newbie and junior coder, that is normal, if you cant find your solution at coding later, read aloud of your coding line by line and explain every lines to your self, that will make you see the error and solution, I am sure that will save your time later when you are coding.

[-1] [2009-06-09 07:07:54] Magnus Österlind

A method I try to stick to is that when you find that you've made some stupid mistake, write a test (or just an assert), that will catch the mistake the next time you make it. Hopefully it won't happen, but if it does, you'll get a little satisfaction from knowing that you've saved yourself a couple of hours worth of debugging pains.