• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please review my code

 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Following is a method. I want to know how will I indent long lines (or wrap them) of code.I don't want a line of code to have more than 80 characters.



Apart from the above, how do I line-wrap this statement (one line should not be more than 80 characters)


[ September 17, 2005: Message edited by: Danish Shaukat ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps first you should choose a documented formatting standard and follow its rules. For example Elements of Java Style.

Otherwise, I would suggest throwing the code into an IDE like Eclipse and choosing Source->Format. After you find out what that looks like, you can then tweak Eclipse's code formatter to produce the results you would like to have.

I guess there are other pretty-printers that would also do the job for you.

To do it manually you can set your tab width to 4 spaces and a wrap indention to be 8 spaces. String literals have to be broken by hand into pieces and concatenated with the + operator. The compiler joins the pieces up at compile time.
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A second spent formatting code is a second wasted. There are tools that will automatically format your code and many of them run from the command line if you have no interest in an software development console commonly known as an IDE � integrated development environment.

Use your editor/IDE to format the code for you. Use a battle-tested format rather than presume that some how you know better than what the industry is using. Without question, the worst programmers I know also have this habit of "cleaning up" code to fit a bizarre non-standard style.

Your employer won't like paying to do something that has been automated for probably 30 years now.

P.S. Your code looks excellent as shown.
[ September 17, 2005: Message edited by: Rick O'Shay ]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

although, btw, since these particular exceptions are runtime exceptions, they don't need to be declared at all.
[ September 17, 2005: Message edited by: Marilyn de Queiroz ]
 
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They don't need to be as per the rules of a compileable source code unit, but they mey need to be in accordance perhaps with some other fundamentals. That is, if your public contract may throw a NullPointerException, you should let your clients know (shouldn't you?), and by declaring it with a 'throws' clause allows this information to be available through reflection. In fact, all public contract operations (interface methods) that accept one or more reference type parameters should (at least mine do) declare to throw NullPointerException; the optimal, but not very nice, workaround to the flawed existence of 'null' i.e. fail as early as possible.

Alternatively, if you don't wish to encourage the bind from your API to the language (and particularly its flaws), use an annotation; although unconventional, you get all the benefits otherwise.

 
Danish Shaukat
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the guidance, everyone.

I do use Text Pad as my Java editor. But still I wish to keep my line length less than 80 characters so sometimes I have to line wrap the code myself.

Anyway, here is the above code with line length less than or equal to 80 characters. If there are flaws in line wrapping, please let me know.




And the last line...


[ September 17, 2005: Message edited by: Danish Shaukat ]
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you use eclipse, install the Checkstyle plug-in. This will display all violations of Sun's Code Conventions for the Java Programming Language.
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Putting a space in front of and after "=" would help with the legability.
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I myself use Textpad, and have found that Jalopy works great within Textpad -- I set it up as a tool, and so to format I simply do a CTRL-4 and voila! I have formatted code.
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic