BT
x Your opinion matters! Please fill in the InfoQ Survey about your reading habits!

Implicit line continuations in Visual Basic

by Jonathan Allen on Feb 28, 2008 |

Line continuation characters have always been a wart on the VB syntax. Unlike languages in the Pascal and C families, Visual Basic does not require a trailing semi-colon to denote the end of a statement. The trade-off for this is that it does need a character to indicate when the statement does not end.

The line continuation character, an underscore, was introduced in Visual Basic 4. Prior to that, logical lines of code had to be on a single physical line of source code. This generally was more of a nuisance than a real problem unless you are using inline SQL. But with the introduction of LINQ one can easily foresee single query statements, especially ones with deep nesting, becoming quite problematic.

In a purely speculative post, Paul Vic of Microsoft is proposing to eliminate the need for continuation characters in most common cases. While VB, unlike SQL, cannot completely eliminate continuation characters it can get really close.

Paul's proposal would eliminate continuation characters in the following five situations:

  1. After binary operators in expression contexts.
  2. After the following punctuators: comma (","), open parenthesis ("("), open curly brace ("{"), begin embedded expression in XML ("<%=").
  3. Before the following punctuators: close parenthesis (")"), close curly brace ("}"), end embedded expression in XML ("%>").
  4. After an open angle bracket ("<") in an attribute context, before a close angle bracket (">") in an attribute context, and after a close angle bracket in a non-file-level attribute context (i.e. an attribute that does not specify "Assembly" or "Module").
  5. Before and after query expression operators.

Other ideas being kicked around by the community include

  • Before the Handles and Implements statements (and also after commas in those statements)
  • Between open " and closing " of a string :)

Allowing inline comments was also brought up. Currently VB does not support comments except at the end of a statement which making it difficult to document complex LINQ queries.

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT