Hacker News new | ask | show | jobs
by TheLoneWolfling 4175 days ago
And this is one of the major reasons why Java is regarded as verbose. There's a simple solution (have the compiler transparently rewrite references to x.foo to x.getFoo / x.setFoo and transparently add getFoo/setFoo - the JVM inlines (trivial) getters and setters anyways) and yet Java, in the interests of "transparency", doesn't allow it.

And their justification fails. Sure, currently if you read x.foo you know that no code is being executed - but you never see x.foo because everything has getters and setters. So all it does in practice is make things (even) more verbose.

1 comments

That's one of my favorite things about Swift. I can do, for example:

    // version 1
    var author: String

    // version 2
    var author: String {
        get {"\(authorFirst) \(authorLast)"}
    }
C# as well. C# 6 is very concise.