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.
分享到:
相关推荐
标题中的“Ruby、Python不能威胁Java的13个理由”表明了作者认为尽管这两种脚本语言在某些领域受到关注,但它们无法撼动Java在编程领域的主导地位。描述提到,作者通过数据分析反驳了Java将被替代的观点,并提出了...
3. Procyon:一个开源的反编译和反汇编框架,它提供了比其他工具更精确的源代码重构能力。 三、使用步骤 以JD-GUI为例,了解如何查看经典代码实现: 1. 下载并安装JD-GUI。 2. 打开JD-GUI,将下载的`java反编译.EXE...
SWT是由Eclipse基金会开发的一个开源库,它提供了与操作系统直接交互的能力,让Java应用程序可以创建原生、高性能的用户界面。在Java领域,SWT常被用来替代早期的抽象窗口工具包AWT和轻量级组件Swing,因为它能够...
虽然"smali2java"提供了一种快速查看代码的方式,但它并不能替代对Smali的直接理解。 总之,"smali2java"是Android逆向工程中的一个重要工具,它帮助开发者将难以理解的Smali代码转化为更易于阅读和分析的Java代码...
在Java编程语言中,我们通常使用Java AWT(Abstract Window Toolkit)和Swing库来创建图形用户界面(GUI),而更高级的图形处理则可以通过Java 2D API或JavaFX来实现。本项目“毕业答辩-JAVA画图形学程序(论文源代码...
Java语言编程规范是软件开发中的重要组成部分,尤其对于大型企业如华为技术有限公司,制定统一的编程规范至关重要。这些规范确保代码的一致性、可读性和维护性,促进团队协作,提高软件质量。以下是对"Java语言编程...
其核心优势体现在以下十个方面: 1. **嵌入式工作流引擎**:jBPM采用嵌入式设计,显著减少了硬件投入,降低了网络与集群的复杂度,从而降低了整体成本和管理难度。 2. **图形化开发工具**:配备的图形化开发工具与...
### 用Java语言编写程序最容易犯的21种错误 #### 1. 代码重复 (Duplicated Code) 在软件开发过程中,代码重复是最常见的问题之一。这种现象通常来源于程序员使用复制粘贴的方式来快速构建功能,这导致代码库中存在...
之所以说汇编重要,其一个重要的原因就是,汇编语言能够让你更好的理解高级语言,尤其是高级语言中的C语言。汇编语言对于内存的操作都是基于内存地址的,而C语言中最令人头疼的指针概念,说白了就是内存的地址。指针...
总的来说,XJad、Jad和jd-gui都是Java开发者在特定场景下不可或缺的工具,它们帮助我们揭示了字节码背后的秘密,尽管不能完全替代源代码,但在许多情况下,它们提供的信息已经足够进行进一步的分析和理解。
Java程序首先被编译成字节码,这是一种平台无关的中间语言,由Java虚拟机(JVM)执行。字节码虽然不是人类可读的,但通过反编译器,我们可以将其转换为接近原始源代码的形式,以便理解其功能和逻辑。反编译的过程并...
Java编程语言以其强大的功能和广泛的应用领域而闻名,但为了保持代码的一致性和可维护性,遵循一套良好的编码规范至关重要。这份"Java Code 编码规范"文档详细阐述了在编写Java源代码时应遵循的最佳实践和标准。下面...
Java程序的编译过程分为几个阶段: 1. **源程序(.java)**:开发者编写的初始代码。 2. **编译**: 使用编译器将源程序编译成字节码文件(.class)。 3. **字节码文件(.class)**:编译后的中间文件,可在不同平台上运行...
### 现代编程语言-Kotlin之美:当下的高效编程典范 #### Kotlin:站在巨人的肩膀上 Kotlin,作为一种新兴的编程语言,...未来,随着更多开发者加入到Kotlin社区中,我们有理由相信它将在编程领域发挥更加重要的作用。
4. **为什么应摒弃 Java 语言**:从多个角度论证 Java 的局限性,并提出 C# 作为替代方案的理由。 #### 语言特性对比 ##### 原始类型处理 - **Java**:原始类型不是对象,导致在处理数组列表等容器时需要进行显式...
- **描述**:反射是Java语言的一项强大特性,但应谨慎使用。 - **应用**:仅在确实需要动态获取类信息时使用反射。 #### 原则六十一:避免频繁修改对象状态 - **描述**:频繁修改对象状态可能导致不可预测的结果。 ...
### Java面试题详解 #### 短类型变量与自动类型提升问题 - **问题描述**:`short s1 = 1; s1 = s1 + 1;` 和 `short s1 = 1; s1 += 1;` 有什么不同? - **解答**: - 在第一种情况下,`s1 = s1 + 1;` 会导致编译...
10. **让Java来的更容易些吧**: - 文章可能提出了简化Java学习曲线和提高开发体验的方法,可能包括新的工具、教程或编程实践。 11. **NetBeans6.1中文版**: - NetBeans IDE的中文版发布,使得中文开发者能更...