Use of Groovy, Scala, and Clojure

Source: Internet
Author: User
Tags garbage collection mixed

In a keynote speech with Martin Fowler, he provided an astute observation:

Java's legacy is platform, not language.

The original Java Technology engineer made a terrific decision to detach the language from the runtime, eventually enabling more than 200 languages to run on the Java platform. The infrastructure is critical to the long-term viability of the platform, because the computer programming language is usually short-lived. The JVM language summit, hosted by Oracle every year since 2008, provides an opportunity for the implementation of alternative languages on the JVM to work openly with platform engineers.

Welcome to the next generation of Java column series. Here, I'll briefly introduce three modern JVM languages: Groovy, Scala, and Clojure, which have an interesting combination of paradigms, design choices, and comfort factors. I do not intend to introduce each language in detail here, and there are introductions on their respective websites. But the language Community Web site (primarily for evangelism) does not provide objective information or task examples that are not adapted to the language. In this series of articles, I will make a substantial comparison to help fill this gap. This article prepares to outline the benefits of Java's next-generation language and learning these languages.

Beyond Java

The Java language is famous for Bruce Tate, which is known as the perfect storm in its writings beyond Java, leading to the emergence of the web, the adaptability of existing web technologies for various reasons, and the rise of multi-tier application development in the enterprise. Tate also believes that the perfect storm is a series of independent events, and other languages do not reach the same heights in the same way.

The Java language has proved to be quite flexible, but it is well known that its syntax and inherent paradigm have certain limitations. Although the Java language is making some seemingly beautiful changes, its syntax does not support some important future goals, such as functional programming elements. However, if you try to find a new language instead of Java, you are wrong.

Multi-language programming

Multi-language programming is a term that I have put forward and promoted in a blog post in 2006, and multi-language programming is based on the knowledge that a single language is not suitable for solving all problems. Some languages have intrinsic properties that are better suited to certain problems. For example, while swing is as mature as Java, developers find it cumbersome to write a Swing UI in Java because it requires a type declaration, requires an anonymous inner class of behavior, and has other conflicting factors. Using a language that is more suitable for building a UI, such as Groovy with Swingbuilder, makes it easier to build Swing applications.

The extension of the language running on the JVM makes the idea of multilanguage programming more appealing because you can mix it up while maintaining the same underlying bytecode and libraries. For example, Swingbuilder does not replace swing; it is layered on existing swing APIs. Of course, developers have long mixed up with languages other than the JVM (for example, mashup uses SQL and JavaScript for specific purposes), which is more prevalent within the JVM. Many ThoughtWorks projects contain multiple languages, and all tools developed by ThoughtWorks Studios use mixed languages.

Even if Java is still your primary development language, you can learn how to run other languages to use them strategically. Java remains an important part of the JVM ecosystem, but ultimately people tend to use it as Platform assembly language-a place where you can fully understand performance or meet specific needs.

Development

In the early 1980s, when I was in college, we used the development environment called Pecan Pascal. It is unique in that it can run the same Pascal code on both Apple II or IBM PCs. Pecan engineers have achieved this feat by using something called "bytecode" in mysterious ways. Developers compile their Pascal code into this "bytecode" and run it on a "virtual machine" that is written locally for each platform. What a terrible experience! Even for simple tasks, the generation code is extremely slow. The hardware at the time was simply not able to meet the challenge.

In the decade following the release of Pecan Pascal, Sun released Java,java using the same architecture, which was a bit strained to run the code for the the mid 1990s hardware environment, but eventually succeeded. Java also adds other developer-friendly features, such as automated garbage collection. After using a language like C + +, I never want to write code in a language that has no garbage collection. I would rather spend my time on abstraction at a higher level, thinking of ways to solve complex business problems, than wasting time on complex plumbing issues such as memory management.

Computer languages usually do not have a long life, one reason is the speed of innovation in language and platform design. As our platform grows stronger, the more heavy work we can handle. For example, Groovy's memo feature, added in 2010, buffers The result of a function call. Without the need for handwritten buffer code, this may introduce bugs, just call the Memoize () method, as shown in Listing 1:


Listing 1. Remember a function in Groovy

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

In Listing 1, the result of the Sumoffactors method is automatically cached. You can also use another method to customize the buffering behavior, such as Memoizeatleast () and Memoizeatmost (). Clojure also provides a memo feature that is irrelevant to Scala's implementation. Advanced features (such as the memo feature) in the next language (and some Java frameworks) will gradually find their way into the Java language. The next version of Java will add higher-order functions to make the implementation of the memo feature easier. Learn about future Java features in advance by learning the next-generation Java language.

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.