-
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
What's syntax or feature you would like to create for VB or .net ? #587
Comments
@RevensofT The moment you begin to make use of pointers is the moment you bring a world of hellish trouble. They are a necessary evil for very specific situations, but 99% of the time you don't need them and are better off without them. Of course, behind the scenes, inevitably the compiler will generate code that makes use of pointers. That is perfectly fine, because any given compiler will be designed and tested against a very specific architecture; it will be up to the compiler designers to get everything critical done correctly. It can be a hellish landscape to properly navigate: padding, caching, byte-order, thread safety, etc. But with pointers, one must be super-mindful and disciplined to do it right, and not for much gain versus the alternatives of properly designed language constructs and libraries. Actually, performance with pointers can be worse - see https://stackoverflow.com/questions/5374815/true-unsafe-code-performance. Have a look at https://gitter.im/VB-NET/HowTo - it is possible to do ref types and pointers in VB.NET via MemoryMarshal. It is, of course, somewhat risky to do so, since the VB.NET compiler wasn't designed with these possibilities in mind. But it can be done. So the one thing that would be nice is if the |
Note that the
|
Weren't pointers/unsafe code one of the things that was specifically mentioned that MS was opposed to adding to VB.Net? I personally would love to have pointers, as it would make interop with unmanaged libraries easier without resorting to ungainly workarounds or writing wrappers in another language. |
No, not necessarily, because a pointer is an architecture dependent thing (and part of a grander scheme known as a memory model). Of course, most of the time we're looking to interop with C/C++ libraries, so it's usually a matter of coming from other languages and contorting the code as needed to seem as C/C++ like as possible. (See https://stackoverflow.com/questions/6319146/c11-introduced-a-standardized-memory-model-what-does-it-mean-and-how-is-it-g) The other major interop issue is calling conventions, which can't be helped without direct access to the stack and/or CPU registers (so it must be a language feature). Pointers offer nothing here. (See https://stackoverflow.com/questions/949862/what-are-the-different-calling-conventions-in-c-c-and-what-do-each-mean) Anything else that a pointer might seem particularly handy for, such as stepping through arrays or naive type casting from raw, can be done well enough via API or language constructs. |
@rskar-git About custom statement, I'm not touch on this subject after I saw someone try to create new language on VS on Youtube and they have to fall back to use By the way, your issue #231 , if it can be a new VB keyword, it would be nice; this is what's I use (it's a lot easier to read for me then full code it). '''<summary>Update var.</summary>
<Extension>
Public Function be(Of T)(ByRef Input As T, Value As T) As T
Input = Value
Return Input
End Function
'''<summary>Set input var to this value.</summary>
<Extension>
Public Function via(Of T)(Value As T, ByRef Input As T) As T
Input = Value
Return Value
End Function
'''<summary>Update var after using it.</summary>
<Extension>
Public Function [then](Of T)(ByRef Input As T, Update As T) As T
Dim Out = Input
Input = Update
Return Out
End Function @Echo-8-ERA Yes, it was, that why I and other coder create it, some maybe fork VB.net to add more feature; by the way, do you have anything you frequency use on other language and you think it would be nice to have it on VB.net ? |
Don't we all!! :) Just look at all the fun choices programmers have made over the years!: etc. etc. etc. |
@rskar-git By the way, I don't see you talk about |
(I hadn't realized this was a general question; I thought it was devoted to pointers etc.). My wishlist of features for VB.NET (from easier/more likely to harder/less likely):
|
If I had one vote it would be for changing the TypeOf Is SomeType Syntax to allow a definition of a local variable of SomeType as part of the test. Not a fan of #172 as a solution to the issue. #337 might be a superset. It seems there are may open issues related to this one concept with different names. If #277 is a bug and not a new feature it should be fixed, if its not it should be closed. |
Could you elaborate on this? Of the list I've mentioned, it's the only one which doesn't require any new syntax, but simply gives the compiler some new information. But it sounds as though you have some objection in principle. I feel that if I've checked the type of the local variable against a derived type, I shouldn't need to create a new variable of the derived type in order to use members of the derived type. To my mind, that is the issue which #72 solves.
Personally, I think pattern matching stands on its own merits, beyond multiple type checks -- instead of multiple
It's not a bug in the sense of "the compiler/runtime is behaving oddly". But VB.NET is English-like in syntax, and even though some parts range from the sensible ( Imagine if |
@zspitz #172 is confusing when you read the code, the examples are close to the TypeOf but if they are further away it is easy to get confused. Also is the Obj still a string, if somewhere below I set it to an integer? I like the C# model to create a new variable. I agree pattern matching stands alone, but to me the compelling use case to me is to solve above. VB already has some pattern matching, and how would this new one work with what exists. I don't think #277 is going to change, but the issue should be addressed or closed. |
I think this is an occupational hazard of any long code where variable usage is far from the declaration. This is mitigated somewhat when working in the IDE -- I usually hover over the variable to display the type in a tooltip, or press F12 to jump to the declaration. Both of these could be modified for typecheck inferred types -- the tooltip could display something like
At that point, no; at least the way Anthony suggests it, the type of
As if the variable under question was of type |
...where the harm isn't limited to themselves, and ends up doing great harm to many others. Buffer overruns, for starters...
I most certainly did, although I used the phrase "naive type casting from raw". They are fine by me, generally, and can be done well enough via API or language constructs (pointers not required).
Yep, suggested above, BTW, I cannot see any code at RevensofT/STD, only README.md and LICENSE. |
@rskar-git About RevensofT/STD code, I write it in IL directly so if anyone want to look at code just |
Pointer
One of syntax I don't think it going to be apply to VB.net by MS is
pointer
, I half agree and half disagree with this decision because it's hard to guarantee its safety but it also give you a lot of performance if you use it right.This is latest version I created and use.
https://github.com/RevensofT/STD
ref(Of T) type
A new type for unsafe pointer, it's value of reference type aka it's value type but invoke by method as reference type.
Constructor via extension method
ref(Of T)(ByRef Input As T) As ref(Of T)
Create pointer from target, field of class and element of array are most safe pointer you can create without any concern, pointer of local var and value type should be use within their life cycle.
Property
value As T
Get and set value via pointer, simply ldobj and stobj.
Default Readonly index(Offset As Int64) As ref(Of T)
Move current pointer to other index offset of
T
unit.Readonly range(Destination As ref(Of T)) As Int64
Measure distance between this pointer and
Destination
pointer inT
unit.Shared size As UInt64
Get size of
T
unit.Method
Sub copy(Destination As ref(Of T), Length As UInt64)
Copy data from this pointer to Destination pointer.
Function change(Of V)() As ref(Of V)
Get new pointer of
V
type point at the same address as this pointer.Unsafe cast type
Other thing I'm would love to have but hate to live with is
unsafe cast
, DirectCast and CType do a good job to keep a code safe but also give me no other way to cast some type I know it fine like cast base type to inherit that only add method without touch field.as(Of T, V)(Input As T) As V
Unsafe cast type on .net, you can cast object to any type, doesn't matter if it ref type or val type, highly cause an error if you don't know what are you doing.
Stack frame allocate memory
Only 2 way I can think to create it until now is create a local var of structure and reference it via pointer to simulate is like
stack alloc
and other way islocalloc
akastack alloc
via method and use it on other argument method delegate, first one is uneasy to create a large alloc and second one request 2 extra stack frame to do it, cost over performance.The text was updated successfully, but these errors were encountered: