Columnar Code

Consider these two blocks of code, best viewed with line wrap turned
off.
entityArrow = new PrintWriter( new BufferedWriter( new FileWriter(
"entityarrow.htmlfrag" ), 4096/* buffsize */ ), autoflush );
entityCase = new PrintWriter( new BufferedWriter( new FileWriter(
"entitycase.javafrag" ), 4096/* buffsize */ ), autoflush );
entityCaseHex = new PrintWriter( new BufferedWriter( new FileWriter(
"entitycasehex.javafrag" ), 4096/* buffsize */ ), autoflush );
entityCyrillic = new PrintWriter( new BufferedWriter( new FileWriter(
"entitycyrillic.htmlfrag" ), 4096/* buffsize */ ), autoflush );
entityGreek = new PrintWriter( new BufferedWriter( new FileWriter(
"entitygreek.htmlfrag" ), 4096/* buffsize */ ), autoflush );
entityPolish = new PrintWriter( new BufferedWriter( new FileWriter(
"entitypolish.htmlfrag" ), 4096/* buffsize */ ), autoflush );
entityJustKeys = new PrintWriter( new BufferedWriter( new FileWriter(
"entityjustkeys.javafrag" ), 4096/* buffsize */ ), autoflush );
entityJustValues = new PrintWriter( new BufferedWriter( new
FileWriter( "entityjustvalues.javafrag" ), 4096/* buffsize */ ),
autoflush );
entityHTML5 = new PrintWriter( new BufferedWriter( new FileWriter(
"entityhtml5.htmlfrag" ), 4096/* buffsize */ ), autoflush );
entityLatin = new PrintWriter( new BufferedWriter( new FileWriter(
"entitylatin.htmlfrag" ), 4096/* buffsize */ ), autoflush );
entitySpecial = new PrintWriter( new BufferedWriter( new FileWriter(
"entityspecial.htmlfrag" ), 4096/* buffsize */ ), autoflush );
entitySymbol = new PrintWriter( new BufferedWriter( new FileWriter(
"entitysymbol.htmlfrag" ), 4096/* buffsize */ ), autoflush );
entityQuoter = new PrintWriter( new BufferedWriter( new FileWriter(
"entityquoter.htmlfrag" ), 4096/* buffsize */ ), autoflush );


vs


entityArrow      = new PrintWriter( new BufferedWriter( new
FileWriter( "entityarrow.htmlfrag"      ), 4096/* buffsize */ ),
autoflush );
entityCase       = new PrintWriter( new BufferedWriter( new
FileWriter( "entitycase.javafrag"       ), 4096/* buffsize */ ),
autoflush );
entityCaseHex    = new PrintWriter( new BufferedWriter( new
FileWriter( "entitycasehex.javafrag"    ), 4096/* buffsize */ ),
autoflush );
entityCyrillic   = new PrintWriter( new BufferedWriter( new
FileWriter( "entitycyrillic.htmlfrag"   ), 4096/* buffsize */ ),
autoflush );
entityGreek      = new PrintWriter( new BufferedWriter( new
FileWriter( "entitygreek.htmlfrag"      ), 4096/* buffsize */ ),
autoflush );
entityPolish     = new PrintWriter( new BufferedWriter( new
FileWriter( "entitypolish.htmlfrag"     ), 4096/* buffsize */ ),
autoflush );
entityJustKeys   = new PrintWriter( new BufferedWriter( new
FileWriter( "entityjustkeys.javafrag"   ), 4096/* buffsize */ ),
autoflush );
entityJustValues = new PrintWriter( new BufferedWriter( new
FileWriter( "entityjustvalues.javafrag" ), 4096/* buffsize */ ),
autoflush );
entityHTML5      = new PrintWriter( new BufferedWriter( new
FileWriter( "entityhtml5.htmlfrag"      ), 4096/* buffsize */ ),
autoflush );
entityLatin      = new PrintWriter( new BufferedWriter( new
FileWriter( "entitylatin.htmlfrag"      ), 4096/* buffsize */ ),
autoflush );
entitySpecial    = new PrintWriter( new BufferedWriter( new
FileWriter( "entityspecial.htmlfrag"    ), 4096/* buffsize */ ),
autoflush );
entitySymbol     = new PrintWriter( new BufferedWriter( new
FileWriter( "entitysymbol.htmlfrag"     ), 4096/* buffsize */ ),
autoflush );
entityQuoter     = new PrintWriter( new BufferedWriter( new
FileWriter( "entityquoter.htmlfrag"     ), 4096/* buffsize */ ),
autoflush );

The second will much easier to read and proofread insid ethe Intellij
Editor.

The Reformatter will turn the second into the first.  It would be nice
if instead it intelligently turned the first into the second. Failing
that it would be nice if it turned the first into the second is
specially marked blocks. Failing that it would be nice to fence off a
piece of code so that the reformatter would leave it alone as manually
aligned in columns.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Computers are useless. They can only give you answers.
~ Pablo Picasso (born: 1881-10-25 died: 1973-04-08 at age: 91)

10 comments
Comment actions Permalink

Hey, Roedy,

I'm with you, man, but 99 programmers out of a hundred prefer their code in a dense little blob.

Here's another related IDEA behavior: Internal tabs (between two non-whitespace characters) present as zero-width in Find output, causing the text separated by tabs to merge.


RRS

0
Comment actions Permalink

If your code is actually regular enough that this sort of thing makes sense, it's regular enough to be refactored into something simpler.  In this case,
a quick extract method refactoring should leave you with a bunch of lines that look like this

entityArrow = buildWriter("entityarrow.htmlfrag");


at which point the columnization becomes a lot less important.


--Dave Griffith

0
Comment actions Permalink

+1 WHS.

Eliminate redundant code duplication.

0
Comment actions Permalink

Of course, but it's not a universal refutation of the value of columnar layout of your code.

Randall Schulz

0
Comment actions Permalink

On 2/1/2010 6:23 PM, Randall Schulz wrote:

Of course, but it's not a universal refutation of the value of columnar layout of your code.


Indeed, if you have a bunch of lines.

doFoo("asdf", 2);
doFoo("bar",  4);
etc...

You still would want columnar layout, and that code can't necessarily
be refactored.

0
Comment actions Permalink

Have you tried the Tabifier plug-in?

I copied the OP's code and applied Tabifier (Ctrl-Alt-Shift-T), giving this result:

entityArrow      = new PrintWriter(new BufferedWriter(new FileWriter("entityarrow.htmlfrag"     ), 4096/* buffsize */), autoflush); entityCase       = new PrintWriter(new BufferedWriter(new FileWriter("entitycase.javafrag"      ), 4096/* buffsize */), autoflush); entityCaseHex    = new PrintWriter(new BufferedWriter(new FileWriter("entitycasehex.javafrag"   ), 4096/* buffsize */), autoflush); entityCyrillic   = new PrintWriter(new BufferedWriter(new FileWriter("entitycyrillic.htmlfrag"  ), 4096/* buffsize */), autoflush); entityGreek      = new PrintWriter(new BufferedWriter(new FileWriter("entitygreek.htmlfrag"     ), 4096/* buffsize */), autoflush); entityPolish     = new PrintWriter(new BufferedWriter(new FileWriter("entitypolish.htmlfrag"    ), 4096/* buffsize */), autoflush); entityJustKeys   = new PrintWriter(new BufferedWriter(new FileWriter("entityjustkeys.javafrag"  ), 4096/* buffsize */), autoflush); entityJustValues = new PrintWriter(new BufferedWriter(new FileWriter("entityjustvalues.javafrag"), 4096/* buffsize */), autoflush); entityHTML5      = new PrintWriter(new BufferedWriter(new FileWriter("entityhtml5.htmlfrag"     ), 4096/* buffsize */), autoflush); entityLatin      = new PrintWriter(new BufferedWriter(new FileWriter("entitylatin.htmlfrag"     ), 4096/* buffsize */), autoflush); entitySpecial    = new PrintWriter(new BufferedWriter(new FileWriter("entityspecial.htmlfrag"   ), 4096/* buffsize */), autoflush); entitySymbol     = new PrintWriter(new BufferedWriter(new FileWriter("entitysymbol.htmlfrag"    ), 4096/* buffsize */), autoflush); entityQuoter     = new PrintWriter(new BufferedWriter(new FileWriter("entityquoter.htmlfrag"    ), 4096/* buffsize */), autoflush);



Looks OK to me...

0
Comment actions Permalink

Nice. I'll check it out. I wonder if it can use tabs? And I wonder if it'll work on Scala source?


Randall Schulz

0
Comment actions Permalink

On Sat, 30 Jan 2010 18:24:09 MSK, Randall Schulz <rschulz@sonic.net>
wrote, quoted or indirectly quoted someone who said :

>
>I'm with you, man, but 99 programmers out of a hundred prefer their code in a dense little blob

How about a SCID philosophy then where you get to VIEW your code
either way, (much the way you can collapse or expand imports viewing
without changing the underlying source code) where the master copy is
not formatted in any particular way.

see http://mindprod.com/project/scid.html

--
Roedy Green Canadian Mind Products
http://mindprod.com
Computers are useless. They can only give you answers.
~ Pablo Picasso (born: 1881-10-25 died: 1973-04-08 at age: 91)

0
Comment actions Permalink

On Sat, 30 Jan 2010 19:46:16 MSK, Dave Griffith
<no_reply@jetbrains.com> wrote, quoted or indirectly quoted someone
who said :

>If your code is actually regular enough that this sort of thing makes sense, it's regular enough to be refactored into something simpler.  In this case,
>a quick extract method refactoring should leave you with a bunch of lines that look like this
>
>entityArrow = buildWriter("entityarrow.htmlfrag");

That works nicely if you have only one literal or variable.

It will not help if you have two or more.

Another case where lining up helps proofread is a list of constructor
invocations, particularly ones with a large number of parameters, a
list of similar method invocations each with many parameters.

--
Roedy Green Canadian Mind Products
http://mindprod.com
Computers are useless. They can only give you answers.
~ Pablo Picasso (born: 1881-10-25 died: 1973-04-08 at age: 91)

0
Comment actions Permalink

On Tue, 02 Feb 2010 17:09:07 MSK, Dave Lorde <no_reply@jetbrains.com>
wrote, quoted or indirectly quoted someone who said :

>Have you tried the Tabifier plug-in?
How does it get along with Reformat and Rearranger?
--
Roedy Green Canadian Mind Products
http://mindprod.com
Computers are useless. They can only give you answers.
~ Pablo Picasso (born: 1881-10-25 died: 1973-04-08 at age: 91)

0

Please sign in to leave a comment.