• Post Reply Bookmark Topic Watch Topic
  • New Topic

Making the Java language terse like Ruby  RSS feed

 
sid smith
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a Ruby class:



Its a small improvement, but nice and short. There is no need to write member variables separately outside the constructor. Is it possible to change Java to be like this in the future with all its goodness ?
I know that lambdas have been introduced in java 8. Not sure how well received it is and if its causing any inconvenience.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Project Lombok should be of interest to you; it goes into that direction.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sid smith wrote:Here is a Ruby class:
Its a small improvement, but nice and short. There is no need to write member variables separately outside the constructor.

Which, in your example, saves you precisely one line. Not wild about all those '@'s either - reminds me of scripting languages.

But, at the end of the day, we probably like what we're used to, so I'm not knocking Ruby. I've heard it's very powerful.

If you really like terse, have a look at C. I remember genuflecting at the guy who wrote the getchar() macro, because it was so beautifully terse - one line to do something that's really quite involved.
But then it occurred to me that I'd just spent 45 minutes working out how that one line of code worked.

Beauty, as they say, is in the eye of the beholder. We actually spend a fair bit of time on these forums telling beginners NOT to make their code so terse.

However, I may take Ulf's advice myself and have a look at Lombok.

Is it possible to change Java to be like this in the future with all its goodness ?

I doubt it; but there may be certain moves in that direction. You might be interested to read the "goodies" page for version 8, because it contains lots of interesting new stuff like streams.

However, I doubt it will ever look like Ruby. After all - if you want that, why not just use Ruby?

I know that lambdas have been introduced in java 8. Not sure how well received it is and if its causing any inconvenience.

TBH, I haven't really had much chance to use them because it just doesn't crop up that much. But if it helps me to avoid using reflection, you can bet I will.

My 2 ¢.

Winston
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might want to have a look at the Groovy language.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Too much terseness has an adverse affect on readability and maintainability. I'd argue that terseness is not always a good thing and can be taken too far.
 
sid smith
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:You might want to have a look at the Groovy language.


Can Groovy be a replacement for Java ? If yes, then I'd learn it right away.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!