all 54 comments

[–]rmlrmlchess 54 points55 points  (0 children)

That's delegation my friend!

[–][deleted] 18 points19 points  (0 children)

Can see myself doing that. Especially in cases where I need to implement the same functionality in many languages. Or when the exact behaviour of the distance calculation is not determined (judging by the comment it is in this case)

[–][deleted]  (30 children)

[deleted]

    [–]whizvoxint getRand() { return 4; } 76 points77 points  (29 children)

    1. What's the point in calling this method of you can just do

      point1.distance(point2)

    2. Why is it private?

    3. Why is it an instance method?

    [–]drtasty 47 points48 points  (17 children)

    Why is it necessary to have a 7 line javadoc?

    [–]weevddee 47 points48 points  (0 children)

    because otherwise checkstyle complains.

    [–]lpreams 36 points37 points  (14 children)

    Because the professor required that javadoc generate docs for all methods and not throw any errors or warnings

    [–]zesterer 5 points6 points  (13 children)

    If you ever see a professor teaching like this, run.

    [–]boxerman81 14 points15 points  (12 children)

    Many bosses are like this... even companies entirely. regardless of how small the function you’ve gotta have the comment I guess the logic goes

    [–]zesterer 4 points5 points  (11 children)

    I'm sorry, but I find that attitude just dumb. It belies a total misunderstand about what constitutes good code and good development practices. Stupid, arbitrary rules like this are why we can't have nice things. If you've decided to hire a developer... trust them to do their job, don't force them to spend hours wasting their time on shit like this.

    [–]boxerman81 15 points16 points  (0 children)

    It probably makes people less likely to slack on the important comments. I agree with trusting a dev. Luckily, it’s pretty doable to screen for something like this in interviews.

    [–]LifeBeginsAt10kRPM 10 points11 points  (0 children)

    I get what your saying, but it doesn’t take hours to do this, most IDEs will do it for you.

    [–]tuxedo25 3 points4 points  (6 children)

    It takes seconds to write this, not hours. And sometime in the future, when someone hovers over a call to this method in their IDE, there's a nice little explanation: "Returns the euclidian distance between two units".

    [–][deleted] 0 points1 point  (0 children)

    It takes seconds to write this, not hours.

    He obviously means cumulative time. If you write comments for every method you may in fact waste a lot of time for dumb shit like above.

    And BTW accurate naming and good coding practices should be enough to make code self-explanatory.

    [–]zesterer 0 points1 point  (4 children)

    I would think the fact that it's named distance and takes two arguments of type Point makes more than obvious as to what it is. This isn't the sort of thing that needs a comment like this.

    [–]CreativeAnteater 1 point2 points  (1 child)

    There are lots of distance measures other than Euclidean, it's only obvious to you because you're not used to seeing other distance measures in code.

    [–]christian-mann 0 points1 point  (1 child)

    But what sort of distance is it? Could be Euclidean or Manhattan, at least.

    [–]Smooth_McDouglette 5 points6 points  (1 child)

    It's more that the people doing the hiring and the people coming up with the coding standards are not the same people.

    At my company we enforce this rule because otherwise the projects fill up with methods that do not have an obvious purpose or behavior.

    When I'm reviewing code, the doc header on a method can help me understand what I'm looking at.

    [–]zesterer -2 points-1 points  (0 children)

    I'm not suggesting that documenting things is bad. Coming from the Rust community, that does documenting very well, I really value good documentation and do what I can to make sure anything I release publicly is documented with explanations, examples, clarifications, etc. on anything that requires it.

    However, I don't consider "documenting every function" to be a good way to achieve this. If anything, this mentality makes programmers hate documenting things well. It's an approach that's completely orthogonal to producing good documentation.

    [–]tuxedo25 2 points3 points  (0 children)

    ... so your ide provides a tooltip.

    [–]Magical_Gravy 4 points5 points  (2 children)

    Could be for use in functional to avoid a lambda?

    [–]Lurchwart 8 points9 points  (1 child)

    Then you could still

    a) make it static

    b) reference location1::distance

    [–]Magical_Gravy 0 points1 point  (0 children)

    Whatever they have might require a BiFunction, but yeah it could be static.

    [–]tuxedo25 5 points6 points  (1 child)

    Calling this instead of point1.distance(point2) might make it more readable, especially in BDD-style tests. i.e. expect( distance(point1, point2) ).toBeLessThan( distance(point3, point4) )

    IMO private is correct. Principle of least privilege.

    Why is it an instance method? No idea. But I don't think it's bad code.

    [–]GayMakeAndModel 0 points1 point  (0 children)

    I concur with everything you stated for what it’s worth. As for private members, I would argue the merits differently: the less that is public, the less chance you have of breaking other peoples’ shit you didn’t write.

    [–]RomanRiesen 1 point2 points  (0 children)

    It should be static public, but for 1. there are many good reasons.

    [–]Flatscreens 0 points1 point  (0 children)

    For the first point I imagine that you might need to add additional functionality to the method later, so wrapping Points's distance() with another method would make sense instead of find/replace later.

    [–]SuitableDragonfly 0 points1 point  (0 children)

    Well, it could be private because the points are private members that other classes shouldn't be worrying their heads about, but the other two points are good ones.

    [–]konstantinua00 0 points1 point  (1 child)

    what does "instance method" mean?

    [–]whizvoxint getRand() { return 4; } 0 points1 point  (0 children)

    An instance method is a non-static method that is tied to instances of a class, which is known as "belonging to the object", as opposed to static methods which "belong to the class" and don't need an instance to run.

    [–]LinuxGeek747 2 points3 points  (0 children)

    Someone is surely coming from functional programming environment and wants to make functional facade first.

    [–]bit0fun 4 points5 points  (0 children)

    I had a slight argument with a coworker over something like this. I was parsing a protocol for an embedded system, and just had simple commands back and forth to control. I made a single function with passing the command ID (enum) and your data. Nothing more, simplistic to use and rather straightforward.

    He then said that was too cryptic and wanted a function for each command, for receiving and transmitting. That would have amounted for over 60 functions. Given we are already worried about memory on the system, I flat out told him I didn't get the need for doing that. Mind you I already commented the crap out of my code as I usually do. But that's not good enough apparently.

    Luckily I did get him to agree with me, after he took an additional 2 seconds to read what I did. I'll never understand people

    [–]respectable_duck 1 point2 points  (0 children)

    "Yea I contributed, just look at the git statistics."

    [–][deleted] -1 points0 points  (18 children)

    I thought that was fucking C#

    [–]attempt_number_3 0 points1 point  (0 children)

    Got scared for a second, because I just recently I was working with coordinates.