The JDBC interface `DataSource` has a method `getC...
# codingconventions
k
The JDBC interface
DataSource
has a method
getConnection()
which creates a new
Connection
every time it's called. Is it therefore better to write
Copy code
val connection = dataSource.getConnection()
rather than
Copy code
val connection = dataSource.connection
?
j
I would personally declare a method, not a property in this case. And instead of
getConnection()
, how about
connect()
? It makes it pretty clear that a new connection is created when using the verb, and it also happens to be shorter
Oh wait I just realized you don't control that class 🤦 then yeah I would probably call the getter explicitly here... ...or declare an extension function
DataSource.connect()
to avoid IDEA warnings and make it clearer at the same time 😄
👍 1
e
TBH I think
openConnection()
may be a better name, since it more clearly indicates that the result can
.close()
but yeah the original naming is unfortunate :(