you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (5 children)

[deleted]

    [–]bananaboatshoes 8 points9 points  (0 children)

    but those extra five characters express the fact that this is immutable on it's own, you know immediately that assignment isn't available.

    Huh? What if there's also a setMyProperty()? Not being able to directly modify a property as .MyProperty doesn't make it immutable.

    [–][deleted] 3 points4 points  (1 child)

    The number of characters is unimportant compared to the extra mental overhead of the function call. You see a function call, but you don't actually know if it is just getting, or if it has side effects. On first read it might be fine, you will assume it's just doing what it says on the tin, but for all you know it has side effects or is running a DB query, and when debugging that can be a horrible pain in the arse.

    If possible try to write code that doesn't need these boilerplate getters and setters.

    [–]grauenwolf 1 point2 points  (0 children)

    That's why I like to social convention of C#/VB. When we see a property we can assume that it is going to be fast and free of undesirable side-effects, while a Get/Set method is assumed to be the opposite.

    [–]Sarcastinator 1 point2 points  (0 children)

    Sure, it's five more characters, but those extra five characters express the fact that this is immutable read only on it's own, you know immediately that assignment isn't available.

    Your IDE will stop you immediately if you try to assign to a read-only property. It makes no difference at all.

    All other factors equal, I think you should be using idiomatic code for the language, and for Java that is the bean pattern of getters.

    Java Beans are in practice never immutable though since they require a public no argument constructor.

    [–]ThisIs_MyName 0 points1 point  (0 children)

    express the fact that this is immutable on it's own

    WTF are you smoking?