Re: Alignment Nazi?
"Steve Berczuk" <[email protected]>
| Newsgroups | gmane.comp.programming.language-of-the-year |
|---|---|
| Message-ID | <[email protected]> |
I don't think that there are absolutes here. What is more important is that the code is consistent enough in style than anyone working on it can pick up what it does. Some might argue that the alignment can cause one to lose the details; everything becomes rows of stuff making it harder to read lines across. Also the spacing to make things line up can cause lines to split where they might not have before, making the code "harder" to read. If lining things up like this works for your team, great. But I don't think that there are absolutes here. What is interesting for me is this line: >>I don't know why my brain finds this easier, it just does. What amazes me, however, is how many of those I have worked with over the years have no problem with the the former code layout.<< It depends on what it is that you see as the problem: the fact that some lines use the "columns" convention, but not all, or that some code is not lined up. Steve On Sun, Apr 27, 2008 at 6:06 PM, gjmilne64 <[email protected]> wrote: > > > > > > > Hi! > > I am an Alignment Nazi. When I see a block of code like this: > > final int counts = result.getCounts(); > final int periodMicros = result.getMicros(); > final Rate rate = new Rate(new > Duration(periodMicros, Duration.MICROSECOND), counts); > final Current reagentIntensity = upsElectrometer.getValue(); > final Current productIntensity = dwsElectrometer.getValue(); > final Temperature flowtubeTemperature = > flowtubeThermocouple.getValue(); > final Pressure flowtubePressure = > flowtubePressureGauge.getValue(); > final FlowRate carrierFlow = reagent.getIon().isPositive() ? > pcgFlowMeter.getValue() : nicgFlowMeter.getValue(); > final FlowRate sampleFlow = sampleFlowMeter.getValue(); > final Duration reactionTime = getReactionTime(carrierFlow); > final Lut ICF_LUT = > CONFIG.getLut(DefaultConfigIfc.ConfigId.ION_ICF_LUT); > > I find it so much easier to read when I change it to this: > > final int counts = result.getCounts(); > final int periodMicros = result.getMicros(); > final Rate rate = new Rate(new > Duration(periodMicros, Duration.MICROSECOND), counts); > final Current reagentIntensity = upsElectrometer.getValue(); > final Current productIntensity = dwsElectrometer.getValue(); > final Temperature flowtubeTemperature = > flowtubeThermocouple.getValue(); > final Pressure flowtubePressure = > flowtubePressureGauge.getValue(); > final FlowRate carrierFlow = > reagent.getIon().isPositive() ? pcgFlowMeter.getValue() : > nicgFlowMeter.getValue(); > final FlowRate sampleFlow = sampleFlowMeter.getValue(); > final Duration reactionTime = > getReactionTime(carrierFlow); > final Lut ICF_LUT = > CONFIG.getLut(DefaultConfigIfc.ConfigId.ION_ICF_LUT); > > Of course, this works so long as you use a monospaced font in your editor. > > The question I want to ask is "does my need for visual clarity excuse my > fetish for alignment of equals signs in blocks of code"? > > My personal justification is that I can more easily assimilate the block of > code if the left-hand side of variable names is clearly separated from the > right-hand side of assignments. I don't know why my brain finds this easier, > it just does. What amazes me, however, is how many of those I have worked > with over the years have no problem with the the former code layout. > > Perhaps I should write a book (or blog) on the merits of "Pretty Code". > > Regards, > > Gordon > -- Steve Berczuk | steve-Bvnk/[email protected] | http://www.berczuk.com SCM Patterns: Effective Teamwork, Practical Integration www.scmpatterns.com