5 ms·
"I am currently working in Java to re-implement an algorithm I prototyped in lisp." Maybe this is the problem. If I develop in Java, I think in Java. I don't
by nadam 16y ago
"I am currently working in Java to re-implement an algorithm I
prototyped in lisp."
Maybe this is the problem. If I develop in Java, I think in Java. I don't prototype in other languages. I don't use 'factory objects' and 'visitors' and all such things. The syntax of JAva is a bit verbose, but I just cannot imagine that if you write something in 20 lines in any language I cannot write that in 40 lines in Java. Maybe a concrete example would be nice.
Otherwise for me performnce is very important. One of the reasons that I use Java is that it is very fast (and I know how to write fast code in it.)
- dpritchett 16y agoPeople do this a good bit for algorithm programming contests. Use dynamic languages to prototype out all of the good ideas you can think of, then rewrite the most promising ones in C for maximum performance.
- coliveira 16y agoYou're probably not very creative about the language... Have you ever tried J? There are a lot of 1 line programs in J that require 100 lines of Java.
- nadam 16y agoThe most concise language I know is Joy. http://en.wikipedia.org/wiki/Joy_(programming_language) http://en.wikipedia.org/wiki/Joy_(programming_language) The 100 factor must be an exaggeration for most problems. In 100 lines I can put lots of information or quite complex algorithm even in Java. Some things are quite concise even in Java. See the greatest common denominator code: int gcd(int a, int b) { return a==b ? a : gcd(Math.abs(a-b), Math.min(a,b)); }
- sanderjd 16y agoYeah but gcd is very simple (and also your version of it stack overflows around 7 digits, depending on how quickly a gcd is found, so it isn't really "correct") - most simple tasks will have similarly sized simple representations in nearly any language. The argument levied against Java is that it's code size does not scale linearly in relation to other languages as the complexity of the problem increases.
- gcanyon 16y agoIt's not really fair since J has a built-in function, but in J the gcd function is +. 15 +. 10 5 The near-canonical example is the mean, which is not built in: mean =: +/%# mean 2 3 4 5 3.5 Other code is similarly terse. On http://projecteuler.net/ http://projecteuler.net/ it's not uncommon to see one-line J solutions to problems where other languages have solutions from 20 to 50 or more lines of code.
- 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.