#What's wrong with my code thread

1 messages · Page 1 of 1 (latest)

obtuse goblet
drifting anvil
#
class Database {

  public Database(…){}

  public void bootUp() throws DatabaseBootstrapException{

  }

  public static Database create(…){
    
    var result = new Database(…)
    result.bootUp();
    return result;
  }
}
#

Assuming I was coding for lets say origin realms or some bigger server, I would go about it in this way

#

It allows for bootUp to be unit tested

#

The instantiation is isolated and decoupled from the creation

obtuse goblet
#

the irony that I am coding a realms plugin like that server

drifting anvil
#

Whilst you still have the convenience of doing all of that in one line, Database.create()

obtuse goblet
#

ill do it that way

#

Should I make the statements an Enum?

#

Statement.CREATE_WORLD

drifting anvil
#

Na

#

Just have private static final String is enough i think

#

Arguably could deserve its own class

#

But that will just be inconvenient if they are not strings

obtuse goblet
#

oki

#

Wait @drifting anvil, I am already using PreparedStatement

willow plaza
#

good

obtuse goblet
#

Done: Arguably static abuse, config can be static but make sure it to name it as a constant then.

Done: Your static initializer is way too big, the issue is that its hard to test logic of methods and classes when you use so much static.

Don’t use poopy File legacy api, use Path instead.

Done: Those SQL statements, make them into constants, that way your code becomes a bit more readable and maintainable.

Done: Be consistent on the names of your names for the exception variables, you go between e, throwables etc. Stick with one, arguably e since it follows the proportional name principle.

Also feels like these database calls should be async. 

Use this keyword if possible, its better as it shows if a method call or field access is from the instance itself.

Done: Use PreparedStatement.```
#

Where should I use this?

untold cosmos
#

use what

obtuse goblet
#

use this

obtuse goblet
untold cosmos
#

ugh im not a fan of that, conclure probably wants you to use it when accessing fields