Monthly Archives: February 2008

Implicit line continuations

WARNING: This is a speculative post. Caveat emptor.

One of the things that we’d like to address in the next version is line continuations. We know that they tend to annoy many developers who want to break their logical lines across multiple physical lines, and we’ve gotten many requests to get rid of them altogether. Unfortunately, there’s a reason we haven’t just dropped them–they actually are needed in certain scenarios. For example, take the following contrived example:

    Sub Main()
    End _
    Sub

If I remove the line continuation, I’ll now get a compile error because “End” now is the “End” statement, and the Sub looks like it’s trying to start a new subroutine in the middle of the current subroutine. There are quite a few of these syntactic ambiguities sprinkled throughout our grammar, some of which might be quite obscure and unnoticed until someone’s code actually broke. So instead of taking a maximalist approach and trying to remove the line continuation everywhere, we’ve been thinking about a more minimalist approach and looking at where removing the line continuation might be most useful. This produced a much more tractable list of places where we might productively remove the line continuation. In particular:

  1. After binary operators in expression contexts. Note that this does not include assignment operators. For example:
    a = b +
        c
  2. After the following punctuators: comma (“,”), open parenthesis (“(“), open curly brace (“{“), begin embedded expression in XML (“<%=”). For example:
    Console.WriteLine(
        "{0} {1}",
        FirstName,
        LastName)
    
  3. Before the following punctuators: close parenthesis (“)”), close curly brace (“}”), end embedded expression in XML (“%>”). For example:
    Console.WriteLine(
        "{0} {1}",
        FirstName,
        LastName
    )
  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”). For example:
        <
            Conditional("Foo"),
            Conditional("Bar")
        >
        <
            Conditional("Baz")
        >
        Sub Main()
        End Sub
    
  5. Before and after query expression operators. For example:
    Dim ys = From x In xs
             Where x > 5
             Select
                ten = x * 10,
                twenty = x * 20,
                thirty = x * 30

One thing that is not currently on the list is allowing an implicit line continuation after a dot, so you couldn’t break up “a.b.c” implicitly. It’s not that we can’t do dot, just that it’s quite a bit more expensive and problematic for Intellisense. We’d be interested to hear if this is something people really want to/need to do, or if it’s just a nice-to-have.

Are there any other places that we missed that you can think of?

Lang .NET 2008, Scripting, and Visual Basic

WARNING: This is a speculative post. Caveat emptor.

Several weeks ago, I gave a presentation entitled Bringing Scripting (Back) to Visual Basic at the Lang .NET 2008 conference. A video of the presentation has now been posted, so you can check it out for yourself. (The presentation was also covered by EWeek in an article entitled Bringing Sexy Back to Visual Basic.)

The main theme of the presentation is the same one I’ve been talking about on and off over the past year or two: moving Visual Basic back towards it’s scripting roots. The main thrust of this presentation was the technical side of the story–namely, what we would need to do to the existing Visual Basic compiler to be able to effectively use it as a scripting engine. The presentation talks some about the way the compiler is structured, how it might change and some of the things were thinking about enabling. In particular, what we’d like to see is not just that Visual Basic can be embedded anywhere, but that all the services that the compiler provides–parsing, semantic analysis, code generation–are available to be used by any program that needs them. The DLR is a key part of this, but there’s a lot of work on top of that.

I also showed some fun demos of some prototypes that we’ve whipped up using our current codebase. Nothing we’re committing to at the moment, but it gives you some of the flavor of what we’re thinking about.

One thing this presentation didn’t cover (and which Ted Neward brought up in the Q&A afterward) is what we might do to the language itself to make it more scripting-friendly. That’s an area where things are less well-defined and even more speculative than what I talked about, so I left it out for now. Maybe soon I can talk more about it…

I haven’t given up blogging yet…

Just a quick note for those who might care–I haven’t given up blogging just yet, even though January was the first time in the history of this blog that I went without saying anything for a month. My wife, kids and I went on a big vacation to the Dominican Republic in January, with a swing by the East Coast for a baptism for good measure, and that took up most of the month! Then, just as I was starting to dig myself out of the hole from that trip, I was off for another week. So needless to say, I’ve got a good sized backlog of stuff to get out on the blog. I’ll apologize in advance for any old news…