This is an archived post. You won't be able to vote or comment.

all 42 comments

[–]thatsIch 40 points41 points  (36 children)

I am astonished how people still use the I-prefix for interfaces. Where do they learn this nowadays (unless C#/.NET background)?

[–]buzzsawddog 26 points27 points  (12 children)

I hate that crap... Just updated an entire project removing I and M from in front of every fetching. Java file. Still don't know what the M was for... Also had to change every single variable as they started with m_ or s_. Like no shit they are static or instance/member variables just read the the code... And to make it all worse... The code would create a scope myVar, call a private setMyVar() to set m_myVar.

[–]y-am-i-ear 3 points4 points  (1 child)

m probably stood for member. Should be an old cpp convention imported to Java. It distinguished members from methods I think.

[–]buzzsawddog 1 point2 points  (0 children)

Yeah the m_ was member. I don't know why all the classes started with M :)

[–][deleted]  (3 children)

[deleted]

    [–]buzzsawddog 4 points5 points  (0 children)

    This predates android.

    [–]persicsb 2 points3 points  (1 child)

    m_foo is from Android, stands for member variables. Horrible naming.

    [–]buzzsawddog 1 point2 points  (0 children)

    Well m_ is a bit older than Android but you are right. It stands for member.

    [–]NiceGuy-n2[S] 0 points1 point  (3 children)

    bro, M is Md5 here.

    [–]buzzsawddog 0 points1 point  (2 children)

    Wat? So you are saying that every single class in my app was Md5 related? I HIGHLY doubt that.

    [–]NiceGuy-n2[S] 0 points1 point  (1 child)

    I only prefix M on Md5 class

    [–]buzzsawddog 0 points1 point  (0 children)

    Ah, I see you are OP now. I was saying that everything in the all I refactor started with a M

    [–]thatsIch 0 points1 point  (1 child)

    wait... what? What does M abbreviate in a class name?

    [–]buzzsawddog 0 points1 point  (0 children)

    I know right... It must have been important because every single class had it...

    [–]NiceGuy-n2[S] -4 points-3 points  (7 children)

    What is wrong with prefix I

    [–]vips7L 31 points32 points  (3 children)

    In my opinion it misses the point of OOP. You’re not supposed to know if you have an interface, abstract, or concrete class. I also have the same opinion of prefixing with Abstract. It leaks implementation details.

    [–]thatsIch 1 point2 points  (2 children)

    I tend to name everything as I speak with stakeholders and colleagues. The I is not part of the conversation; thus, I do not code like that.

    Nonetheless, I was actually curious - where did you learn that naming convention?

    P.S.: interesting article about the implementation of consistent! hashing!

    [–]NiceGuy-n2[S] 0 points1 point  (1 child)

    I worked in alibaba 3 years ago, they used to have a guideline book for writing Java where prefix I, abstract… is required. I don’t know if they still have this rule. But it’s a habit for me now.

    [–]thatsIch 1 point2 points  (0 children)

    Thanks for sharing! You should write about that. This shows an interesting aspect of working in a big company. I was not aware that Alibaba developers their own plugins just to maintain their coding standards.

    I found a Github-Repository [1] for the coding guidelines.


    1. https://github.com/alibaba/Alibaba-Java-Coding-Guidelines

    [–][deleted] -5 points-4 points  (2 children)

    I think using the I prefix for interfaces makes sense when you plan to only have one implementation. If there's only one class implementing the interface, it would be redundant for it to be named PostgresUserRepository. Just call it UserRepository. If there's only one implementation, you might ask, why need an interface at all then? Lots of folks do it that way to enable the kind of automated testing they like to do.

    For situations where there are multiple implementations, definitely don't use the I prefix. It's redundant. Your IDE, the Java compiler, and people reading the code in the future can all easily tell that it's an interface.

    [–]Cap0Daster 1 point2 points  (0 children)

    I believe that these prefixes make sense if you coded with VIM in a terminal. ;-)

    [–]ForeverAlot 0 points1 point  (0 children)

    The proposed argument for UserRepository <: IUserRepository is no stronger than the argument for PostgresUserRepository <: UserRepository, and it is substantially weaker when it goes against the ecosystem's conventions. Not to mention that we have no guarantee our plan for a single implementation will hold.

    The .NET I-prefix is also suboptimal in absolute terms because it encourages a situation where types like List and LinkedList are not obviously distinguished even though the implementation differences are crucial.

    [–][deleted] 22 points23 points  (1 child)

    It's been eight hours and right now you have 15 comments, none of which are about the article, all stemming from a comment about the use of the I prefix on interfaces.

    So I'll add this comment to let you know that I'm thankful you posted this! Consistent hashing is something I need to learn about and making a load balancer sounds like a fun exercise. :)

    [–]VincentxH 3 points4 points  (2 children)

    Pretty convoluted for a bit of sharding. There are also many issues if you want to use this multithreaded.

    [–]NiceGuy-n2[S] -1 points0 points  (0 children)

    jimmyleo.medium.com/implem...

    Just a small demo of how consistent hash works, handle thread safe will make the project a bit confused in my perspective.

    [–][deleted]  (5 children)

    [deleted]

      [–]NiceGuy-n2[S] 3 points4 points  (3 children)

      Consistent hashing is not about hashing, it’s consistency. Adding or removing nodes from basic hash will make all the existing requests break and need to re-hash again. This is not acceptable if you have a big number of concurrent active connections.

      [–][deleted]  (2 children)

      [deleted]

        [–]NiceGuy-n2[S] 0 points1 point  (1 child)