[JAVA] There is a copy / paste programmer-look at someone and look back at me

Introduction

Recently, there are a lot of copy and paste programmers in my development team ...: sweat_drops: Personally, I don't think "copype = evil". I think that you can copy the ʻinput Stream`-like thing that you google almost every time, and if you copy it, the source code in the project will be unified and it will be easier to maintain.

But don't just copy and paste without thinking: angry: It's hard to read and it's full of bugs: droplet:

So, let's summarize what I think, "If you copy and paste, be aware of this at least."

Notice

――It is not an article that asks the good and evil of copy and paste. ――Subjectivity based on personal experience is included ** much **. ――I wrote it with the expectation that "If you think,'Oh, that's me ...?', I'll reduce the number of bad copies a little.": Sweat_smile:

1. 1. The variable name / method is incorrect.

Since it is still copied, (for example) if the copy source is "tel", it remains "tel". It may be "mail", but it remains "tel". I think there are many people who only think, "Just move, I want you to move as you want." When I read it back later, it was confusing because it was like "Why is the variable that stores the email address tel?" The method name is the same, and even though it is getMail (), I sometimes see a source that returns a phone number ...

2. The constants such as error messages are incorrect.

It is often seen in the process of getting a fixed message from a property file using a key code. If it's terrible, even the message written in Japanese will be copied and pasted, and even though it is a normal system, it may be "An error has occurred".

3. 3. Static constants are scattered and proliferate.

It will be copied for the time being, so if there is no class constant, an error will occur. "Then, you should just copy and paste the constants: thumbs up_tone3:". In that way, static constants with exactly the same name and the same content grow in each class. If it's a few at first, I'll push it into an Enum or property file as soon as I find it, but when it comes to conservative projects, it grows too much, and on the contrary, I start thinking "I think it's better to grow it as it is". : disappointed_relieved:

As a request, if you want to copy something that looks like a constant, check "Is anyone defining it for general use somewhere?": Bow:

4. JavaDoc is wrong.

JavaDoc is "established as a formal program specification". However, it may be copied from somewhere, or it may be generated by default. As a result, the actual source movement and JavaDoc Japanese often deviate from each other. Please see here: arrow_down: for the difference between JavaDoc and comments. : link: [Java] Comment types and writing style A few months later, I look at the JavaDoc and say, "Who is the one who wrote such a lie!" !!

5. I don't understand how it works.

As a matter of course, you say, "Something, it worked when I wrote this": cold_sweat: But it's not "written". Because I just "copied". This type often freezes when asked "Why did you write this like this?"

6. I don't notice if there are any bugs left.

It is the same as "5. I don't understand the operation." I don't understand, so I don't even notice if I copy and paste the bug together: disappointed_relieved: Also, there are times when "it's okay if it's a copy source, but it's a bug because the specifications are wrong at the copy destination."

Please understand it properly. Really···.

7. When I get an error, the first thing I think is "Maybe I made a copy mistake?" And I don't see the error message.

Even though it's much faster to see the error message, they suspect copy and paste and go first to compare it with the original copy and paste source: disappointed: Most of the time, after worrying for a while, there is a pattern that asks, "That .... The source here is throwing an error, but it's not exactly different from the copy source ..." I feel that there are many. For the time being, please read the error message and then come to ask a question ...

Also, it's a miso in the foreground, but I hope it will be helpful in reading the error message: point_down_tone3: : link: [Java] Are you reading the error message properly? [How to read the stack trace]

in conclusion

As I wrote at the beginning, I don't think "copype = evil", so I think it's okay to copype itself. By copying, I think you can study the good source code of our predecessors.

However, even if it is a copy, it is "you made it". If you inadvertently add a bug, I think it's your fault. The point is, "Take responsibility for the code you write": thumbs up_tone2:

I wrote something erratic, but I thought I should be careful because I sometimes copy it myself: sweat_smile:

Recommended Posts

There is a copy / paste programmer-look at someone and look back at me
A look at Jenkins, OpenJDK 8 and Java 11
[Rails] [Docker] Copy and paste is OK! How to build a Rails development environment with Docker
Use Vue.js on a CDN (only copy and paste!)
A quick look back at Java over the last five years