-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] Make the Dim keyword optional #177
Comments
The parser certainly could do this, but how would type-inference work?
is an assignment and we couldn't treat every assignment as a declaration. And I think the conciseness gained from omitting the 'As Type' is greater than that from omitting the Out of curiosity, is it the requirement for any keyword there that bothers you or is it the |
Also, for what's it's worth, the LocalDeclarationStatement
: LocalModifier VariableDeclarators StatementTerminator
;
LocalModifier
: 'Static' | 'Dim' | 'Const'
; It just so happens that |
I was anticipating that if
I have no problem with the |
Ah! So you're thinking more like what Python does and how VB works when Option Explicit is Off. If Python gets away with it I don't see why we can't. |
@AnthonyDGreen just out of curiosity, do you have any telemetry stats about how many projects have Option Explicit Off? Ever since Option Infer was added, I have personally never found a need for Option Explicit being Off...and along those lines having Dim made it clear that a variable is being declared without it being much of burden in terms of keyboard typing effort. Also keeping Dim required helps with #159. |
@ericmutta, with respect to your last sentence, just in case this proposal is being interpreted as removing the Dim keyword, it only asks to make it optional. Dim would still be able to be used for clarity when desired. More than just typing, I think removing the need for Dim makes the code look 'cleaner' and sometimes (albeit infrequently) having a shorter line reduces the need for scrolling or line continuations in the editor. |
@erlebo More that just typing, I think removing the need for Dim makes the code look 'cleaner' I realise concepts like 'cleaner' can be quite subjective when it comes to syntax, so I am curious: do you have an explicit example where removing Dim makes it cleaner in your opinion? I ask because at the moment Dim can only ever appear at the beginning of a line and being just three letters long, making it optional seems to be a request to reduce what is already minimal typing effort. Even worse, is that if you make Dim optional you end up typing more to add the From a parsing perspective keeping Dim required is actually helpful, both for humans and machines (compilers, intellisense, pretty printers, etc). When you see Without Dim you have an identifier the meaning of which is not clear until you lookahead to see what follows (i.e if followed by For humans, lookahead is not a big deal since we read entire words and sequences of words "in parallel" but lexers/parsers "read" character by character, and then it matters a big deal (see Wikipedia for the parsing theory). In summary: let's keep Dim the way it is. Making it optional introduces a potential host of (potential) complexities that far outweight the 3 characters of typing that are saved. |
@ericmutta I'm not that keen to argue further the merits or otherwise of this change, as it was mainly intended as a suggestion to improve the flexibility of the language to support those who prefer to omit Dim, for whatever reasons. If whoever would be tasked with recommending, approving and/or implementing the change considers that it's not worth the effort, I can accept that. |
For example, as an alternative to:
Dim a As Integer
also recognise:
a As Integer
Possibly the compiler/parser could use the
As
keyword to recognise that a variable is being declared? This would help to make VB.NET more concise.The text was updated successfully, but these errors were encountered: