`
vipcowrie
  • 浏览: 351080 次
  • 性别: Icon_minigender_1
  • 来自: 南京
博客专栏
1167aa84-228b-38f8-88a0-4733613efdef
让Java跑起来
浏览量:64403
文章分类
社区版块
存档分类
最新评论

让我们选择其他语言替代JAVA的10个理由

阅读更多

10 good reasons to look for something better than Java

Posted by: Mario Fusco on ?? 14, 2009 DIGG

我是JAVA的一个专业开发者,写过无数行JAVA代码,但是我现在认为JAVA是否已经该到了他的时间了?time is up?
Don't get me wrong. During my professional life I have written tons of Java code and of course I think it is a great language still. For sure it has been a great improvement from C++ and Smalltalk. But now even Java is starting to feel the weight of its 15 years.

现实是世界上存在N多JAVA程序员和代码,使得我们不得不接受、面对JAVA的一些问题,
我觉得SCALA脚本语言的出现不错,让我开心了一下,但是还是有不少的问题:
Indeed during my experience I had to face up with some mistakes, flaws and lacks in its design and specification that made my Java programmer life less pleasant. With millions of Java programmers and billions of lines of code out in the world, I am far to say that Java is going to be dead in the near future. Anyway after the rise of some JVM compatible languages (my favorite is Scala), these issues are becoming even less tolerable and I am starting thinking that it is time to slowly move away from Java (but not from the JVM). More in detail, in my opinion, the 10 most important problems of the Java language are:

缺乏对面向功能的编程的支持,脚本语言的强项。
1. Lack of closure: I don't think I have to explain this. Functional programming exists since decades, but in the last years they are gaining more and more interests, mostly because it allows to write naturally parallelizable programs. I partially agree with Joshua Bloch that underlined the problems of introducing them in Java as a second thought (the BGGA proposal was truly awful), but anyway their lack makes impossible to have any kind of real functional programming in Java.

同上
2. Lack of first class function: this issue is in some way related to the former one but I believe it is even worse. The only way to achieve a similar result in Java is by using the ugly and sadly famous one-method anonymous inner classes, but it looks actually a poor solution. Even in C# has been provided a better one by the implementation of the delegate mechanism.

非纯OO
3. Primitive types: it should be beautiful if everything in Java was an Object, but they didn't design it in that way. That leaded to some issue, like the impossibility to have a Collection of int partially resolved in Java 5 through the autoboxing feature (see below). It also generated some confusion between passing by value and passing by reference. Indeed a primitive data type is passed to a method by value (a copy of the data type is duplicated, and passed to the function) while true objects are passed by reference.

自动拆装包带来的问题,解决3的问题
4. Autoboxing and autounboxing: this feature has been introduced in Java 5 to overcome the problems caused by the presence of primitive types. It allows to silently convert a primitive type in the corresponding object, but often it is cause of other problems. For example an Integer can have null value, but the same doesn't apply to int, so in this case when the Integer is changed in an int the JVM can't do anything else than throw a difficult to debug NullPointerException. Moreover it is cause of other strange behavior like in the following example where it is not so easy to understand why the test variable is false:

Intger a = new Integer(1024);
Intger b = new Integer(1024);
boolean test = a < b || a == b || a > b;

语法不自然
5. Lack of generics reification: generics are one of the cool features introduced with Java 5, but in order to mantain the compatibility with the older version of java they miss some important characteristic. In particular it is not possible to introspect their generic type at runtime. For example if you have a method that accepts as parameter a List<?> and you pass to it a List<String> you are not allowed to know at runtime the actual type of the generic. For the same reason you cannot create array of generics. It means that despite it looks quite natural the following statement won't compile:

List<String>[] listsOfStrings = new List<String>[3];

不能规避的告警
6. Unavoidable generics warnings: have you ever found yourself in the impossibility to get rid of a bothering warning about generics? If you make a large use of generics like me, I bet you did. And the fact that they felt the need to introduce a special annotation to manage this situation (@SuppressWarnings("unchecked")) is symptomatic of the dimension of this problem and, in my opinion, that generics could have been designed better.

不能传递void给方法
7. Impossibility to pass a void to a method invocation: I admit that the need to pass a void to a method could look weird at a first glance. Anyway I like DSL and while implementing a special feature of my DSL library (lambdaj) I had the need to have a method with a simple signature like this: void doSomething(Object parameter) where the parameter passed to this method is the result of another method invocation done with the only purpose to register the invocation itself and execute it in the future. With my big surprise, and apparently without a good reason, since the println method returns void, I am not allowed to write something like this:

doSomething(System.out.println("test"));

没有本地代理支持机制
8. No native proxy mechanism: proxy is a very powerful and widely used pattern, but Java offers a mechanism to proxy only interfaces and not concrete classes. This is why a library that provide this feature like cglib is employed in so many main stream frameworks like Spring and Hibernate. Moreover cglib implements this feature by creating at runtime a Class that extends the proxied one, so this approach has a well known limitation in the impossibility to extend and then proxy a final Class like String.

switch case不爽
9. Poor switch ... case statement: the switch ... case as specified in java allows to switch only on int and (starting from java 5) enum. That looks extremely few powerful especially if compared with what offered by a more modern language like Scala.

还是3引起的问题
10. Checked exception: like primitive types, checked exception have been one of the original sins of Java. They oblige programmers to do one of the following two equally horrible things: fill your code with tons of poorly readable and error prone try ... catch statement where often the most meaningful thing to do is to wrap the catched exception in a runtime one and rethrow it; or blurring your API with lots of throws clause making them less flexible and extensible.

解决方法是不支持向下兼容,但是不可能,所以我需要一种新的语言。
The real problem here is that the only way to fix the biggest part of the issues I mentioned is to take a painful decision and define a specification of the language that drops the backward compatibility with the current one. I guess they will never do that, even if I believe it should not be extremely difficult to write a program that allows to automatically translate the old Java sources in order to make them compatible with this new hypothetic release. And in the end, this is the reason why I decided to start looking for a better JVM compatible language.
分享到:
评论
3 楼 RednaxelaFX 2010-08-05  
vipcowrie 写道
缺乏对面向功能的编程的支持

原文是functional programming么,那一般译作函数式编程吧…
2 楼 ray_linn 2010-08-05  
python和ruby调试起来太痛苦了,比如变量名的typo错误被当成一个新的变量处理,然后满世界找为什么逻辑出错了,长期用过python,短暂用过ruby之后,才体会到编译才是王道。。。。
1 楼 whjpyyyy 2010-08-05  

相关推荐

    第1章-Java语言概述-Java面向对象程序设计教程-微课视频版-程杰-清华大学出版社.pptx

    JAVA 面向对象程序设计教程 第1章 Java语言概述 第1章-Java语言概述-Java面向对象程序设计教程-微课视频版-程杰-清华大学出版社全文共20页,当前为第1页。 第1章 Java语言概述 第1章-Java语言概述-Java面向对象程序...

    Java入门:状态对象--数据库的替代者

    Java入门:状态对象--数据库的替代者

    autojs_java_aotujs_autojs替代品_自动化_autojs_

    可以实现自动化代替人工,在连击小视频的软件实现自动连击,滑动视频等

    AES加密算法(java)实现

    这个标准用来替代原先的DES,已经被多方分析且广为全世界所使用。经过五年的甄选流程,高级加密标准由美国国家标准与技术研究院(NIST)于2001年11月26日发布于FIPS PUB 197,并在2002年5月26日成为有效的标准。2006...

    C#和JAVA的比较

    C#(C-Sharp)是Microsoft的新编程语言,被誉为“C/C++家族中第一种面向组件的语言”。...如果你是一个Java开发者,想要学习C#或者了解更多有关C#的知识,那么本文就是你必须把最初10分钟投入于其中的所在。

    java NIO 视频教程

    Java NIO(New IO)是一个可以替代标准Java IO API的IO API(从Java 1.4开始),Java NIO提供了与标准IO不同的IO工作方式。 Java NIO: Channels and Buffers(通道和缓冲区) 标准的IO基于字节流和字符流进行操作的,...

    Java自学项目,包含java例程及文档说明.rar

    J2SE:标准版,也是其他两个版本的基础。在JDK1.5时正式更名为JavaSE。 J2ME:小型版,一般用来开发嵌入式程序,已经被andorid替代。在JDK1.5时正式更名为JavaME。 J2EE:企业版,一般开发企业级互联网程序。在JDK...

    北京大学《JAVA语言程序设计》课程复习指导

    北京大学《JAVA语言程序设计》课程复习指导 第一部分 大纲说明 课程的性质和任务 面向对象技术被称为是程序设计方法学的一场革命,它已经逐步替代了面向过程的程序设计技术,成为计算机应用开发领域的主流...

    JavaApplet

    而这里,我们将带领读者用一周的时间学会如何从一个生手,到初步掌握JavaApplet,最后转入到Java的应用程序开发之中去。当然对于大家来说,要用一周的时间掌握一门语言,这当然是不可能的,但我们将尽力地给大家一个...

    Go-Goism在Emacs使用Go语言替代EmacsLisp语言

    Goism: 在Emacs 使用Go语言 替代Emacs Lisp语言

    huffman编码java实现

    包含huffman编码java实现源程序、该java程序的javadoc文档、huffman编码简单原理ppt

    基于java语言的游戏编程毕业设计论文

    通过对 J2ME 的详细介绍我们可以从中了解到其自身的作用,近年来,随着 JAVA 手机的诞生,其无可替代的灵活性与轻便性致使 JAVA 手机游戏成为游戏市场的又一亮点,它的前景无可限量,必将在我们以后的生活中发挥着...

    epub格式原版 Swift Programming Language 苹果Swift编程语言 替代Objective C

    苹果官方 The Swift Programming Language 文档 苹果 IOS Swift编程语言 epub格式原版 2014年6月3日发布。

    Kotlin和Java混合开发入门教程

    Kotlin是一门基于JVM的编程语言,它正成长为Android开发中用于替代Java语言的继承者。Java是世界上使用最多的编程语 言之一,当其他编程语言为更加便于开发者使用而不断进化时,Java并没有像预期那样及时跟进。 Java...

    Java开发一款功能完善的网盘/云盘系统.zip

    一款便捷、功能完善的 JAVA 网盘 / 云盘 系统。专门面向个人、团队或小型组织来搭建属于自己的网盘。它不仅仅是替代U盘的不二之选,还是一款具备在线视频播放、文档在线预览、音乐播放、图片查看等高级功能的文件云...

    开源免费的博客系统, Java语言开发, 支持数据库.rar

    许可证:Apache-2.0 开发语言:Java、JavaScript、TypeScript 官网:/ Appsmith 是一个用于构建管理面板、内部工具和仪表板的低代码项目。与超过 15 个数据库和任何 API 集成。构建你需要的一切,速度提高 10 倍。...

    C#和 Java比较

    C#(C-Sharp)是Microsoft的新编程语言,被誉为“C/C++家族中第一种面向组件的语言”。...如果你是一个Java开发者,想要学习C#或者了解更多有关C#的知识,那么本文就是你必须把最初10分钟投入于其中的所在。

    基于JAVA的学生通讯录管理系统设计和实现[文献综述].doc

    除了Java语言具有的许多安全特性以外,Java对通过网络下载 的类具有一个安全防范机制(类ClassLoader),如分配不同的名字空间以防替代本地的 同名类、字节代码检查,并提供安全管理机制让Java应用设置安全哨兵。...

Global site tag (gtag.js) - Google Analytics