- 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
Anyone else notice how butt hurt PHP programmers seem to get when anyone bad mouths their language at all? Saying how only bad developers write bad code!
Yet somehow that compassion disappears when it's VB, cause that's TRWTF am i rite?
At least we don't need to import our globals... wtf?!?
Captcha: Plaga - What is a bad developer!
Admin
You can declare new globals just the same way. If the variable doesn't exist, it will be created. So you really do can declare globals inside functions in PHP.
Admin
There's a popular chemistry blog that has a section called "Things I Won't Work With". PHP seems to be the software equivalent of thioacetone.
Admin
Actually I've been there, done that - in fact the biggest system at my present employer started out just like the one described. But over time, I and later others have gradually been migrating the old code to a new system that uses OO. It's generally not that big a deal to slice off a section that sits fairly well by itself, and create a class around it. Then one can pass (for example) the db connection handle as a parameter to the constructor. I don't work on that system any more (haven't for several years) but these 'baby steps' have fixed a lot of problems on pieces of code as they have been subject to modification for other reasons, without ever having a budget to do a big changeover.
It's worth noting that redesigning from scratch (I've done that before as well, with a code base of several hundred thousand lines of code in multiple languages.) is almost NEVER a good idea. This amounts to trying to build a ferrari that is backwards compatible with a Model T. You have to duplicate the 'bugs' as well as the 'features', and you rarely know which exists, much less which is which.
Also, these projects almost always take 2 or 3 times as much time and effort (= money) as planned, and have a much higher probability of failure. Refactoring piecewise can be difficult, but can almost always be done piecewise, and limits development risk.
Admin
A great page. Regarding triazadienyl fluoride, he has these thought-provoking words (italics mine):
"...The next step is introduction of the fluorine, and when elemental fluorine is the most easily handled reagent in your scheme, let me tell you, you're in pretty deep."
Admin
Admin
There, that makes more sense.
Admin
Off topic: Somebody knows how the pictures in the topic got obfuscated?
Admin
Yep. Talk about code smell.. :-)
(My personal favourite would be the FOOF or ClF3 entries though.. :-)
Yazeran
Plan: To go to Mars one day with a hammer
Admin
Opening a DB connection shouldn't be a significant processing burden for either the client app or the DB in question.
The idea that you open a database connection once, and then hang on to it indefinitely is stupid.
Admin
Nice to see a fellow NetBeans user.
Admin
I'm sure with 'enterprisey', they mean small company needing internal tools... no real enterprise system can exist from php :-P
Admin
int myGlobal = 0; // This is a global variable. This is bad.
int someFunc() { // trivial example of a variable that is, technically, globally allocated but isn't within global scope static myStaticVariable = 1; return myStaticVariable++; }
int main() { int someInt = myStaticVariable; // Compiler error, not in sope
return; }
Admin
Using php correctly in web applications is a piece of Cake(PHP)
Admin
Admin
Yes, but first 'down the line' and as we all know no PHB will authorise an 'unnecessary' expense this year (even if it means savings next year)
Admin
Your knowledge isn't best as far as I know.
You can declare a global inside a function just fine within PHP.
Admin
Unfortunate, I disagree.
Admin
Yes... but its ok... They know me here.
Admin
I think bolding it cause it to get pointed.
Admin
Still, why do it if you dont have to? Sure, your code may be "only" 5% faster without it - but all those 5%s add up.
Yes, that would be stupid. Fortunately, the connection is automagically closed when the script finishes, so the problem doesnt arise.
And while we are on the subject, hating on globals for its own sake without understanding why is every bit as bad as using them for its own sake without understanding why.
I think the problem is something to do with the "without understanding" part, not with the "globals" part.
HTH.
Admin
Not Found!
Admin
It's the same like with documentation: we make it when we have time
Admin
Maybe you should write code more instead of badly trolling?
Admin
Wow. Just wow.
Everyone knows it's "bob".
Admin
Come on, you can have local variable in
, that can be accessed from all over the place, because it simply lives long enough to be used :)Admin
Just think what this fabulous usage pattern would be like in a multi-threaded application.
(Even the thought gives me nightmares.)
Admin
Admin
You had me at "PHP".
Admin
Smartass.
Admin
I agree don't think having a utility functions open and closing db connections is really good programming practice. Also get into that habit and will come a day when someone removes the code that closes the db connection.
It's in the same vein as 'don't end a sentence with a preposition, never start a sentence with the word and. In some cases there is no other option (interrupt routines for instance) Or a small program, that does one thing and runs once through, global's aren't bad.
The PHP program, the real wtf is the culture that allowed that problem to fester for so long with no attempt to mitigate it. No attempt at all to deal with maintenance issues.
Admin
Heard of Technical Debt?
In the long run, the little time spent incrementally refactoring would save the company more money than continuing to make the code less maintainable.
Granted, there's a "fuck it" point, but that's besides the point of this WTF.
Admin
It's a culture that tolerates people even when they freely admit to not understanding how to use arrays or functions and prefer to avoid finding out.
Admin
I have read of technical debt, but have you heard of "golden goose"? Any system that is total mess up that no sane programmer is willing to go near it is a golden goose for service providing company.
Admin
This is utter nonsense. Use a different variable in include file B. It is not expensive to use a different variable. Even if you use globals all over, why not GlobalProdDB, GlobalDevDB, etc? You can't go around "temporarily" switching a global var that points to a database. People are talking to the database every microsecond, apparently using that single variable. And of course if you're being sane, just pass the db connection string/object/whatever this is as a parameter.
Admin
It wouldn't take much longer than this fix did. And unlike this abomination of a fix, people in production won't be talking to the test database for brief period where the db con variable is reassigned. How many orders inserted into the test database instead of the prod database do you imagine it would take to cover 20 extra minutes of coding?
Admin
Wait... what? You DON'T think it's a good idea for a utility function to manage the db connections? You think it's better for every dev to manage it manually every single time they talk to the database? Which is more error prone, copy/pasting 1000 times, or one core library that is re-used?
You don't have source control and dev/qa systems?Admin
That is purpose of properties files in java.
Admin
captcha: Asshole.
Admin
I still don't get why the production application is accessing the test database. (Or indeed, why it needs more than one database at all.)
Admin
Sometime it is not possible to have test system. I provide one example.
Ask yourself, is that true test of the system? How will you trust the system to work with real credit card? can you use your own credit card to test?
IN CONCLUSION, NOT POSSIBLE TO HAVE TEST SYSTEM.
Kthxbai.
Admin
So your solution is to spend real money buying items in the test database? GENIUS.
Admin
Admin
My solution is not exist. There is no solution. This is what I am saying, but you're not willing to accept it. Step in my shoes and you will know what I talk of.
Admin
Legitimately, although I truly respect the people who have the tenacity to work in that kind of garbage, I'd quit.
Everybody's different, but having to maintain code like that would be worse than taking a paycut. A friend of mine offered to get me an interview at a company that develops using a framework that I feel is only capable of producing horrible code, and I declined to interview...despite the fact that the wages would be roughly 1.8 times my current salary. My sanity is worth far more than $90,000/year.
Admin
I know the name testdb implied test environment but it actually pointed to a production database...Yea, it got me too when I started.
Admin
Guilty as charged. It's another WTF just to ensure that the next function call, which required that global identifer to point to the correct database, would work without having to modify the function itself, and going around fixing the dependencies from extra tight coupling.
Admin
I renamed $sql to $dbCon in the code to clarify that it is connection identifier.
Admin