• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Are functional programming languages like Groovy capable of expressing object relationships?

 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Kenneth,

Are functional programming languages like groovy capable of expressing object relationships as elegantly as Java is capable of expressing? I've looked at simple demo programs in functional programming languages and from the initial look it looks like functional programming languages make it easy to code a program, but would these programs be as extensible as they'd be if they were written in Java?

Are the type checking, syntax checking and such things as strict in groovy as they are in Java? Are programming languages like Groovy a complete solution?

Thanks,
Chan.
 
gunslinger & author
Posts: 169
16
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chan,

Chan Ag wrote:

Are functional programming languages like groovy capable of expressing object relationships as elegantly as Java is capable of expressing? I've looked at simple demo programs in functional programming languages and from the initial look it looks like functional programming languages make it easy to code a program, but would these programs be as extensible as they'd be if they were written in Java?


First, I wouldn't call Groovy a functional language. It's an object-oriented language with functional capabilities. You still write classes with attributes and methods, but you can process them functionally. For example, if I have a class called Person, I can write this:

Or this:

Or even this:

But I still wouldn't call Groovy functional. But as you can see it has functional capabilities mixed in with the object-oriented stuff.

Chan Ag wrote:
Are the type checking, syntax checking and such things as strict in groovy as they are in Java? Are programming languages like Groovy a complete solution?


Type checking in Groovy is optional. You can use def everywhere (though most people don't), or nowhere (though most people find it useful in places). There's also an AST transformation called @TypeChecked that will allow Groovy to do compile-time type checking of variables and method arguments like Java. In that sense it's a strict as Java, but only if you want it to be.

Is it a complete solution? It can be, but I prefer to use Groovy and Java together and let each do what it does best. I use Java for tools, libraries, and basic infrastructure (like Spring), and I use Groovy for everything else.

One more trivial example. Once a client asked me to print out the numbers from 0 to 15 in binary, but with the leading zeroes included (actually he said no such thing, but that's what he meant). The solution was:

which returns:

0000
0001
0010
...
1111

Note how the solution moves from Groovy (the range and closure) to Java (Integer.toBinaryString) back to Groovy (padLeft, added to String as part of the Groovy JDK), without worrying about which language you happen to be using at any given moment.

I like Groovy and it makes coding fun for me. I will not, however, criticize functional languages like Clojure or hybrid languages like Scala. Use whatever helps you get your job done, and learning any of them helps make you a better coder.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Kenneth.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic