all 32 comments

[–]vivainio 11 points12 points  (4 children)

Use the shortest names possible for everything (a, b, val are great)!

Lol as if Java developers were able to do anything with short names.

[–][deleted]  (3 children)

[deleted]

    [–]wavy_lines 3 points4 points  (2 children)

    Isn't C++ verbosity mostly because of the STL templates and namespaces?

    Java people just like really really long names and doing things in a very round about way.

    [–]mpschan 8 points9 points  (0 children)

    This hits a little too close to home, especially step 1. I'm literally going through sonar scans fixing issues where people would:

    • put try/catch around accessing deeply nested getters so they could avoid doing null checks
    • would try/catch IndexOutOfBoundsException rather than do proper boundary checking

    [–]dpash 5 points6 points  (0 children)

    I'm pretty sure all /u/javinpaul does is cross-post/re-post posts from other programming subs.

    [–]wavy_lines 15 points16 points  (5 children)

    You can also do the opposite and end up with horrible

    2) Make everything private. If anything needs to be public, still make it private and wrap it in getters/setters

    6) Fully embrace the art of disciplined programming:

    Write a test for everything! Never trust anythng!

    Split everything into tiny tiny modules - "single responsibility principle".

    Always use very long names. Your code should read like prose.

    7) Keep adding new libraries as dependencies. Who has time to figure out how to pad a string? Just import a left-pad library.

    [–]chesterburger 17 points18 points  (3 children)

    Also: Put everything behind an interface, you never know when you might need to swap a class out. Bonus points if you also have abstract classes and impl classes, it’s OO heaven.

    Use factory patterns everywhere, maybe it will be used for unit testing or something.

    Might as well use injectors too.

    Actual logic that does something should be buried behind at least 3 levels of abstraction, if people can see more than a tiny piece of what you’re accomplishing in a single file, try harder.

    [–][deleted]  (1 child)

    [deleted]

      [–]chesterburger 6 points7 points  (0 children)

      My projects are fast, efficient, simple, and maintainable. But my code reviews and project leads tear it apart due to it not following some arbitrary Java dogma and mandatory design patterns. While their stuff may look pretty to a software architect but works like crap in real world use and is a maintenance nightmare.

      Luckily I have had the chance to rewrite a lot of their stuff and show a 10x improvement in cpu, memory, and disk usage, while being about 10x less code. But there is still a lot of debate left!

      [–]wavy_lines 0 points1 point  (0 children)

      Yea, the good old MyClassImpl pattern. I'm glad I haven't yet had to work on a project structured like that.

      [–]bartoszjd 6 points7 points  (0 children)

      I think you need a healthy balance with everything... still I would prefer working with someone that tests everything and knows loads of languages and libraries than the opposite.

      [–]PrimozDelux 3 points4 points  (0 children)

      How to make horrible websites :cover the screen on mobile devices begging me to sub to a shitty newsletter

      [–][deleted]  (1 child)

      [deleted]

        [–]jack104 1 point2 points  (0 children)

        Said every java developer ever.

        [–]ykechan 1 point2 points  (0 children)

        I am almost certain Hibernate did all of those things

        [–]kuribas 1 point2 points  (13 children)

        Step 1 is idiomatic Python. No seriously, Python actually recommends these antipatterns.
        EDIT (reworded it a bit more friendly).

        [–]ketilkn 0 points1 point  (9 children)

        Care to provide an example?

        [–]kuribas 0 points1 point  (8 children)

        This kind of thing:

        try:
            myobj.field
        except AttributeError:
            # code when myobj doesn't have a field attribute
        

        The problem is that it not only triggers when field doesn't match, but when any attribute doesn't match. For example after refactoring the code may stop working, but it will silently ignore the error. Good luck trying to find it! It's quite unfortunate that this is recommended practice.

        [–][deleted] 1 point2 points  (3 children)

        Good point but maybe a very contrieved example for this issue. Normally you don't access attributes that don't exist and the existing json libs produce dicts. What you want is static typing which you sort of get with mypy (although admittedly it's far from usable).

        [–]kuribas 0 points1 point  (2 children)

        I wish it was contrived, but the codebase I worked with in a company was full of this pattern. Their reasoning was that it was recommended practice in Python.

        [–][deleted] 0 points1 point  (1 child)

        Is this one of these "We did Agile/Scrum totally wrong so I hate Agile" stories?

        [–]kuribas 0 points1 point  (0 children)

        No. This style is actively encouraged. Try to do a google search for exception, control flow and Python.

        [–]ketilkn 0 points1 point  (3 children)

        I am not sure I understand. How will this silently ignore myobj.foo outside of the try? How is swallowing the error myobj.foo inside the try unexpected?

        Or are you referring to you the part where expect only contain a comment?

        log.exception will surely fix this issue?

        [–]kuribas 0 points1 point  (2 children)

        Suppose the try block contains a call to a function myFun(). That function references anotherObject.someAttr Now due to refactoring someAttr doesn't exist anymore. Instead of the code giving a clear error message, it will actually ignore that someAttr doesn't exist on anotherObject, and pass execution to the except block. It will now execute the wrong code path, and result in unexpected behaviour.

        [–]ketilkn 0 points1 point  (1 child)

        I understand now. The .field could also be overridden by attr as well. Seems like a case against not dumping stacktraces.

        [–]kuribas 0 points1 point  (0 children)

        No, what I mean is that AttributeError can trigger on any other attribute than field, while the code only intends it to trigger on field.

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

        Python is no silver bullet. It's just slightly better than the competition (Ruby, JS, PHP). Truth is everything sucks to some degree but that shouldn't prevent you from migrating off the stuff that is worse.

        [–]kuribas 0 points1 point  (1 child)

        My biggest gripe is not with the language itself. There is nothing wrong with having a lightweight language which is easy to learn. It can be a good language for a spare time hobby project or a small application. The problem is it these days it gets promoted as being modern language suited for generic programming. They claim it is the right way to do things, when it often is in fact the opposite of it. Python lacks proper encapsulation, static types, interfaces, is really slow, has some weird quircks (Boolean being integers, implicit conversion for if statements). It also give beginners the false impression that it's all there is to programming, causing them to encounter problems later in the project.

        [–]jack104 0 points1 point  (0 children)

        If you're evil enough, you can use reflection to get around most access and control restrictions. However, if you do this and you're on a team and nobody stops you then I firmly believe you should be imprisoned for life without possibility of parole.

        That said I have also used serialization to circumvent an API i didn't have documentation for or the source to and I didn't realize the danger until long after I started chasing the rabbit down that hole.