Implicit line continuations in Visual Basic

| by Jonathan Allen Follow 463 Followers on Feb 28, 2008. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

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.

Rate this Article

Adoption Stage

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


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you