LuoSimba / tetris

俄罗斯方块java版
3 stars 0 forks source link

Data Class #2

Open milenortegam opened 3 years ago

milenortegam commented 3 years ago

Hi, me again sorry. I also noticed that your enum classes can become another code smell named Data Class, this one means that you are using class as storage of some data, in this case your data is the constants you keep in them. For example, the class Status just contains 4 types of status READY, RUNNING, PAUSE and END. I understand that enums are very well known to be used for containing data, but is actually very debatable, some people considere it bad practice. Anyway, in case you want to implement my suggestion, you can simply delete the enum class Status, and in the class App change those enum constant to String constants.

LuoSimba commented 3 years ago

You are so warm-hearted, man. I'm glad to see other people point out my shortage.

I learned Java eleven years ago, and for these years I mostly be a PHPer. So I am not so familar with Java. I tried to learn Java again since several months ago, because I've got plenty of time.

I treat enum classes as Data Class, because I think the language is designed to allow this. And I don't want to use String constants, String is UGLY ... String is general-purpose data type that is used widely. If I wrote source code as "READY", "RUNNING", "PAUSE" and "END", then what about "START" or "ABC"?

Let's take a look at this:

Are these the same things? they are all consists of characters. If a function foo can be called as foo("READY"), it is also can be called as foo("ABC") in grammar. What a horrible thing! You even don't know what's wrong in your source code before the program start running.

Enums are different. It will cause error while compile period if you use Status:START, because START is not defined in Status class. It's illegal.

I know less about Virtual Machine and can't tell the nature distinguish between String and Enum. I use enum classes because Java support this feature, and enum just fit my thought.

If I have better understanding of enum someday, I will add comment to this issue. Thank you all the same.

milenortegam commented 3 years ago

Hi. I just wanted to say, first no problem with the English it’s also not my first language and second I’m a college student so inspecting some codes on GitHub was part of one assignment, so in other words I was desperate to found some “code smells” I actually like your code it was very clean and organize. Thank you for replying, I appreciate that you took the time :). -Milen Ortega Mautong.

Sent from my iPhone

On 20 Jan 2021, at 11:25 AM, LuoSimba notifications@github.com wrote:



You are so warm-hearted, man. I'm glad to see other people point out my shortage.

I learned Java eleven years ago, and for these years I mostly be a PHPer. So I am not so familar with Java. I tried to learn Java again since several months ago, because I've got plenty of time.

I treat enum classes as Data Class, because I think the language is designed to allow this. And I don't want to use String constants, String is UGLY ... String is general-purpose data type that is used widely. If I wrote source code as "READY", "RUNNING", "PAUSE" and "END", then what about "START" or "ABC"?

Let's take a look at this:

Are these the same things? they are all consists of characters. If a function foo can be called as foo("READY"), it is also can be called as foo("ABC") in grammar. What a horrible thing! You even don't know what's wrong in your source code before the program start running.

Enums are different. It will cause error while compile period if you use Status:START, because START is not defined in Status class. It's illegal.

I know less about Virtual Machine and can't tell the nature distinguish between String and Enum. I use enum classes because Java support this feature, and enum just fit my thought.

If I have better understanding of enum someday, I will add comment to this issue. Thank you all the same.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/LuoSimba/tetris/issues/2#issuecomment-763759329, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQEB3RFN3KJSAKS5APEHUYTS237W5ANCNFSM4WE67EMQ.