• 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

Line Continuation

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the proper way to cleanly continue a line of code in Java? Say you have a long line of code and when emailing it to the nitpicker, it can be automatically broken into two lines by your email client. In Visual Basic I just used an underscore, but so far I have been unable to find a good way to do it in Java. Only became aware of it this morning when sending a revised assignment.
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Matt,

I don't think I've heard of a standard way of doing that. It kind of depends on what the long line is. If it's a big string, you could concatenate it. If it's a bunch of array elements you could just add in a line break between elements. If it's 32 nested if blocks pushing off the right end of the page, well, maybe a little refactoring is called for.

Does your email program have a setting for the width of the window?

At any rate, you'll get bonus points for being extra special considerate to your nitpicker.

Pauline

PS Welcome to the ranch and the cattle drive!
 
Matt Fry
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Pauline, for the welcome and the advice. I set the margins as far out as I could, but it still wanted to wrap the code to the next line. I ended making the font smaller so it would all fit but I'm sure that will not be too easy on the nitpicker either (at least it seemed harder on my eyes).

I had three comparisons in an If statement ( if ( blah, blah ) && ( blah, blah ) && ( blah, blah ) ). I probably could have done away with some of the spaces and made it fit, but well,

I may not have even done it right anyway so I'll have to wait until I hear back from my nitpicker to know for sure.

Thanks!
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Originally posted by Matt Fry:
I set the margins as far out as I could, but it still wanted to wrap the code to the next line. I ended making the font smaller so it would all fit but I'm sure that will not be too easy on the nitpicker either (at least it seemed harder on my eyes).


Changing the font is not really useful because when we nitpickers read it, we see it in plain text. What you really want to do is split the line where it seems most logical. You can split a comment --
// This is a long comment.
becomes
// This is
// a long comment

As Pauline said,
"This is a very long String."
becomes
"This is a " +
"very long String."

A long array could go from

to

Does this help?
[ March 22, 2006: Message edited by: Marilyn de Queiroz ]
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Matt Fry:
What is the proper way to cleanly continue a line of code in Java? Say you have a long line of code and when emailing it to the nitpicker, it can be automatically broken into two lines by your email client. In Visual Basic I just used an underscore, but so far I have been unable to find a good way to do it in Java. Only became aware of it this morning when sending a revised assignment.





There are two places to address this - your editor and your email client. There definitely are times (such as in initializing arrays) when you will need to manually break up lines - they might otherwise run to 200 or more characters. At other times, though, you might just need to figure out a way to allow more characters per line in your editor.
Some have a default of 72 or 80. If you're working at six levels of indentation, you've already eaten up 1/3 of your available character columns with nothing but whitespace. The instructor's solution to GeekWatch has one line that goes to 137 characters. I set my editor to not wrap lines at all - I manually break them when they become difficult to read on my wide screen - somewhere around 120.

Once you have figured that out, you need to find a way to send it without introducing unwanted line breaks. I had trouble with this too - now I use one mail program for everything except submitting assignments to the cattledrive - for that I use another. I am mac based, though. I assume for your VB experience that you are PC based. I think thunderbird will allow you to send without line breaks. There are probably other clients that do so as well. Alternatively, at least one of the web-based email services (yahoo?) will do what you need.


HTH

-Adam
 
reply
    Bookmark Topic Watch Topic
  • New Topic