Req8: Use [ ] for arrays


[This post is part of a series, “wish-list for future versions of VB“]


 


IDEA: Use [ ] for arrays. This suggestion came from Bill McCarthy. He writes that it’s hard to tell the difference between array-indexing and other uses of parentheses. We could allow [] for arrays, or have some other visual differentiation in the IDE. For consistency reasons we’d also have to do it for property parameters. (Also that would remove the user-confusion about how property args are always passed ByVal even though declared ByRef).


 


Evaluation from VB team: This would be better done by an IDE plugin, rather than by changing the syntax of the language. Now that VS2010 has moved the IDE to WPF, a lot more of these kinds of plugins are possible, and they’ll become drastically easier once our “compiler-as-a-service” features progress.

Comments (6)

  1. Dave R says:

    Are you sure you suggestion box is coming from people who actually like VB, not some C# and Java types who had to write VB code grudgingly? I mean, suggesting [] for arrays, separate equality and assignment operators, all sorts of funky syntax (two rules for adding new punctuation to VB – rule 1: Only do it if you really, really have to. rule 2: You don’t really have to.) , getting rid of the block end statements that massively improve readability and are always written by the IDE anyway… that ain’t VB. That’s C# without semicolons.

  2. Dzonny says:

    First I must say that I’m against this feature. [] are not on Czech keyboard ;-). But imagine this

    Function GetArray() As Integer()

    Function GetArray(param As Integer) As Integer()

    Dim x = GetArray(5) ‘What does this do?

    [] Can avoid some confusion.

  3. Kevin Ryall says:

    As with separate assignment and equality operators, this would undoubtedly make code clearer, but again is probably not worth implementing considering the confusion it would lead to (assuming both syntaxes would have to be supported indefinitely).

  4. Richard says:

    I don’t find it confusing or hard to tell the difference.  I think () is perfectly adequate.  

  5. Robert says:

    Dave R:

    I like VB and I’d very much like to use [] for indexing. In my opinion, () is overused already, with it being used for changing the evaluation order of expressions, generics, indexing and function calls. At least generics have the Of keyword to differntiate them.

    If you came across Aaa(0).Bbb(1).Ccc(2)(3), you can’t tell from a glance which ones are array/property accesses or function calls.

  6. weitzhandler says:

    NO NO NO NO NO NO NO

    Stick to () and don't get confused from C#!!!