Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31594

Re: What could be improved about the assert statement

From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: What could be improved about the assert statement
Date 2015-04-21 07:38 -0400
Organization A noiseless patient Spider
Message-ID <mh5cql$qri$1@dont-email.me> (permalink)
References <assert-20150421090715@ram.dialup.fu-berlin.de>

Show all headers | View raw


On 4/21/2015 3:13 AM, Stefan Ram wrote:
>    I just wrote these assert statements:
>
> assert row >= 0: "row > 0";
> assert row <  3: "row <= 3";
> assert col >= 0: "col > 0";
> assert col <  3: "col <= 3";
> assert state[ row * 3 + col ]== Square.Z: "state[ row * 3 + col ]== Square.Z";
> ...
> assert list.size() > 0: "list.size() > 0";
> ...
> assert worst.size() > 0: "worst.size() > 0"';
> ...
> assert evaluation.board != null : "evaluation.board != null";
> ...
>
>    Maybe, you now already can guess, what I don't like!
>
>    There could be some convention, like for example that
>
> assert row >= 0:;
>
>    means that the text between »assert« and »:« should
>    be trimmed and than be taken for the text of the
>    assert message.

     Although I use `assert' liberally, I can't recall ever using
the colon-and-message part.  IMO, an `assert' failure is a message
from developer to developer, not from application to user, and the
developer who receives it will be looking at the AssertionError --
which will point him straight at the `assert' statement itself,
right there in the source.  Any further (mis-)information seems
pointless.  (In particular, a message that simply repeats the same
source text he's staring at would be pointless.)


-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread


Thread

Re: What could be improved about the assert statement Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-04-21 07:38 -0400

csiph-web