Do you carry over the Java convention of pre-fixin...
# codingconventions
d
Do you carry over the Java convention of pre-fixing 'I' for interfaces? Is there an official Kotlin position?
d
That's by no means an official Java convention. The JDK doesn't do it either.
👆 12
t
You should not carry it over, and stop doing it in your Java code too!
👌 8
👌 4
d
Gladly
d
It's very reminiscent of hungarian notation
which is... old
d
Yeah that makes me mCringe too
😀 2
🔥 4
Gross, can't believe it's so prevalent in Android source.
m
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
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
🙇🏻 gotcha that makes sense
m
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
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
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
Dependency inversion:
UserRepositorer
<-
UserRepositorable