I'm new to java development.

If i am writing a somewhat complicated program,
I hear that it is not good to write all processing in the main method.

What aspects aren't good?
In particular, I would like to ask what kind of problems there are in terms of quality control.
For beginners of development, I'm sorry, but I would like you to explain as much as possible.

Please give me an answer.

Are there any obstacles that could be a problem in the testing process?

  • Answer # 1

    I'm talking about thought ...
    Opinions from people who have been working as programmers for about 3 years.

    For example, if everything is written in main, it will be written in one file.
    First of all, if you have this in mind, the following issues arise:

    Maintenance issues
    When implementing complex processing, there are opportunities to diversify similar processing.
    In the unlikely event that the code needs to be modified, all modifications will be required.
    By making the processing common, it becomes a preventive measure against malfunctions by eliminating omissions and eliminating waste.

    Multi-person development
    If you edit the same file with multiple people, it's easy to get problems,
    It is preferred to implement separately.

    Reading source code
    If everything is written only in main, what processing means what?
    There is a problem that you cannot understand unless you understand all of these points.
    In principle, you can understand the contents of the implementation without reading the program by reading the design specifications.
    However, if you list everything in one, it is highly likely that only the creator will understand.

    In addition, Java is generally developed in an object-oriented manner.
    Considering that, it is a very big problem to list only main.


    In my opinion, if you consider two points: "maintainability" and "general versatility", I think that it should not be written only in main.
    I don't think it's a reason to praise it if it's developed by one person,
    If you want to respond flexibly and quickly, it is better to subdivide into classes and methods, and to use different development methods depending on your needs.

  • Answer # 2

    Writing such a program means that the author of the program does not understand the meaning and significance of object thinking, classes, and methods. And code written without understanding them"No maintainability" "No extensibility" "Bugs are easy to get out" "It is difficult to follow processing" "Not functional unit" " "It ’s not portable".

    Java is designed with an emphasis on object thinking as it is called an object thinking language, but writing everything in main meansthrowing them allThere is nothing else.

  • Answer # 3

    If it is a very simple program that can be written in one main and only needs 10 or more lines, that's fine.

    If a larger scale program is written with one function, it will be difficult to grasp.

  • Answer # 4

    Consider writing a sentence instead of a program.
    If it is short, you can do it with one sentence.
    As it gets longer, there will be more than one sentence.
    If it becomes longer, it will be divided into paragraphs.
    Next, we will divide into chapters or books.

    In comics, there are one-frame comics and four-frame comics, but they are usually divided into chapters and volumes.

    Writing everything in main () in a program is
    It is equivalent to writing with one sentence and writing with only one frame.

  • Answer # 5

    I can only think of a problem.

    Suppose you create an application with the constraint that

    methods should not be created.
    ・ Since the same process cannot be made into a method, the same code must be written.
    If this process is wrong, you must make corrections at all points.
    ・ There are many local variable conflicts, and it is impossible to grasp where the variables are used.
    ・ All field variables must be static
    ・ Because we cannot narrow down influence range, we cannot debug.