-
Notifications
You must be signed in to change notification settings - Fork 66
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] Option Unchecked On | Off #33
Comments
Think I'd prefer a block construct
|
I'd be OK with a block construct (but would that mean the need for a complementary Checked block, or just tell folks to leave the compiler setting alone?), but the Option way is still keeping with the VB idiom, and it seemed to me to be the easier way to go. Since Partial Classes are a thing, one could still mix and match between the two modes within the same class if desired. I'm also shy of introducing yet another keyword into the language - can you imagine some poor soul out there already using Unchecked as an identifier? Who shall we burden with the square bracket fixes? :) |
VB has heavily relied on file level options, but also has compiler directives: So the issue of breaking due to another keyword is addressed if we keep with the # style: or "UnChecked", or something more descriptive such as IntegerOverlowChecking On|Off |
To date, VB has used compiler directives for conditional compilation, and for meta-information about the source (which have no effect on compilation). I have a feeling that any compiler directive that effects compilation at a fundamental level is going to be a hard sell. |
I think VB is long overdue for compiler directives at code, rather than file level. When VB .net first came about (some 15 years ago), it had a legacy from VB6/VBA/VBScript and the file based Option Explicit, Compare and Base. It dropped Base due to vector arrays, and added Strict. Compare was kept for compatibility reasons but really should have long ago been depreciated: it's probably easier to leave it, but it can be a nasty switch thrown at project level that may not be initially obvious. I think it came from the VB3 to 4 transition with unicode introduction. Explicit is from the scripting side of things and is one I really wish didn't exist. Strict when added was a welcome addition, and makes sense at project and file level to allow for compatibility (especially with COM). And then Infer was added. |
File level options Option Checked On
Option Checked Off would fit the stylistic look of VB.net |
I ageee with @AdamSpeight2008 that the File level declaration is more idiomatic with the VB language. Used in conjunction with partial classes it would go someway to providing the flexibility of a block statement |
What you refer to as idiomatic is to me, more problematic. Let's say you have some code you want to fine tune to checked off, which is generally a performance tuning operation. To do so, you'd have to create and check in a new file and document it etc, just to tune existing code. And if you find it has a negative side effect, you then have to merge it back or have all these relic partial classes purely for performance tuning. That idiom is actually an abuse of partial classes, making them a maintenance hassle, when their intention was to split code spit from human code, not to split every time we want a compiler feature |
@Bill-McC, even if the original motivation for partial classes was all about auto code/manual code dichotomy, they are now employed for many other accepted reasons - e.g. see http://stackoverflow.com/questions/3601901/why-use-partial-classes. It isn't problematic when the workaround is straightforward and at worse a mere annoyance. Right now I can't easily mix these integer arithmetic modes within the same assembly (like one can easily do in C#) - that's what's problematic. As things currently stand today, if I insist on mixing modes in VB into a single assembly, I must learn the ins-and-outs of .NET modules; that sort of workaround isn't straightforward. @AdamSpeight2008, OK with Option Checked Off too. In the end, I just want an easy enough way to mix modes. I suggested Option Unchecked On because that's aligned (semantically speaking) with the compiler setting (i.e. /removeintchecks means unchecked), and because the C# keyword for it is "unchecked". On the other hand, after looking at Option Compare, what do you think of this?:
|
@rskar-git I agree that the current way of dealing with unchecked/checked integer arithmetic in VB is unsatisfactory: that alone is not an argument for increasing Option statements at code file level. This addition would bring the possible combinations to something like twelve : and the idea of having twelve different partial classes to allow just for compiler options is ludicrous. And what when /if we add Option Otpimize, would be it be twenty four different possible partial classes. |
@Bill-McC, I do see the point of why a block construct would be better syntactically and practically - I certainly agree with you there. Between a block construct and a file-level Option, I would also prefer a block. However, having said that, my main concern is on the relative level of energy that VB receives versus other projects, such as C# and F#; afterall it has been recently declared that there no longer is a priority in maintaining features parity between C# and VB. The compiler setting has been there for a very long time, perhaps since day one. Yet in all that time, apparently the checked/unchecked thing was never in the plans for VB! If a new block can be done in about the same effort as a new Option, then great! But my gut feel is that the Option route is likely to be the much smaller job. So that's my $0.02. Whether block or Option, just want to have it. |
Just a syntax suggestion, building on the one @rskar-git suggested earlier, to make it clearer what is being checked or not as a result of these directives:
|
@gilfusion I think |
Under "Advanced Compiler Options..." there is "Remove integer overflow checks". That's a cool feature to have, but it's an all-or-nothing proposition.
Could we have a new Option:
Option Unchecked On
The "Remove integer overflow checks" setting could be the default. This new option would only affect the *.vb file it's in. This would make having modulus binary arithmetic operations available when needed, and regular overflow checks also available within the same project.
The text was updated successfully, but these errors were encountered: