I suggest you ...

Allow multiple variable names with single type specifier in functin call

Current:
Public Function DoSomething(x As Integer, y As Integer, w As Integer, h As Integer, Value As Integer, Name As String, Count As Integer) As Boolean

Propsed:
Public Function DoSomething(x, y, w, h, Value As Integer, Name As String, Count As Integer) As Boolean

All variables x, y, w, h, Value would be of type Integer, like in Dim statement.

16 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    PavlinIIPavlinII shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    15 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • AnonymousAnonymous commented  ·   ·  Flag as inappropriate

        @PavlinII : Yeah I Agree with you, it's make uneasy to read when the lines meet upper than 10000 line code. When I create a long parameters for function for example 12 / 13 parameters, I create a structure or class, but if your suggest was available in next release vs, it's useful .. ;-)

      • PavlinIIPavlinII commented  ·   ·  Flag as inappropriate

        Anonymous: Last line of my comment from October 27, 2011:

        > - I could use VB6 notations using %, @, ! and other special characters, but it does not meet my request for easily readable code.

      • AnonymousAnonymous commented  ·   ·  Flag as inappropriate

        Public Function DoSomething(x%, y%, w%, h%, value%, name$, count%) As Boolean
        Return True
        End Function

        It's more simple and ready to use..

      • PavlinIIPavlinII commented  ·   ·  Flag as inappropriate

        You did not understand that this proposal extends current state and does not remove anything.

        Current longer syntax have to be preserved of course.

      • PavlinIIPavlinII commented  ·   ·  Flag as inappropriate

        Nick Roberts:
        DoSomething with x, y, w, h is just an example to illustrate the issue. You can always refactor many arguments into DoSomething(Args As DoSomethingArumentsWrapper) of course.

        But refactoring adds even more code and forces consumer of function to wrap arguments - add unnecessary wrapper creating code when more useful overload member is available.

        Check Rectangle class constructor. location+size constructor is available. And x+y+width+height is available as well. Selection depends on specified scenario.

        My original suggestion would save some code in scenarios when:
        - you just have more arguments of same type
        - you want to provide suitable overloasd (location+size and x+y+w+h)
        - you have more arguments of same type that can't be grouped into meaningfull wrapper (SHA as you mentioned or: From, To, CC, BCC, ReplyTo, Subject, Body etc.)
        - you do not want to write argument wrapper for small private helper functions
        OR
        - when you're writing that wrapper and you want it to have useful constructor ;)

        Inside that wrapper would be for example (prefixes ommited):
        Private x, y, w, h, Value As Integer
        And would just copy paste this into constructor parameters. Now, you have to copy it and add 4x As Integer clause.

        Even Point and Size2D constructors could use suggested feature.

        I think it might be very useful.

      • Nick RobertsNick Roberts commented  ·   ·  Flag as inappropriate

        Hmmm. In your example (perhaps this is not fair) I would rather write:

        Structure Point
        Public X As Integer
        Public Y As Integer
        Public Sub New(X As Integer, Y As Integer)
        Me.X = X
        Me.Y = Y
        End Sub
        End Structure
        Structure Size2D
        Public Width As Integer
        Public Height As Integer
        Public Sub New(Width As Integer, Height As Integer)
        Me.Width = Width
        Me.Height = Height
        End Sub
        End Structure
        Public Function CanDoSomething(TopLeft As Point, Size As Size2D, Value As Integer, Name As String, Count As Integer) As Boolean
        ...
        End Function

        Or better still:

        Public Function CanDoSomething(TopLeft As Point, -- top left corner of box
        Size As Size2D, -- width and height of box
        Value As Integer, -- median value expected
        Name As String, -- name of division to search
        Count As Integer) -- number of sub-boxes within box
        As Boolean

        In other words, I don't think this suggestion is likely to be genuinely useful very often.

        Occasionally it might be. E.g. a function that computes SHA takes eight parameters the same type (if I remember correctly).

      • PavlinIIPavlinII commented  ·   ·  Flag as inappropriate

        Nebire:
        Private Const x As ULong = 18446744073700000000UL
        This line works, of course. But UL suffix is declaring literal value type. My suggestion was about variable name/type declaration.

        It's different scenario than my original suggestion, but I think our misunderstanding is clear now.

      • NEBIRENEBIRE commented  ·   ·  Flag as inappropriate

        Then, how you define any like this:

        This line give error:
        Private Const x As ULong = 18446744073700000000

        This line give it's ok:
        Private Const x As ULong = 18446744073700000000UL

        This function need special chars for correct values. If you retire UI from 0 give error, if you retire 0, give error overflow in both cases.

        ' convert 4 bytes from an array to uinteger.
        Private Function Convert(ByRef Bytes() As Byte, ByVal Index As UInt32) As UInteger
        Return ((0UI Or Bytes(Index)) Or (0UI Or (Bytes(Index + 1)) << 8) Or (0UI Or (Bytes(Index + 2)) << 16) Or (0UI Or (Bytes(Index + 3)) << 24))
        'End Function
        dim X as UInteger = 0UI
        Does work for you, want or not want...

      • PavlinIIPavlinII commented  ·   ·  Flag as inappropriate

        NEBIRE: I'ts far from what I want. I want the code to be read easily.
        - hUL does not work for me.
        - I could use VB6 notations using %, @, ! and other special characters, but it does not meet my request for easily readable code.

      • NEBIRENEBIRE commented  ·   ·  Flag as inappropriate

        You may declare variables with type letters, like vb6.
        So: 'hUL' it's 'h as ULong' ... Don't is very different from you want.

      • PavlinIIPavlinII commented  ·   ·  Flag as inappropriate

        Adding {} is not good idea.
        - variables are declared here like Dim statement. And Dim statement's convention does not use {} in variable list.
        - variable names are not collection initializers in this case
        - {} are not necessary and does not add new information nor differentiate any other situation.

      • Adam SpeightAdam Speight commented  ·   ·  Flag as inappropriate

        I think this is good idea, be using the array literal syntax as way to group the parameter names
        Eg
        [code]
        Public Function DoSomthing( {x,y,w,h} As Integer, {ForeName, Surname } As String ) As Boolean
        [/code]

      Feedback and Knowledge Base