r/computerscience • • Mar 02 '21

Is it still coding, if you spend hours debugging?

I am a true novice in this field and feel like I spend most of my time debugging shit programs that I create. Is it even programming if you are not writing lines of code? Just curious, because I am getting my ass whipped on the simplest of programs. I believe it's because I got a terrible background in math, which I am working on. But yeah just wanted to vent. Any insight is always appreciated.

Edit: Thanks for all the replies homies. This was really unexpected, and very encouraging. I am learning Java in school and trying to learn python/spring on the side, for those who were curious. Stay safe and happy coding.

Edit 2: This is the code I am working on. I am trying to do a simple lottery output and cannot get the correct result. package lottery;

import java.util.Scanner;

public class Lottery {

public static void main(String[] args) {

// Generate a lottery

int lottery = 456;

// Prompt the user to enter a guess

Scanner input = new Scanner(System.in);

System.out.print("Enter your lottery pick (three digits): ");

int guess = input.nextInt();

// Get digits from lottery

int lotteryDigit1 = 4;

int lotteryDigit2 = 6;

int lotteryDigit3 = 6;

// Get digits from guess

int guessDigit1 = 4;

int guessDigit2 = 5;

int guessDigit3 = 6;

System.out.println("The lottery number is " + lottery);

// Check the guess

if (guess == lottery)

System.out.println("Exact match: you win $10,000");

else if

((guessDigit1 == lotteryDigit2 && guessDigit2 == lotteryDigit1 && guessDigit3 == lotteryDigit3)

|| (guessDigit1 == lotteryDigit2

&& guessDigit1 == lotteryDigit3 && guessDigit3 == lotteryDigit1)

|| (guessDigit1 == lotteryDigit3

&& guessDigit2 == lotteryDigit1 && guessDigit3 == lotteryDigit2)

|| (guessDigit1 == lotteryDigit3

&& guessDigit2 == lotteryDigit2 && guessDigit3 == lotteryDigit1)

|| (guessDigit1 == lotteryDigit1

&& guessDigit2 == lotteryDigit3 && guessDigit3 == lotteryDigit2))

System.out.println("Match all digits: you win $3,000");

else

System.out.println("Sorry, no match");

}

}

Any hints/suggestions are welcome, hell even some snarky remarks as long as it helps me move forward.

Prof sent me the "correct" which was if (g1 == l1 && g3 == l2 && g2 == l3 ||

g2 == l1 && g1 == l2 && g3 == l3 ||

g2 == l1 && g3 == l2 && g1 == l3 ||

g3 == l1 && g1 == l2 && g2 == l3 ||

g3 == l1 && g2 == l2 && g1 == l3)

System.out.println("Match all digits: you win $3,000");

That didn't work either.

165 Upvotes

40 comments sorted by

149

u/sacheie Mar 02 '21 edited Mar 02 '21

It is definitely programming even when you're not writing code. In fact, as you gain experience you will often be improving programs by deleting lines of code. Two relevant quotes:

"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away."

"Code that doesn't exist can't contain bugs."

Learning how to efficiently debug is step one, and an essential skill for every good engineer.

Next, you move on to learning how to write fewer bugs in the first place. But that journey will last your whole career, and your debugging skills will never go unused.

Don't fret - your experience so far is perfectly normal.

If you still want practical advice, my suggestion is: slow down. Spend more time thinking about the problem you're trying solve before writing any code. Make doodles and diagrams and notes. Read about the problem on wikipedia. You don't need to be a math wizard, you just need to understand the terms, definitions, and general concepts involved.

The hard part of programming is the thinking part, not the coding part.

2

u/[deleted] Mar 04 '21

I really appreciate the comment. I definitely have to develop the trait of thinking about coding before I actually write it. I will start implementing this practice as I move forward. Thank you.

61

u/MentallyWill Mar 03 '21

The hard part of programming is the thinking part, not the coding part.

In college I was friends with someone whose first step, always, was to start coding. "Iterate iterate iterate" he used to say and would joke that I spend more time on pen and paper than I do on the computer despite being a CS major. Funny part was that I often got the assignments finished before him and he eventually asked how I go from "no code" to "well written code" so quickly and I told him plainly, "once I've actually solved the problem the code really just writes itself."

Don't get me wrong, I'm not a proponent of the waterfall model or anything but there's something to be said about taking a few extra cycles to think through the problem before you break ground on the code itself.

5

u/rally_call Mar 03 '21

Agile and thinking are not at odds!

2

u/[deleted] Mar 03 '21

I'm not a proponent of the waterfall model or anything but there's something to be said about taking a few extra cycles to think through the problem before you break ground on the code itself.

This is absolutely true. I've been with retarded agile/Agile/aGILE/AGile (heh) proponents who would "work by the book". Most ghastly experience of my life.

8

u/[deleted] Mar 02 '21

All true. Great advice here ^

6

u/briannnnnnnnnnnnnnnn Mar 03 '21

this is well said, agree 100%

2

u/ixaacs Aug 07 '24

needed this 💯

2

u/oilaba Mar 03 '21

Which language are you using by the way? I would suggest a strongly and statically typed one, it may save some of your debugging time.

2

u/[deleted] Mar 03 '21

I am using Java. That is the language we are learning for this first CS class.

2

u/oilaba Mar 03 '21

I don't know Java but I know it is strongly and statically typed. Maybe you should try improve your problem solving skills, but note that everybody needs debugging sometimes.

39

u/_heartbreakdancer_ Mar 03 '21

It feels like 80% of my time is just spent planning (diagrams, psudo coding, reading docs) and maintenance (debugging and tracing issues). The actual writing of the code is the easy part.

38

u/onlyforjazzmemes Mar 03 '21

The question should be, "Is it still coding if you don't spend hours debugging."

21

u/mirushae Mar 03 '21

coding is debugging

15

u/1544756405 Mar 03 '21

Yes, a LOT of coding time is spend debugging.

8

u/bsteel364 Mar 03 '21

The the only time your coding my man. If you write a program perfectly the first time your just typing

4

u/[deleted] Mar 03 '21

learning to debug well is absolutely coding.

4

u/[deleted] Mar 03 '21

Is it still art if you are mixing colors and not actually putting the brush to the canvas? Totally! "Coding" sounds like a singular thing but it actually encompasses a large world of work. You learn and get better over time. The more you debug the more you can foresee bugs before they happen when you are writing the actual code. Keep killing it!

4

u/ziltiod94 Mar 03 '21

A college professor said this one and its stuck with me throughout my career: you'll spend more time reading code than you do writing code. Especially when working on existing, large projects, where just to implement your task you need to read the code to understand how your task fits within the existing code base.

3

u/briannnnnnnnnnnnnnnn Mar 03 '21

It is, this is how you learn, super important. Just go through the bugs one by one. Almost anytime I make something new I find unexpected bugs either because I was asleep at the wheel on some aspect or the docs don't line up with reality (happens a surprising amount). But yeah just keep going, you are learning the most when you are debugging. If it was easy, anyone could do it.

3

u/WorldlinessOk8666 Mar 03 '21

I’ve started a stream where I code live and I’ve spent more time debugging than actually coding in some of them, and I’m a PhD in CS doing AI!

If you’re at all curious, feel free to check it out (I’m just starting out) https://m.youtube.com/channel/UCPR_UzIThpHNGEZos1SVmLQ

3

u/[deleted] Mar 03 '21

its software development. most of it.

3

u/Effective_Youth777 Mar 03 '21

Coding is 20% writing code and 80% debugging, as you progress further fewer issues and bugs arise but still a considerable chunk of time is spent on debugging, that's how the industry is don't get discouraged by it.

3

u/duckypotato Mar 03 '21

A professor of mine once said “you’ll always understand code you’ve spent time debugging more than code you haven’t debugged”

2

u/yMcyface Mar 03 '21

Yes, definitely. Debugging gives you deep understanding of the underlying technical details of your sw and hw. Some system knowledge of a certain big system can most efficiently be learned by debugging. According to Embedded Market Study from 2019 debugging takes about 20% of project time, falling second only to "detailed design stage" at 30%. What most all good system and software architects know is that in order to have a stable healthy product system should be designed with testability and "debugability" features in mind, and not just user features in order to guarantee good code health. Good code health is mandatory for every code base that has a lifespan more then couple of weeks. Btw, coding is less that 3% of embedded project total time.

2

u/[deleted] Mar 03 '21 edited Mar 03 '21

Don't feel bad. I am a competant and confident programmer and I still spend a sh!t ton of time debugging, mainly because Unity's resource hungry and many times finnicky debugger has got me into a trial and error & print statement & guess and check sort of debugging style (a poor habit). When debugging other programs its much more straightforward because I know whats going on with the debugger and there better tools available.

Even the best struggle to get code working.

I've always said to be good at this you need three skills:

  1. the ability to problem solve

  2. the ability to break the solution into smaller steps

  3. the ability to plan your solution

Lastly a solid understanding of different levels of mathematics can help you greatly. When you're doing math problems and learning the materials ALWAYS remember to get the process down, but the transformation happening to the numbers or variables is whats key. You'll have a tough time with Cross or Dot products if you don't intuitively understand what they do, their purpose.

Like with Matrices in linear algebra, it really doesn't matter why or how you get to reduced row eschelon form, what matters is the utility of the operation.

Lastly when you're doing algebra always substitute values in at the very end. It helps immensely to keep your stuff straight and catch errors.

2

u/[deleted] Mar 03 '21

Are you learning about what to do different next time?

2

u/jeesuscheesus Mar 03 '21

Programming is all about problem solving, debugging is part of that.

2

u/EighthDayOfficial Mar 03 '21

Software engineering is part determining business requirements, planning, programming (execution), testing (debugging), and validation.

Validation is an often forgotten check where your program appears to work and there are no obvious crashes, but you have to ensure that the inputs and outputs are what you want.

You'll find a lot of mistakes in validation too - you'll think you were outputting a .4*X when you were actually doing 4*X, stuff like that.

Generally, expect to spend 30% of your time programming, an equal if not more time debugging, and another chunk of time equal to both of those doing general testing and validation.

2

u/vvaltchev Mar 03 '21

Spending hours debugging your code is an inevitable part of software development. There's no way to avoid that. Also, the better you become as developer, the fewer bugs you'll have to debug, but those bug will be much harder and much more subtle.

Just, be patient and continue to work hard!

2

u/[deleted] Mar 03 '21

Coding, maybe, takes about 30% of the programming and even less, if we include the whole software development cycle, no matter what model you use.

2

u/[deleted] Mar 03 '21

You can't be a programmer if you don't make mistakes

1

u/Herodegon Mar 03 '21

As a new coder myself, don't feel bad if you spend a lot of time debugging. Debugging is a major process in coding, and can/will consume most of the time you spend on a project.

1

u/ergotofwhy Mar 03 '21

You are coding. Welcome to the club!

1

u/cashycallow Mar 03 '21

Wait til you spend more time in the field and get involved in larger software projects. You can easily spend a day debugging one problem because it's so massive and has so many dependencies

1

u/yellow-yard Mar 03 '21

Coding is only if you produce working code. So, yes, if you fixed the code. Conversely, typing in your bug does count as coding because you did not produce working code.

1

u/istarian Mar 03 '21

For what it's worth careful thought about the problem, coming up with a solutjon, and then implementing in pseudocode is one way to reduce the amount of fixing you have to do later

0

u/[deleted] Mar 03 '21

[deleted]

4

u/CarlGustav2 Mar 03 '21

Weird that this is getting downvoted.

Spending nights/weekends/holidays debugging a critical piece of software is something most code writers will face at one time or another. It's not fun, but it is part of job.

And if you don't run into crappy people in this line of work, you are exceedingly lucky. Lots of people in the industry don't give flying f*ck about producing good code.

3

u/og_m4 Mar 03 '21

Cheer up mate