This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Cattle Drive and the fly likes Limits Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Limits" Watch "Limits" New topic
Author

Limits

Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
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


The very existence of flamethrowers proves that at some time, some where, some place, someone once said to themselves "I'd really like to set those people on fire over there, but I just can't get close enough".
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
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.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Nathan Leniz
Ranch Hand

Joined: Nov 26, 2006
Posts: 132
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

Joined: Jul 22, 2000
Posts: 9044
    
  10
A previous conversaton which I think will shed some light on this question.
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20538
    ∞

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.


permaculture Wood Burning Stoves 2.0 - 4-DVD set
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Limits