- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
one of my quite usefull mathematic functions:
so maybe, not all of them are useless?
Don't ask me what I'm writing right now... It's not buissnes project
Admin
Really, why are you all so negative? These functions have meaningful names and do what their names say. Isn't that perfect coding practice? Now if only they weren't so darned superfluous...
Admin
A pity this guy didn't enter the WTF Calculator contest.
Admin
Does nobody here code in functional style? Assuming C# doesn't already have something like add, it would be useful for passing to higher order functions (like map or reduce).
Admin
You could always try that great function
public static int Max(params int[] values){ return values.Max(); }
too. In fact you could generalize it to
public static int Max(IEnumerable<int> values){ return values.Max(); }
or even go for a generic solution
public static T Max(IEnumerable<T> values){ return values.Max(); }
or then again you could realize that re-programming things that come with the language is stupid.
Admin
They call it Lambda expressions and it comes with C#. For instance, I could code a foldl expression:
///
and now you can do the functional things you were talking about:
double Sum(IEnumerable<double> listOfDoubles){ return foldl(listOfDoubles, (a,b) => a + b); } double Product(IEnumerable<double> listOfDoubles){ return foldl(listOfDouble, (a,b) => a * b); } double Max(IEnumerable<double> listOfDoubles){ return foldl(listOfDouble, (a,b) => Math.Max(a,b)); }
etc.
Admin
There's a good chance you have enterobius vermicularis (AKA Pinworms). You should talk to your GP and/or visit your local pharmacy for over-the-counter medication.
Admin
And I bet he did a bang-up job with the interviewer's "brain-teasers".
Admin
Which came with the latest version of c#.
Admin
TRWTF is that he thinks debugging your coworker's code is all there is to life.
Admin
Perhaps his background is in Common Lisp?
(+ 2 4 (* 5 10))
-> 56
The real WTF is that he neglected to implement a complete and compliant Common Lisp interpreter in C#.
Admin
Who says that's C++? Might be a language that doesn't support operator overloading.
Admin
Yeah, static linking of library code is so unprofessional. Thank God Microsoft didn't keep #include in C#... really good C / C++ programmers never used it anyway. </sarcasm>
I will even go farther than you and say that Utils.dll practically begs for an out-of-process COM implementation (Utils.EXE) preferably running on a dedicated MTS server.
Admin
Not for the ones Stalin talk care of in the 30s.
Admin
I'm sorry, but this is the situation where it pays to have a "senior" programmer who can say. Don't do that kid... ya bother me. Do that again and I'll put you on the help desk for a week.
Admin
why is the Multiplication not using recursive operation? so not OOP
Admin
The same truly brilliant mind that came up with COBOL?
Admin
Heh. The real WTF is that it's statically typed.
import operator, functools
def do(what, *towhom): return reduce(getattr(operator, what), towhom)
add = functools.partial(do, 'add') multiply = functools.partial(do, 'mul') subtract = functools.partial(do, 'sub')
assert add(4,3) == 7 assert multiply(add(2,2),subtract(6,3)) == 12
Admin
I'm surprised that no one mentioned templates. I mean come on. If you are going to rewrite basic addition, at least make i so that you can do it to long doubles, floats, long floats, unsigned doubles, etc.
I mean really, all that code does is add two doubles by using the + operator. At the VERY LEAST we could make it add more than one datatype.
Also, for the record, there are many types when an array isn't given to you in an ordered list, or the array that you have was recently changed due to some earlier operation.
Admin
Where are: public static int returnInt(int input) { return input; }
public static double returnDouble(double input) { return input; }
public static string returnString(string input) { return input; }
public static enum returnBool(bool input) { if (input == true) return true;
if (input == false) return false;
if (input != true && input != false) return FILE_NOT_FOUND; }
??
Admin
[quote user="Mr. Bean The same truly brilliant mind that came up with COBOL? [/quote]
Admiral Grace Hopper did come up with a pretty good language, when the only two real alternatives were Assembler and AutoCoder.
Where were you when the page was blank?
Admin
Isn't this what System.Linq.Enumerable.Aggregate() does?
http://msdn2.microsoft.com/en-us/library/system.linq.enumerable_methods.aspx
Admin
What and idiot. What's he going to do if he wants to add firstNo to secondNo?
Admin
C++ has std::valarray which does just that ;)
Admin
Express those glands, now!
Admin
I'm no fan of COBOL, but I'm a huge fan of Grace Hopper - http://en.wikipedia.org/wiki/Grace_Hopper.
Not the least of her (many) achievements was to admit that COBOL was, in fact, an inferior language to Fortran (and let nobody quote Dr Johnson at me here), but it beat the opposition out because the compiler was easier and quicker to write.
Want to take a little trip back in time to the early 1950s?
Admin
The real wtf is that you're not fixing it.
Is there really no peer review of any kind where you could point out the stupidity?
Admin
It's 2.0 framework and Generic exaple is'nt goood, not all types have to have bigger and lower operators. I'm aware of 3.5 goddies and use them well in 3.5 projects, but these have to be 2.0
Admin
Min/Max are trivial to implement, even in 2.0 - thanks to Comparer<T>.Default which uses IComparable<T> or IComparable; Sum, Avg are trickier, but can be done - but it needs some grungy code.
Gotta love how Matt has added a step, though ;-p
Admin
Thank you, captain obvious!
Admin
tbh such routines are useful for function composition. Which is anything but useless.
Admin
LoL!! The world of systems integration is yours for the taking, SeaDrive!
Admin
Do not repeat yourself - reuse existing code! Thus:
Admin
Admin
Actually... http://www.sgi.com/tech/stl/plus.html
Admin
Addition functions guaranteed to throw a
type in C#.Admin
This makes up for very flexible, easy to maintain code.
Suppose - for instance, that the definition of what 'add' means changes in the future. Or you find a CPU bug about adding ints. You can simple fix it in this method in one place!!!
It is thus just as useful as these #define TEN 10 defs.
(Why didn't I learn something useful, such as carpenter...)