Jump to content

  • Log In with Google      Sign In   
  • Create Account

How powerful is Java?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
48 replies to this topic

#41 PurpleAmethyst   Members   -  Reputation: 324

Like
0Likes
Like

Posted 08 November 2012 - 09:49 AM

Any anything clojure does Groovy does better ;)....

http://groovy.codehaus.org/

Sponsor:

#42 tufflax   Members   -  Reputation: 499

Like
0Likes
Like

Posted 08 November 2012 - 10:10 AM

Any anything clojure does Groovy does better ;)....

http://groovy.codehaus.org/


And you have tried Clojure?

#43 PurpleAmethyst   Members   -  Reputation: 324

Like
0Likes
Like

Posted 08 November 2012 - 11:56 AM

I've never used Clojure on a commercial project. I have, however, used Groovy. I liked the fact I could inline JAVA and Groovy together. It helped get the job done very quickly.

Also, as you can see below, Groovy is less typing (Trivial example I know).

Groovy (70 Characters):

[source lang="groovy"]for (i in 1..100) { println "${i%3?'':'Fizz'}${i%5?'':'Buzz'}" ?: i }[/source]

Clojure (116 Characters):

(map #(cond (zero? (mod % 15)) "FizzBuzz" (zero? (mod % 3)) "Fizz" (zero? (mod % 5)) "Buzz" :else %) (range 1 101))


#44 tufflax   Members   -  Reputation: 499

Like
0Likes
Like

Posted 08 November 2012 - 01:18 PM

[source lang="plain"](map #(condp (fn [d n] (= 0 (mod n d))) % 15 "FizzBuzz" 3 "Fizz" 5 "Buzz" %) (range 1 101))[/source]
91 characters. Posted Image

I haven't used Groovy, but I can't imagine that it could be better than Clojure. Posted Image Anyway, I wouldn't inline Java in Clojure even if I could. Clojure's Java interop is very good. For example:
[source lang="java"]JButton okButton = new JButton("Ok");okButton.setBounds(30, 35, 80, 25);okButton.addActionListener(this);panel.add(okButton);[/source]
becomes
[source lang="java"](.add panel (doto (JButton. "Ok") (.setBounds 30 35 80 25) (.addActionListener this)))[/source]

And even though Clojure is code not the shortest when it comes to small examples, the homoiconicity and simplicity of the syntax is very useful, and macros can get rid of a lot of code in longer programs.

Edited by tufflax, 08 November 2012 - 03:46 PM.


#45 Yrjö P.   Crossbones+   -  Reputation: 1412

Like
0Likes
Like

Posted 08 November 2012 - 01:46 PM

Also, as you can see below, Groovy is less typing (Trivial example I know).
Groovy (70 Characters):
[source lang="groovy"]for (i in 1..100) { println "${i%3?'':'Fizz'}${i%5?'':'Buzz'}" ?: i }[/source]
Clojure (116 Characters):

(map #(cond (zero? (mod % 15)) "FizzBuzz" (zero? (mod % 3)) "Fizz" (zero? (mod % 5)) "Buzz" :else %) (range 1 101))

Comparing apples to oranges. The Groovy one-liner is so clever it's no longer readable (nested ternary operators? please) and I'd complain about it in a code review, whereas both your and tufflax' Clojure implementations are clean code minus whitespace.

#46 PurpleAmethyst   Members   -  Reputation: 324

Like
0Likes
Like

Posted 08 November 2012 - 05:52 PM

Yeah, I realize it was a bit trivial. Neither example is mine. I guess I'm not a big fan of LISP (yet) which doesn't help. I'm studying Haskell at the moment with some friends in the local hackerspace so my mind may change.

One thing I do like about Groovy is the ability to encode statements in the quotes using ${}. The in the above example isn't really a great demonstration of where it would be useful and I wouldn't be using nested ternary operators myself either, I'd complain about it too in a code review.

#47 jbadams   Senior Staff   -  Reputation: 19429

Like
0Likes
Like

Posted 08 November 2012 - 06:24 PM

Debugging is atrocious and the tools for it are from the archaic at best and intentionally tortuous at worst. (compared to something like VS2010/2012).

Try IntelliJ -- I haven't used it for quite some time, but last time I tried it was very good, and the other products from the same company are excellent. Posted Image

#48 Bacterius   Crossbones+   -  Reputation: 9305

Like
0Likes
Like

Posted 08 November 2012 - 06:40 PM

I'm not sure why people are fighting over which language can produce the shortest one-liner to the fizzbuzz challenge, or any other problem for that matter. As far as I'm concerned it's the logic, concepts and train of thought behind the code that matter, rather than how many bytes I can encode my solution into. Sure, it's fun and all to compare, but unless said one-liners are readable, I don't want them in any code I look at (the Clojure code is quite nice, actually, but the Groovy one is at the edge).

It's like that guy who implemented a basic ray tracer in 99 lines of ultra-compressed - and, quite frankly, unreadable without adding line breaks - C code. I just don't see the point. Every time I stumble across it, I die a little inside. I too can compress my code with 7z and end up with sub-1KB source code, big deal. Is it useful? No. Is it helpful to others? No. Does it warrant bragging rights? To people who want to understand the code, certainly not.

Edited by Bacterius, 08 November 2012 - 06:40 PM.

The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.

 

- Pessimal Algorithms and Simplexity Analysis


#49 Alpha_ProgDes   Crossbones+   -  Reputation: 4692

Like
0Likes
Like

Posted 08 November 2012 - 06:42 PM


Also, as you can see below, Groovy is less typing (Trivial example I know).
Groovy (70 Characters):
[source lang="groovy"]for (i in 1..100) { println "${i%3?'':'Fizz'}${i%5?'':'Buzz'}" ?: i }[/source]
Clojure (116 Characters):

(map #(cond (zero? (mod % 15)) "FizzBuzz" (zero? (mod % 3)) "Fizz" (zero? (mod % 5)) "Buzz" :else %) (range 1 101))

Comparing apples to oranges. The Groovy one-liner is so clever it's no longer readable (nested ternary operators? please) and I'd complain about it in a code review, whereas both your and tufflax' Clojure implementations are clean code minus whitespace.

I'm sorry but that Groovy isn't that clever (ie. terse) and it's very readable. And actually it's easier to read the Groovy than the Clojure. As far as Scheme-like languages go, I've used Racket, as a learning tool. And I think it's great.

But to get back on topic, Java as a language or a platform can address all the needs a developer or business may have.
Beginner in Game Development? Read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS