Live data from Hacker News

Why Java? Tales from a Python Convert

sookocheff.com

51–60 of 102 posts

Re: Why Java? Tales from a Python Convert

#51
post #7

Earlier quoted context omitted.

I'm seriously tired of this argument against getters and setters, just generate them with the IDE some also support collapsible regions with a start and end comment, and forget about them. So considering you can just generate and forget why is it tedious?

If it can be generated, why doesn't the compiler do it for you? This shouldn't be done at the IDE level.

The best argument is that the compiler doing it add complexity to the language. One might say adding complexity to the language is justified if it means removing complexity from the programmer's workload, but in many languages that attempt to solve this problem that's not how it works out.

Most solutions to this amount to allowing programmers to intercept field access via getters/setters. This way they can just use public fields and switch to getters/setters when they need to add special behavior without breaking the interface. Pseudocode:

    // using methods; no special behavior
    class Foo {
        private bar
        public get_bar() { return bar }
        public set_bar(_bar) { bar = _bar }
    }
    // using methods; special behavior
    class Foo {
        private bar
        public get_bar() { return decode(bar) }
        public set_bar(_bar) { bar = encode(_bar) }
    }
    // using getters/setters; no special behavior
    class Foo {
        public bar
    }
    // using methods; special behavior
    class Foo {
        public get bar { return decode(bar) }
        public set bar(_bar) { bar = encode(_bar) }
    }
Rather than eliminate complexity from the programmer's workload, this just moves it elsewhere. Instead of tedium, which is something that can be alleviated by simple tooling (copy/paste, editor macros, templated code snippets), you get a constant concern over whether a field access will have unexpected behavior, which is something that can only be alleviated by complex tooling (semantic code analysis).

So ultimately this approach adds complexity to the language/compiler, adds complexity to the tooling, and has no effect on the programmer's workload.

I'm trying to think of a better approach and the best I can come up with right now is a macro system in the language (one that makes it very clear where a macro is being expanded, to avoid the same problem of "constant concern"). For example:

    macro #generate_accessors(field) {
        let paramname = unique_identifier()
        return #[
            public #[ identifier_from_string("get_" + field.as_string()) ]() { return #[ field ] }
            public #[ identifier_from_string("set_" + field.as_string()) ](#[ paramname ]) { #[ field ] = #[ paramname ] }
        ]
    }
    // no special behavior
    class Foo {
        private bar
        #generate_accessors(bar)
    }
    // special behavior
    class Foo {
        private bar
        public get_bar() { return decode(bar) }
        public set_bar(_bar) { bar = encode(_bar) }
    }
But I haven't seen any language where this is the canonical approach.

Re: Why Java? Tales from a Python Convert

#52
post #34

> Java’s type system, while verbose at times, allows you to write code that largely “just works”. NullPointerException would like to have a word with you about that. In all seriousness, it feels unreal that people can be that impressed by Java's safety or lambdas. Makes you shudder to think about what they've used before that.

Now with Optional in Java 8 its not an issue.

Re: Why Java? Tales from a Python Convert

#53
post #31
post #10

Earlier quoted context omitted.

That's because Java is object-oriented. Data and the functions that operate on that data are not supposed to be separated. A clean object-oriented design has no plain getters and setters.

That's because Java is pedantically and obsessively object-oriented

I've found that most people who think Java is overly OO are actually writing procedural programmers, who use objects as ornamentation.

It is fundamental to OO that implementation details are not exposed. Accessor methods are, by their very definition, not Object Oriented.

It's okay to use them, but you're not doing OO, and you very likely shouldn't be using Java if that's the case.

Re: Why Java? Tales from a Python Convert

#54
I love the jvm, I love the tooling and the ecosystem, but Java I do not love. The author presents many of Java 7/8 features as a reason for Java's greatness. The language features of Java 7/8 are really not that compelling. Let's consider that C# has had much a more progressive approach to language design for a while now.

Most places I've worked at recently have moved to Java 8 because 7 has been EOLed. It feels like we were pushed onto 8 rather than enticed by its shininess.

What makes Java great isn't java it's the jvm. It's such a brilliant piece of engineering. What makes the jvm 'meh' is it's association with java. The arguments the author makes about Java being great are in my eyes really about the JVM, its tooling and its languages.

Re: Why Java? Tales from a Python Convert

#55
post #5
post #2

These examples look like C# 2.5 with a little bit of LINQ.

IMHO, C#'s tooling and is definitely ahead. Java is starting to get there, and I can see why the JVM is still popular. But given the actions of Oracle and MS as of late, I think I'd take MS. VS starter projects are easy to setup and run... Every Java application I've worked on has been an exercise in frustration just getting the environment setup.

I've found the opposite. For me, C# as a language is nicer than Java. The libraries themselves are a bit of hit and miss - personally I've found Java's concurrency APIs to be much better than C#'s, however I've found the async and LINQ support in C# to be far nicer than the Java equivalent (including Java 8 streams etc). But tooling... wow... Visual Studio feels like such a huge dinosaur compared to IntelliJ IDEA. Not to say it's that bad, but IDEA is so far ahead of any other dev environment I've ever worked with it's not even funny. Even adding Resharper to VS doesn't feel much more than scratching the surface. As always, YMMV.

Re: Why Java? Tales from a Python Convert

#57
post #37

OP is glossing way too many things. 1. Desktop users are tricked in to installing Ask toolbar crapware. Which other language tricks users in to doing that? 2. Java development actually have languished for very long time and it is very recent that it started to catch up with C# and other modern languages. Java forums are filled with cries and screams for adding these improvements for years on. 3. Java is built on lang…

> Java is built on language concepts that are now 20 years old. Name me at least one language, even remotely mainstream, that is built on language concepts which aren't at least 20 years old.

Well, you know Archimedes and Aristotle had thought through all concepts in everything so nothing is new really :). Or more recently, all languages are just little flavors on Turin machine or Lambda calculus. But practically, Python had been one of the language that sets aside itself dramatically. It's still surprising to me that language designers - including folks on Go team - still have hard time thinking outside of braces. It's almost disguesting how C# requires braces and uses == vs =. When you look at Python, it's apparent that Guido van Rossum had no inclination to do things as it was popular at the time and he put a lot of thought in removing redundancy, putting else clause in for and so many other cool things that are now so obvious.

Re: Why Java? Tales from a Python Convert

#58
post #34

> Java’s type system, while verbose at times, allows you to write code that largely “just works”. NullPointerException would like to have a word with you about that. In all seriousness, it feels unreal that people can be that impressed by Java's safety or lambdas. Makes you shudder to think about what they've used before that.

AttributeError: 'NoneType' object has no attribute isn't much better. Java might not be perfect, but it does let you catch a lot of problems at compile time rather than run time, which is a step in the right direction. The alternative (run it and see) gets old fast.

While I agree - this particular alternative is worse - it's not the only alternative. I was talking about more expressive type systems, not less.

Re: Why Java? Tales from a Python Convert

#59
Just a spin on this: as a java developer that recently started doing a lot of python, what has really annoyed me (apart from the utterly woeful IDE functionality compared to typed languages) is the extra "boiler plate" thinking you need to do with python because of the dynamicness meaning you have to keep the types and classes you're using for your codebase in your head, rather than letting the computer deal with that.

e.g. you have a function with a "database" parameter ... it could be a string, it could be a dict, another class, or even a number. There is no way to know apart from back-tracking through the code (or run it and wait for it to fail with a TypeError when that code gets hit). With java you just read the type off the screen and you can get on with solving the problem at hand without extra thinking, and even if you do screw up your IDE tells you right away with a nice squiggly red underline, or if you're not using an IDE during compile time. With Python you might not find out about that TypeError until that 3am pager call.

People have suggested that the answer to this is forcing strict naming conventions and/or strict docstring conventions ... but if you are going to go with that level of extra work of typing "database_string" or """Lots of long docstrings explaining exactly what type the database parameter is.""" (and maintaining it!!!),you're not saving any boilerplate (biggest complaint I've seen levelled at java) so why not just use a statically typed language ?

tl;dr - for me, python adds cognitive load of keeping the minutiae of the code in my head on top of solving the actual task at hand.

That said, I like the "pick up and go" prototyping feel of Python for quick jobs - java sucks for that.

Re: Why Java? Tales from a Python Convert

#60
post #57

Earlier quoted context omitted.

> Java is built on language concepts that are now 20 years old. Name me at least one language, even remotely mainstream, that is built on language concepts which aren't at least 20 years old.

Well, you know Archimedes and Aristotle had thought through all concepts in everything so nothing is new really :). Or more recently, all languages are just little flavors on Turin machine or Lambda calculus. But practically, Python had been one of the language that sets aside itself dramatically. It's still surprising to me that language designers - including folks on Go team - still have hard time thinking outside…

So does that waffle mean you can't think of any languages not built on 20 year old constructs then?
Post reply on HN