• Cesa (unregistered)

    Well, see it this way, pointless code is better than code full of errors. ;)

  • Anonymous Coward (unregistered)

    public static double Post(double fristPost, double sceondPost) { double comment=fristPost+sceondPost; return comment; }

  • fraserofthenight (unregistered)

    Why write something passe like "(a + b) * c)" when you could write the much more descriptive "Utils.Multiply(Utils.Add(a, b), c)". Plus, with the Utils class there's no longer any need to worry about that pesky order of operations. Truly only a brillant mind could have come up with that.

  • incognito (unregistered)

    wow, i bet he was an A+ student back in university

  • Adriano (unregistered)

    Nice how he at least checks for value under- and overflows

  • Pyro (unregistered)

    Meh, including same file everywhere is so lame. Real pro would compile it separately and link it as a library. Bonus points for naming library utils.dll.

  • Trondster (unregistered)

    Bah - he's not even reusing his own code:

    public static double Add(double firstNo, double secondNo) { double total = Add(new double[] {firstNo,secondNo}); return total; }

  • Pete Repete (unregistered) in reply to Adriano

    I wonder why he didn't recursively call his ADD function to add inside the ADD function. That would be sweet.

  • Vollhorst (unregistered)

    It is a nice thing. If you ever need to use a multiply where you before added something you just have to change this class. It is perfect. Easy to use. Easy to adjust. Perfect.

  • (cs)

    I would say the sum of an array of doubles can be useful as a shorthand. But only in odd applications that happen to use it.

  • (cs)

    Wait, I see the problem, he didn't use Inversion Control / Dependency Injection in his library, along with a messaging framework. What happens if I want to change the way AddTwoNumbersTogether works? what happens if I need to use the Util function but someone hasn't written the actual 'addition' logic yet.

    AdditionFirstOperandMessage x = new AdditionFirstOperandMEssage(3);

    AdditionSecondOperandMessage y = new AdditionSecondOperandMEssage(9);

    AdditionMessageRequest = request = NewAdditionRequestMessage(x, y);

    IMathsProcessUnit maths = MathFactory.GetInstance(); IUtil utils = UtilFactory.GetInstance(); AdditionResponseMessage response = utils.AddTwoNumbersTogether(request, maths);

    Console.WriteLine(response.Result)

    of course, really.. I should have MessageBuilders constructing IAdditionRequest instances.

  • (cs)

    I actually find the sum of array function useful. Its much more readable if you need to do a lot of array sums. The rest... O_o

  • (cs)

    Would have been better if he named it HisName.ArrayMath and just left in the method to do manipulations on arrays. Or maybe even add things for moving averages, statistics, or matrices. Would have been more useful that way.

  • JonC (unregistered)

    I think I get it, the real WTF is that he didn't use operator overloading to create his routines.

  • (cs)

    So you'd want him to just open code additions and multiplications? Think of the maintenance nightmare! If the semantics of addition or multiplication changed he'd have to go through and change everything!

    Sheesh. Think ahead, people.

  • (cs) in reply to pitchingchris

    Fixed his implementation, he had duplicated logic..

    public static double Add(double firstNo, double secondNo) { double total=firstNo+secondNo; return total; }

    public static double Add(double[] valueArray) { double total = 0.00; foreach(double val in valueArray) { // total+=val total = Add(total, val) } return total; }

  • (cs)

    Well you know Communism was a good idea 'in general'

  • Justin (unregistered) in reply to death
    death:
    I actually find the sum of array function useful. Its much more readable if you need to do a lot of array sums. The rest... O_o

    decimal sum = valueArray.Sum();

  • J. Walter Weatherman (unregistered)

    Jesus Christ my ass itches.

  • Trondster (unregistered)

    Or rather:

    public static double Add(double[] valueArray)
    {
        double total = 0.00;
        if (valueArray.Length > 0)
        {
            total = Add(total, valueArray[(int)Add(valueArray.Length, -1)]);
            Array.Resize<double>(ref valueArray, (int)Add(valueArray.Length, -1));
            total = Add(total, Add(valueArray));
        }
        return total;
    }
    
    public static double Add(double firstNo, double secondNo)
    {
        double total = firstNo + secondNo;
        return total;
    }
    

    Mmmh. Code Reuse. :)

  • Maks Verver (unregistered)

    So did you select the three dumbest functions from the file to showcase? Because if you did, I'm not impressed: the Add(double[]) function seems somewhat useful if you need to sum arrays of doubles at various points in the code. I can also see why you'd like to define a similar method for individual arguments out of a sense of consistency (although it's not very useful on its own).

    C++ has functions for sums, differences, counts, maximum/minimum etc. in its standard library, not because it's hard to implement these algorithms from scratch, but because by using standard functions your code becomes clearer (and less vulnerable to bugs due to e.g. typos). If C# does not provide these functions, why shouldn't this guy be allowed to add them?

  • Graham Wills (unregistered)

    I do a lot of work in numerical applications. Often there are differing logics on how to do addition. For example, if we are using NaNs to denote missing values (not an uncommon scenario), we might have differing desires for summing an array of NaNs:

    • NaN, in which case basic IEEE logic works
    • Ignore the NaNs, in which case we can modify the code
    • Throw an exception, because we didn't expect to find them at this stage in the calculation.

    Although this code is pretty useless, it should not be hard to see WHY you might want to have add functions in general. I'd say the array add would eb a good idea for general numeric programming. The two value version, not so much.

  • SeaDrive (unregistered)

    If you combine this re-write from Trondster:

    public static double Add(double firstNo, double secondNo) { double total = Add(new double[] {firstNo,secondNo}); return total; }

    with this rewrite from Grovsey:

    public static double Add(double[] valueArray) { double total = 0.00; foreach(double val in valueArray) { total = Add(total, val) } return total; }

    you would really be getting somewhere!

  • Søren (unregistered)

    That is just plain stupid. Oh my...

  • Sam K (unregistered)

    The real WTF is that fact he didn't use the params modifier in public static double Add(double[] valueArray).

  • (cs) in reply to Maks Verver
    Maks Verver:
    So did you select the three dumbest functions from the file to showcase? Because if you did, I'm not impressed: the Add(double[]) function seems somewhat useful if you need to sum arrays of doubles at various points in the code. I can also see why you'd like to define a similar method for individual arguments out of a sense of consistency (although it's not very useful on its own).

    C++ has functions for sums, differences, counts, maximum/minimum etc. in its standard library, not because it's hard to implement these algorithms from scratch, but because by using standard functions your code becomes clearer (and less vulnerable to bugs due to e.g. typos). If C# does not provide these functions, why shouldn't this guy be allowed to add them?

    I can see the array function being usefull... in many situations though, you rarely have a 'prepared' list of numbers.. by that I mean, the chances are those numbers are already going to be in something like an OrderList, containing Order objects, which in turn will have a list of LineItems... would make more sense to add a 'Total' property to the Order, which enumerates the LineItems, and a Sum to the Customer class which would in turn call the Total of on each Order.

    Or to say it another way, you would be enumerating one list, creating an array of doubles to pass into a function which then enumerates through creating a sum. Why bother with the second step? why not just create the total when you loop through the original list?

    Anyway, I digress :)

  • Matt (unregistered) in reply to Maks Verver

    Because C# DOES have these functions.

    double Add(double a, double b){ return a + b; } double Add(double[] arr){ return arr.Sum(); }

  • The Undroid (unregistered)

    You could borrow a model from Newspeak:

    double plusUngood(double a, double b) { return (double) a + b; }

  • (cs) in reply to Grovesy

    [quote user="Grovesy"] Or to say it another way, you would be enumerating one list, creating an array of doubles to pass into a function which then enumerates through creating a sum. Why bother with the second step? why not just create the total when you loop through the original list? quote]

    That is a good idea. Would be easy to provide a generic function that uses delegates to get the value. That way you can provide a custom delegate to get different values from collection objects, and the generic class will provide a way to get the sum of items based on the delegate you provided; something like GetOrderAmountDelegate.

  • (cs) in reply to Matt
    Matt:
    double Add(double[] arr){ return arr.Sum(); }

    Last I checked, .Sum is not available without LINQ, and this code will likely have been written before .NET 3.5 (not to mention that the project might have an earlier .NET version as compile target).

  • Dennis (unregistered) in reply to Graham Wills
    Graham Wills:
    ...for general numeric programming...

    in general

  • Izzy (unregistered)

    Can I bet double or nothing on the next deal?

  • DaDutchDude (unregistered)

    I think "firstNo" and "secondNo" are bad variable names. Being used to rejection, I'd think they were booleans with default value "False".

  • (cs) in reply to belgariontheking
    belgariontheking:
    Well you know Communism was a good idea 'in general'
    Don't you mean 'for the Generals' ?
  • (cs) in reply to DaDutchDude

    Well it's not too bad. This at least makes it obvious that adding two "No"s makes a Nono, which perfectly describes the kind of functions he's written.

  • Some Coder (unregistered)

    Wow, I did this make-a-utils-library too, back when I was 16 and using Turbo C++ v3.0 for DOS.

    It was so handy to have a function that would center a line of text on the screen; printed ((80-line_length)/2) spaces plus the string.

    I even learned how to handle variable arguments so I could make a cprintf() function that would take color arguments and print strings with colors; cprintf("%zRED%zGREEN%zBLUE", COLOR_RED, COLOR_GREEN, COLOR_BLUE);

    Ahhh, those were the days.

    After getting Watcom v10.5 and realizing that none of that stuff from #include <conio.h> was going to work (not to mention Windows programming was a completely different ball of wax); I abandoned the library. It sure was fun to write something so "useful" (in hindsight, completely useless) though.

    Sweet.

  • (cs) in reply to SenTree
    SenTree:
    belgariontheking:
    Well you know Communism was a good idea 'in general'
    Don't you mean 'for the Generals' ?
    Don't look at me; ask the Politburo!
  • (cs) in reply to death
    death:
    I actually find the sum of array function useful. Its much more readable if you need to do a lot of array sums. The rest... O_o

    Generally speaking I think it makes more sense to have an array_reduce function and pass "add" as a parameter. Making two kinds for each function -- one to handle two scalars, and another to handle an array of scalars -- only leads to confusion. What if somebody changes the implementation for Add(Scalar,Scalar) and forgets to make a corresponding change in Add(Array)?

  • umm... (unregistered) in reply to The Undroid
    The Undroid:
    You could borrow a model from Newspeak:

    double plusUngood(double a, double b) { return (double) a + b; }

    What is a 'double'? Unorthodox thought is pervasive, brother - we must be always on our guard.
    void Add(refs DoublePlusNumber a, DoublePlusNumber b)
    {
        a += b;
    }

    e.g.:

    DoublePlusNumber a = 2;
    DoublePlusNumber b = 2;
    Add(refs a, b);
    Console.WriteLine(a.ToString());

    Which, of course, prints...5.

  • (cs) in reply to belgariontheking
    belgariontheking:
    Well you know Communism was a good idea 'in general'
    Ditto any political or religeous idea taken to the level of dogma, including free market capitalism.
  • anon (unregistered)

    As far as I remember, C# does not provide access to the operators as functions. So if he used functional style a lot, all these reduce/map/zip, then he had to have a function like this (and worse, there might have been Identity too) and it's not a WTF at all.

  • aweofajfjifwa (unregistered) in reply to Grovesy
    Grovesy:
    Wait, I see the problem, he didn't use Inversion Control / Dependency Injection in his library, along with a messaging framework. What happens if I want to change the way AddTwoNumbersTogether works? what happens if I need to use the Util function but someone hasn't written the actual 'addition' logic yet.

    AdditionFirstOperandMessage x = new AdditionFirstOperandMEssage(3);

    AdditionSecondOperandMessage y = new AdditionSecondOperandMEssage(9);

    AdditionMessageRequest = request = NewAdditionRequestMessage(x, y);

    IMathsProcessUnit maths = MathFactory.GetInstance(); IUtil utils = UtilFactory.GetInstance(); AdditionResponseMessage response = utils.AddTwoNumbersTogether(request, maths);

    Console.WriteLine(response.Result)

    of course, really.. I should have MessageBuilders constructing IAdditionRequest instances.

    I would find this funny, except that you've just described all of the posers at codebetter.com. Taking CRUD to a whole new level of infernal machiness...

  • bpk (unregistered)

    Hey Guys...there's this great new invention that i just came up with called "the wheel"! It's awesome, it's round and it rolls and stuff....It's amazing and you should totally buy it from me.

  • (cs) in reply to aweofajfjifwa
    aweofajfjifwa:
    Grovesy:
    Wait, I see the problem, he didn't use Inversion Control / Dependency Injection in his library, along with a messaging framework. What happens if I want to change the way AddTwoNumbersTogether works? what happens if I need to use the Util function but someone hasn't written the actual 'addition' logic yet.

    AdditionFirstOperandMessage x = new AdditionFirstOperandMEssage(3);

    AdditionSecondOperandMessage y = new AdditionSecondOperandMEssage(9);

    AdditionMessageRequest = request = NewAdditionRequestMessage(x, y);

    IMathsProcessUnit maths = MathFactory.GetInstance(); IUtil utils = UtilFactory.GetInstance(); AdditionResponseMessage response = utils.AddTwoNumbersTogether(request, maths);

    Console.WriteLine(response.Result)

    of course, really.. I should have MessageBuilders constructing IAdditionRequest instances.

    I would find this funny, except that you've just described all of the posers at codebetter.com. Taking CRUD to a whole new level of infernal machiness...

    I would too, if it wasn't for the fact that this was pretty much a copy of something I saw in our code base a few days ago (computes the value of two orders)..... it's all a bit enterprisey here.

  • (cs)

    The two-parameter Add could be used as a parameter to a "map" operation.

    // apply the $5 surcharge to each item charges = Map(charges, Add, 5);

    Though I doubt that's why the function was written...

  • Paolo G (unregistered) in reply to incognito
    incognito:
    wow, i bet he was an A+ student back in university

    No, he was a Utils.AppendCharacter("A", '+') student.

  • A. Cube (unregistered) in reply to Cesa

    Pointless code IS code full of errors--just errors waiting to be found.

  • Tommy American (unregistered) in reply to Paolo G
    Paolo G:
    incognito:
    wow, i bet he was an A+ student back in university

    No, he was a Utils.AppendCharacter("A", '+') student.

    Good one! Cracking me up.

  • (cs) in reply to Paolo G
    Paolo G:
    incognito:
    wow, i bet he was an A+ student back in university

    No, he was a Utils.AppendCharacter("A", '+') student.

    Both wrong, he was a: Utils.Append(Utiles.GetCharFromString(Utils.ToUpperCase(Utils.GetFirstLetter(Utils.Alphabet()))), Utils.Solve("1 ? 1 = 2"), Utils.GetSpace(), Utils.GetCV().GetEducation().GetPosition());

  • Walleye (unregistered) in reply to bpk
    bpk:
    Hey Guys...there's this great new invention that i just came up with called "the wheel"! It's awesome, it's round and it rolls and stuff....It's amazing and you should totally buy it from me.

    The real WTF with this is that it's round. It will just roll away from you. It should be flat on the bottom so it doesn't get away.

Leave a comment on “They're Useful... In General”

Log In or post as a guest

Replying to comment #189614:

« Return to Article