- 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
The real WTF is the deep nesting. The fact that nesting involves loops comes as a bonus, I guess. But this is not an exception, I am afraid, this is a standard pattern (C++):
if (..) { if (...) { if (...) { ..... }}}}
I think I counted 14 levels once (10 for sure).
The justification around here is: avoid multiple returns, break, and continue.
Admin
I find that my LINQ to SQL code is considerably less efficient than the equivalent SQL. What I think needs to happen is a replacement language for SQL that is stored and run directly in the DBMS. SQL is powerful, but it can also be a nightmare for non-trivial queries. I think it's time we rethought the whole querying relational data thing and came up with a more modern language. :) But still something at the DBMS level.
Admin
It's not enough. We need to go deeper.
Admin
The flip side here is that code like this, combined with non tech-ignorant management provide the perfect opportunity for any decent developer to come along, fix this with about 30 minutes work and become an instant hero for management.
All praise to the original author you hero maker =D
Admin
Sigh... another group of people trying to impersonate my greatness. And for the record, I don't speak Hindu at all, just another myth from the rumour from the gossip mill.
Admin
As someone who has taught himself both VB and SQL, I disagree. This is what happens when a bad programmer partially learns something and doesn't get their code reviewed.
Admin
I used to be like that, then I learned the value of using the right tool for the right job.
Admin
As someone who has taught himself both VB and SQL, I disagree. This is what happens when a bad programmer partially learns something and doesn't get their code reviewed.
Admin
ABAP == As Bad As Possible??
Admin
Why isn't The Cow in that picture?
Admin
Admin
We have customers who do that to us, but in the context of comparing our product to a competitors product.
Admin
Clearly he did this all wrong, he should have put a 4 hour sleep and told the boss he halved the time the report took to generate.
Then say he was still working on it, spend some days reading the interwebs, then change the sleep to 2 hours.
Tell the boss hes halved it again but recons he can squeeze some more performance out of it. Spend some days reading the interwebs, then take the sleep off.
1 week of free reading.
Admin
Chicks don't always like it when you go that deep.
Admin
It's just FOREACHs, all the way down.
Admin
Quite!
Admin
Also, do not type "Google" into Google. You can break the internet. Seriously. Don't even do it as a joke.
Admin
Admin
Get reasonable performance requirements written into the requirements for the product. By that I mean actual numbers e.g. "such and such and operation will take no longer than XXX seconds on YYY hardware" or "able to perform XXX operations within a YYY period with the ZZZ constraints <insert network bandwidth, CPU, etc as required>". Make sure that by your estimate the numbers should be achievable. Also make sure that any schedule includes an optimisation phase, and a stakeholder who needs those performance numbers met to champion it.
If such performance is not met by the project, you then negotiate to do one or more of the following (preferably as early as possible):
a. Relax the performance requirements; b. Change the hardware requirements; c. Add developer time for optimisation.
On multiple projects I've negotiated an amount of time for optimising in the schedule (waterfall, agile and hybrid projects). I always advocate "make it work, then make it fast". On my last project we were well off the performance requirements after "making it work". I'd already got a committed 3 weeks for optimisation in the schedule. After the first 2 days of my "make it fast" phase I'd improved performance about 10x (working with my own codebase, so easier), but we still weren't at the numbers. After 1 week I'd achieved 100x improvement in the most important areas and we were well within our performance requirements.
I then made it clear that the remaining 2 weeks were still committed for optimisation if I determined that it was needed.
I was in the fortunate position of being the technical lead on that project, but I've previously managed to negotiate time for optimisation on projects where I was "just a developer". The important points are to "prove" that it is needed (e.g. customers set the requirements); to have someone with enough influence to enforce that it happens, and to be confident enough to say "I think this is achievable within XXX timeframe".
Admin
I should add in our defence that it was a J2EE project using JPA (Hibernate) and the initial slowness (most of which was due to the database) was (a) largely due to strong relationships between entities (i.e. fetching the entire tree instead of just what was needed) and (b) didn't show up until we had large amounts of data in our performance tests (actually a similar setup to the article - agents with skills, assigned to supervisors, etc - about 20,000 of them).
Admin
How about we added to DBMS the capability to store compiled code inside them? Then this code could be call-able through queries as functions or as procedures. I think I would call them saved procedures or stored functions or something like that.
I might as well patent the idea right now.
Admin
Admin
Are you sure he shouldn't be using some Spaten Optimator instead?
Admin
I thought lazy loading is on by default?
Admin
The Elders of the Internets would never let you do that anyway.
Admin
The Elders of the Internet would never let you do that anyway.
Admin
Whereas I'm the kind of developer that likes to let the RDBMS do what it's good at. Frankly I'll push as much work as is possible and practical on to the database.
Admin
This is valid PHP due to variable variables (pure evil):
<?php class BossClass { public $BOSS; public $Offspring; public function __toString() { return "BOSS"; } } $BOSS = new BossClass(); $BOSS->BOSS = new BossClass(); $BOSS->BOSS->Offspring = Array("Offspring 0", "Offspring 1"); echo $BOSS->$BOSS->Offspring[1]; ?>Admin
Admin
Having to remember back a bit (was made redundant, been fixing up a house for the last 6 or so months ...) but whether a relationship is lazy or eager by default is configurable and/or depends on the version of Hibernate (I'm pretty sure the default changed between major versions or something).
In our case, an eager-by-default policy suited the third-party libraries we were working with (remember - first, make it work), in particular because the retrieved data needed to escape the EJB boundary - everything that was needed outside that boundary had to be loaded by the time it escaped. Selectively making relationships lazy and ensuring they were used appropriately made more sense. Unfortunately, this usually resulted in much much more data being loaded than was required.
Admin
स्तन
Admin
Addendum - nevermind - didn't notice the Hibernate
Admin
That translate to "boob" in english.
Admin
Admin
Admin
I've seen that happened once, it was indeed sad and funny (specially funny since I didn't have to fix/deal with it:P)
Funny thing is that the CodeSOD is exactly the type of code I had to deal with with my first full-time programming job. Only difference was that it was written in FoxBase (instead of forEach we had SCANs)... and at least this CodeSOD has decent indentation. Imagine this CodeSOD with truly random indentation, duplicated by the dozen in a single source file... and then hundreds of such source files (evil grin.)
My team, myself, had to deal with that type of crap by the hundreds, literally hundreds of legacy reports originally written by a consultant who I'm sure charged more than all of us combined, with logic liberally copied and pasted from each other in a combinatorial madness.
It took us about 2 years non-stop just to clean that shit with proper SQL and a modicum of modularity. Baptism by fire baby!
Admin
How about this: http://lmgtfy.com/?q=letmegooglethatforyou&l=1 ?
Admin
Indeed. When run amok, cyclomatic complexity can be an unforgiving fat singing lady.
Admin
Depends on the type of organization you work and the urgency of refactoring. If the code is ugly and suboptimal, but the cost of living with it as-is is much less than the cost of fixing it, you just let it be.
It's only for code that really needs to be refactor (because it can't be extended, or runs unacceptably slow, or whatever) that you put the effort to refactor, and only when the organization or team (not you) allocates time for it.
Otherwise, it is typically a losing battle. And at this point, the only other alternative is to make sure that new code is properly refactored and written. Otherwise, it's like adding more techno-shit on a techno-shit lasagna... and this is typically what happens (sadly so.)
And writing code with continuous, judicious refactoring should be way to go (barring emergencies), independently of whether the existing code base is good or bad.
Maybe you need to be a bit pickier where you work (which is obviously not an easy thing to do, specially with today's economy). When push come to shove, we work in whatever festering software cesspool that is available. Bread to the table first and foremost. But when the opportunity arises (and it always does if you keep your eyes open), one should pursue better teams, better projects, better organizations.
Many times you will find that you cannot go back to fix things that are just truly ugly. So the only way to move forward is to work on the "new" things. And here I have to ask you: do you write these "new" things the proper way? Do you refactor? Do you constantly clean as you go forward?
Because that's the only thing one can do when there is no time (or organizational will) to clean existing systems. The things that are written like crap is a given. The new things that come from that point, they are not given.
So the only practical solution is to make things better by not making them worse, by raising a working standard. As you do that, typically, productivity goes up. And if goes up sufficiently, the organization might get the will (and the ability) to free resources to refactor (or replace) the old things that need refactoring.
Only if doing so directly helps you deliver on your current tasks on the required time, in a manner where refactoring is a living, continuous practice. At the end of the day, you are a professional on payroll, paid (for better or worse) to produce something on a schedule (on their schedule, not yours.)
Even then, I would be hesitant to do such a thing because it artificially inflates the actual time to implement your current task. So from there it becomes impossible to estimate the actual cost of building things.
Even worse, it hides the cost of refactoring old things, so all of the sudden management gets this improvement (old code being refactored) all of the sudden obtained for free (since the cost in man/hours is hidden.) They will semi-rightly assume (given the faulty data) that these things are easy to do. Good luck trying to convince them otherwise. And it will not be their fault, but yours.
There are implications on inflating your current tasks so as to do other tasks that are under the radar, implications that can work against you and your team.
What you can do is provide a root-cause analysis, linking code that needs refactoring to code that you need to implement, the "new" stuff. If you can prove that refactoring the old stuff your new stuff depends on will be beneficial to your new stuff (and perhaps other things on your pipeline), then you can track the refactoring of old stuff, you can make management aware of it and they can allocate time for it.
Obviously, it depends on the type of management, but that's the part you cannot control. What you can control is the work you do and how you present that work to them, independently of whether they go for it or not. You have to think less in terms of coding, and more in terms of software engineering and process/resource management.
That could be a better thing to do, but you understand that you'll have to do it on your own time, not on the clock and certainly not to the detriment of your current tasks.
I think that's the best thing to do in such situations. You use it also as a way to train yourself, to better understand those systems that need refactoring, to understand new technologies and ultimately to remain (and be more) employable, marketable.
Even if management still doesn't go for it, the knowledge you get from it, it stays with you, and that's gold.
Admin
Obligatory xkcd reference to good code: http://xkcd.com/844/
Admin
This is not always a WTF. In particular, if the database was something like MySQL with the default backend, which implements only table-level locking, then a query which takes one minute to perform is a serious no-no, as it will cause all other queries to also grind to a halt for one minute. Thankfully, even MySQL has changed since the 90s and has provided backends which do not do this (although you still can, if you like).
Sometimes, a procedure which takes 8 hours is better than a procedure which takes 1 minute, especially if the latter causes all other operations to grind to a halt.
So I'd say either the original programmer was trained on MySQL and did not realize the advantages of a more mature database, or the original application was on MySQL, and the programmer was smart enough to avoid taking down the system for a management report (and the database was later upgraded without fixing the reports).
Admin
Admin
Lol! I once worked on a program where the developers would not guarantee the results were accurate, only that the results would be the same as the previous versions gave.
Admin
Lol! I once worked on a program where the developers would not guarantee the results were accurate, only that they were the same results as you got from previous versions.
(better with the original post for context, eh?)
Admin
Admin
What? He couldn't get a select with a few joins to sub-second? Fire him!
Admin
If you have 14 nested foreach's, that's not 14 layers, it's 14 dimensions.
WTF? String theory can explain the whole universe with 11 dimensions. Who needs 14?
Admin
Real Scientist: "Please just run the hoover round and be on your way Pablo, I don't have time for your flights of fancy today."
Admin
No, its all ilusion of the projection of event horizon of a massive black hole in the center of universe. the universe has only 2 dimensions. everyting else is fake.
Admin
ps: the reality (tm) is a mere hologram.