- 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
Admin
How does people work at all without source control? I find sources control to be the easiest way to share code. What do they do, mail tarballs?
Admin
Wha...I...OW! Please, take it away. I'll do whatever you want! What did I do to deserve this? cry OK, I'll admit it. I'm the one that ran over the neighbor's cat. Please, just don't make me look at that code again!
Admin
Admin
Nice bow, btw...
Admin
Maybe this is a noob question then, but I wonder, if you e.g. jumped over the
line, what value would i1 have? also, what would happen if you didn't jump out of the loop again at the end?I have no problems using this on switch{} as Duff's Device does. But loops? oO
Admin
Trying to iterate combinations of up to 15 items?
Admin
It brings a tear to my eye. Such elegance. Such beauty. Such simplicity.
Well, yes, there's the bit about violating just about every written and unwritten rule and lore about programming, but still ...
I suspect this started life as a simple, single "if-then" construct, but then, over time, grew, like the Loch Ness monster.
On the other hand, extending it to include m(17) is practically trivial. So then: extendible code? Yes, 2 marks.
Admin
If I came across code like this where I work, I'd start working on refactoring it. With the full blessings of everyone that has a say on code quality. If it'd take me two weeks, I'd get two weeks. And daaamn, that feels so bloody good right now. >.< And srsly? How the fuck can he just sodomize his on stuff with that thing?
Admin
It's really straightforward, convert it to C++ and run it, benchmark it and see what kind of results you get, it's hard to believe he has the entire original program and can't figure out what's referencing it during execution.
Admin
Two good WTFs in a row.. Can Alex cap the week off with a hattrick ??
<RandomRant>Why on earth do people put in a captcha below their posts, and call it exactly that. Call it a signature if you want, but captcha is just a wrong term.</RandomRant>
Admin
WTF?! Really...
Excuse me, gonna go puke now.
Admin
I find it hard to believe they have no idea what it does when they can see what's happening just before and just after.
Also, I LOVED the use of "uplift".
Admin
Might want to hit up youtube for the real wording. Hint: it's not what everyone thinks it is.
Admin
No one would admit to any knowledge of that code. I dont think the writer of that code even remembers what it does. They were prolly possessed by satan himself when they wrote it.
Admin
This looks like what happens when computers generate code.
Admin
Admin
HAHAHA.. I guess you've never worked in a corporate IT department :)
Okay, sure, I guess some probably have decent processes, but most it's like the Wild West.
Admin
I wonder how that code would react like this if it saw itself. Possibly somewhat like this:
http://www.youtube.com/watch?v=Ka1PeNNi6dg
Admin
Admin
You, sir are the only one whose posts demonstrate that you comprehend what the code is doing (but almost).
The format(inn, '00')'s are unconditional, so there are a lot of '00's missing from your output.
Here's a nearly-competent rendering of this code in Ruby: class Combinator Combinations = []
def initialize(m) @m = m.dup setup_minimums end
def setup_minimums @minimums[17] = 0 (1..16).to_a.reverse.each do |i| @minimums[i] = @minimums[i + 1] + (@m[i] == 0 ? 0 : 1) end (1..16).to_a.each{|i| @minimums[i] = 0 if @m[i] == 0} end
def combinations loop_stage(1, 0, '') end
def loop_stage(stage, limit, string) max = limit == 0 ? @m[stage] : min(limit, @m[stage]) (@minimums[stage] .. max).to_a.each do |i| s = ('%02d' % i) + string if stage == 16 Combinations << s else loop_stage(stage + 1, i == 0 ? limit : i - 1, s) end end end
m is an 16-element array starting at 1 with integer elements from
0 to 99
def self.combinations(m) Combinations.clear new(m).combinations end
private :initialize
end
Yes, all those limit compares can not only be moved to the loop, you only need to compare against ONE thing. Furthermore, in the event that you aren't actually going to print out anything, you can do that with fewer than 100 compares.
The VB code is horribly unoptimized for the likely cases.
Question: If m = [15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15], what would the original code output, and how many compares would it take?
Admin
The real wtf is that he expects he can copy VB code and have it compile in a C++ compiler...
Admin
He's in for a surprise when he tries to compile that... unless the preprocessor is going to translate that :o
Admin
Yes, absolutely, and the Church-Turing thesis proves it if memory serves. In lay terms, it states that what is computable by recursive functions is computable by an iterative model (such as the Turing machine) and vice versa.
HOWEVER, The thesis does not tell you precisely how to do the conversion, but it does say that it's definitely possible.
In many cases, converting a recursive function is easy. Knuth offers several techniques in "The Art of Computer Programming". And often, a thing computed recursively can be computed by a completely different approach in less time and space. The classic example of this is Fibonacci numbers or sequences thereof. You've surely met this problem in your degree plan.
http://stackoverflow.com/questions/931762/can-every-recursion-be-converted-into-iteration
Admin
You are delusional...
Admin
You think Unit tests, source control, and peer reviews actually happen in most of the places code gets written in this world? Are you still in college or something?!
(Actually, I don't think you are - you probably work in one of the LARGE software firms that actually does stuff like that. And have obviously never worked for a small consulting company that produces custom applications.)
Admin
How would unit tests help you out here?
Cheers, S.
Admin
No afraid not. It's like trying to explain your really amazing dream to someone else - it never seems quite as good...
Admin
I own all your bases!
Admin
I think it calculates all combinations of the given set m.
The if-for-if-next constructs in comination with the labels and goto's are to make sure all loops are executed at least once. Like a do-loop-while..
Admin
Not sure if you're trolling or not, but I'll bite.
Currently I work for a small 20man consultancy, on a project with around 6 of us.. so fairly small
Yes we write unit tests, yes we have integrationt tests, yes we have BVT / deployment tests, yes we use source control, yes with have continuous build, integration builds and release builds.
As a contractor, I often work on small projects on my own, and yes I do all that even when it's me on my own.
Safe refactoring of code becomes very difficult without a good unit/integration tests suite.
Admin
svn blame?
Admin
Which part of "legacy code" and "vb5" did you miss? Pretty sure that the code was written before unit tests were invented.
And as for the source control, that's probably how he discovered who had touched the code.
Admin
Does a FOR loop always execute at least once in VB5? (ISTR this pitfall when learning BASIC many years ago.) In that case even a hard-coded "FOR i = 1 TO 0" would go through the loop once (i.e. it's more like a do...while loop), and to avoid that, you need the IF to skip the case where m(x) = 0. Therefore, after "pasting into C++" (and changing the syntax to suit, presumably) you could get rid of all these IFs, because in C++ "for (i=1 ; i<m(1) ; ++i)" skips the loop if m(1) < 1.
Admin
The original 'UnitTest' comment was in jest, some people picked up on that some didn't.
A conversation then went onto to say that source control and and unit testing where not applicable in the read world and something that was just taught on courses.
Admin
Brenda?
Admin
I accidentally this code, would this be a problem?
Admin
Yawn. XP never claimed to be doing anything new. You've missed the point. Why complain about a process whilst simultaneously claiming to have been doing it all along anyway? Oh yeh, because old duffers like nothing more than a whinge.
Admin
What you need is a fatty boom batty blunt. Then I guarantee you'll see a dolphin, a sail boat, and maybe some of those big titty mermaids doing some of that lesbian shit.
Admin
With unit tests you can poke the code with different inputs and see what it actually does. Then you write your own function and run the exact same unit tests on it and see if it works the same way. This is what you do every time you refactor code.
Admin
as if most companies did any of the above - god I wish they did. Sad truth is ppl use CVS and unit tests just take away development time (until they reach the end of a project and realize that the contract requires a shitload of tests. Then they start hacking in tests....)
sigh
wonder if I should switch to working in a totally computer unrelated business. Gardening.. Do ppl use computers for gardening?!? ;]
G.
Admin
Admin
I find that people dodge testing formally (and I know they do) when they do it anyway. I mean, its better to have a good testing base that can be run over and over when the need arises than to do it manually. And well, in my experience testing thoughroughly as you develop actually cuts developing time since you catch problems sooner. And the later you catch a problem the more expensive it is to fix it.
Admin
Feelin' stupid for writing something similar?
;-)
Admin
I can think of a few other things which require those same implements... Can't mention them here though
Admin
In the modern Web 2.0 world everybody uses Wiki for this. Anonymous can write code for free!
Admin
I've also noticed another trait on systems with good tests.
Systems with good test coverage, with sensible well written clean tests are less likley to suffer from 'big ball of mud', and many other anti-patterns (though bad brittle tests can introduce another kind of anti-pattern).
I belive the reason is two-fold, can refactor easily with confidence, and good tests tend to produce well designed code. (complex tests tend to suggest complex-doing-to-much code underneath)
Admin
Thanks for the belly laugh. Hilarious
Admin
I didn't think anyone could use that monstrosity even weekly, but it appears that some people are daily cursed to use it daily. Does that mean that each day, they are forced to use it against their will, and that as a result they have to use it daily? Or was this whole article put through google translate from some foreign language, such as british, that has ridiculous constructs such as that?
Admin
How about:
?