Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Limits

 
Nathan Leniz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted in the beginner forums regarding limiting the number of methods we use in a single statement. Should we go with the "Law of Demeter" or should we go with the "one line, one thing" approach?

If it is in the style guide, please forgive me for not seeing it. If not, could it be introduced so we have clear guidance on how much is too far?

Also, what do you (the nitpickers) want us to limit our ternary statements to? I asked about this as well. It looks like some people love em, some only like em, some are reluctant, and some don't know what is going on. Should we limit it to 2 or 3, or just a single statement?

Again, I hope this isn't taken as duplicating a topic. I'd just like to know what the nitpickers want before I send in something they don't like that I could have avoided by knowing what is acceptable.

Nate
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Links are helpful when referring to a different thread. In this case, I believe one of the threads you are referring to is this thread, but I couldn't seem to find the other one.

I would have to agree with Scott that "it depends". In general, I think that one line per method is better, but this is not always the case.

We've had a few conversations about the ternary operator here in the Cattle Drive forum. You can click on the "Search" link in the top right corner of this page to find those conversations (search on "ternary"). The number of ternary operators is not "limited", but, depending on the code, may or may not be the most readable way to write the application. That's the advantage of having real people review your code rather than trying to follow a rule book that's 600 pages long because it's trying to cover every possible way the code might be written. There is not only one "correct" solution for each assignment.
 
Nathan Leniz
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, sorry for not posting links. And regarding the ternary, I think a simple

is pretty straightforward, but we had started talking about stuff like

And I've also seen people do stuff like put the logical and/or operators in their ternary statements. Aha, found the link. Ternary Question
[ January 02, 2007: Message edited by: Nathan Leniz ]
 
Marilyn de Queiroz
Sheriff
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A previous conversaton which I think will shed some light on this question.
 
paul wheaton
Trailboss
Pie
Posts: 21660
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to endorse "it depends".

Readability is, by far, the most important thing. The real test for readability is to ask somebody to read it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic