| « Prev | Page 1 | Page 2 | Next » |
|
The funniest thing about this to me is that not only does it reinvent the wheel, it reinvents it as an oval. I've had to write code to do this in a language that didn't have this feaure (or at least I didn't know what it was) and I would just add "000000" to the front and then substring the last 6 characters. |
|
Cripes.
// not far from... public int intValue(int i) { return i; } |
|
Three words: W T F???
In Perl (non-production code!) I've used inelegant formatting constructs like this: index="000000$i" rtindex=$((${#index}-5)) nrtindex=${index:$rtindex} But switch/case? Ack! (Note I am not a particularly expert Perl programmer, and there's almost certainly a more elegant way to do that.) |
|
Why not use an XSLT stylesheet to format this output?
|
Re: IFormatProvider? Oh no, not me ...
2005-04-19 14:49
•
by
Charles Nadolski
|
You could also do... while(strWhatever.GetLength()<6) strWhatever.Insert('0'); Though your version might use fewer CPU cycles :) |
Well, they sure did that. Adapted the hell out of it, I would say. |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 15:09
•
by
Irrelevant
|
erm... that's not perl. You've got $s missing off the variables to the left of the equalss, no semicolons, $(...) is invalid, and I'm not even going to try to guess what ${index:$rtindex} is supposed to do. Not trying to troll, that's just too alarmingly non-perl to not comment. But in terms of elegant solutions, $str = sprintf '%05d', $i;and $str = '0' x (5 - length "$i") . $i;both spring to my mind. And (take note all perl-is-ugly fundies) neithier of these are particularly ugly (unlike stevekj's non-perl there ;] ). |
|
So the first one would be from CSC Australia, then? http://au.country.csc.com/en/mcs/mcs43/index.shtml contains the incriminating quote, though thankfully no actual code. |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 15:13
•
by
John Bigboote
|
I think it's P#. |
|
inputEmployeeNo.PadLeft(6, "0"c) seems the easiest way to do it to me...
|
Re: IFormatProvider? Oh no, not me ...
2005-04-19 15:19
•
by
Matt
|
uh, because like the original post says, the .NET Framework has extensive built-in support for number formatting? |
|
adapts leading-edge technology, best practices, and experience to help customers realise their business objectives Looks awfully lot like what can be found on this page... |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 15:22
•
by
Charles Nadolski
|
Any VB.NET people know if you can use that method? If so, that's a one-line replacement for WTF #1. |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 15:28
•
by
John Bigboote
|
I would just leave the emp no as an int value and do intValue.ToString("000000") It may be that the conversion to string was only done for the length-check/padding anyway. |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 16:12
•
by
dopefish
|
It's actually bash (UNIX shell), not Perl. And it does work, though it's still not a particularly good solution (bash has a printf command just like the C function, you know...) |
|
[:S] Wow. That was depressing. WTF!
|
Re: IFormatProvider? Oh no, not me ...
2005-04-19 17:19
•
by
nonDev
|
Actually there are 10 kinds of people in the world. Those who count binary and thouse who don't. |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 17:33
•
by
diaphanein
|
But if only you and dead people can read hex, how many people can read hex? [:D] |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 17:35
•
by
dubwai
|
Not sure about CPU cycles but if String is immutable in the language in question, this creates a bunch of junk Objects. Never more than 6 but still. |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 17:52
•
by
Cthulhon
|
Well, that's 1 (you) plus DEAD which is 57005 is decimal, so one can reasonably assume that about 57006 can read hex. |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 18:14
•
by
MeMe
|
A better question would be... If only you, me and dead people can read hex, how many people can read hex? |
Re: IFormatProvider? Oh no, not me ...
2005-04-19 20:06
•
by
Free
|
|
Those who understand binary and those who don't. ( 10 - 3 == 1 )
There are 11 kinds of people, those who understand string theory and those who don't.
|
|
This is the line I really like:
Select Case (inputEmployeeNo.Length) ' Evaluate userid.
In what way is "inputEmployeeNo.Length" evaluating a userid (whatever that may be)? It's evaluating the length of the ID in digits, not the ID itself. Insane. Incidentally: the Perl idiom I would use is sprintf("%04d",$n) rather than any other silliness. Why? Because it's good enough, it's fast enough, and it's obvious to anyone who's familiar with the C [sf]printf format, which is a large majority of programmers. Oh, and regarding the kinds of people: my favourite version is: There are two kinds of people in the world: those who divide the people in the world into two kinds, and those who don't.
But the original poster who brought it up was misquoting a subtly different (and considerably wittier) original: There are three kinds of people in the world: those who count, and those who don't.
No, it's not a typo; it's wit. |
|
Just in case you were wondering, Example 2 is C#. *sob*
|
Re: IFormatProvider? Oh no, not me ...
2005-04-19 22:26
•
by
bubezleeb
|
|
Check out this page http://au.country.csc.com/en/mcs/mcs46/index.shtml
in Firefox (and perhaps other Non-IE browsers) to see how much on the leading edge they are! |
|
Read The F_ing Manual!
Read The F_ing MSDN! Read the F_ing Intellisense! WTF, just read!!! |
Re: IFormatProvider? Oh no, not me ...
2005-04-20 01:27
•
by
Drak
|
|
At least in the second example you get an empty string if you input the wrong month. Reminds me of something with 13 months in a fiscal year? Month 13? Oh, thats "" [:O] Drak |
Re: IFormatProvider? Oh no, not me ...
2005-04-20 03:33
•
by
midas_dk
|
|
|
Sigh:
strEmployeeNumber = Right("000000" & inputEmployeeNo, 6)Or: -for those that really want an "if" statement: if len(cstr(l_intMonthNum))> 1 then |
|
In the mid to late 80s I worked as an analyst programmer at a company developing applications for the shipping industry, specifically to be used on board ships. One of the other developers was clue impaired and routinely did...
if this = that then do something else i = i
he insisted that strange things happened if he excluded an else clause and this was his way of doing a no-op. The same guy wrote a screen clearing routine like this (it was basic) ... (20 more) ... when asked about loop optimisation and if that was what he was doing, he didnt know what I was talking about.
so, you see, some things don't change. |
|
In that month number format, forgetting for the moment the general stupidity, would it not be better to throw an exception on the default case?
|
Re: IFormatProvider? Oh no, not me ...
2005-04-20 08:40
•
by
Mike R
|
|
"when asked about loop optimisation and if that was what he was doing, he didnt know what I was talking about." Loop optimisation, hell. What about CLS? |
Re: IFormatProvider? Oh no, not me ...
2005-04-20 09:50
•
by
fatgeekuk
|
|
Well yes, but we where developing on both
HP-150b (using MS CBASIC on MSDOS) and IBM PCs, the HPs did not support things like CLS as the system was a NONIBMPC MSDOS system that was effectively a graphic terminal with a PC shoved in the bottom of the case, so the interface between the "PC" and the terminal was done by printing sets of ANSI command strings. :-( But, even so, there WAS an ANSI sequence for clear screen. so, no excuses I spose. |
Re: IFormatProvider? Oh no, not me ...
2005-04-20 09:52
•
by
Drak
|
|
10 print "{insert inverted heart symbol here}"; Usually the first line of any program I ever wrote on my VIC 20 Drak |
Re: IFormatProvider? Oh no, not me ...
2005-04-20 09:53
•
by
Zatanix
|
|
Or perhaps more normal: PRINT"§" , where § is a reversed heart
|
Re: IFormatProvider? Oh no, not me ...
2005-04-20 09:53
•
by
Zatanix
|
|
argh, drak beat me to it! :)
|
|
For when you absolutely have to have your data your way! |
Re: IFormatProvider? Oh no, not me ...
2005-04-20 10:28
•
by
JamesCurran
|
I imagine he once got caught by the construct: IF A=B THEN
|
Re: IFormatProvider? Oh no, not me ...
2005-04-20 10:33
•
by
Charles Nadolski
|
Heh, I didn't notice it at first, for those wondering what the WTF is, just scroll down the page. |
|
How about a bogosort version? That would be cool.
|
Re: IFormatProvider? Oh no, not me ...
2005-04-20 12:35
•
by
Charles Nadolski
|
Hire a bunch of monkeys to smash the keyboard until the proper number of zeroes are padded to the string? This looks like a job for Primate Programming Inc. |
Re: IFormatProvider? Oh no, not me ...
2005-04-20 15:51
•
by
wakeskate
|
I made a comment a couple days back that we shouldn't blame noobs for not knowing the framework, but are there still people who program without google groups or msdn in .NET? I can't possibly disagree with that quote... About that website though - any company with 4,000 employees is going to have tonnes of horrible programmers (let's include whoever made that website). Most of the ones that have been procedural programming for the last 10 years and just switching into oo now are too stubborn to learn anything new properly. Before you slag me for that you should know I worked for a company with 46,000 IT staff and half the programmers did daily WTF's - mostly VB6 and cobol programmers stepping over to .NET. |
|
I know where you can find a stupider solution. On our HR website,
you login with your employee id. They just have a blurb that says: ":" If you guess wrong on the number of digits they're thinking about, you get this: "Employee ID# not found. Please read directions carefully - check your Employee ID# entry; be sure to enter a total of 6 digits, using zero(s) as needed." Why code it, when you can just force the user to fix it? |
Re: IFormatProvider? Oh no, not me ...
2005-04-20 19:05
•
by
Maurits
|
On your last day, hack in to the database and set the identity seed to 999999 - they won't be able to hire anyone else ;) |
|
In terms of speed and memory consumption, both WTFs are probably better than the usual straight-forward solution.
The first example does the most simple possible action - append the string to a constant length string. Probably there will be only one intermediate object, a StringBuilder used by the compiler, which cannot be avoided. The second example always returns a constant string, so it doesn't even have to create a new object. This are examples where ugly WTF-solutions probably perform better than anything else. Although I doubt anyone will ever notice the difference |
Re: IFormatProvider? Oh no, not me ...
2005-04-21 12:46
•
by
Rick Mogstad
|
Yes, this works in VB.NET as well as C# I would imagine. Its a method in the string class, so it should work in any managed language. The real syntax would of course be inputEmployeeNo = inputEmployeeNo.PadLeft(6, "0"c) |
Re: IFormatProvider? Oh no, not me ...
2005-04-23 22:41
•
by
AdmittedHack
|
|
They have their site map / site outline at the bottom of every page .. WTF ???
|
Re: IFormatProvider? Oh no, not me ...
2005-04-27 09:09
•
by
joss
|
|
Exactly. The second example is good code IMHO, its totally clear how it
behaves, its not bug prone, its a few lines longer than obvious alternative, but so what, its much faster than the alternatives and although this wouldnt make a difference unless it was called *very* frequently, why the hell not just write a fast function in the first place. |
Re: IFormatProvider? Oh no, not me ...
2005-04-27 11:23
•
by
wtijsma
|
I can read some hex too, that would mean deaf people can read hex |
|
Well assuming they had the profiler numbers to back it up, there is
probably a performance advantage here over the default implementations, especially the latter case. Particularly against the Java alternatives, which probably carried over to C#--they are probably an order of magnitude or two slower. An array lookup would have been cleaner still, and we can probably assume there was no such excuse, but heck I just have to play devil's advocate sometimes... |
| « Prev | Page 1 | Page 2 | Next » |