4 ms·
> I just cannot imagine that if you write something in 20 lines in any language I cannot write that in 40 lines in Java Try lisp. Hell, try Python or Ruby. Y
by rikthevik 16y ago
> I just cannot imagine that if you write something in 20 lines in any language I cannot write that in 40 lines in Java
Try lisp. Hell, try Python or Ruby. You may be surprised.
That being said, if you are determined to write Java-esque code in other languages, I'm certain you won't reduce the number of lines greatly.
- nadam 16y agoI know that it is possible to write shorter code in the above mentioned languages than in Java, but my experience is that it is rarely more than a 2 times factor. Some Java haters make exaggerations. Java (the language) does not equal J2EE, EJBs and all the buroctratic frameworks which I also don' like. Java is a simple (a bit primitive) and a bit verbose strongly typed and _fast_ language. You can even do closures in Java with anonymous inner classes. It is verbose, but it is hard to imagine that it is more verbose than 2 times. Here is how I calculate greatest common denominator in Java: int gcd(int a, int b) { return a==b ? a : gcd(Math.abs(a-b), Math.min(a,b)); } Maybe the issue is I don't code in Java 'Java-esque' enough.:)
- lispm 16y ago(defun gcd (a b) (if (= a b) a (gcd (abs (- a b)) (min a b)))) Declaring types makes it longer. There is not much an advantage for that type of code. Unless you go to specific languages like J, where even the math code gets quite a bit shorter. But my personal goal is not to write the small stuff even smaller. My goal is to get rid of the larger structures and hide them. The big win comes when one uses higher-order functions and macros in any non-trivial piece of software. Imagine all the boilerplate code that one writes for class definitions can be hidden behind some macros. If one creates the code from domain data, you can get very dense code. Then all kinds of combinations of control structures can be hidden behind macros. In large software systems Java developers were/are doing the same using XML files to describe the code and generate code from there.
- nadam 16y agoI definitely don't want to code in Java all my life. I am in the middle of a project, and I don't want to change language until it is finished. Fortunatelly there are languages which compile to the JVM, and I can use existing Java libraries from them. The only thing I want to figure out is performance. I need a language which is almost as fast as Java. I am planning to learn Scala, Clojure or something like that. If the performance will also be ok, I will probably change.