This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Cattle Drive and the fly likes Howdie y'all Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Howdie y Watch "Howdie y New topic
Author

Howdie y'all

Patrick van Zandbeek
Ranch Hand

Joined: Aug 17, 2005
Posts: 37
Well, I saddled up for the cattle drive and sent in my first assignment last night. Hope I come out nit free at the other end eventually

One quick question about the style guide though. Is there a good reason for the style guide to demand braces like this:
class BlahBlah
{
// cool code
}

instead of what sun thinks it should be and uses on all certification like this:
class BlahBlah {
// cool code
}

I personally like the first better, but in order to learn the sun way of doing things I was training myself to use (and dare I say it, like) the sun way of using the braces.


u is a letter, not a word.
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
I think its a matter of choice. Personally, I don't know why anyone would want to use the sun style over ranch style. It's much easier to identify blocks of code when the enclosing braces are aligned vertically, and the different elements of the code are placed in such a way as to visually represent the structure.
Besides, it's aesthetically more appealing!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
I believe that the JavaRanch Style Guide was actually written before the Sun Style Guide. Also, at least at that time, most of the developers that Paul (the author of the style guide) asked preferred the non-K&R style. Also, Paul's personal feeling is that ".. the K&R style of brace placement. It's focus is on saving precious bytes in the source file and on screen real estate. This is from an age when you would be lucky if you had a teletype terminal and 100k of disk space."

It is a debatable subject, turning, at times, almost into a "holy war".

One of the things the Cattle Drive focuses on is the ability to follow whatever style the employer may want to enforce, even if it seems totally stupid to the developer. (Hopefully the braces issue doesn't fall into this category)


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[MdQ]: I believe that the JavaRanch Style Guide was actually written before the Sun Style Guide.

Unlikely. Note the copyright dates on each. It may have been before Paul read the Sun guide. As I recall Paul has observerved that at the time he wrote it, Sun's style guide was not being used consistently for most of Sun's code. (In fact one might argue it's still not in many cases - but there's now a lot more consistency thaan there used to be.) Of course, the JavaRanch style guide had a whole lot of internal inconsistencies when I first saw it, and the code examples in the guide itself did not actually follow what the guide instructed. So that whole line of argument seem neither here nore there. Fortunately both (Paul's guide and Sun's) are much better now.

Also, Paul's personal feeling is that ".. the K&R style of brace placement. It's focus is on saving precious bytes in the source file

This is a straw man argument. It might have been very weakly valid 20 years ago; it's not remotely valid now. No one* on either side of the debate cares about the number of bytes used in whitespace.

* where "no one" would more properly be: an insignificant number of people, who may be safely ignored.

and on screen real estate.

This is the main actual issue of interest nowadays. Along with its sister issue, space on the printed page - which was the real reason why K&R was adopted in the first place. (Nothing about number of bytes.) Many of us find considerable value in being able to see the logic of a method all in one place, with no scrolling. I'm not going to go on about this - I just wanted to separate the real issue from the silly straw man which Paul provided.


"I'm not back." - Bill Harding, Twister
Patrick van Zandbeek
Ranch Hand

Joined: Aug 17, 2005
Posts: 37
Well, like I said I prefer the cattle drive one better, it feels more natural to me and makes it easier to spot the coding blocks.

But I did learn myself to use the sun style so I would be used to it when I go to do the SCJP exam. Oh well, this way I get to get used to both, maybe I should put that on my resume? "Can use curly braces in multiple styles."
Kristin Stromberg
Ranch Hand

Joined: May 17, 2005
Posts: 91
Hi Patrick -

I agree with you and Carol - I prefer the Cattle Drive curly braces to the Sun ones (there are other parts of the Cattle Drive style guide that I don't like so much, but that's another thread some day). But just so you know, the SCJP code examples do not follow the Sun style guide at all - in fact, they're generally downright atrocious. I think the point on the exam is to format code in a way that is intentionally confusing. So the Sun style guide will definitely come in handy for the SCJD if and when you decide to go for that, but probably not for the SCJP. Since we don't use any particular style guide at work, I'm sort of picking and choosing the things I like best about both guides and trying to remain consistent. Anyway, long story short and all that...

Kristin
Patrick van Zandbeek
Ranch Hand

Joined: Aug 17, 2005
Posts: 37
Thanks Kristin,

I didn't know that. I do eventually plan on taking SCJD but that won't be any time soon, since SCJP will come first anyway, so I'll happily forget about the sun style guide for now then.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Kristin]: But just so you know, the SCJP code examples do not follow the Sun style guide at all - in fact, they're generally downright atrocious. I think the point on the exam is to format code in a way that is intentionally confusing.

In some cases yes, the SCJP format may be intentionally confusing. (And I would argue that any halfway decent Java programmer should be able to read either K&R or BSD style with no problem, regardless of which they prefer - both are common in the industry.) More commonly though, the code samples have been formatted specifically in order to fit into a very small allowed screen area. Which generally means removing newlines wherever possible. So you may see something like:

That's not because the exam authors prefer such a style; it's generally because they had to.

Having said that, I think you'll find that SCJP style (such as it is) is typically closer to Sun style than to Coop style.
[ September 03, 2005: Message edited by: Jim Yingst ]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Ahhh, why I love IDEA's CTRL-ALT-L.


GenRocket - Experts at Building Test Data
Kristin Stromberg
Ranch Hand

Joined: May 17, 2005
Posts: 91
Jim: In some cases yes, the SCJP format may be intentionally confusing...[snip]...More commonly though, the code samples have been formatted specifically in order to fit into a very small allowed screen area.


Good point... sometimes I forget that those evil test writers are not just out to get us!!!
[ September 02, 2005: Message edited by: Kristin Stromberg ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[Kristin]: sometimes I forget that those evil test writers are not just out to get us!!!

Oh, I didn't say that. But there are more interesting things to test people on than whether or not they can understand unusual brace structures.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Originally posted by Carol Murphy:
I think its a matter of choice. Personally, I don't know why anyone would want to use the sun style over ranch style. It's much easier to identify blocks of code when the enclosing braces are aligned vertically, and the different elements of the code are placed in such a way as to visually represent the structure.
Besides, it's aesthetically more appealing!


Sorry, I completely disagree. I'll leave it at that.

My main issue is that there should be one and only one standard in the Java World, so that everyone is using the same way. Well, since Sun created Java I would let them set the standard, which they have. So Everyone in the world should use it because Sun is the stake holder, creator, and the best to get it out to the entire Java World.

Our standard written at JavaRanch won't reach the entire Java World.

The purpose of standards is so that everyone can easily read other people's code and reduce the costs of maintenance. Everyone can get used to any style of "curly braces" that they want. Regardless of whether one's opinion is that one is more aesthetically appealing than the other, and someone has the complete opposite opinion.

I just want to cry. Can't we all just get along.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Carol Murphy
village idiot
Bartender

Joined: Mar 15, 2001
Posts: 1194
Of course we can all get along! Just admit that I'm right, and everything will be jake!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Howdie y'all
 
Similar Threads
Could some one explain whats happening here.
style guide
Style guide question
Coding Style Standards
Does everybody seriously follow the Style Guide?