• Anonymous (unregistered) in reply to If I were King...

    Finally someone displays some common sense around here!

    It amazes me that the sort of people who frequent this site, who you would imagine would all be highly competent programmers (and there clearly are a few...) simply do not understand pass by reference. In my opinion this means they should not be a professional developer.

    In interviews I have posed the following questions to candidates who claim several years experience in C and Java:

    What does this C function do?: (then present a simple (if stupid) C function that does an add operation similar to the one in this WTF, using one pointer-to-int and one int.)

    Explain what happens in Java when evaluating string1 == string2 versus what happens when evaluating string1.equals(string2)

    The results are frankly, horrifying. "Senior developers", "team leads", "head programmers" all crumble into dust. Don't let this be you - UNDERSTAND what you are instructing your computer to do!

     

     

     

     

     

     

  • (cs) in reply to Are you deluded?

    Yeah... what's up with that?

    This is a perfect example of de-coupling the numbers from math. Similar to de-coupling the letters from the alphabet, as in cryptography. The fact that the initial value is a ref, suggests that it is a moving target, and the function add() is simply, an effect on the target. One would only hope there is a reason for the reference, and that there are similar functions that affect the target, such as div, mult, sub. And that the target is really an array of possible targets, run throught a gamet of possibilities. 

    Or perhaps the function is really as pointless as it appears. 

  • Eric L (unregistered) in reply to MaGnA

    MaGnA:
    I think some people are confused about the purpose of this website. It's not "What does That Function do?" :) If something is posted here, it is safe to assume that there's something wrong with it...

    Funny enough, this is the fist time I've seen a post I couldn't say that for. Other than maybe the function not returning the value and using ByRef, but thats not a WTF, and neither is moderately bad naming structure. since those are local to the function, and the function is all of one line. Granted that sort of though process gets you into trouble later. but in the context of this piece of code its lame, but no WTF like yesterdays access db :)

    captcha - perfection

  • (cs) in reply to olddog

    Or... perhaps it's a primitive function for a home spun quick-sort routine where the ByRef[which] is an index to an array of pointer/handles of sort values, and the ByVal[HowMany] is the bi-section of the candidates.

    I'm trying really hard to put a positive spin on this sucker.

  • (cs) in reply to Ben Adams
    Ben Adams:

    Another effective [debugging] technique is to explain your code to someone else. This will often cause you to explain the bug to yourself. Sometimes it takes no more than a few sentences, followed by an embarrassed "Never mind, I see what's wrong. Sorry to bother you." This works remarkably well; you can even use non-programmers as listeners. One university computer center kept a teddy bear near the help desk. Students with mysterious bugs were required to explain them to the bear before they could speak to a human counselor. - B. Kernighan & D. Pike (in "The Practice of Programming" pp. 123)

     

    Hmm, Love the comment, and can see how it could work.  However I can just see the flood of calls to the helpdesk afterwards:

    User:  I still can't print to the printer.

    Help Desk:  I'm sorry sir, I don't have any record of your contacting the help desk.

    User:  But I told the teddy bear . . .

  • Cherry Barnet (unregistered)

    This function does not return a value.  If it's a database project, you could write the result to a table.  Or otherwise use a file.

    CB

  • asdfsadfasf (unregistered) in reply to Are you deluded?
    Anonymous:

    This is a function which ADDS TWO NUMBERS

    Addition is such a basic operation, its even supported in ASSEMBLER!  For goddsake, it's even implemented in SILICON!

    And this guy wrote a function to do it?

    I assume there is a 'Sub', 'Multiply' and 'Divide' function as well?

     

     

    Why bother using someone else's addition operation, when I can just make my own, more superior addition function!!!!
  • UnKnown (unregistered)
    <FONT color=#808080><FONT color=#000000>Its for added security,</FONT> </FONT><FONT color=#000000>so they can track who is adding all the time and taking resources.</FONT>
    Private Function Add(ByRef Which As Integer, ByVal HowMany As Integer)
    

    Which = Which + HowMany
    WriteToLog("Add",GetUserID()) End Function

  • (cs) in reply to Anonymous
    ReallyAnonymous:

    ...

    It amazes me that the sort of people who frequent this site, who you would imagine would all be highly competent programmers (and there clearly are a few...) simply do not understand pass by reference. In my opinion this means they should not be a professional developer.

    ...

    I'm not sure where this 'people frequenting this site ought to be competent' comes from. My guess is that TDWTF is like a magnet to stupid and incompetent people who have an urge to feel superior and laugh at other people's shortcomings.

    (This is obviously no different from us inteligennt and commpetent people seeking amusement, but I'm not sure we're even in majority.)

  • byWTF (unregistered) in reply to impslayer
    impslayer:
    ReallyAnonymous:

    ...

    It amazes me that the sort of people who frequent this site, who you would imagine would all be highly competent programmers (and there clearly are a few...) simply do not understand pass by reference. In my opinion this means they should not be a professional developer.

    ...

    I'm not sure where this 'people frequenting this site ought to be competent' comes from. My guess is that TDWTF is like a magnet to stupid and incompetent people who have an urge to feel superior and laugh at other people's shortcomings.

    (This is obviously no different from us inteligennt and commpetent people seeking amusement, but I'm not sure we're even in majority.)



    Nice of you to drop by and visit us "Birds of a Feather"
  • (cs)

    The really interesting question is:

    XYZ = 5
    XYZ = Add(XYX, 3)

    What is the value of XYZ when the Add function returns?



  • TheRoper (unregistered)

    I dont really see this as a What TF, more as a Why TF

    My biggest issue with this is that it will change whatever variable I pass in for Which,

    So my calling code has to be aware of this, If i dont want to change the value of the parameter i am passing in then the calling code will get messy. As i have to assign a temp variable to see the result i.e.

    <FONT color=#0000ff size=1>Dim</FONT><FONT size=1> a </FONT><FONT color=#0000ff size=1>As</FONT><FONT size=1> </FONT><FONT color=#0000ff size=1>Integer</FONT><FONT size=1> = 5</FONT>

    <FONT color=#0000ff size=1>Dim</FONT><FONT size=1> x </FONT><FONT color=#0000ff size=1>As</FONT><FONT size=1> </FONT><FONT color=#0000ff size=1>Integer</FONT><FONT size=1> = 0

    x = a

    Add(x, 10)

    </FONT>
  • anonymous (unregistered) in reply to bit
    Anonymous:

    We all know that you could do i = i + 5. But

    Add(nProdQuantity,3)

    is faster to type and less error-prone than

    nProdQuantity = nProdQuantity + 3

    It's a stupid example, but you get it.   



    I dont know VB, maybe B able to pass functions ar arguments (example is provided as fake Basic, I dont know VB)

    <font color="#0000ff"></font><font color="#0000ff" face="Courier New">Function ForEach(ByVal FunctionExec As Function, ByRef Operator As Array, ByVal Params as Array)
      FOR T=0 TO T<LENGHT(Operators) THEN
        FunctionExec(Operator[T],Params[T]);
      NEXT
    End Function</font>

    so you can do:

    <font color="#0000ff" face="Courier New">ForEach( Add, Accounts, Tax )</font>

    This can be usefull If you have assembler, c , perl, python or ruby background and you code VB.

    --Tei
  • checkup21 (unregistered) in reply to anonymous
    Anonymous:
    Anonymous:

    We all know that you could do i = i + 5. But

    Add(nProdQuantity,3)

    is faster to type and less error-prone than

    nProdQuantity = nProdQuantity + 3

    It's a stupid example, but you get it.   



    I dont know VB, maybe B able to pass functions ar arguments (example is provided as fake Basic, I dont know VB)

    <font color="#0000ff"></font><font color="#0000ff" face="Courier New">Function ForEach(ByVal FunctionExec As Function, ByRef Operator As Array, ByVal Params as Array)
      FOR T=0 TO T<LENGHT(Operators) THEN
        FunctionExec(Operator[T],Params[T]);
      NEXT
    End Function</font>

    so you can do:

    <font color="#0000ff" face="Courier New">ForEach( Add, Accounts, Tax )</font>

    This can be usefull If you have assembler, c , perl, python or ruby background and you code VB.

    --Tei



    sorry pal. It can not. VB.NET arrays _can_ start with index 1 (i will not discuss this over and over). The For Each statement detects this for itself. But "<font color="#0000ff" face="Courier New">FOR T=0 TO T<LENGHT(Operators) THEN" <font color="#000000">will not</font>. <font color="#000000">You will most likely miss the last element.</font> <font color="#000000" face="Arial" size="2">If you wanna know more. Google yourself, or better: use the debugger!</font><font face="Arial" size="2">
    </font>
    </font>
  • Marc (unregistered)
    Alex Papadimoulis:
    Private Function Add(ByRef Which As Integer, ByVal HowMany As Integer)
      Which = Which + HowMany
    End Function


    This code reminds me of the days I was hired to assist on a VB456 (cant remember the version) project.
    One day I came across the following function:

    <font color="#008000">' 10 lines of standard function description here
    '
    ...
    '
    </font>Private
    Function ConcatString(ByVal String1 As <font color="#0000ff">String</font>, ByVal String2 As String)
    <font color="#0000ff">Return</font> String1 & String2
    End Function
    When I asked my coworker what the reason for this function was, he replied that the previous coder couldn't remember that in VB you use the & to concatinate strings. So they added a function for it.

  • Nonym (unregistered) in reply to Anonymous

    Anonymous:
    Jeff S:
    You know, even in languages with or without +=, you are allowed to write:

    a = a + b



    That can get quite lengthy. Imagine:

    Connect2Computer("Bean").Hardware.Disks.Partition[0].GetPersonalData().Dir("Paula").File("Brillant").GetContents () = Connect2Computer("Bean").Hardware.Disks.Partition[0].GetPersonalData().Dir("Paula").File("Brillant").GetContents () + 5

    What a funny thing. I'm wondering which language has ever tried to implement the assignment of a value to the result of a function. After all... Why not ! I assume it could reverse the execution of the function and give back the original parameters ?

    public function add5(int a) {
      return a + 5;
    }

    Now, let's say add5(3) = 10

    Would x = 7 ?...

  • TheDoom (unregistered) in reply to Nonym

    Yanks eh? Still trying to do it their own way, they tried but got knocked out of the World* Cup early doors.

    Also - Visual Studio.NET will point out stupid WTFs like this with the default warning settings. Anyone who can't see 'This function does not return a value' needs training. As language flame wars develop you should remember that c# and vb.net are far superior to java simply by virtue of the fact that they have used all the good ideas from Java and binned the rubbish ones. Build on this you dont need the rubbish JVM as all .net msil runs direct from the chipset.

    Loved the teddybear helpdesk thing.

    Also - agree with the 'incompetent noobs looking at mistakes to feel clever' point. I feel cleverer just by agreeing.

    *WHERE World = 'ALL_COUNTRIES' NOT 'USA'+'CANADA'

  • (cs) in reply to TheDoom

    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




  • Wake Up (unregistered) in reply to dandare100

    When will people learn there is a time and a place for every langauge. If you are so short sighted and narrow minded that you think that the language you choose to develop in is the best  for every situation you are sadly mistaken.

  • Hill (unregistered) in reply to Onanymous
    Anonymous:
    jovnas:
    doh...
    ment "sense" not "since"...


    Yeah, I was wondering why it didn't make any since...


    Me, too.  I tried "seines", but that didn't make any sins, and I'm feeling kinda evil today.
  • Bubu (unregistered)

    The /real/ WTF here ist the initial Posting... Let's go back to the roots:

     - In the beginning, there has been someone who /thought/, that he understood this -simple looking- function
     - afterwards he /thought/, that there would be a quite easier, equivalent solution (+=)
     - and posted it to WTF.

    But let's start to look at the gory details:
    1.) This function /is not/ the same as a "+=". I don't know anything about VB - but I assume, that "+=" is allowed for many datatypes - so let's say two longs. This function assures that the calling block uses at least one integer (I assume automatic conversion with byValue-Types but not with byReference). So when a caller uses something like "byte a ; add(a,5);" - the mistake could easily be spotted.

    2.) I never had the idea to code an add-Function, but now I know what I missed all the time :-) Assume you are sometimes working with a german keyboard-layout, sometimes on a french, sometimes on an US, ... - both "+" and "=" are always on different keys... Big problem. Assuming 50000 Programmers working 10 times a day on different keyboards, they sacrify at least 5 minutes a day for "refinding" the right "+"-key, so throughout a year, the company will lose some trillion USD. So after years of losing dollars and competitions - finally the ultimate "add"-function was built... Voila: No more "+" or "="-seeking... And... take a closer look at the clever name of the function:

    Function-names with an "X" or "Y" would be a stupid solution (as they also change place in different keyboard-layouts).

    So after years of searching, an intuitive name "add" was born. I'm fascinated !

  • (cs) in reply to AlphaGeek

    AlphaGeek:
    The really interesting question is:

    XYZ = 5
    XYZ = Add(XYX, 3)

    What is the value of XYZ when the Add function returns?

    The function increments it to 8, then the returned value of zero overwrites it: zero

  • creaothceann (unregistered) in reply to Marcelo

    quoted from Marcelo:
    > i used to only know VB and i hated language flame wars because I was on the weaker side.
    LOL! Brilliant!

    > steering as far from pascal as humanly possible.
    I agree if you meant Wirth's original Pascal. Delphi's Pascal > *

  • .Net fanatic (unregistered)

    Looks to me as this code is a left over from switching from old ASP to ASP.Net. In ASP the return value of a Function is implicitly a Variant if it is not specified (still the wtf is that no value is returned). So this will introduce 2 more WTFs:

    1. a function that does not return a value should be declared as Sub

    2. Integer in old ASP is 2 byte while it is 4 byte in .Net

    So long ... and cheers that site is awesome :)

    PS: cba to read all 129 comments so forgive me if someone did already point that out :P

  • Rob Garrett (unregistered) in reply to a possible explanation:
    Anonymous:
    Since the += operator does not exist in VB6, and it is possible to import VB6 code into .NET, this could simply be a remnant from a convenience function ported from a VB6 app.

    Sure it could have been rewritten to use += (in every instance of its usage, and moreover cannot be changed using a simple Find..Replace) it would be a wasted effort to change something that works, even though it is ugly.

    Not a WTF.


    Maybe so, but it's still a WTF in my opinion because the whole function could have been replaced by in the first place:

    Which = Which + HowMany

    Consider the performance implications of using a function/method to perform a simple addition.  Under the hood, the function translates into low-level code that:

    1. pushes two parameters on the stack (the first being a reference pointer - an address)
    2. pushes the current instruction pointer on the stack
    3. creates thread local storage for any local variables (even if we have none). 
    4. jumps to the function address
    5. performs the addition (see steps 1-4 below)
    6. pops the original instruction pointer
    7. pops the original parameter values

    Contrast that with a simple addition operation which translates into:

    1. Move contents of "Which" (memory value) into a register
    2. Move contents of "HowMany" (memory value) into a register
    3. Perform a register addition
    4. Copy register result into "Which" memory location.

    A lot of overhead for a simple math operation. 

    You do touch on an interesting point though - there are a lot of really bad VB.NET applications out there that started their life as a VB6 port.  When migrating VB6 code, why not do a good thing and rewrite the bad portions of code as part of the process?
  • Rob Garrett (unregistered) in reply to Jimmy Jimmy
    Anonymous:
    The real wtf is the lack of understanding passing by reference and value by the comment posters.


    Yes, it's scary!  I've worked with a lot of .NET programmers, and a lot of them don't know how reference parameters work - computer science 101.

    Oooer.
  • Kieren Johnstone (unregistered) in reply to Anonymous
    Anonymous:
    Jeff S:
    You know, even in languages with or without +=, you are allowed to write:

    a = a + b



    That can get quite lengthy. Imagine:

    Connect2Computer("Bean").Hardware.Disks.Partition[0].GetPersonalData().Dir("Paula").File("Brillant").GetContents () = Connect2Computer("Bean").Hardware.Disks.Partition[0].GetPersonalData().Dir("Paula").File("Brillant").GetContents () + 5


    You're using "Something.....GetContents() = value"?  Why??

    There's always a solution to messy things like that.  You'd never do that since Connect2Computer, Hardware, Disks, Partition, Indexer, GetPersonalData etc... any of those propery accessors/methods might fail - if you can think of a 'real' example similar to this one but just as long, I can explain how there's always a really nice, easy, far cleaner method of accessing things.  Creating an 'add' function is crap.

    (captcha: 1337)


  • Eric (unregistered) in reply to Guybrush Threepwood
    Anonymous:
    <font face="Courier New">Wow, I think this is the first thread I've seen where the responses are funnier and more WTF-worthy than the actual parent post.  Thanks Obi-Wan and Rammadman!</font>


    You must be new here.

    Captcha: knowhutimean
  • (cs) in reply to byWTF
    Anonymous:
    the REAL wtf... is that this Stupid language has to put by in front of a ref or a val.

    like wtf .. ref would have been fine, and so would have val

    byRef
    by reference, no shit huh sherlock?
    Ref would have been fine as anyone who grasps byRef knows wtf a Reference is.

    same goes for byVal.

    would anyone like to argue with me about this?
    I'm Ready.

    hehe j/k, seriously tho by is dumb.

    CAPTCHA:
     1337
    ...
    lame.


    This thread disproves your theory.  Even with the By, a lot of people didn't realize that it was being passed by reference.  Also, VB tends to be more descriptive rather than optimizing for shorter source code.  Think about it, are you limited in how much code you write each day by your typing speed?  Whould making all functions one or two letters help or hinder productivity?
  • anonymous (unregistered) in reply to Kieren Johnstone
    Anonymous:
    Anonymous:
    You know, even in languages with or without +=, you are allowed to write:

    a = a + b



    That can get quite lengthy. Imagine:

    Connect2Computer("Bean").Hardware.Disks.Partition[0].GetPersonalData().Dir("Paula").File("Brillant").GetContents () = Connect2Computer("Bean").Hardware.Disks.Partition[0].GetPersonalData().Dir("Paula").File("Brillant").GetContents () + 5


    A real world example, change "Which is on HowMany?" to "Re: Which is on HowMany?" in this forum:
    <font size="1">
    </font>[1]

    <font size="2">document.getElementById("_ctl0__ctl1_bcr_PostForm___PostSubject").setAttribute("value","Re:" + document.getElementById("_ctl0__ctl1_bcr_PostForm___PostSubject").getAttribute("value"));

    And a alternate:

    </font><font size="1">
    </font>[2]

    <font size="2">function id(nameThing){
        return document.getElementById(nameThing);
    }

    </font><font size="1">
    </font>[3]
    <font size="2">
    id("</font><font size="2">_ctl0__ctl1_bcr_PostForm___PostSubject").value = "Re: " +</font><font size="2">id("</font><font size="2">_ctl0__ctl1_bcr_PostForm___PostSubject").value;

    Yet another alternate:
    </font><font size="1">
    </font>[4]
    <font size="2">
    </font><font size="2">var xsubject = id("</font><font size="2">_ctl0__ctl1_bcr_PostForm___PostSubject");
    </font><font size="2">xsubject.value = "Re: " + </font><font size="2">xsubject.value;</font>
    <font size="2">
    </font><font size="2">Some people nowdays code with style [1].  Notice that the use of a simple function "id", is for more easy to read code. Better code.  So maybe this Add funcion is not a WTF.
    </font><font size="2">
    --Tei
    </font>
  • Bruteforce (unregistered) in reply to snoofle
    snoofle:

    AlphaGeek:
    The really interesting question is:

    XYZ = 5
    XYZ = Add(XYX, 3)

    What is the value of XYZ when the Add function returns?

    The function increments it to 8, then the returned value of zero overwrites it: zero


    Actually, the very moment it is returning I'd not be so sure it wont still be 8. The moment after it has returned 0.

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

    Ok, got it. Last time I coded was in VB 3.0 (yes, the 16-bit version) so I was blissfully unawares. :P

  • Bustaz Kool (unregistered) in reply to Buh Foon

    Anonymous:
    "Dah...which way did he go? Which way did he go?"

    Get it? That was a Looney Tunes reference.

    Ah, forget it. You people have no sense of humor.

    You're deth-th-th-th-picable!

  • Obi Wan (unregistered) in reply to Anon
    Anonymous:
    HowMany is declared at beginning of function (same as Which)


    The real WTF is (presumably) professional programmers who do not understand pass-by-reference (or apparently parameter passing at all).

    I never claimed I was a PROFESSIONAL programmer... :P

  • Anonymous (unregistered)
    byWTF:



    Hail, hail, fire and snow;
    Query Google, it will know.
    Where's the website that I seek?
    Friendly Google, answer me!

    Man, that is absolutely the Suck dude..
     that is one Dumb looking sign.

    like cmon' at least put some effort in, that is so bad it stinks.


    Wait, somebody missed a Star Trek referrence? On an IT site? Shameful....
  • (cs) in reply to Anon

    Anon:
    byte_lancer:
    It's not symmetric.
    Imagine the maintenance programmer who has to hack his way around to find why
    Add(10,5) and Add(5,10) return different values.
    Um, check that one again.

    Hey, give byte_lancer a break.  The return values are, of course, the same, but it's still not symmetric.  The side effects are different.

    In the first case, 15 gets assigned to 10 while in the second case, 15 is assigned to 5.

  • Jeff (unregistered)
    Alex Papadimoulis:

    For the VB.NET deprived, I've posted the first comment with some cliff notes provided by D.



    As opposed to the VB.NET depraved?
  • (cs)

    149 responses, and no one has pointed out how convenient this function is if they ever change the definition of "add"?

    --Rank

  • Foo Bar (unregistered) in reply to dandare100

    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

  • (cs) in reply to Jeff S

    Jeff S:

    You know, even in languages with or without +=, you are allowed to write:

    a = a + b

    No, no, no. You cannot write that unless you know that b = 0. Otherwise you get something like 1 = 1 + 2, which is wrong. That's why you need an Add function.

    And don't ever Let 1 = 1 + 2. If you let that happen, the universe will come to an end. Worse, my bank balance will be cut in third.

    --Rank

  • (cs) in reply to Brent Seidel

    Brent Seidel:
    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...

    I remember that horror - ran into it on my first job (FORTRAN IV) - debugged it all the way down to a constant, dumped the assembly code in the debugger - looked at the data segment, and the location for '5' had been overwritten, so all subsequent references at that, and all other points - for '5' got the location of '5', but used the subsequently changed value. - argh!

    Learned a *lot* from programming with those tools ;)

  • (cs) in reply to Phil the ruler of heck

    The anonymizers!! They do nothing.
    Ok, I've got to admit that I goofed up. Twice. Got my mind cluttered by thinking too much.
    And since this place cannot afford the luxury of a delete I let it be.
    I should not have used constants in my 1st example; my bad - should have passed my code through a compiler like the others do.
    I knew it returned the same values, but with two different side effects. Should have used post and pre-conditions to talk about the symmetric part.
    Hope I'm excused now.

  • dasmb (unregistered)

    You know, this is an example of a WTF that makes no sense at first, and then you find more and more legal uses the longer you look at it.

    A few good ones:

    1) Suppose the object that implements this add method already has an add method -- maybe it extends AddableObject or something -- that takes two Objects, itnent on adding the second to the first.  Now let's say the base class's method is very slow, uses reflection or something.  Our new Add(Integer, Integer) method would shadow Add, and be much faster for Add methods internal to the class where both arguments are guaranteed to be Integers.

    2) Suppose I have a delegate, Operation(Integer ByRef, Integer ByVal).  Now, when the object is in count up mode, I set my local operation = new Operation(Add), and when it's in count down mode, I set operation = new Operation(Subtract).  Now my Step() method just calls operation(counter, byHowMuch) -- no need for an ugly case statement.  You could also build a multicast delegate and chain together a bunch of addition operations, throw in a subtraction, maybe an absolute value, anything that takes a pair of integers and affects the first one by the second.

    And complaining because this is a function, not a subroutine, is pretty silly.

  • Buh Foon (unregistered)

    The real WTF is that...is that...oh never mind.

  • (cs) in reply to Obi Wan
    Anonymous:
    Private Function Add(ByRef Which As Integer, ByVal HowMany As Integer)
      Which = Which + HowMany
    End Function
    Ok, let's seeeeeeeee...
    Which is declared at beginning of function (so now it extists)
    HowMany is declared at beginning of function (same as Which)
    With no values assigned to either, they are both added and stored in Which (therefore it is still null)
    Then the function ends and the variables dissolve into nothingness...
    Therefore, as the function itself does nothing useful, it is there only for the purpose of making the person proofing it go WTF!?!?!

    WTF are you talking about?

  • VoodooC (unregistered) in reply to Wake Up

    True dat.  Except for ruby, which is just more evolved than the rest of the languages and actually makes you SMAERTER and increases your penis size when you write code in it.

    I'm going to have to stop writing code soon, one of the hot chicks walks by and I accidentally knock my cube wall over.

    sd

  • Loren Pechtel (unregistered) in reply to undo
    Anonymous:
    Delphi and Turbo Pascal both have a function that does the same thing built in:

    inc(x, 5);

    They also have a function for subtracting:

    dec(x, 5);

    Back in the days when I was coding in Delphi (and didn't know C and its +=), I thought this was handy and used it a lot in my code.



    Integers only.

  • Loren Pechtel (unregistered) in reply to Are you deluded?
    Anonymous:

    This is a function which ADDS TWO NUMBERS

    Addition is such a basic operation, its even supported in ASSEMBLER!  For goddsake, it's even implemented in SILICON!

    And this guy wrote a function to do it?

    I assume there is a 'Sub', 'Multiply' and 'Divide' function as well?

    Well, I have written all 4 of these for varying reasons.

    Add and sub are for cases where the field being added to is buried two or three levels down in a record type.

    Mult and divide were functions that operated on data elements bigger than what the system supported.
  • (cs) in reply to undo
    Anonymous:
    Delphi and Turbo Pascal both have a function that does the same thing built in:

    inc(x, 5);

    They also have a function for subtracting:

    dec(x, 5);

    Back in the days when I was coding in Delphi (and didn't know C and its +=), I thought this was handy and used it a lot in my code.



    Well, I am very in doubt with myself, whether I should call the original one a WTF. My first opinion was: This is a clear WTF, because even if the += Operator doesn't exist (for example in VB6), you could always do
    <font size="2">a = a + b</font>
    so there is no need for this function.
    Then I remembered that I did the same in my early VB6 days:

    <font face="Courier New" size="2">Public Function Inc(ByRef X As Long, Optional Y As Long = 1)
      X = X + Y
      Inc = X
    End Function

    Public Function Dec(ByRef X As Long, Optional Y As Long = 1)
      X = X - Y
      Dec = X
    End Function</font>

    The reason was the language I used before which had functions like that. I also thought, this was very handy, because you could write
    <font face="Courier New" size="2">inc a</font>
    instead of
    <font face="Courier New" size="2">a = a + 1
    </font>which of course is most used and some kind shorter, especially the longer the variable name is. And if you wanted to add something other, you could use it like our origin post code, something like:
    <font size="2"><font face="Courier New">inc a, 5</font>
    </font>But afterwards I didn't use it very much. First I put it in a separate common module to be independent and include it in several projekts. But then I was not very pleased to have to include another module for some sort of "basic" functions.
    When I came across OOP, it was the dead for this function. I you want to have your classes as independent as possible, you should avoid refering to as few outside functions as possible. So the other choice is to put it in the class as a private method. And looking forward, to have this in many classes as as a private method looked very silly. So inside of classes I used the built in traditional
    <font face="Courier New" size="2">a = a + 1<font face="Times New Roman">
    </font><font face="Arial" size="3">My conclusion is:
    In procedural programming maybe nice, in OOP it's a complete crap.</font><font face="Arial">
    </font>
    </font>

  • Sini (unregistered) in reply to byte_lancer

    byte_lancer:
    Anonymous:
    byte_lancer:
    Meh..
    It's not symmetric.
    Imagine the maintenance programmer who has to hack his way around to find why
    Add(10,5) and Add(5,10) return different values.


    Um, check that one again.


    Why?
    Add(x,y) will update x while Add(y,x) will update y when all it should do semantically is to provide the sum of x and y.

    captcha : gotcha?
    That seems a little inaccurate?

    Look at this: Add(x,y)

    Imagine you're a programmer looking at this line. You'll be asking yourself why it doesn't say AnyVariable = Add(x,y), and you'll most likely take one look at the add function and know why instantly. Provided you have any concept of reference values.

    The only problem I can see in that respect is when a new guy starts using Add without reading the function or its previous applications.

    x = Add(x,y) // Add assigns a value to (reference) x, and return 0: x = 0.

    To be sure this doesn't happen, it should be declared a sub (with no ability to return values) rather than a function, so that x = Add(x,y) will be a syntax error and quickly debugged. (If ever occuring)

    This is mostly based on assumptions regarding VB function handling. I've only programmed in Euphoria and C# myself.

Leave a comment on “Which is on HowMany?”

Log In or post as a guest

Replying to comment #:

« Return to Article