https://kotlinlang.org logo
#codingconventions
Title
# codingconventions
d

darkmoon_uk

07/25/2019, 11:10 AM
Do you carry over the Java convention of pre-fixing 'I' for interfaces? Is there an official Kotlin position?
d

diesieben07

07/25/2019, 11:10 AM
That's by no means an official Java convention. The JDK doesn't do it either.
👆 12
t

tddmonkey

07/25/2019, 11:11 AM
You should not carry it over, and stop doing it in your Java code too!
👌 8
👌 4
d

darkmoon_uk

07/25/2019, 11:11 AM
Gladly
d

diesieben07

07/25/2019, 11:12 AM
It's very reminiscent of hungarian notation
which is... old
d

darkmoon_uk

07/25/2019, 11:12 AM
Yeah that makes me mCringe too
😀 2
🔥 4
Gross, can't believe it's so prevalent in Android source.
m

Mike

07/25/2019, 11:28 AM
If you have to preface your interfaces with I, or put Impl on the end of the implementation to differentiate them, then you're not naming things very well. It's very late 1990's coding style for people that thought you HAD to have an interface to do DI, but only had one implementation, and didn't want to think about the actual name for the interface vs the implementation object. And yes, unfortunately, this discussion continues to this day...
c

Cody Engel

07/25/2019, 3:54 PM
mNope
I name interfaces as the thing because that’s what will be passed around everywhere. Concrete interfaces usually end with
Real
on my projects, it’s not something I love but I also don’t totally hate it. I’d be interested in @Mike’s take on naming concrete implementations
Passing around an interface is a convention, and not a requirement. I choose a different convention.
c

Cody Engel

07/25/2019, 4:08 PM
🙇🏻 gotcha that makes sense
m

Mike

07/25/2019, 4:09 PM
But ultimately it comes down to what the team is comfortable with. I've done both, and prefer the 'less work' option when I have to make changes.
c

carrot

07/26/2019, 8:30 PM
As a constructive alternative, I really like using "-ing" "-able" "-er" style suffixes for interface types (or protocols in Swift). So,
HttpFetching
as the interface and
HttpFetcher
as an implementation, for example.
👍 1
t

tddmonkey

07/27/2019, 10:57 AM
See I would prefer it so that you impl is my interface - so something like
FetchUsers
for the interface and
FetchUsersViaHttp
for the implementation
❤️ 1
g

ghedeon

09/25/2019, 10:16 AM
Dependency inversion:
UserRepositorer
<-
UserRepositorable