Risky to choose a non-standard Java code indentation style? -



Risky to choose a non-standard Java code indentation style? -

does create difference if take non-standard indent style?

this style see often:

import java.io.fileinputstream; import java.io.fileoutputstream; import java.nio.bytebuffer; import java.nio.channels.filechannel; public class test { static public void main(string args[]) throws exception { fileinputstream fin = new fileinputstream("infile.txt"); fileoutputstream fout = new fileoutputstream("outfile.txt"); filechannel inc = fin.getchannel(); filechannel outc = fout.getchannel(); bytebuffer bb = bytebuffer.allocatedirect(1024); while (true) { int ret = inc.read(bb); if (ret == -1) break; bb.flip(); outc.write(bb); bb.clear(); } } }

but prefer style starts on next line:

import java.io.fileinputstream; import java.io.fileoutputstream; import java.nio.bytebuffer; import java.nio.channels.filechannel; public class test { static public void main(string args[]) throws exception { fileinputstream fin = new fileinputstream("infile.txt"); fileoutputstream fout = new fileoutputstream("outfile.txt"); filechannel inc = fin.getchannel(); filechannel outc = fout.getchannel(); bytebuffer bb = bytebuffer.allocatedirect(1024); while (true) { int ret = inc.read(bb); if (ret == -1) break; bb.flip(); outc.write(bb); bb.clear(); } } }

i find easier read encounter problems working others if utilize style?

decide on single convention on team (preferably standard 1 in case want work others later) configure , everybody elses ide utilize format , only. make reformat happen automatically , preferably @ every ctrl-s.

this create sources uniform @ times, , ensure changes in source repository actual changes , not reformats @ later time.

for eclipse can done configuring formatter (i happen defaults), , save preferences can loaded else. java -> editor -> save actions allow automatic reformatting @ every ctrl-s, also savable preference.

i've found above additional heuristic

everything must fit on single line

gives lot of automatically triggered refactorings giving lot of named locals capture intent naming, in turn works debugging have more values in variables show in debugger when single stepping, , tend have less opportunities nullpointerexceptions on each line.

edit: i wrote on blog this.

edit 2014-08-19: appears if eclipse formatter settings saved file, intellij thought can format source using file.

java coding-style indentation

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -