Re: How to create string of repeated characters?
From: Alex Hunsley (lard_at_tardis.ed.ac.molar.uk)
Date: 06/11/04
- Next message: Roedy Green: "Re: Blow me away, (long) does not truncate."
- Previous message: Nigel Wade: "Re: Servlet to execute task at predetermined time"
- In reply to: Boudewijn Dijkstra: "Re: How to create string of repeated characters?"
- Next in thread: Boudewijn Dijkstra: "Re: How to create string of repeated characters?"
- Reply: Boudewijn Dijkstra: "Re: How to create string of repeated characters?"
- Reply: Roedy Green: "Re: How to create string of repeated characters?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 11 Jun 2004 15:00:35 +0100
Boudewijn Dijkstra wrote:
> "Alex Hunsley" <lard@tardis.ed.ac.molar.uk> schreef in bericht
> news:W8Gwc.27889$B63.25283@doctor.cableinet.net...
>
>>Boudewijn Dijkstra wrote:
>>
>>>"Roy Smith" <roy@panix.com> schreef in bericht
>>>news:roy-ADE825.12380604052004@reader2.panix.com...
>>>
>>>
>>>>In article <4097C0C4.8E9CD8A3@sun.com>,
>>>>Eric Sosman <Eric.Sosman@sun.com> wrote:
>>>>
>>>>
>>>>
>>>>>Roy Smith wrote:
>>>>>
>>>>>
>>>>>>What's the easiest way to create a String of 20 x's in Java? I know I
>>>>>>could do
>>>>>>
>>>>>>String s = "xxxxxxxxxxxxxxxxxxxx";
>>>>>>
>>>>>>but I don't want to count out 20 *'s (it's error prone and hard to
>>>>>>read). In python, I would just do
>>>>>>
>>>>>>s = "x" * 20
>>>>>>
>>>>>>is there a direct equivalent of that in Java? I've checked the
>>>>>>documentation for the Character, String, and StringBuffer classes but
>>>>>>don't see anything obvious.
>>>>>
>>>>> Do you mean to tell me that all these high-falutin'
>>>>>fancy-pants code-completin' auto-refactorin' buzzword-totin'
>>>>>Aye Dee Ease still haven't discovered `^U 2 0 x'?
>>>>
>>>>I use emacs too, but just because I could do that, doesn't mean I think
>>>>it's the right way to code. Someday, somebody else is going to have to
>>>>read, maintain, or modify my code. Reading (and counting) a string of
>>>>20 x's isn't what humans are very good at.
>>>
>>>
>>>Counting is hardly necessary when using editor which can show you what
>>>column the cursor is currently on. Most Java-developing humans are
>>>perfectly capable of placing the cursor on the start and end of the x's,
>>>subtracting the column values and comparing with 20.
>>
>>Irrelevant. As soon as code readability starts depending on features of
>>the editor you're using (or not using), it's bad practise.
>
>
> Hmm. So I should use spaces in stead of tabs,
tabs are ok!
> I should manually break off
> every line at ca. 40 columns
The recommended maximum column width is 80. Yes, it is good style to limit line
lengths to 80 chars.
> and I shouldn't use non-ASCII characters
> anymore?
You can escape non-ascii characters.
> That seems a little bit restrictive, also counter-productive if
> you ask me. The only post-Win95 editors I know that do not show the current
> column, are Notepad and some crappy Un*x-gizmo's.
You are making the assumption that you, and possibly other people, will be
editing the code on a computer setup completely by them, and with whatever
software they want. The real world isn't always like this. Quite a few times
I've had to do work on at a client site where all I had was a 80char dumb
terminal. No column markers there and no option to have a wider screen.
Well written code will be just as editable in this sort of environment.
alex
- Next message: Roedy Green: "Re: Blow me away, (long) does not truncate."
- Previous message: Nigel Wade: "Re: Servlet to execute task at predetermined time"
- In reply to: Boudewijn Dijkstra: "Re: How to create string of repeated characters?"
- Next in thread: Boudewijn Dijkstra: "Re: How to create string of repeated characters?"
- Reply: Boudewijn Dijkstra: "Re: How to create string of repeated characters?"
- Reply: Roedy Green: "Re: How to create string of repeated characters?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|