Re: How to create string of repeated characters?

From: Alex Hunsley (lard_at_tardis.ed.ac.molar.uk)
Date: 06/11/04


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



Relevant Pages

  • Re: Great SWT Program
    ... It's not putting mouse support into an editor running on modern ... Didn't I explain that this whole thing is "you don't like tabs" ... characters into spaces" feature on. ...
    (comp.lang.java.programmer)
  • Re: Bluefish (was: HTML tools for linux)
    ... > things like open multiple files recursively based on regular ... > I like this editor a lot, and only have a few nits to pick. ... > spaces instead of tabs, the page appears to be saved with tabs. ... Feel free to contact me off the list about Bluefish. ...
    (Fedora)
  • Re: AfxGetApp() returns NULL
    ... VS to edit my code, it gets the identation right, following my indentation ... OPTION of whether to use spaces or tabs. ... me, and written using my editor, and given away free to others as a courtesy, I see no ... of my automation; worse still, the creators of VS think that there is no ...
    (microsoft.public.vc.mfc)
  • Re: Creating cvf project files
    ... convenient for me than the Visual Studio editor), ... I try to avoid tabs when it comes to fortran. ...
    (comp.lang.fortran)
  • Re: [opensuse] editor that does not eat out TAB characters
    ... But, regardless of which editor I use, python interpreter prints ... Your editor, editor toolkit, clipboard, or terminal toolkit may be munging ... It's often not easy to copy/paste tabs. ...
    (SuSE)