• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java College  RSS feed

 
paul wheaton
Trailboss
Posts: 22580
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've made some more progress on the Java College and would appreciate input.
Go to www.eporkchop.com/college to get a taste. All of the links are now there. I think I've included all of the suggestions people have made so far.
 
Michael Finney
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.eporkchop.com/college/about.html
" the style sheet." link is linked to "http://www.eporkchop.com/college/www.eporkchop.com/style.html" which of course does not exist.
 
Michael Finney
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I disagree with the following statement in the style sheet (coding standards).
"While it is possible to declare a variable within the for loop construct, it makes the scope unclear"
IMHO,
It is clear where the scope of the variable is for those who know Java well. I believe learning the scope of the variable, in the initialization section of a 'for loop', is part of learning Java.
Of course the coding standards are up to you. However, I suggest you do not use that line as your reason. Unless I am mistaken, scope is well defined in the "for loop construct".

[This message has been edited by Michael Finney (edited May 02, 1999).]
 
paul wheaton
Trailboss
Posts: 22580
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If everyone knew C++ well, we would not have to track down all those nasty pointer bugs. But there is always someone on the team that is a little shaky on pointers --- so Java doesn't have pointers.
The scope of the initialization of a for loop is different between C++ and Java. Many developers will probably flip-flop between the two languages for a while. I think it is best err on the side of safety and clarity.
 
Michael Finney
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
5.1.1 - Avoid do..while
You have:
<PRE>
boolean done = false ;
do
{
...
} while( ! done )

use:

boolean done = false ;
while ( ! done )
{
...
}
</PRE>
Well, that is not equivalent code.
it would be something like
<PRE>
...
boolean done = false ;
while ( ! done )
{
...
}
</PRE>
As you know, the do ensures that the body is done once. Translating from the do to the while, requires the body of the while to be repeated before the condition check.
 
Michael Finney
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IMHO,
your style sheet with regards to "5.1 Constructs to Avoid", inhibits learning with regards to those constructs. You said yourself that writing Java code, helps you understand Java.
While looking at the reasons you inhibit those things, I thought of another. Throwing exceptions from inside a construct. Based on your other rules, you may wish to limit that too.
 
paul wheaton
Trailboss
Posts: 22580
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do..while: the example I gave is correct, although I suppose I might have used a different condition to demonstrate a decent use of do..while.
exceptions inside a construct: good point. It would kinda like having a return in the middle a method. On the flip side, I think "try" statements surrounding all of the innards of a method isn't always a good idea either. I'll have to ponder this a bit. Good suggestion!
 
Michael Finney
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In regards to the do .. while thing:
As long as the programmer understands that:
<PRE>
do
{
someFunc();
} while (0 == 1);
</PRE>
is equivalent to
<PRE>
someFunc();
while (0 == 1) // always false.
{
someFunc();
}
</PRE>
Since the "do while" guarentees that its body will be executed once and the "while" loop does not, the call to someFunc before the "while" loop is required. That was my concern. (Ignore the always false thing. It has nothing to do with the point.)
[This message has been edited by Michael Finney (edited May 09, 1999).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!