- 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
return "This " + "is " + "a " + /* "brillant " + */ "comment!";
Admin
May I be the first to say: StringConcat("Not ", "even ", "close ", "f*cking ", "idiot", "!");
Gives a whole new meaning to stripping bad words...
Admin
Hmmm... didn't really pay attention in programming class, because the teachers usually couldn't remember how to log in... but wasn't there one group that was always telling us to use functions wherever possible? Functional programming is better than procedural, or something like that?
Admin
I'm not sure I'd call a concat method that ignores one of its parameters "functional".
Admin
Admin
Admin
throw new NotSupportedException("Paul G.");
Admin
The genius part of it is that if you use it to concatenate two string literals, it will (presumably) stop the pesky compiler from optimizing it!
Admin
err... I'm not a perl programmer, but wouldn't this return "There'salwaysanotherway"?
Admin
that pretty much sums up all that's good and bad about perl
Admin
Just call it one of those weird but frequent cases where Perl does what (it thought) you wanted, not necessarily what you expected.
Admin
It's such a pity C# doesn't support default parameters. Or else code author might have written
thus supporting 2 and 4 parameters as well while reusing existing code. Best coding practices!
Admin
You're thinking of 'print @;' as opposed to 'print "@";'.
Admin
C# does now support default / optional parameters. It's a 'new' feature of C# 4.
Admin
in OOP those two "simple tests" will be often violated in favor of a more refactorable / extendable / inheritable etc. code
Admin
I mean why use String str = "this" + " code" + " sucks"; when you could have a BRILLIANT method to do this for you!
You should either change professions or go back to school. I'ld prefer if you did option A personally.
Admin
Quick! Let's dissemble his car!
Admin
Admin
The real WTF is he did not use Extension Methods
public static string StringConcat(this string param0, string param1, string param2) { return param0 + param1 + param2; }
"So ".StringConcat("much ", "better!");
Admin
StringConcat("DELETE ", "FROM ", table, " WHERE id=:id", ";");
Admin
public string StringConcat(string param0, string param1, string param2, string param3, string param4, string param5) { return StringConcat(StringConcat(param0, param1, param2), param4, param5); }
Optimized!
Admin
Using built-in functions are fine if you want to write code that is not portable and will probably be obsolete in 2 years. I on the other hand have taken measures to make sure my code lasts longer than other peoples. We disallow the use of the Imports statement (or "using" if you are a C# snob) because we DON'T OWN THE SOURCE CODE for those functions contained in those libraries. It is much more portable to write a StringConcat function that you have the ability to maintain than to use someone else's proprietary version of String Concatenation. Also, it lets you tailor the implementation to your specific system. I ngen all of my libraries so they are highly optimized versus the ones that come with .NET.
So the moral is it is not a bad thing to write your own version of built in functions, because the built in ones are there more or less for demonstration purposes.
Admin
Admin
Uh oh, hide the babies, he's back!
Admin
Admin
Given that .NET has String.Concat already, since version 1.0, this entire snippet is pointless, if it is C#.
Incidentally .NET has three overloads that take two, three, and four string arguments respectively, and one which takes a params string array. Presumably the calling convention is more efficient with four parameters than constructing an array of four strings, but it tips the other way with five. C# programmers should also know that the compiler converts consecutive '+' operations to a call to String.Concat anyway.
It could be Java, of course, which only gained variable argument lists quite recently - they appear in the Third Edition of the Java Language Specification (2005, Java 5 IIRC), where they are spelled e.g.:
public static string StringConcat(string... params)
Admin
I just wanted to say "you're an idiot". Then I saw you're TopCod3r... Well, I haven't read the comments for a while, but last I saw you had apparently been banned. Well, welcome back.
Admin
Admin
StringConcat ('But ', StringConcat ('why ', StringConcat ('not ', StringConcat ('support ', StringConcat ('infinite ', StringConcat ('params ', StringConcat ('with ', StringConcat ('one ', 'function?'))))))))
Admin
Using bad functions is not functional or elegant.
Admin
I really, really hope you're a troll, because if not you're a bit of an idiot.
.NET runs ngen on all of its own assemblies when it's installed. .NET 2.0 installs a service - .NET Runtime Optimization Service - that can rebuild native assemblies when a patch is installed.
I doubt very much that you can do better than the built-in implementation of String.Concat, which involves a trip into the C++ portion of the CLR to allocate a string of specific length, then some string copying by pointer arithmetic, using a partially-unrolled loop to copy 8 characters at a time.
Sometimes you can beat the built-in implementation if it's a general one that has to cover corner cases that you're not interested in. But Microsoft have aimed to make it generally usable and suitably performant for the most common cases, precisely so that you don't have to reinvent basic functionality.
Admin
Dang, that was meant to be a reply to TopCod3r.
Admin
What I really like is that it's a static number of parameters. I mean, what if I wanted to contatenate the following...
This is a six word sentence
I couldn't do it. I'd have to write a whole new function!
Admin
Admin
Reverse operator overloading -- nice. I look forward to ROO becoming the hot new programming "paradigm".
Admin
Welcome back.
Admin
Well there actually is a legitimate reason for this kind of stuff at certain times.
Game engine I'm working on has to be both DX9 and DX10 capable and which one to use is decided at runtime, not compile time. That way a Vista user can automatically get DX10 (if supported by hardware), XP user automatically gets DX9.
Now DirectX does ship with the handy D3DX libraries with lots of functions needed for your basic 3D math (vectors, matrices, quaternions, etc.) However DX9 and DX10 both each have their own versions. DX10 libs may have functions DX9 libs don't. I can't also guarantee that DX9 libs may not have functions that aren't going to be replaced by something else in DX10 libs.
So in my case, I actually do have my own Vector, Matrix, Quaternion, etc. classes because that way I'm API version independent. May also be of future benefit for cross-platform if OpenGL ever manages to fix their version 3.0 fuckup and becomes a viable alternate implementation.
Admin
Admin
Go for it. If you work anywhere where you are evaluated by lines of code produced or source code checkins, you can expect a nice bonus at the end of the year.
Admin
param3 left with W and Y from yesterday's WTF.
Admin
You are surely attempting to out-troll TopCod3r - good luck with that.
Admin
public string Concat(params string[] arg) { var stringBuilder = new StringBuilder(arg.Sum(s => s.Length)); foreach (string s in arg) { stringBuilder.Append(s); } return stringBuilder.ToString(); }
Admin
But also
Nothing new under the sun after you learn LISP, that is :)
OTOH, I am now very much a believer in requiring LISP in all undergrad CS education: it does broaden your horizons, so that you at least look for features that can potentially exist in the language you have to work with.
People who have no clue as to what may be reasonably expected of a programming language never look for those features, and end up producing their own polygonal approximations of a wheel.
Cheers, Kuba
Admin
I think you're correct. However, what the post kind of implies to me at least is that it would be wrong to do:
Just like this wouldn't be an as bad form of this function (in my opinion):
Admin
Blargh... Coffee gods haven't visited me yet. That isZeroMod function should be renamed or changed to
Admin
Yeah, well maybe you want to write that gddmn login page yourself, hmm?
CM
Admin
unwords ["This","is","neat."] or, if you don't want spaces, concat ["This","less."]
Admin
If you don't think number % 2 == 0 is readable as determining wether number is even or not, you shouldn't write any code other than Visual Basic.
Admin
Well, there's your problem right there.
Admin
the real wtf is java overloads the + operator, but won't extend that same convenience to the users of the language.