From: Eric Sosman on
On 3/13/2010 6:36 PM, Lothar Kimmeringer wrote:
> Stefan Ram wrote:
>
>> Actually, it holds /less/ information. We do not know its text,
>> it could be defined as
>>
>> EMPTY_STRING := "EMPTY_STRING"
>>
>> or
>>
>> EMPTY_STRING := "empty"
>>
>> or so.
>
> That would be a new entry for the dailywtf. Best until now was
> enum Bool = {True, False, FileNotFound}

I'll offer one that a colleague once came across
(in a different programming language):

#define HASHSIZE 51 /* a smallish prime */

The day when compilers can detect this class of error
is the day when we'll all lose our jobs.

--
Eric Sosman
esosman(a)ieee-dot-org.invalid
From: Arne Vajhøj on
On 14-03-2010 09:53, Stefan Ram wrote:
> Eric Sosman<esosman(a)ieee-dot-org.invalid> writes:
>> #define HASHSIZE 51 /* a smallish prime */
>> The day when compilers can detect this class of error
>> is the day when we'll all lose our jobs.
>
> Already today one can write:
>
> #define HASHSIZE 51
> #define HASHSIZE_ASSERTATIONS \
> assert new java.math.BigInteger( HASHSIZE ).isProbablePrime( 999999 ); \
> assert HASHSIZE>= 1; \
> assert HASHSIZE<= 1000;

Do you run your Java code through the C preprocessor?

Arne
From: Arne Vajhøj on
On 14-03-2010 11:47, Roedy Green wrote:
> On Sat, 13 Mar 2010 08:37:09 -0800 (PST), "david.karr"
> <davidmichaelkarr(a)gmail.com> wrote, quoted or indirectly quoted
> someone who said :
>> String foo = "";
>>
>> should instead be:
>>
>> String foo = StringConstants.EMPTY_STRING;
>
> The first generates almost the same code and is terser.
>
> If it were your money, would you pay programmers to type the longer
> form?

In projects where developers are paid for programming, then the
time to type in code is usually insignificant.

Arne

From: Lew on
Eric Sosman writes:
>> #define HASHSIZE 51 /* a smallish prime */
>> The day when compilers can detect this class of error
>> is the day when we'll all lose our jobs.

Stefan Ram wrote:
> Already today one can write:
>
> #define HASHSIZE 51
> #define HASHSIZE_ASSERTATIONS \
> assert new java.math.BigInteger( HASHSIZE ).isProbablePrime( 999999 ); \
> assert HASHSIZE >= 1; \
> assert HASHSIZE <= 1000;
>
> . I'd call this the »replace-comments-by-asserts refactor«.

I would really, really hope that first assertion fails. (I'm ignoring the
blend of C and Java syntax. I pretend that "#define" is really a 'private
static final ...')

> However, the word »smallish« has a certain vagueness that

"Prime", however, does not.

> can be resolved by a human given a certain application/context.
> So my translation to »<= 1000« might not be appropriate.

Irrelevant, perhaps.

--
Lew