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


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

Re: Unmathematical interface (contract) in Java?

From Daniel Pitts <usenet@coloraura.com>
Newsgroups comp.lang.java.programmer
Subject Re: Unmathematical interface (contract) in Java?
Date 2016-10-19 08:19 -0700
Organization A noiseless patient Spider
Message-ID <nu82su$90g$1@dont-email.me> (permalink)
References <Java-20161003185250@ram.dialup.fu-berlin.de>

Show all headers | View raw


On 10/3/16 11:01 AM, Stefan Ram wrote:
>   Dr. E. F. Codd wrote about mathematics:
>
>       "A special concern is that of avoiding the need
>       for special treatment of special cases except when
>       absolutely necessary.".
>
>   In Java, to print »s« indented by »n« spaces
>   (assuming we are at the start of a new line),
>   one can write:
>
> java.lang.System.out.printf
> ( "%" +( n > 0 ? n : "" )+ "s%s%n", "", s );
>
>   . Yes, you can write "%2s" or "%1s", but "%0s"
>   is not allowed! Now, how unmathematical is this!
>
I mean, its weird to construct a printf format string, so I'm not 
surprised that its troubling to do so...

I imagine you can do something of similar effect without special cases, 
if you give up on the idea of a one-liner...


    final char[] indent = new char[n];
    java.util.Arrays.fill(indent, ' ');
    java.lang.System.out.println(java.lang.String.valueOf(indent) + s);

I would say its even more clear what the intent of this snippet of code 
is, compared to yours.  It is possible its more efficient too, though I 
wouldn't put much weight on that.

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


Thread

Re: Unmathematical interface (contract) in Java? Daniel Pitts <usenet@coloraura.com> - 2016-10-19 08:19 -0700
  Re: Unmathematical interface (contract) in Java? Arne Vajhøj <arne@vajhoej.dk> - 2016-10-19 21:49 -0400

csiph-web