News for hackers. Stuff that matters.
Re:The myth of using Scala as a better Java by agentgt on Thursday March 02, 2017 @12:36PM (#13776160)
> The problem with Java+XML isn't XML itself, it's that the Java community for a long time was pushing more and more critical code into XML

You are going to have to show some examples.

> because doing non-trivial dynamic things in Java itself can be a huge pain

Actually Java has always been a fairly dynamic language. If it wasn't you wouldn't have all the XML and annotation stuff but code generation like you do in C/C++ and to some extent Go.

You have to remember one of the reasons why there was a shit load of declarative configuration in old Java for enterprise is because software was on premise software. Customers would have different databases, hardware, etc. And there was no way you could say to those customers: "hey how about you go recompile this and that" or "use this syntactically weird DSL".

Really the only better enterprise option back in those days was Lisp we all know how that played out.

> Your program's behavior still depends on tagging the right language constructs with the right magic tags, which is a horrible way to program IMO.

I agree/disagree. It depends on context. Annotations are declarative and thus IMO easier to not screw up and even easier to understand in many cases. Particularly for serialization and code generation. Most languages now have some sort of annotations and this is for good reason.

But yeah too much (annotations) is a bad thing. Java now has annotation overload (spring boot).... probably because people bitched about XML :) ... pretty soon will have convention overload as well (Spring Boot is heading down that path as well like Rails).

You can always take the explicit programmatic option... you know like wiring up your own beans and writing manual SQL but people want "magic". There is probably an even ground somewhere.

Re:The myth of using Scala as a better Java by sreque on Thursday March 02, 2017 @01:34PM (#13776812)
I agree with cle, and I care enough to give examples of painful XML coding in Java:

* Spring startup config (this is basically coding in another XML-based language)

* JSPs (again, programming in a new XML-based language)

* Maven Config (IMO incredibly painful-to-use XML-based language)

* Hibernate config, mapping files

* Tomcat config (basically a pre-cursor to Spring in some sense)

Java is not a dynamic language, sorry. The JVM bytecode is fairly dynamic, but the language certainly isn't.

Also, I think Java would have been better off never introducing annotations. They have their uses, but they've been so over-abused that I would consider them a net negative on the language as a whole. I've been thinking about starting a blog, and one of my initial blog posts may be why annotations are bad for Java.

Re:The myth of using Scala as a better Java by agentgt on Thursday March 02, 2017 @02:06PM (#13777138)
> * Spring startup config (this is basically coding in another XML-based language)

The alternative of manually wiring up beans or giving up and using shitty singleton patterns is pretty awful (remember this was preannotation days).

A pretty sexy annotation DI these days is Dagger2 but alas you seem to hate annotations.

> * JSPs (again, programming in a new XML-based language)

That is not an XML language unless you are talking about JSPX or JSF. It is a crappy templating language. Lots of languages have those (like PHP had Smarty or Pear...). I totally agree JSP and the future JSF was a horrible addition to Java.

> * Maven Config (IMO incredibly painful-to-use XML-based language)

A config that your IDE instantly knows how to properly setup and allows for massively powerful inheritance (see super poms). If you import a Maven project with Eclipse or IntelliJ it just works.

Now I admit Maven is verbose and has lots of baggage but it has some serious pros and a lot of those pros are actually because it uses XML (like Eclipse can automatically adjust your Maven file without changing formatting). I have scripts that I have written in many languages (bash, python, etc) that can read Maven POM files thanks to XML. You can't do this with Gradle.

> * Hibernate config, mapping files

Yep that sucked but you hate annotations... so I guess you propose programmatically doing the mappings?

I despite hibernate anyway.

> * Tomcat config (basically a pre-cursor to Spring in some sense)

Oh like Apache config is any better. I mean seriously Apache has made up weird SGML config.

> Java is not a dynamic language, sorry. The JVM bytecode is fairly dynamic, but the language certainly isn't.

It is a dynamic language. You can instantiate classes by string names and manipulate their bytecode on the fly. You can call methods dynamically as well. Yeah it doesn't have the ease of metaprogramming like Ruby or Python but its its there through libraries (CGLIB).

Honestly I'm not sure what you mean by dynamic (please cite something) but I guess you mean interpreted and even that is sort of wrong as well (bytecode is interpreted by the JVM).

> Also, I think Java would have been better off never introducing annotations

Annotations also allow for preprocessing aka light weight macros. A full macro system probably would have been better. I look forward to your blog post (in all honesty).

Re:The myth of using Scala as a better Java by sreque on Thursday March 02, 2017 @02:17PM (#13777246)
You asked for examples and that proceeded to defend almost all of the ones I listed, which basically proves my point that this is how things work in the Java community.

You can call things via reflection, therefore the language is dynamic? You have a strange definition of what makes a language dynamic. By that definition just about every language is dynamic. In C/C++ I can dynamically load symbols, call functions by string names, call C++ constructor functions, etc.

I've never in practice seen anyone use compile-time annotation processors. In practice, annotations define runtime global variables that some frameworks make use of by doing expensive classpath scanning on startup to add or rewrite bytecode at runtime. These frameworks basically help cement java's reputation for having incredibly slow startup times while at the same time making it very difficult to understand how your code works. Even if you aren't doing classpath scanning to generate code, using annotations also introduces unnecessary coupling in your code in practice. The blog post will have some good examples I've seen in the wild. :)

Re:The myth of using Scala as a better Java by agentgt on Thursday March 02, 2017 @02:29PM (#13777362)
> In practice, annotations define runtime global variables that other frameworks can make use of by doing expensive classpath scanning on startup to rewrite bytecode at runtime.

Dagger2 is DI a compile time annotation library. Yes there needs to be a lot more libraries like this.

I totally understand some of your hate for annotations (I have my own with Spring Boot).

Despite my tone from the previous comment I think there should be a lot more plain old programmatic configuration (ie just load up objects and setup some properties during the bootstrap).

I had aspirations of making a howto guide using Dagger2 and various other compile time / code generation libraries (like jOOQ and MapStruct) as I too absolutely hate the classpath scanning hell that is Spring these days.

I can't deny though that some people find the "magic" more productive particularly for ramp up time.

All in all I violently agree with you more than you think (hence why I'm looking forward to your post).

I still don't know what a dynamic language is and neither does Wikipedia for that matter [1]. Its pretty nebulous. Its like saying strongly typed.

[1]: https://en.wikipedia.org/wiki/Dynamic_programming_language#E...

Re:The myth of using Scala as a better Java by NiceGuy_Ty on Friday March 03, 2017 @09:59AM (#13783241)
Dynamically typed languages carry the types of values at runtime. That is, whatever is executing your code can look at a value itself and read off the type of it. Statically typed languages check all of the types of their values at compile time to make sure that it's sound. Then, they can strip the type information from those values and execute them without having to perform any runtime checks. In a dynamically typed language, the way to apply an operation is to read the type tag on it first, make sure the operation you want to apply can be applied to it, and then execute that operation. In a statically typed language, that check happened at compile time, so you're safe to just apply the operation to the value. Oftentimes languages may not be fully statically typed or fully dynamically typed. Java's use of reflection, instanceof, and casting means that it carries some type information at runtime. C++ has typid, C# has GetType(), etc. etc. Haskell as a language has full type erasure and can be considered fully statically typed, but there are some. GHC extensions (Typeable) which point to some type information being held at runtime by the compiler.
Re:The myth of using Scala as a better Java by xg15 on Friday March 03, 2017 @12:39PM (#13784523)
> Actually Java has always been a fairly dynamic language. If it wasn't you wouldn't have all the XML and annotation stuff but code generation like you do in C/C++ and to some extent Go.

That's a point I never really understood. Code generation has it's downsides, but it seems vastly preferrable to the current mess of reflection: There seemed to have been a trend to move a lot of stuff that should logically occur at compile time to run time - therefore both adding a performance penalty and making debugging a royal pain - for what benefit?

There are some recent projects (e.g. Immutables and Dagger2) which seem to favour code generation over reflection again and I really hope this trend picks up steam.

> You have to remember one of the reasons why there was a shit load of declarative configuration in old Java for enterprise is because software was on premise software.

Which sounds reasonable - until you see real-world use where all components of an application are wired together with XML - even though for most of it, there is only a single setting that wouldn't break the application.

Re:The myth of using Scala as a better Java by hota_mazi on Saturday March 04, 2017 @12:04AM (#13789386)
> Actually Java has always been a fairly dynamic language. If it wasn't you wouldn't have all the XML and annotation stuff but code generation like you do in C/C++ and to some extent Go.

You're equivocating on "dynamic".

Java is not a dynamically typed language.

It can be seen as "dynamic" in the sense that its behavior can be modified at runtime by external files. Then again, what languages can't?