Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    CyrusNajmabadi
    @CyrusNajmabadi
    you've seen people here file issues that have been fixed :)
    Cory Smith
    @DualBrain

    Di you accept new proposals? Or at least, do you fix well known errors?

    Changes have been made... they continue to be made. Suggesting a change isn't any sort of guarantee, but not suggesting is a sure fire way to not have it happen. When suggesting, you need to provide context... reason... benefit... etc. behind the suggestion; otherwise, without context, it will most likely be rejected. Again, having context is... again... no guarantee that it will be accepted. Furthermore, suggesting it... alone... will most likely not result in getting it done (unless it is a verifiable bug... and then... maybe... most likely... possibly). The policy, as best I know it, is to make a strong case (positive point of view being key) for the why and, only then, if it is approved should you spend more time working on it as a community contribution.

    In other words... and I'm a full believer of this myself... the "automatic answer" for any change to the language at this point is "No.". So a very strong case has to be made for any language changes and improvements... this is still true to some degree when "fixing bugs" as there is a possibility that fixing it could create additional issues. So I would recommend that you prepare for the answer of an "automatic 'No'" when making the initial request and consider carefully all the the supporting evidence you can to back up the request from the very beginning to help reduce the possibility of the to be expected "automatic No". (To be clear, I'm using these terms... there is nothing official or even evidentiary to these terms from the teams... these are just the general mindset that I work with when I consider suggestions that I'm sending.)
    Mohammad Hamdy Ghanem
    @VBAndCs
    Why can't we use For each on a type that implements IEnumerator ?
    For each works on the IEnumerable types to call GetEneumerator. Why cam't it just skip this step and work on IEnumerator directly if it is the type we have?
    SB compiler has this enumerator:
    Public Class TokenEnumerator
            Implements IEnumerator(Of TokenInfo)
    End Class
    Mohammad Hamdy Ghanem
    @VBAndCs
    It is the return type from the LineScanner, so I can't use it with for each.
    I used this trick to make it work:
        Public Class TokenEnumerator
            Implements IEnumerable(Of TokenInfo)
            Implements IEnumerator(Of TokenInfo)
    
            Public Function GetEnumerator() As IEnumerator(Of TokenInfo) Implements IEnumerable(Of TokenInfo).GetEnumerator
                Return Me
            End Function
    
            Private Function IEnumerable_GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
                Return GetEnumerator()
            End Function
    End Class
    So, it is an IEnumerable and I Enumerator in the same time. Hilarious :D
    I hope VB and C# allow for each to handle this so we don't have to make the code that unnecessary verbose!
    CyrusNajmabadi
    @CyrusNajmabadi
    Why are you implementing an iterator directly?
    Instead of an ienumerable in the first place?
    I hope VB and C# allow for each to handle this so we don't have to make the code that unnecessary verbose!
    I think you'd have to explain why your code was doing this weird thing.
    Here's the thing, the language generally changes to make common ecosystem patterns easier. It rarely changes to make one off strange cases better.
    Mohammad Hamdy Ghanem
    @VBAndCs
    I hsve an easy solution to intialize readonly collection in vb. Just inherit the class, override the collection with a wrapper, abd do the trick

    Class StackPanel2
    Inherits StackPanel

    Public Overloads Property Children As UIElementCollection
        Get
            Return MyBase.Children
        End Get
        Set(value As UIElementCollection)
            MyBase.Children.Clear()
            For Each child In value
                MyBase.Children.Add(child)
            Next
        End Set
    End Property

    End Class

    Mohammad Hamdy Ghanem
    @VBAndCs
    Vb treats nothing as the def val of value types, and string as a special case,
    So if x iis nothing, the condition x="" is true
    But this doesn't apply to turnery if.l, as it does consider "" a non null value
    In vb i expect to treat "" as Nothing
    John Moreno
    @jrmoreno1
    I don’t think you are talking about the ternary operator, but rather the null coalesce operator, where that wouldn’t make sense as it is explicitly checking for null. For the same reason if (“” is nothing) then will not match
    Cory Smith
    @DualBrain
    Yes, there are two versions of if(); once that is if(thisvalueistrue, usethis, otherwiseusethis) and if(hasavalueusethis, otherwiseusethis).
    Paul M Cohen
    @paul1956
    In both cases about if you pass a string with the value "" it will return "" and if you pass a string = Nothing it will return otherwiseusethis. There are 2 helper functions in String class that should be used to get consistent behavior. String.IsNullOrEmpty and String.IsNullOrWhiteSpace.
    Adam Speight
    @AdamSpeight2008

    To test to see if a value is within a range of numbers, we can use a simple expression like min <= value and value <= max.
    Is there an equivalent expression to test if a value is within a range that uses a stepping.
    I think the following function would suffice, for ascending range. ​Not too sure about descending ranges.

        <extension>
        function IsBewteen( value As Integer, min As Integer, max As Integer, stepping As Integer) As BooleanIf min <= max Then
                If stepping <= 0 Then Throw New ArgumentOutOfRangeException(NameOf(stepping), "Must have a non-zero positive value.")
            Return ((min <= value) And (value <= max)) AndAlso ( (value Mod stepping) = (min Mod stepping) )
            Else
                If stepping >=0 Then Throw New ArgumentOutOfRangeException(NameOf(stepping), "Must have a non-zero negative value.")
                Return value.IsBewteen(max, min, -stepping)
    ​     End IFEnd Function

    There is still an issue around the Integer.MinValue and Integer.MaxValue, any suggestion on how to manage them with out resorting to enclosing it in a try ... catch block?

    Mohammad Hamdy Ghanem
    @VBAndCs
    Are the community willing to take over ghe fate of vb?
    Cory Smith
    @DualBrain
    @VBAndCs ummm, because people like @paul1956 and I (to mention a couple) are doing nothing to improve VB directly... nothing at all.
    Paul M Cohen
    @paul1956
    @AdamSpeight2008 what is "an issue around the Integer.MinValue and Integer.MaxValue, any suggestion on how to manage them with out resorting to enclosing it in a try ... catch block?"
    John Moreno
    @jrmoreno1
    @AdamSpeight2008: just the obvious of checking against min/max manually, be a bit complicated but doable
    Are allowing arbitrary step size?
    Paul M Cohen
    @paul1956
    I don't understand purpose of stepping
    CyrusNajmabadi
    @CyrusNajmabadi
    me neither
    what is the use case where you are doing a range check.. and you have some concept of a step?
    John Moreno
    @jrmoreno1
    Find the difference between min/max and then compare that to step and MaxValue-value
    CyrusNajmabadi
    @CyrusNajmabadi
    when is that useful?
    when would i use IsBewteen?
    John Moreno
    @jrmoreno1
    @CyrusNajmabadi : don’t know his use case, but it could be useful when examining a for loop with a step
    Although I have never had a for/step with values anywhere near the limits….
    CyrusNajmabadi
    @CyrusNajmabadi
    i'm asking what hte use case is because i don't understand it :)
    i genuinely can't even figure out what that code really does :)
    Paul M Cohen
    @paul1956
    I think it is for a "For i as byte = Byte.Min to Byte.Max Step anything" and I don't believe it ever worked correctly in VB when step is used especially when it is negative. But I can't point out what is broken, there was a bug report when I first started looking a Roslyn. This goes back a very long time and I have never used it.
    CyrusNajmabadi
    @CyrusNajmabadi
    i understand stepping in teh context of a for loop
    it's how the value is incremented/decremented at the end of each pass.
    what i don't undertand is hte IsBewteen method and what it does
    Paul M Cohen
    @paul1956
    I think it was proposed to replace the For loop to handle the edge cases. While i.Inbetween(Byte.Min, Byte.Max, Step:=2) But maybe Adam had something else in mind.
    Adam Speight
    @AdamSpeight2008

    I want to fairly efficiently to check if a value, is within two bounds but that range isn't continuous but has a regular stepping.
    start := 0, finish := 10, stepping:= 2' Ifvalue:=2then return true. Ifvalue=7` return false.
    The following works, assuming we if pass in arguments that satisfies the for loop conditions.

    Function IsBetween(value as Integer, start As Integer, finish As Integer, stepping As Integer ) As Boolean
      For index = start To finish Step stepping
        If index = value Then Return True
      Next
      Return False
    End Function

    But it is rather inefficient, since we could check if a value is within some bounds simply using Math.Min(start, finish) <= value and value<=Math.Max(start, finish). But this doesn't take into account a stepping. My question is, "Is there an efficient way to do that?"

    CyrusNajmabadi
    @CyrusNajmabadi
    why do you need the for loop?
    ignoring negatives for now, isn't this just seeing if the distance from start to your value is a integer multiple of your step?
    so like... (value - start) % step == 0?