- Feature Articles
-
CodeSOD
- Most Recent Articles
- Crossly Joined
- My Identification
- Mr Number
- intint
- Empty Reasoning
- Zero Competence
- One Month
- A Little Extra Padding
-
Error'd
- Most Recent Articles
- Not Impossible
- Monkeys
- Killing Time
- Hypersensitive
- Infallabella
- Doubled Daniel
- It Figures
- Three Little Nyms
- 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
He didn't use something that was introduced after he wrote the program - isn't he a fool.
Seriously, give use the date the original was written when you're posting WTFs like this.
Admin
To all of you defending this code: Learn to program proper!
This codebase is a huge W-T-clusterFuck.
1.) Violation of separation-of-concerns / single-responsibility-principle. Implementing too many functionality in each method. 2.) Misleading method names: "ReturnEmptyStringIfNullElseValue" does not return the value, it returns the trimmed value. 3.) Violation of Don't-Repeat-Yourself all over the place. Why the animosity against temporary / local variables? And that replace-code is repeated all over again instead of put into a separate method. 4.) What's the point of first parsing as Int and if that fails, parsing as Decimal? Why not parse it as decimal from the beginning? 5.) Other WTfs already pointed out: Calling ToString() on a string, inefficient coding: using Substring instead of an indexer to retrieve a single Char from a String. 6.) What's the idea of accepting input data and convert it into a number even if it is not a number? One might accept the idea that a money input may be in the form "$123.45", but this code will also accept ",7$56$,18.$9". This is worse than PHP!
Admin
This was my initial assumption on the matter. It has been a while since I've played in 1.1, so I don't remember everything it lacked, but as the guy who wrote the code is supposedly retiring, I don't doubt he had old libraries.
Admin
Ummm... where is all this commentary about basic coming from? That was c# code in the story.
Finally... as to your ignorant comment... well... all I can say is that the coder makes the app, not the language. VB and c# are both converted to clr, and both compiled to run on .NET framework. The result is dictated by the imagination and knowledge of whomever wrote the code... so how that code was expressed carries no relavence whatsoever. My suggestion would be to use whichever language one is comfortable with. I choose c# (when I have a choice) because the syntax is more commonly held across multiple languages, and I have used many. But one who claims that VB or those who use it are in some way intellectually deficient is clearly someone who speaks without knowledge.
Admin
Java similar construct:
String someVal = stringArg == null ? "" : stringArg;
Admin
Admin
Apparently -10, 0xA, and 1e1 are all not numbers. One could also make a case about 10.0, but that depends on if your definition of numeric includes floats or just integers.
Admin
I'll take a crack at a Java isNumeric() function:
...Maybe I'm overthinking this...
Admin
Throw/catching exceptions in non-exceptional cases: good job.
Admin
Moot point, the original function checks for "== null". The example I posted would be expanded by the compiler into:
if (someString == null) notNullString = string.Empty; else notNullString = someString;
Admin
Not to beat on a dead horse, but I just love the string.ToString because the 'string' might mysteriously convert itself to some other type. Let's add another one to the library of functions:
Public Static string GetString(string str) { return str.ToString() }
Admin
This ain't being necesary as Java having no null check on parse of Integar from String for performing reason.
This is meking Nagesh mother cry. [image]
Admin
Somebody tell Nagesh to stop showing mother the code !
Admin
This reminds me of that George Carlin joke about speeding... "Anybody who knows less about programming than me is an idiot. Anybody who knows more about programming than me is a maniac!"
Admin
In the function ReturnDecimalValueOfString(string value) where is OM declared?
In the function isNumeric(string value) at the very least why use value.Substring(i, 1) as opposed to value(i); why not break out of the loop: for (int i = 0; i < value.Length; i++) { if (!"1234567890".Contains(value.Substring(i, 1))) { isNum = false; //EXIT FOR; //or this //i = value.Length; } }
Admin
That's a Zero, not an O as in Omega. It's a numeric constant, M suffix designates Decimal.
Admin
I have not seen this mentioned yet. In the 'ReturnIntValueOfString' function I would have handled the decimal portion by trimming it as so:
if(value.IndexOf(".") > -1) {value=value.Substring(0,value.IndexOf("."));}
Admin
There's a (rather large) difference between IIF() and if() in VB.Net (3.5 or 4 ... can't remember) Plus if() can also do the C# ?? operator if using the two argument version.
if(boolean expression, A, B) if(X,Y) both exists in VB.Net now.
Always easier to find flaws in other peoples code.
Admin
Or just "return false;"
Admin
Admin
Admin
Admin
This is a joke or are you genuinely curious?
If you really need it explained, perhaps it would make more sense if I told you that 5 and 53 can be represented by the same value :p.
Numerically, 53 is a standard integer that can fit in a 1 byte (8 bit) space. If (however) I say ((char)53) then I end up with a '5'.
As people typically enter numbers in the form of text (and not the way that number looks in memory)... int.Parse( "5" ); would yield the number 5 while (int)"5"[0] would yield 53. If the user enters 5 in a text box, I am grabbing that as a string and would prefer to covert it to the number 5 instead of the number 53... seems a tad more accurate.
Admin
I had a very similar mess to work with where out coders had decided that all database functions for ALL classes should be kept in the "DatabaseCommon" file and the SQL that those database calls use should be retrieved from "DatabaseCommonSQL" functions...
Yeah it was fun fixing that :S
As to the string being null or empty, VB.net covers that nicely:
Return IIf(String.IsNullOrEmpty(value), "", value)
Admin
Ya know, I'm starting to see a pattern here... What I mean is, it looks like these type of "programmers" seem to exhibit the same coding habits. I happen (to have the misfortune !) to work in the company of a couple of them geniuses too, although not as pathetic as the hero of this article.
Anyway - seems like they all like to abuse string arithmetic! Trim() is their most popular, along with Contains(), Upper(), Split() and last but not least - Substring(). Another "feature" of their code is conversion of basic types to string and back. One of my guys once told me that (quote) "the string is the most user-friendly type in the world"...
Admin
I think I'll post some gems on WTF.com too. The author of this article mentioned that the Functions class had "thousands-of-lines", which made me remember the cold reality that I'm in. I've got a class with 10,000 (that's right, TEN THOUSANDS) lines, and growing. Wait till I show you what's in there ! It's a horror story !
Admin
Funny, I hardly ever use Python's ternary operator. If something is "something_positive or default" I just use "or", once I've written "foo if this else bar", I find I want to break it out into a proper block anyway.
Why do you want operator overloading (or did you mean short-circuiting?) in VB? VB has bog-simple semantics by design: it's BASIC for crying out loud.
Admin
Admin
Admin
Bad coding, yes, but hardly a WTF.
/Jon
Admin
I am sure if I had to solve this situation in a language that is not my own I would have avoided some of the WTFs there but my code probably wouldn't be that great.
The real WTF though is that your comment got featured while none of my comments on the C++ WTF we had a week or two ago got featured, in fact Alex decided to have a day off featuring comments on that WTF. It's a WTF that Alex never featuers any of my comments and I will continue to moan about it on here every day until he does.
Admin
Admin
I'm a programmer, not a philosopher, so I won't argue with such grandiloquent phrases as separation-of-concerns and single-responsibility-principle. I believe you are right (for most points), maybe in the Java world there is an emphasis on doing things in accordance to some specific doctrines and if it actually works is a secondary issue.
However, I don't agree with point 5. I strongly deem that using both words "Java" and "efficiency" in one sentence is a stylistic error, because these words are simply incompatible.
If you care about efficiency, don't use Java. If you use Java, don't aim for efficiency, because this is something you already lost choosing Java.
Admin
In Java, String implements the CharSequence interface, so it definitely sees strings as a sequence as chars. It does not provide the []-operator, you have to use the charAt(int) - method.
C# does provide the []-operator.
That's correct, but not relevant for the code in question, as Substring() also operates on sequences of 16Bit-characters, not Unicode codepoints. If that input data comes from user input there is no guarantee that you won't get that input (as we already know, cats like to sleep on keyboards) and the correct behaviour is to reject such erronous input. As others already have suggested: Use the methods / libraries that are part of the platform instead of re-inventing them poorly. I have also noticed that in the last weeks Alex performance in the featuring department was very poor. He seems to be trying to overcompensate for this now, so maybe in a few days he might get a better review on his core field of action from you!Just keep on reading yourdailyfeaturedcomment.com.
Admin
Point of fact... yes... Java runs like an old hound with only 2 legs and a severe case of IBS on a Windows system... primarily when utilizing the UI components. This problem exists exclusively for Windows however. Running a Java app on Fedora or any Mac/Nix OS will yield much more positive results. Therefore, many people choose to use Java and manage to incorporate efficiency quite well. They are simply writing the code to execute within its' native environment.
Admin
I've got a variant of ReturnIntValueOfString function in a few of my classes where I needed to do a lot of converting strings (that were often null or blank) into integers...
Is mine a WTF?
private static int ToIntOrZero(this string str) { if(string.IsNullOrWhiteSpace(str)) return 0; // quick return.
}
Admin
[quote user="Cbuttius] The real WTF though is that your comment got featured while none of my comments on the C++ WTF we had a week or two ago got featured, in fact Alex decided to have a day off featuring comments on that WTF. It's a WTF that Alex never featuers any of my comments and I will continue to moan about it on here every day until he does.
[/quote] That is surprising to read so directly from someone. Do you ever go to your friend's house and complain that he drinks someone else's beer and never your own? This website is a lot of fun, and it is enjoyable to be vocal and all... but bottom line, this is Alex's personal space that we are privileged to share.
I suspect that the comments that are featured are featured because Alex enjoyed reading them. I seriously doubt the name next to the post is even considered. Therefore... if getting featured means so much to you, then spend more time thinking before you post... and post something that is interesting to read.
Admin
:( I broke it
Admin
This does NOT produce the same results.
I think you could do it with:
return (someString ?? string.Empty).Trim();
Admin
return string.Format("{0}", someString).Trim();
Admin
If you are a programmer, you are a philosopher too, even if you don't realize that. Granted, those grandiloquent words sound like mouthful, but so is "deterministic finite state automaton", or "binary space partitioning trees", or even "object-oriented programming", although the latter term may appear cryptic only to outsiders.
Just by the fact that you are reading this article, and engaging in arguments over coding practices - that in itself is philosophy.
Admin
Wow, you really are one of those arrogant pricks, aren't you?
There's nothing wrong with VB.NET. Personally, I prefer C# and that's what I do for my job. But ultimately either language is syntactic sugar over the .NET Framework. As long as you're not writing your VB.NET like it's VB6 then I really don't see a problem with an individual or company settling on it as their language of choice.
Admin
Glad I am not the only one who sees it that way. Perhaps next year we will see people suggesting that the real WTF is that the coder was wearing blue when they wrote the code.
I think arrogant might not be the most precise term however. How does ignorant and E-Biggot work for you?
Admin
So true... I saw some kids complaining about why no generic and why using arraylist etc without knowing they were looking at .NET 1.0 or 1.1 as they never seen one before.
These kids tend to create super cool linq code that loops and loops and loops and loops and wondering why their newly reengineered fancy code takes 30 minutes to produce output whilst that old clumpsy code took just few seconds to do the same job..
TRWTF is really these arrogant kids with shallow knowledge not willing to understand why certain things are done in certin ways. Sure, string to string looks real stupid, but guys, it may be written by someone who is maybe less intelligent than you are.
Also not only we use to write isnullorempty,but also isnullorwhitespace ourselves with exactly the same name not so long ago. Now some kids will say why you would do this and do that.. They just assume you are stupid before even ask you why.
I really enjoy reading here and also find it mostly funny but this one just remind me of few kids with full of egos.
Admin
Admin
In other words: The post you are referring to is not "So true", it is only proof of even more ignorance!
String to string is just a sure sign that the programmer was just to dumb to program at all.Admin
Thank you, yes. It's not so much that the functions exist, it's that they're full of bugs!
While we're at it, isNumeric fails on floating point strings, etc.
Admin
I would not call the isNumeric code "one of the more... clever approaches". In Perl, my regular check that a string is a positive integer is
The only other alternative is to load the
function. Or you just convert to integer and live with the warning on standard error. Meh.Admin
I like to include a .ToString() on a string reference at times, like when I'm writing a jump tree where every other branch has .ToString(), or when punching a bunch of other typed objects into a string collection. It generally makes the code quicker for the reader to digest.
Also, in .NET, the compiler will see the implementation of String.ToString(), specifically "return this;" being the only statement in the body. It will be then inlined and in the next processing step, removed as redundant. There really is no efficiency concern. Even if there were, if you're concerned about a single jump, then NO vm based language is for you. Not Java, any .NET variant, Python, Perl, or PHP. From the looks, we only have one person here capable of C/C++ regurgitation. And a TRUE efficiency die hard would complain of the inefficiencies that C adds to the code. ASM or NOTHING!
The real WTF here is that all of you "experienced" programmers here apparently cannot tell the difference between Java and C#. Even more disturbing is the number of contributers which do not realize this is not actually VB.NET
Admin
Because otherwise I'll end up sounding like the Architect I've no idea what the hell I'm saying... (watch at 56s)