Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > assert-like debug { /* code */ } feature?

Reply
Thread Tools

assert-like debug { /* code */ } feature?

 
 
Andreas Leitgeb
Guest
Posts: n/a
 
      09-06-2008
Eric Sosman <(E-Mail Removed)> wrote:
> Andreas Leitgeb wrote:
>>>> If there were a feature like:
>>>> debug {
>>>> int check;
>>>> // some costly code to determine some supposed invariant
>>>> assert check==42;
>>>> }


> If `assert' statements are used, the class is *always*
> "compiled with assertions." They can be enabled or disabled
> at run-time, forty-two weeks after the compiler ran.


I apologize for having once again made a fool of myself, for
not sufficiently researching how assertions really work, before
making wild claims.

While my reasoning went far off the facts, I think that the
result is still valid.

It boils down to providing access to that hidden boolean field
$assertionsDisabled, either directly, or through a getter or
wrapped as a "debug"-block.

I also had a look at Class.desiredAssertionStatus() and it does a couple
of things including calling a native method(whose implementation
I didn't care to look up). Obviously it must be "expensive"
enough, so the compiler creates the above-mentioned field as
a cache.

 
Reply With Quote
 
 
 
 
Andreas Leitgeb
Guest
Posts: n/a
 
      09-06-2008
Stefan Ram <(E-Mail Removed)-berlin.de> wrote:
> Andreas Leitgeb <(E-Mail Removed)> writes:
>> debug {
>> int check;
>> // some costly code to determine some supposed invariant
>> assert check==42;
>> }

>
> public class Main
> { public static void main( final java.lang.String[] args )
> { assert new java.util.concurrent.Callable<java.lang.Boolean>()
> { public java.lang.Boolean call()
> { java.lang.System.out.println( "alpha" ); return true; }}.call(); }}


Heck, I didn't think it could get that much worse than Eric's
assert-misuse

Anyway, it still can only read final local vars from the context
that way.

 
Reply With Quote
 
 
 
 
Tom Anderson
Guest
Posts: n/a
 
      09-06-2008
On Fri, 5 Sep 2008, Kenny Riodan wrote:

> On Sep 5, 8:13 pm, Tegiri Nenashi <(E-Mail Removed)> wrote:
>
>> Writing it in currying style: ICMP.write("A").write("B"); is asking for
>> a trouble!

>
> The others are right. You are a troll. *Good bye*. Plonk!


I think he's a crank rather than a troll, but the appropriate response is
much the same.

tom

--
Ed editor textorum probatissimus est -- Cicero, De officiis IV.7
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      09-06-2008
On Fri, 5 Sep 2008, Kenny Riodan wrote:

> On Sep 5, 5:42 pm, Tegiri Nenashi <(E-Mail Removed)> wrote:
>
>> Now is assignment realy an expression? I don't mean that you answer
>> that by trivially checking your favorite language grammar. Expression
>> is a way to construct some values from existing ones by applying some
>> functions (with many functions being built-in operations). From this
>> perspective assignment is not an expression.

>
> It's useful as a form of currying. And it's purely up to a language
> designer or a library designer's choice. And it's purely subjective and
> depends on individual's taste.
>
> For example, even method calls can be curried.
>
> Suppose you have a File object, which has a "write(String)" method. Now,
> the library designer could have implemented it without currying:
>
> void write(String x) { for(char c: x) this.writeChar(c); }
> Then to write 3 strings, you would write:
> file.write("A");
> file.write("B");
> file.write("C");
>
> Or the library designer could have implemented it with currying (an
> example of this is the StringBuilder class in Java standard library)
>
> File write(String x) { for(char c: x) this.writeChar(c); return
> this; }
> Then to write 3 strings you can write:
> file.write("A").write("B").write("C);


Okay, firstly, this example has nothing at all to do with assignment being
an expression. But never mind.

Secondly, may i ask where you learned to call this 'currying'? I'm aware
of the term, but its established meaning in computer science is something
rather different. Admittedly, something that if you look at it from a
distance, in the right light, looks strangely related, but different
nonetheless. I've heard the style you're describing referred to as
'chaining', or 'invocation chaining' before, but never 'currying'.

Personally, i'm not a big fan of it. In fact, i really, really dislike it
- it means abusing a method's return value to return something that isn't
in any sense a result of the method's execution. This is purely an
aesthetic concern, and a matter of taste, though.

I will mention that Smalltalk has something called method cascading.
Smalltalk statements are normally terminated by a full stop, but if you
use a semicolon, then you can omit a receiver from the next statement, and
it will use the receiver of the previous one. Which is clear as mud, so
here's an example:

file write: 'A'.
file write: 'B'.
file write: 'C'.

Becomes:

file write: 'A';
write: 'B';
write: 'C'.

Or, all on one line:

file write: 'A'; write: 'B'; write: 'C'.

It's a terribly simple bit of syntactic sugar which gives you all the
benefits of chaining without having to (a) design your classes to support
it or (b) pervert your design, depending on how you look at it. It's
particularly useful in Smalltalk, where the style is to write lots of
little methods, rather than a few big ones.

It's another thing that would (arguably) be nice to have in java, although
i don't know what punctuation we've got left for it! Comma, perhaps?

file.write("A"), write("B"), write("C") ;

Or perhaps indicate it by just omitting the receiver:

file.write("A"); .write("B"); .write("C") ;

tom

--
Ed editor textorum probatissimus est -- Cicero, De officiis IV.7
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      09-06-2008
On Fri, 5 Sep 2008, Peter Duniho wrote:

> On Fri, 05 Sep 2008 12:59:41 -0700, Tegiri Nenashi <(E-Mail Removed)>
> wrote:
>
>> Sure you are aware of the fact that both cases are legal in C.

>
> Your reply comes across as being hostile. I have no idea why you seem
> upset about this topic.


Cranks are allergic to facts.

tom

--
Ed editor textorum probatissimus est -- Cicero, De officiis IV.7
 
Reply With Quote
 
John B. Matthews
Guest
Posts: n/a
 
      09-06-2008
In article <(E-Mail Removed)> ,
Tom Anderson <(E-Mail Removed)> wrote:

> On Fri, 5 Sep 2008, Peter Duniho wrote:
>
> > On Fri, 05 Sep 2008 12:59:41 -0700, Tegiri Nenashi
> > <(E-Mail Removed)>
> > wrote:
> >
> >> Sure you are aware of the fact that both cases are legal in C.

> >
> > Your reply comes across as being hostile. I have no idea why you
> > seem upset about this topic.

>
> Cranks are allergic to facts.


> Ed editor textorum probatissimus est -- Cicero, De officiis IV.7


[OT] I'm pretty sure he switched to vi in A.U.C. 711... Hey, wait a
minute, three's only _three_ books in De officiis!

--
John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
netvmini.sys still not working on Windows 7 even after driver signing disabled ?! (Windows debug mode necessary for debug drivers ???) Skybuck Flying Windows 64bit 3 08-09-2009 05:54 AM
debug="false" in web.config and <%@ debug="true" ...%> in aspx file => true or false? André ASP .Net 3 08-28-2006 12:02 PM
Config Mgr Debug/Release and Web.config Compilation debug=true RonL ASP .Net 0 04-08-2006 03:50 PM
Debug (DLL MFC) -> Debug (Static MFC) ringos75 C++ 0 04-14-2005 01:50 PM
[Howto] Compiling debug Python extensions for non-debug Python Mike C. Fletcher Python 3 10-12-2003 09:37 PM



Advertisments