How to edit gigantic codes?

Asked

Viewed 74 times

0

It’s a question I’ve had since I started reading codes. I see some classes with a thousand, two thousand, thousands of lines.

How a programmer can edit so much without "getting lost" in the middle of so much stuff?

Even commenting on the code, using logical names for variables, procedures/functions etc, it is still very difficult to change even the name of a variable in the scope, thus having to change all inputs and outputs in the code. At the moment I am developing a code for booking hotels (a college work, in group). The code is about a thousand lines and nobody can manage so much, even with comments, switchs, if nestled etc.

In general, I want to know if there are any rules or tricks used by professional programmers to be able to edit huge codes without getting lost in the middle of them. I hope I wasn’t too vague. I searched for answers in forums but without success.

  • If the code is well written, you will not suffer so much. Otherwise, good luck to you.

  • You just need to edit what you want to change. What is working, at first, you should not touch. It is good to just have a review to see if something can be improved. It is work of "ant" same. Check row by row if there are things that can be optimized to dry up the code, and so on.

  • Let’s say that in this group work one person alone wrote 1,000 lines of code. I said it was unnecessary and that no one could handle so much information, the same did not accept the opinion and said it will be his way. I think the way I’m going to have to make a little ant and go out and pick it up. Unfortunately I’ll have to deal with inflexible people again.

  • This is what project patterns are for: common solutions to common problems. By using them you don’t need to analyze line by line code.

  • Believe it or not => the Method has 34 thousand lines

2 answers

3


I see some classes with a thousand, two thousand, thousands of lines

A thousand lines is a lot? "I guess" I don’t.

How a programmer can edit so much without "getting lost" in the middle of so much stuff?

Doing what computers do very well and that humans should know how to do all the time: dividing to conquer.

Deal with one part at a time. Build each part so that it depends at least on other parts. Plan ahead. Create a summary of all that. Understand what you’re doing. Don’t put anything you don’t need there.

Making big, messy, inefficient is easy, doing organized, small and efficient is difficult, but it pays for itself. This is how people manage large databases of code, doing right and decupado according to the responsibility of each thing, putting in function and in the data structure only what it does, without relying on anything external without need and give good names make everything simple.

When you separate and deal with one part at a time there’s nothing gigantic.

A good IDE can help. It’s just a help tool, you have to know how to use it properly.

Even commenting on the code, using logical names for variables, procedures/functions, etc., it is still very difficult to change even the name of a variable in the scope, thus having to change all inputs and outputs in the code.

It seems to me to be incongruous things. If you are giving good names why need to comment code? I think I know the answer, is not giving good names.

In fact comment usually does more harm than good.

If changing the name of a variable in the scope is difficult this scope must be very wrong.

I think that people do very long functions, obviously with many variables, and put the declaration of the variable away from its use and in an illogical way. The mistake starts there.

The description shows symptoms of other problems.

At the moment I am developing a code for booking hotels (a college work, in group). The code is about a thousand lines and nobody can manage so much, even with comments, switchs, if nestled etc.

In addition to being very complicated it may be that they still don’t understand what they are doing. It’s obvious that you learn things from a lot of gaps, you can’t use what you’ve learned properly. And most people learn that way. They do something, but they don’t understand what they’re doing, so when it comes out of the minimal complexity of an isolated exercise and goes into the real complexity of a real problem it can’t manage that anymore.

And there is a lot of case that is not knowing programming, is not knowing mathematics (I don’t mean memorizing formulas), communication and expression, scientific method, philosophy (yes, it is important for the correct logic), and other basic things that build the person’s ability to deal with problems.

I’m gonna rule out a person’s cognitive problems, but there’s a lot of cases like this.

Overall, I want to know if there are any rules or tricks used by professional programmers to be able to edit huge codes without getting lost in the middle of them.

There’s no magic rule. It is to evolve little by little, not to want to burn stages, to dedicate yourself, to search better each individual aspect that is having difficulty, to ask for help with specific things, to train, to ask feedback of experienced, recognized (real) people and confront with the feddback of other people who think differently. And of course, organize and simplify (but first have to learn to do this).

Let’s say that in this group work a single person wrote 1000 lines of code. I said it was unnecessary

If it’s unnecessary, make it smaller. If the team does not accept make your and present, after all a few hundred lines can do in a few hours, if it is already set and only need to encode maybe take minutes.

I could even say other things about this, but it would be very out of scope.

1

If you have a well-documented system, no matter the size of the code it is easy to identify what each method does within a class, another thing, a documentation with well-defined requirements there is no need to change variable name, at most add or decrease.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.