None World Cup related.
-
As a programmer, I am but an Acorn amongst so many mighty Oaks, however even I at my worst, laziest, cut and pastiest would never do something as kludgy and inelegant as that! It smacks of Yuck! I mean obviously it is functional, but ugly.
------------------------------------ I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
-
He clearly missed an excellent opportunity for using a switch statement. Yet another reason why programmers shouldn't be payed by the hour or the number of LOC. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, it preserves indentation, improves readability.
-
Might not be so much of a WTF - it might be deliberate. The compiler will concatenate the static strings at compile time, so there is only ever one string concatentation operation, and (assuming an even distribution of number lengths), an average of 50 integer comparisons. That may be *much* faster than the "better" implementation of a for loop or similar which could involve lots of string concatentations. In time-critical code, allocating memory on the heap (as most string concatenation operations do), can be quite expensive, especially with a multi-threaded CRT. Granted, the call to
Data.substring(length-2,length);
when length is 2 is silly, but I bet that the substring function has some optimisations for the special case of start = 0, length = (length of string). As with a lot of these Daily WTF code examples, you need a broader context to fully appreciate it. If this code is called once per day, it's completely stupid. If it's called thousands of times per second as part of a real-time algorithmic trading application, it makes much more sense. -
Now if I could just get Visual Studio to alternate the code row line colors like that.
Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane
-
Might not be so much of a WTF - it might be deliberate. The compiler will concatenate the static strings at compile time, so there is only ever one string concatentation operation, and (assuming an even distribution of number lengths), an average of 50 integer comparisons. That may be *much* faster than the "better" implementation of a for loop or similar which could involve lots of string concatentations. In time-critical code, allocating memory on the heap (as most string concatenation operations do), can be quite expensive, especially with a multi-threaded CRT. Granted, the call to
Data.substring(length-2,length);
when length is 2 is silly, but I bet that the substring function has some optimisations for the special case of start = 0, length = (length of string). As with a lot of these Daily WTF code examples, you need a broader context to fully appreciate it. If this code is called once per day, it's completely stupid. If it's called thousands of times per second as part of a real-time algorithmic trading application, it makes much more sense.How about:
left("000000...00000000", 100 - length(data)) + data
-
How about:
left("000000...00000000", 100 - length(data)) + data
Yep, that would also work (with a special case for length > 100)
-
Might not be so much of a WTF - it might be deliberate. The compiler will concatenate the static strings at compile time, so there is only ever one string concatentation operation, and (assuming an even distribution of number lengths), an average of 50 integer comparisons. That may be *much* faster than the "better" implementation of a for loop or similar which could involve lots of string concatentations. In time-critical code, allocating memory on the heap (as most string concatenation operations do), can be quite expensive, especially with a multi-threaded CRT. Granted, the call to
Data.substring(length-2,length);
when length is 2 is silly, but I bet that the substring function has some optimisations for the special case of start = 0, length = (length of string). As with a lot of these Daily WTF code examples, you need a broader context to fully appreciate it. If this code is called once per day, it's completely stupid. If it's called thousands of times per second as part of a real-time algorithmic trading application, it makes much more sense. -
OMFG :laugh:
-
Yep, that would also work (with a special case for length > 100)
-
He clearly missed an excellent opportunity for using a switch statement. Yet another reason why programmers shouldn't be payed by the hour or the number of LOC. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, it preserves indentation, improves readability.
Luc Pattyn wrote:
Yet another reason why programmers shouldn't be payed by the hour or the number of LOC.
I was at a presentation last week where a national military standards group qualified time-savings & dollars through LOC generated by a tool. Now given it will take you a week to install the thing, a week to get your "object model approved" and who knows how long to design the damn object model given that there is no way to verify on-site that the darn thing is correct other than generating code, compiling and failing, so going back to check your Object Model change something, generate code, compile, fail... etc... until it works. It sends data in a bogged down 85% overhead packet on the network, with a middle-man communicator in-between.... :) Gotta love all that time&dollar savings! all of their $ figures came from LOC. The middleware library freely given is saving your company x$ because of the 50,000LOC. Plus the OM code generator is saving you y$ for every 1000LOC it generates. :rolleyes: :rolleyes: The worst part is, they were completely serious, AND the military uses their numbers as proof of project worth.... :rolleyes:
_________________________ John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others." Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
-
Luc Pattyn wrote:
Yet another reason why programmers shouldn't be payed by the hour or the number of LOC.
I was at a presentation last week where a national military standards group qualified time-savings & dollars through LOC generated by a tool. Now given it will take you a week to install the thing, a week to get your "object model approved" and who knows how long to design the damn object model given that there is no way to verify on-site that the darn thing is correct other than generating code, compiling and failing, so going back to check your Object Model change something, generate code, compile, fail... etc... until it works. It sends data in a bogged down 85% overhead packet on the network, with a middle-man communicator in-between.... :) Gotta love all that time&dollar savings! all of their $ figures came from LOC. The middleware library freely given is saving your company x$ because of the 50,000LOC. Plus the OM code generator is saving you y$ for every 1000LOC it generates. :rolleyes: :rolleyes: The worst part is, they were completely serious, AND the military uses their numbers as proof of project worth.... :rolleyes:
_________________________ John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others." Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
El Corazon wrote:
they were completely serious
Numbers are particularly suitable for telling the future. If only all assumptions were explicit, known, valid, and constant over time. Quod numquam. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
40 characters to let.
-
El Corazon wrote:
they were completely serious
Numbers are particularly suitable for telling the future. If only all assumptions were explicit, known, valid, and constant over time. Quod numquam. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use < PRE > tags for code snippets, it preserves indentation, and improves readability.
40 characters to let.
Luc Pattyn wrote:
Numbers are particularly suitable for telling the future. If only all assumptions were explicit, known, valid, and constant over time. Quod numquam.
I wonder how their record for predicting the future meets up with mine? :-D
_________________________ John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others." Shhhhh.... I am not really here. I am a figment of your imagination.... I am still in my cave so this must be an illusion....
-
My head hurts. :omg:
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Might not be so much of a WTF - it might be deliberate. The compiler will concatenate the static strings at compile time, so there is only ever one string concatentation operation, and (assuming an even distribution of number lengths), an average of 50 integer comparisons. That may be *much* faster than the "better" implementation of a for loop or similar which could involve lots of string concatentations. In time-critical code, allocating memory on the heap (as most string concatenation operations do), can be quite expensive, especially with a multi-threaded CRT. Granted, the call to
Data.substring(length-2,length);
when length is 2 is silly, but I bet that the substring function has some optimisations for the special case of start = 0, length = (length of string). As with a lot of these Daily WTF code examples, you need a broader context to fully appreciate it. If this code is called once per day, it's completely stupid. If it's called thousands of times per second as part of a real-time algorithmic trading application, it makes much more sense.I supposed they may not have been aware of StringBuilder. Or string.Concat. Or the string constructor that takes a character and the number of times to repeat it. Or populating an array once up front (using a for loop, a bunch of index operations, or one of the above listed concatenation techniques) and then using an index operation to access the appropriate string of zeroes. And I supposed they may not be in an environment where they can create a static variable (i.e., an array). My guess is they are just inexperienced.
-
Might not be so much of a WTF - it might be deliberate. The compiler will concatenate the static strings at compile time, so there is only ever one string concatentation operation, and (assuming an even distribution of number lengths), an average of 50 integer comparisons. That may be *much* faster than the "better" implementation of a for loop or similar which could involve lots of string concatentations. In time-critical code, allocating memory on the heap (as most string concatenation operations do), can be quite expensive, especially with a multi-threaded CRT. Granted, the call to
Data.substring(length-2,length);
when length is 2 is silly, but I bet that the substring function has some optimisations for the special case of start = 0, length = (length of string). As with a lot of these Daily WTF code examples, you need a broader context to fully appreciate it. If this code is called once per day, it's completely stupid. If it's called thousands of times per second as part of a real-time algorithmic trading application, it makes much more sense.Oh, that looks like another language (JavaScript?) than what I was initially thinking (C#). I supposed join would be the way to go in that case.