Java.next: The next generation JVM language

Source: Internet
Author: User
Tags final garbage collection mixed new features

This is the ThoughtWorks company architect Neal Ford at IBM The first of the Developerworks series Java.next, based on Groovy,scala and Clojure, describes the importance of multi-language programming and compares static and dynamic types, functional programming and imperative programming. (Last updated in 2013.02.06)

In a keynote address I worked with Martin Fowler, he made an insightful point:

The legacy of Java will be the platform, not the programming language.

The original engineers of Java technology made a wise decision to separate the programming language from the Run-time environment, which ultimately enabled more than 200 languages to run on the Java platform. This architecture is critical to the long-term viability of the platform, since the life of the computer programming language is generally relatively short. Starting in 2008, the annual JVM Language Summit hosted by Oracle provides an opportunity for other language implementations on the JVM to open up with Java platform engineers.

Welcome to the Java.next column series, in this series of articles, I'll talk about three modern JVM languages--groovy,scala and clojure--that provide paradigms, a fun mix of design choices and comfort factors. I'm not going to take the time to go into each language in depth and have this kind of depth introduction on their respective sites. But the sites of these language communities-whose primary purpose is to spread these languages-are devoid of objective information or examples that are not applicable to the language. In this series of articles I will make an independent comparison to fill the blanks above. These articles will outline the Java.next programming languages and the benefits of learning them.

Beyond Java

The degree to which the Java programming language achieves excellence is that, according to Bruce Tate in his beyond Java book, the Perfect Storm: The Rise of Web applications, the emergence of web technologies for a variety of reasons, and the rise of enterprise-level multi-tier application development, These factors together create the Java excellence. Tate also pointed out that the storm was a unique series of events in which no other language had used the same approach to achieve the same process of excellence.

The Java language has proven its powerful flexibility in functionality, but its syntax and intrinsic paradigm have long known limitations. Although some of the promised changes are about to be introduced into the language, Java syntax cannot easily support some important future syntax features, such as some features in functional programming. But if you try to find a language to replace Java, you're looking for the wrong one.

Multi-language programming

Multi-language programming--in a blog post in 2006, I revitalized the term and got it back into fashion-based on the understanding that no programming language solves every problem. Some languages have some built-in features that enable them to better adapt to specific problems. For example, because of the complexity of swing, developers find it difficult to write a swing UI in Java because it requires declaring types in advance, defining annoying anonymous inner classes for UI actions, and other troubling things. It would be much better to build a swing application using a language that is more suitable for building the UI, such as the Swingbuilder tool in groovy.

The proliferation of programming languages running on the JVM has greatly stimulated the idea of multi-language programming, because you can mix numbered languages and use the best matching language, while maintaining the same underlying bytecode and class libraries. For example, Swingbuilder is not meant to replace swing; it's just built on the existing swing API. Of course, for a long time, developers will still be mixing programming languages outside the JVM-for example, using SQL and javascript--for specific purposes, but mixed programming will become more prevalent in the JVM world. Many of the projects in ThoughtWorks share multiple programming languages, and all tools developed by ThoughtWorks Studios use mixed languages.

Even if Java is still your main development language, learning how other languages work will allow you to incorporate them into your future strategy. Java will still be an important part of the JVM ecosystem, but ultimately it is more of an assembly language for the platform-either for purely performance reasons or for special needs.

The evolution of programming languages

When I was in college in the late 80, we used a development environment called Pecan Pascal. Its unique feature is that it enables the same Pascal code to run both on Apple II and on the IBM PC. Pecan engineers used a mysterious object called "bytecode" to achieve this goal. Developers compile their Pascal code into "bytecode," which runs on the native "virtual machines" written for each platform. It was a terrible experience! The final program is surprisingly slow, even if it's just a simple class assignment. The hardware at the time was unable to meet the challenge.
In the decade after Pecan Pascal, Sun released Java with the same architecture, which was limited to the hardware environment of the last century of the 90. Java also adds other developer-friendly features, such as automated garbage collection. Since I used a language like C + +, I don't want to use a language that doesn't have garbage collection anymore. I would rather take the time to think about complex business problems at a higher level of abstraction than a complex plumbing problem like memory management.

One of the reasons that computer languages usually do not have a long lifespan is the speed at which language and platform design are innovative. As our platforms become more powerful, they can handle more of the extra work. For example, Groovy's memory (memoization) feature (joined in 2010) caches the results of a function call. There is no need to write cached code manually, which introduces a potential flaw, and you simply need to invoke the Memoize method, as shown in Listing 1:
Listing 1. Memory Functions in Groovy

def static sum = {Number->
  factorsof (number). Inject (0, {i, J-> i + J})
}
def static sumoffactors = su M.memoize ()

In Listing 1, the results returned by the Sumoffactors method are automatically cached. You can also use the method Memoizeatleast () and Memoizeatmost () to customize the caching behavior. Clojure also contains memory features that are slightly implemented in Scala. Advanced features such as memory that exist in the next-generation programming language (and some Java frameworks) will gradually enter the Java language. A higher order function (Higher-order function) is added to the next version of Java, which makes memory easier to implement. By studying the next-generation Java language, you can see the future features of Java quickly.

Groovy,scala and Clojure

Groovy is the Java syntax of the 21st century-espresso coffee replaces traditional coffee. Groovy's design goal is to update and eliminate the obstacles in Java syntax, as well as support the main programming paradigm in the Java language. As a result, groovy wants to "know" things like JavaBean, which simplifies access to properties. Groovy will quickly incorporate new features, including important features in functional programming, which I will focus on in subsequent chapters of this series. Groovy is still primarily an object-oriented command language. Groovy differs from Java's two fundamental differences: it is dynamic rather than static; it is much better at metaprogramming.

Scala is designed to use the JVM in its bones, but its syntax is completely redesigned. Scala is a strongly static type language-its type requirements are more stringent than Java's, but the problem is minimal-it supports object-oriented and functional paradigms, but prefers the latter. For example, Scala prefers the Val declaration, which generates immutable variables (similar to declaring a variable as final in Java) to Var, and Var creates a more familiar variable. With deep support for both paradigms, Scala has a bridge between what you might want (object-oriented command programming) and what you should want (functional programming).

Clojure is the most radical, its grammar is separated from other languages, is considered a Lisp dialect. Clojure is a strongly dynamic type language (like groovy) that reflects a design decision that is not going to go without hesitation. While Clojure allows you to interact fully and deeply with legacy Java programs, it does not attempt to build a bridge to connect object-oriented paradigms. For example, Clojure is a hardcore of functional programming and also supports object-oriented to allow interoperability with that paradigm. Although it supports all the features that are used by object programmers, such as polymorphism, it is implemented in functional style rather than object-oriented style. The design of Clojure follows a core set of engineering principles, such as software transaction memory (Software transactional Memory), which breaks the old programming paradigm to cater to new features.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.