Allow conditional inclusion of elements in array/dictionary literals?

Okay. I agreed to move forward on this.

Now I have a question in the design. Sorry for bikeshedding but the following example is legal?

[
#if FLAG
  42
#endif
]

if so, how about:

[
#if FLAG
  42
#endif

#if !FLAG
  12
#endif
]

If you think of #if .. #endif as C like pre-processing directive, this expression ends up with

[
  42

]

or

[

  12
]

So it should be legal. But I think this is error prone for developers because requirement for , relies on the flags or platform conditions.

So, to keep things simple, my proposal here is: "trailing comma is mandatory in #if block in collection literal regardless of the position in the literal"
What do you think?

6 Likes