Hi Jochen,
I agree with all you say including that Tennent's principle isn't
necessarily the best way to design a language. An alternative that I
find better is to be pure OO and say everything is an instance of a
class. This isn't Java at present, i.e. Java has blocks and
primitives. For new features though it would be nice if everything was
an object. This would make refactoring easier, e.g. lifting a block to
a method, e.g. your block example:
while ( true ) {
out.println( "1" );
if ( b ) break;
out.println( "2" );
}
Would, if blocks were methods, become:
while ( true ) {
out.println( "1" );
if ( b ) return BREAK;
out.println( "2" );
}
IE the stuff between {} is a method, so return BREAK behaves like
break and the advantage is that you can refactor to:
while ( true ) { method( b ); }
Status method( boolean b ) {
out.println( "1" );
if ( b ) return BREAK;
out.println( "2" );
}
Then onto:
while ( true ) { example.method( b ); }
class Example {
Status method( boolean b ) {
out.println( "1" );
if ( b ) return BREAK;
out.println( "2" );
}
}
Anyway this is rather off topic, but I am with you that Tennent's
principle may not be the best choice.
Cheers,
Howard.
On Oct 30, 10:09 am, Jochen Theodorou <[EMAIL PROTECTED]> wrote:
> hlovatt schrieb:
>
> > Tennent's book is quite old and talks about Pascal, I don't recall any
> > specific discussion of exceptions and exceptions were not part of
> > standard Pascal. So my guess is that any form of non-local jumps would
> > not be covered by Tennent directly. The princiople says that the
> > meaning of the code should not change if enclosed in a block, e.g.
> > while loop, but it means any type of block and therefore also a try
> > catch block.
>
> I found out it is from around 1977, another reason why it is so hard to
> find... citeseer doesn't have papers that old ;) But I also think that
> an exception would be counted as exit point. On the other hand
> simulating an exception by control variables is not very nice.
>
>
>
> > So my reading is that any form of non-block structured jump is
> > excluded by the principle, i.e. no return, break, continue, or throw
> > statements. All these have to be simulated with a status variable.
> > Interestingly if an inner class was used instead of a block then a
> > control variable could be used and exceptions avoided all together:
>
> > enum Status { CONTINUE, BREAK; }
>
> > class Loop implements Method1< Void, Object > {
> > Status status = CONTINUE;
> > void breakLoop() { status = BREAK; }
> > }
>
> > class List {
> > private Object[] data;
> > ...
> > void each( Loop l ) {
> > for ( int i = 0; i < data.length && l.status == CONTINUE; i++ )
> > { l.call( data[ i ] ); }
> > }
> > }
>
> > // My favourite syntax follows!
> > list.each method( e ) { if ( someCondition ) { breakLoop() } };
>
> but you are not showing that the call to breakLoop() has to be at a
> position where no further commands follow. so if you have
>
> while (true) {
> println "1"
> if (b) break;
> println "2"
>
> }
>
> you would have to split it in a b==true and b!=true part:
>
> while (doLoop) {
> if (b) {
> println "1"
> doLoop=false
> } else {
> println "1"
> println "2"
> }
>
> }
>
> which might have less exit points, but is also less readable in my eyes.
> All in all it seems I will be no fan of Tennent's idea. In my last post
> I used something compareable to your breakLoop() command, but I had in
> mind that it throws an exception, that is cached before the block is
> left and then a iterator method from outside could handle that.... in
> your case, instead of doing a simple l.call you would have to put a
> try-catch around to be able to skip parts of the contents of your Loop
> subclass.
>
> bye blackdrag
>
> --
> Jochen "blackdrag" Theodorou
> Groovy Tech Lead
> (http://groovy.codehaus.org)http://blackdragsview.blogspot.com/http://www.g2one.com/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JVM
Languages" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/jvm-languages?hl=en
-~----------~----~----~----~------~----~------~--~---