*
The moose likes Cattle Drive and the fly likes Line Continuation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Line Continuation" Watch "Line Continuation" New topic
Author

Line Continuation

Matt Fry
Greenhorn

Joined: Mar 07, 2006
Posts: 2
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.
Pauline McNamara
Sheriff

Joined: Jan 19, 2001
Posts: 4012
    
    6
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

Joined: Mar 07, 2006
Posts: 2
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!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
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 ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Adam Price
Ranch Hand

Joined: Nov 11, 2005
Posts: 95
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Line Continuation
 
Similar Threads
How did YOU learn Java?
Target Unreachable, 'null' returned null
Array without ints
Security Policy File
NullPointer Exception in Executing a Struts Program