nanovche / expense-tracker

Rest api with spring boot; follows youtube tutorial
0 stars 0 forks source link

repeating 5 times `userID` #22

Open velizartodorov opened 3 years ago

velizartodorov commented 3 years ago

https://github.com/nanovche/expense-tracker/blob/62d3f2e5dc3c7f51fe5f968d5518da08cef777ae/expense-tracker-api/src/main/java/com/pairlearning/expensetracker/resources/CategoryController.java#L26

velizartodorov commented 3 years ago

Repeating 5 times userId as a constant makes it a perfect candidate for a constant. The same goes for categoryId.

nanovche commented 3 years ago
  1. Do every string message needs to be in constant(even the ones present only one time at the code). ? I extracted all of them since some of them may need to be used more than once in future.
  2. I have suspicision about the constants' names. What i mean:
    • does EMAIL = "email" create ambiguity about holding actual email address string, is EMAIL_TEXT = "email" better naming henceforth
  3. Do constants class need to be in constant package?
velizartodorov commented 3 years ago
  1. Only if it's repeated more than once.
  2. Your suspicion is correct. I'd call it EMAIL_PARAM or EMAIL_KEY.
  3. Depends on the domain of the project itself. If the project is about math problems - probably yes, if it's something related to non-science stuff - I'd rather keep them to the package, where they are used, because in this case a package named constant doesn't bring any value to the reader of your code.