Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Mohammad Hamdy Ghanem
    @VBAndCs
    I see no value of using ? for printing, even if it possible. In C#, we use cw+tab shortcut for Console.writeline snippent, which doesn't exist in VB, and there is an issue about that dotnet/roslyn#37049
    However, we can add this snippet to vs. Add this to a file and name it writeline.snippet:
    <?xml version="1.0" encoding="utf-8"?>
    <CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
        <CodeSnippet Format="1.0.0">
            <Header>
                <Title>Console.WriteLine</Title>
                <Author>M. Hmdy Ghanem</Author>
        <Shortcut>cw</Shortcut>
            </Header>
            <Snippet>
                <Code Language="VB">
                    <![CDATA[Console.WriteLine($msg$)]]>
                </Code>
      <Declarations>
        <Object>
          <ID>msg</ID>
          <Type>System.String</Type>
          <ToolTip>The message you want to write.</ToolTip>
          <Default>"Hello"</Default>
        </Object>
      </Declarations>
            </Snippet>
        </CodeSnippet>
    </CodeSnippets>
    Now, write cw and press tab, to get:
    Console.WriteLine("Hello")
    The "Hello" text will be highlighted so you can replace it.
    Mohammad Hamdy Ghanem
    @VBAndCs
    It will be helpful to have this snippet added to VS to be available for all vb users. I will add a comment to that issue and vote for it.
    Note: I tried to use ? as a shortcut for the snippet, but didn't work as it is used to show the snippet context menu. It would be nice ;)
    Mohammad Hamdy Ghanem
    @VBAndCs
    One more anointing thing: After writing cw, you need to press Esc to dismiss the auto completion list before pressing Tab, otherwise the editor will convert cw to ChrW!
    one solution to avoid this, is to change the snippet shortcut to cwl.
    or any other shortcut that has no corresponding auto-completion word. I go for cw to be the same as C#.
    Mohammad Hamdy Ghanem
    @VBAndCs
    Of course it would be better if intellisense take snippets shortcuts into account.
    CyrusNajmabadi
    @CyrusNajmabadi
    please file issues and/or fixes.
    currently snippets are in maintenance mode only
    so this would be backlogged unless you can contribute the fixes.
    we've mentioned this before, but backlog items are already lower pri than what the team can currently afford to look at.
    Mohammad Hamdy Ghanem
    @VBAndCs
    I am putting these notes if the filed isue dotnet/roslyn#37049
    Adam Speight
    @AdamSpeight2008

    @CyrusNajmabadi
    Does the visual basic specification and compiler, assert atomicity within "multi-part" block structures.
    For example the ElseIf in an If Then ... End If block.

    We have the following code (as is).

    ' statements 0
    If someCondition = True Then
       ' statements 1
    ElseIf someCondition = False Then
       ' statements 2
    Else
       ' statements 3
    End If
    ' statements 4

    is transformed into

    ' statements 0
    If someCondition = True Then
       ' statements 1
    Else
      ' *** What prevents evaluate of someCondition being different from prior evaluation.
       If someCondition = False Then
          ' statements 2
       Else
          ' statements 3
       End If
    End If
    ' statements 4

    Is someCondition asserted to be atomic ( non-changing ) between each usage?
    As from my knowledge the lowered form does not seem to have that "ambient property", or does the transformation production obtain that "ambient property" from the transformation of an ElseIf statement.
    If it doesn't would a copy of the value of "someConditon" into "tmp" prior to the If Block, and rename the usage of "someCondition" with on this block to "tmp". Gain that guarentee.

    I think this is something to do with Side-Effects and/or Contract propagation.

    CyrusNajmabadi
    @CyrusNajmabadi
    1. it entirely depends on what 'someCondition' is (like a field/prop/parameter/local).
    if it's a field/prop, definitely not. indeed, it's the opposite. each time it will be read from teh original source
    if it's a parmaeter/local. sure. however, it will depend on what is in the rest of hte method
    for example, if it's captured by some lambda and the lambda mutates it, then it will be different
    so, absent any more info about the code, i cannot say
    but i can certainly say you can only depend on this if your code operates in a very specific fashion.
    Adam Speight
    @AdamSpeight2008
    @CyrusNajmabadi
    How do we advise the programmer that this suitable exists, and is a code fix possible? I can only think of using sencasing it within a SyncLock(someCondition) ... End SyncLock We'd need the notion of immutable usage, and enforcement.
    Cory Smith
    @DualBrain
    * What prevents evaluate of someCondition being different from prior evaluation.
    You could put this variable in an immutable property/class...

    Otherwise, if the variable you are testing is not a local variable but instead a property of a class... the class could literally return a different result each and every check.

    Alternatively (I believe) this could be resolve by using Select Case.

    If it doesn't would a copy of the value of "someConditon" into "tmp" prior to the If Block, and rename the usage of "someCondition" with on this block to "tmp". Gain that guarentee.

    This would only be true if the developer honored this restriction.

    (Unless, of course, that variable was some sort of immutable property.)
    Adam Speight
    @AdamSpeight2008
    Adam Speight
    @AdamSpeight2008
    'Select Caseis predominantly is lowered to anIf ... Then` structure, so same suitable effect exists. In a "pure" single threaded non-eventing/interuptting evaluation it trivial and can be ignored. In a non-linear evaluation environment it does, so assisting the programmer to have awareness, or code-fix.
    Cory Smith
    @DualBrain
    I suppose I'm not following what is trying to be resolved here. I mean I do get the idea that the value could change under some conditions... but there are many ways to ensure that the code executed against a variable is safe (isn't going to change). If you pass in a variable to a method, that variable is (if Byval) local to that routine... so the only code that will modify that variable within the scope of the If checking is completely within the context of the If statements. So multi-threaded code shouldn't be an issue (in this example - which I feel is more common). In the event the value does change, there is a high possibility this was what the developer desired/intended. Now if we talk about properties... the value of the property is controlled by the object and one would have to wonder under what conditions that this would be an issue. In some circumstances, the value changing between the If statements may actually be desired. There are also two very different Select Case models (lowering)... as you said there is one that is basically a bunch of individual If statements while the (ultimately) desired lowering would be the "jump list". To my knowledge, the "jump list" version would evaluate the value once and is significantly faster than and something I tend to try to setup for under normal conditions. If the desire is to make the variable unchanging, there are (of course) mechanisms in place to assist with that as well. But I don't think there is a "blanket" mechanism or even warning that would cover all the scenarios and my gut is telling me this would create more confusion than it would potentially address any sort of pitfall. In other words, I can't imagine how one would look at the code a know whether or not this might be a potential issue across all the possible scenarios that could exist. I could, of course, be missing something... so there is always that. ;-)
    CyrusNajmabadi
    @CyrusNajmabadi
    How do we advise the programmer that this suitable exists,
    I don't know how to read your question.
    and is a code fix possible?
    A code fix for what?
    It's unclear what the problem is that you're even describing.
    Mohammad Hamdy Ghanem
    @VBAndCs

    Of course it would be better if intellisense take snippets shortcuts into account.

    A nice surprise: @sharwell pointed out that there is an option to trun on this feature!
    https://github.com/dotnet/roslyn/issues/37049#issuecomment-998997945

    Adam Speight
    @AdamSpeight2008
    It's hard for me to explain, as it very abstract especially the exact terms.
    I think that if we consider Nullable References as a form of "value tracking" (is this allways non-null etc), we could also in theory also track mutability of "variable".
    Adam Speight
    @AdamSpeight2008
    If the specification states that, within this context / region / section. That these variables (something, otherthing) are to be treated as having a single immutable value (or the "value" will not be altered.). Is there enough evidence to support or proof that statement, from the specification.
    Cristian FRC
    @cristianlt23
    I wish you all a Merry Christmas and a New Year full of achievements!๐Ÿงก ๐Ÿ’› ๐Ÿ’š ๐Ÿ’™ ๐Ÿ’œ
    Cristian FRC
    @cristianlt23
    @VBAndCs , I missed you, I'm glad you came back!!!
    Mohammad Hamdy Ghanem
    @VBAndCs
    Thanks @cristianlt23 .I am in a c# mode now. Happy new year.
    Luckly, I am dicovering somethings about vb via c#, like the cw snippet, and adding a GetEnumeration inner or extension method to classes to be supported with for each. This allows using this syntax for example
    Foe Each i in (1, 5)
    Mohammad Hamdy Ghanem
    @VBAndCs
    Console.writeline(i)
    Next
    Sorry, GetEnumerator.
    Using gitter app.
    Mohammad Hamdy Ghanem
    @VBAndCs
    Imports System.Runtime.CompilerServices
    Public Module Tools
        <Extension>
        Public Iterator Function GetEnumerator(
                       range As ValueTuple(Of Integer, Integer, Integer)
                   ) As IEnumerator(Of Integer)
            Dim start = range.Item1
            Dim [end] = range.Item2
            Dim [step] = range.Item3
            If ([step] > 0) Then
                For i = start To [end] Step [step]
                    Yield i
                Next
            Else
                For i = start To [end] Step [step]
                    Yield i
                Next
            End If
        End Function
    End Module
    
    Sub Main(args As String())
            For Each i In (1, 10, 2)
                Console.WriteLine(i)
            Next
    End Sub