tag:blogger.com,1999:blog-20633170.post946480750924199474..comments2023-11-03T10:08:09.830+00:00Comments on Graeme Rocher's Blog: Groovy is Java AND Groovy is not JavaGraeme Rocherhttp://www.blogger.com/profile/12301973191113958910noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-20633170.post-50865796849084939782008-11-04T14:11:00.000+00:002008-11-04T14:11:00.000+00:00Hi Graeme,i’ve seen your blog and i think that you...Hi Graeme,<BR/><BR/>i’ve seen your blog and i think that you can give me a response about a script in Groovy.<BR/>I have think to a new programming style using Groovy and Closures.<BR/>The script is:<BR/><BR/>Code<BR/>———–<BR/><BR/>/*<BR/>Give a structure with N array containing data, the code analyze each array contained and<BR/>if elements number major 5 do this:<BR/><BR/>sumElementList, storeSumInCache, printSum<BR/><BR/>else if minor:<BR/><BR/>sumElementList,printSum<BR/><BR/>look at SKELETHON section is the main part of code and can make reading a program more readable.<BR/><BR/>———–<BR/>*/<BR/><BR/>// ### DECLARATION ELEMENTS ###<BR/>def cache = new ArrayList()<BR/>def structure = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4]]<BR/>def elementList = structure[0]<BR/>def sum = 0;<BR/><BR/>// ### DECLARATION GENERIC CLOSURES ###<BR/>def execute = {<BR/>Object[] closures -><BR/>def currentClosure = null;<BR/>closures.each() {<BR/>currentClosure = it.call(currentClosure)<BR/>}<BR/>return currentClosure<BR/>}<BR/><BR/>def forDo = {<BR/>indexFor, Object[] closures -><BR/>indexFor.times {<BR/>execute(closures)<BR/>}<BR/>}<BR/><BR/>// #### ACTIVITY : SOMMA ELEMENTI ####<BR/><BR/>def ifElementNumberMajor5 = {<BR/>Object[] closures -><BR/>if (elementList.size() > 5) {<BR/>println ‘rilevato NumeroElementiListaSupera5'<BR/>execute(closures)<BR/>}<BR/>}<BR/><BR/>def ifElementNumberMinor5 = {<BR/>Object[] closures -><BR/>if (elementList.size() <= 5) {<BR/>println ‘rilevato NumeroElementiListaNonSupera5'<BR/>execute(closures)<BR/>}<BR/>}<BR/><BR/>def sumElementList = {<BR/>println ‘ Closure [ sommaTuttiGliElementiDellaLista ]‘<BR/>elementList.each { sum += it }<BR/>sum<BR/>}<BR/><BR/>def storeSumInCache = {<BR/>println ‘ Closure [ memorizzaSommaInCache ]‘<BR/>if (!cache.contains(it)) cache.add(it);<BR/>it<BR/>}<BR/><BR/>def printSum = {<BR/>println ‘ Closure [ stampaSomma ]‘<BR/>println “stampo risultato somma $it”<BR/>}<BR/><BR/>def updateVariablesActivitySomma = {<BR/>println ‘ Closure [ aggiornaVariabiliActivitySomma ]‘<BR/>elementList = structure[index++]<BR/>}<BR/><BR/>// #### SKELETHON ####<BR/><BR/>index = 0<BR/>forDo(structure.size()) {<BR/>updateVariablesActivitySomma<BR/>ifElementNumberMajor5(sumElementList, storeSumInCache, printSum)<BR/>ifElementNumberMinor5(sumElementList, printSum)<BR/>}<BR/><BR/>———–<BR/>what do you think about this ?<BR/><BR/>Thank’s for response.<BR/><BR/>By<BR/><BR/>Giuseppe Astarita<BR/>Software developer<BR/>Telecom Software factory Division.Unknownhttps://www.blogger.com/profile/02113234552073858962noreply@blogger.comtag:blogger.com,1999:blog-20633170.post-43044700259981949642008-03-12T20:41:00.000+00:002008-03-12T20:41:00.000+00:00I guess it all boils down to where you're moving t...I guess it all boils down to where you're moving the ball of hair. convinience to the programmer doesn't always translate to convenience to the end user...<BR/><BR/>Sometimes what you gain in productivity up front is taxed (plus interest) in maintenance cost.<BR/><BR/>Personally, I think Ruby/Rails trying to move Java people to their camp is a mute point. Few Java developers would throw away their investment in learning and tools. If I want to do scripting, Groovy is more than good enough. <BR/><BR/>To me, the real value with Groovy is in Grails though. Through plugins I can integrate just about any Java solution, pretty effortless :)<BR/><BR/>/java-dudeAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-20633170.post-20001678180483691962008-03-12T09:37:00.000+00:002008-03-12T09:37:00.000+00:00@AnonymousIt's good to detect errors statically. ...@Anonymous<BR/><BR/>It's good to detect errors statically. This is valid Groovy code that throws an exception: int i="hello" - I'm not sure why that should be a runtime error when you can establish that the error will happen just by looking at the source code.Ricky Clarksonhttps://www.blogger.com/profile/13845104548520132930noreply@blogger.comtag:blogger.com,1999:blog-20633170.post-59165952445073934592008-03-12T05:28:00.000+00:002008-03-12T05:28:00.000+00:00@RickyWhich is truly the best of both worlds. :)@Ricky<BR/><BR/>Which is truly the best of both worlds. :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-20633170.post-55264591446602500232008-03-12T01:34:00.000+00:002008-03-12T01:34:00.000+00:00"In other words, you get the best of both worlds."..."In other words, you get the best of both worlds."<BR/><BR/>Minus static typing.Ricky Clarksonhttps://www.blogger.com/profile/13845104548520132930noreply@blogger.comtag:blogger.com,1999:blog-20633170.post-27599892654587807132008-03-11T22:00:00.000+00:002008-03-11T22:00:00.000+00:00The original post makes an important point when sa...The original post makes an important point when saying 'I think Grails is on its way, if it doesn't get usurped by the Java platform desire to make everything unbearably complicated.'<BR/><BR/>Certainly one of the aspects that make Grails superior to Rails is that integrates very well with existing enterprise software and enterprise requirements in general while remaining simple to use at the same time.<BR/>In contrast to that Rails guys more often than not simply state that 'If you don't do it our way, then, sorry, Rails is not for your.'<BR/><BR/>However, the Grails community has to beware of 'enterprisey' features slowly creeping into the framework as the standard way of doing things.<BR/><BR/>While there is nothing wrong with supporting these as well, Grails' main objective IMO should always be to keep things simple and productive.Willyhttps://www.blogger.com/profile/09662549267021807333noreply@blogger.comtag:blogger.com,1999:blog-20633170.post-77202496537421563602008-03-11T18:21:00.000+00:002008-03-11T18:21:00.000+00:00The way I explain the relationship between Groovy ...The way I explain the relationship between Groovy and Java is as follows:<BR/><BR/>I speak and understand English I also speak and understand (computer) Jargon.<BR/><BR/>Speaking and understanding English gives me easy access to an incredible resource. <BR/><BR/>Speaking and understanding Jargon allows me to communicate with speed and precision with other Jargon speakers. I get more done in less time and have fewer misunderstandings. I can have exactly the same interaction with English speakers but I have to use very many more words, and make more mistakes.<BR/><BR/>Jargon is, of course, English but it's English in a context.<BR/><BR/>Java is English, Groovy is English + Jargontughttps://www.blogger.com/profile/06981358099361272923noreply@blogger.comtag:blogger.com,1999:blog-20633170.post-50767132518521500772008-03-11T16:58:00.000+00:002008-03-11T16:58:00.000+00:00re: scott's quote.Delightful. Very much like a Zen...re: scott's quote.<BR/><BR/>Delightful. Very much like a Zen koan.<BR/><BR/>I can envision an entire talk based on some Zen paradoxes that illustrate the Groovy Way.Michael Easterhttps://www.blogger.com/profile/14799771593145201161noreply@blogger.comtag:blogger.com,1999:blog-20633170.post-17932713040021689962008-03-11T16:38:00.000+00:002008-03-11T16:38:00.000+00:00@GraemeI agree having to extend the ActiveRecord B...@Graeme<BR/><BR/>I agree having to extend the ActiveRecord Base class is unnecessary. DataMapper, another Ruby ORM, doesn't require you to extend a base class, you can just mixin a module, but in practice you end up extending from a base class anyway, because it doesn't cause any problems. DataMapper also has you define the properties in the model, rather than the database, which is another thing a lot of Java/Hibernate programmers tend to hate about ActiveRecord. I bring that up because a lot of times in these Java/Groovy vs. Ruby debates, things about specific frameworks like ActiveRecord get brought up, which have nothing to do with the language itself.<BR/><BR/>I don't think having ORM-neutral classes and being able to swap out ORM frameworks with no changes really buys you anything. But you may want to have your own class hierarchy, so not extending a base class could be nice in some situations, but most of the time it just doesn't matter. <BR/><BR/>In Java, not having to inherit from certain classes is a big deal, but in Ruby, it just doesn't matter as much. I suppose it's combination of mixins, duck-typing and meta-programming that make that the case.Paul Barryhttps://www.blogger.com/profile/07064248848168296715noreply@blogger.comtag:blogger.com,1999:blog-20633170.post-69121464587002786902008-03-11T16:13:00.000+00:002008-03-11T16:13:00.000+00:00Yes that is a nice feature of Ruby. I wouldn't say...Yes that is a nice feature of Ruby. I wouldn't say its better, just different<BR/><BR/>Also note that to get the ActiveRecord magic happening you have to extend the ActiveRecord class, essentially binding you to the framework.<BR/><BR/>GORM requires no inheritance, in fact it doesn't care if its a Java or a Groovy class as long as it exists in Hibernate it adds the magic. That seems cleaner and more powerful to me. Am I wrong? ;-)Graeme Rocherhttps://www.blogger.com/profile/12301973191113958910noreply@blogger.comtag:blogger.com,1999:blog-20633170.post-23803580516940175642008-03-11T16:01:00.000+00:002008-03-11T16:01:00.000+00:00But Groovy is not Ruby. One feature of Ruby is to...But Groovy is not Ruby. One feature of Ruby is to be able to call methods during the process of class definition, which can add methods to the class being defined. This is used in ActiveRecord for things like defining the belongs_to relationships. In GORM, you have to declare a static property (which acts as the equivalent of an annotation), which something else comes along and reads and uses to add methods to the class. The Ruby way seems cleaner and more powerful to me. Am I wrong?Paul Barryhttps://www.blogger.com/profile/07064248848168296715noreply@blogger.com