• (david) (unregistered) in reply to Minkey
    Anonymous:

    These guys obviously write my employer's accounts software:

    thismonthscash = salary / 12

    pay(employee,add(thismonthscash, bonus))

    transfer(thismonthscash, beerfund)


    That is the way we were taught to write COBOL
  • (david) (unregistered)
    Alex Papadimoulis:
    Private Function Add(ByRef Which As Integer, ByVal HowMany As Integer)
      Which = Which + HowMany
    End Function


    I don't like the variable name convention: I read that the original intention was
        Which = Which  + (HowMany * Which)

    By the way, += was a good way to do pointer arithmetic in languages which didn't directly support structured data arrays, and is an important construct when doing hardware integration where you want to specify that the receiving variable is not being read.

    In all other situations, it's a handy contraction for people who can't type.

  • (david) (unregistered) in reply to Brent Seidel
    Anonymous:
    I think that you could do this with an early version of FORTRAN. In one case you would wind up with 10 having the value of 15 through the rest of your program and in the other case 5 would have the value of 15. Made for some interesting debugging...


    All variables were 'by ref', and numbers were treated as pre-assigned variables (like some kinds of 'constants' in C). This made the compiler smaller and simpler, but at the cost of allowing you to overwrite constants like 1 or 10.

    And if you think THAT was interesting, many of the machines these FORTRANS ran on had no memory protection at all: an error in an array index would allow you to overwrite the operating system, bringing that down as well. It didn't make debugging any easier, but at least you KNEW that you had a bug....
    (david)
  • hypernewbie (unregistered)

    well, according to our software design and development school HSC syllabus, a function is a module of a system, and should do a specific, well documented, well defined process. Intrinsic documentation and internal documentation is also important, as the programmer is able to debug easily. Also, functional decomposition allows for easy debugging as the bug can be tracked down to a specific location.

    so therefore, thats a perfectly good function. it does a well defined specific action, it adds two numbers together.it also has intrinsic documentation, as it has good variable and function names.

    would someone please get us rid of that hsc subject?

  • john autry (unregistered)

    so, like, where's the comment?

  • john autry (unregistered)

    on my way back out of this tangle by repeatingly clicking on the back button which is actually a left button, it occured to me that I bet a bunch of you have never wondered how long it takes a dead cat to begin smelling bad.

    I know!!!

    I just bet you dont.

    John

  • Mikeyd (unregistered) in reply to squirrel

    I think you're attempting to illustrate the different between macros and function, but nonetheless you just wrote

    foo() = foo() + 1;

    (a) You need an lvalue (c) It makes no sense to pass foo() by reference

    No, it's an array access based on the result of a function, so it's fine. arr[foo()] = arr[foo()] + 1. Nothing wrong with that.

    (b) You need to store the result somewhere anyway, so it is no more complicated to write a = a + b

    No you don't, you just call the function and it modifies the first parameter. So you only need to put it in once, rather than twice.

  • Richard (unregistered) in reply to is it that hard?

    "Is it that hard" wrote - <font color="#0000ff">What is 8</font>

    Well at the most basic level, 8 is a number. It is one more than 7, and one less than 9.

    If you read Terry Pratchett you'll find that 8 is quite special.

    8 appears in lots of places. I'm sure you can find a special mention of 8 in whatever culture/religion you practice. ;-)

  • thooper (unregistered) in reply to Antony
    Anonymous:

    The only thing i can see wrong with this function is that the author was unaware that the += operator exists. Sure, he should probably have written it so that it doesn't use a byRef design, but that doesn't make it wrong.



    This was my thought exactly.  Instead of taking advantage of an operator within the language, lets write a method or a 'sub' to do exactly the same thing.  It would almost be as good as writing your multiply function that does nothing more then the '*' operand:

    <font face="Courier New">function multiply(byref which as integer, byval howmuch as integer)
        which = which * homuch
    end function

    <font face="Times New Roman">which is </font></font><font face="Times New Roman">absolutly useless.  It only complicates the code and increase memory overhead since the function call would require space on the heap to pass the pointer of which and howmuch value and THEN actually perform the action/operation to make the addition.</font>
    <font face="Courier New">

    </font>
  • shawnz (unregistered) in reply to Alex Papadimoulis

    Well, it doesn't need to return anything. Which is passed ByRef, so adding to Which adds to it in the original scope of the variable.

  • shawnz (unregistered) in reply to Foo Bar

    -double post alert-

    Anonymous:

    dandare100:
    We have a name for guys like you here "TheDoom".

    You are a "drag and drop doos"..............

    "c# and vb.net are far superior to java" .....bwahahwahawwaaaa

    Jeez what a chop..........

    So tell me, is the actual "pointer" passed by value with reference to an object, or .....oh sh*t, hang on .....can't talk object orientated stuff with C# .NET guys.......sorry dude

    Fell for it hook, line and sinker noob......nice troll Doom....lol msil on chipset.....haha



    Well, the post is half right. IL is far more advanced than java bytecode, but that doesn't mean it preforms better. Also, IL _can_ be put on a chip -- MSN Direct watches have the framework.
  • Greg Beamer (unregistered)

    Yes, Virginia, you should not use return values to return something from a function. Interestingly enough, VB.NET's method of making an indexer allows from some really strange code. Try this one ... it works!

    <FONT face="Courier New">Public Property SomeValue(ByVal UselessCrap As Integer, _
                ByVal MoreUselessCrap As Integer) As String
      Get
        Return _someValue
      End Get
      Set(ByVal Value As String)
        _someValue = Value
        _uselessCrap = UselessCrap
        _moreUselessCrap = MoreUselessCrap
      End Set
    End Property</FONT>

    And, yes, I have run into one person (who did not understand constructors) who actually used it this way. To give some benefit of the doubt, he did add this overload of the Property to avoid lengthy signatures when attempting to return the property:

    <FONT face="Courier New">Public Property SomeValue() As String
      Get
        Return _someValue
      End Get
      Set(ByVal Value As String)
        _someValue = Value
      End Set
    End Property</FONT>

    :-)

  • Seann Alexander (unregistered) in reply to rammadman
    <quote>
    The question is how is result returned to the caller.
    </quote>


    <code>
    Private
    Function Add(ByRef Which As Integer, ByVal HowMany As Integer)
    Which = Which + HowMany
    End Function
    </code>

    Which = Which + HowMany

    Which is sent to Add() By Reference.
    When Which is assigned, it is modifying the value in the parent function.

    VB lets you do this.

    <code>
    Private Sub CommandButton1_Click()
    Dim which As Integer

    Call Add(which, 2)
    MsgBox which
    End Sub

    Private Function Add(ByRef which As Integer, ByVal HowMany As Integer)
    which = which + HowMany
    End Function
    </code>

    captcha, wtf <--- ----
  • Liz (unregistered) in reply to Jimmy Jimmy

    I couldn't agree more.

  • Different Anonymous (unregistered) in reply to JS

    Anonymous:
    Actually, the fact that it's a function means the "byref" is wrong, and in fact means the whole thing is wrong.

    You've never had a function populate objects by reference and return a status code?

  • Philip P wolcott (unregistered)

    Please Clean the erros this computer.Thank you,

            Sincerly,

                      Philip P Wolcott

     

     

  • Etienne (unregistered) in reply to Alex Papadimoulis
    Alex Papadimoulis:

    * It's a function, right? (what's it return?)

    You're passing "Which" by reference, so you're modifying the variable passed to the placeholder "Which" itself...

    <FONT face=Georgia size=1>a=10;</FONT>

    <FONT face=Georgia size=1>b=15;</FONT>

    <FONT face=Georgia size=1>add(a,b);</FONT>

    "a" now equals 35...

     

  • Martin (unregistered)

    This function CAN make sense IF it returns something...
    My guess is this was a replacement for a C# construct where the addition operator also returns the result of the addition:

    //C#
    if ( (someValue += 2) > 100 ) { ...

    'VB
    Private
    Function Add(ByRef Which As Integer, ByVal HowMany As Integer) as Integer
    Which += HowMany
    Return Which
    End Function

    'then, for example, you can write...
    If Add(
    someValue, 2) > 100 Then
    ...

    'instead of
    someValue += 2
    If
    someValue > 100 Then
    ...

    p.s. my captcha was truthiness! Go Colbert!!

  • thanh (unregistered) in reply to dandare100

    introduce c#winsock and c#connect22computer

     

  • Kapow (unregistered)

    I debugged it.

    Private Function Add(ByRef Which As Integer, ByVal HowMany As Integer)
      Equals(Which, Which + HowMany)
    End Function
    
    Private Function Equals(ByRef Which As Integer, ByVal Other As Integer)
      Which = Other
    End Function

Leave a comment on “Which is on HowMany?”

Log In or post as a guest

Replying to comment #:

« Return to Article