| « Prev | Page 1 | Page 2 | Next » |
|
FRIST maybe?
TRWTF is Enterprisey PHP |
|
not frist because aksimet needs shooting...
|
|
This is why people don't like PHP; they see code like this.
As a PHP supporter, I have to point out that PHP DOES allow OOP including some great frameworks. Just preempting the PHP bashing. captcha: damnum: my thoughts on this code |
Re: Globally Coupled
2012-01-23 11:33
•
by
Shutterbug
(unregistered)
|
|
Agreed Fyrilin - PHP isn't as bad as that when it's used with an ounce of common sense.
Given the option if presented with code like this to maintain, it's either being rewritten from the ground up or I'll be making sure the door doesn't hit me too hard on the way out. |
|
I don't do PHP, but rather C++ so I may be a little off here, but this is a prime reason why you don't use Global variables for anything (Variables that get allocated globally are a different matter - and yes, there is a difference).
|
|
Real
PHP WTF In no specific order |
|
Yeah, general "rule of thumb", if you cannot count your globals on your fingers, there's probably something wrong. On that note, I once had a vendor BRAG to me that the next release of their software used over 6,000 global variables. The poor fool thought that it was a measure of the size, and therefore sophistication, of their product. To me, well, let's just say that data point explained a lot ;-)
|
Re: Globally Coupled
2012-01-23 12:05
•
by
michael
(unregistered)
|
|
Variables that get allocated globally are a different matter - and yes, there is a difference."
Are you speaking of heap variables? If so, it's far better to call them "heap variables" than "variables that get allocated globally." If you mean something else, please do educate us. |
Re: Globally Coupled
2012-01-23 12:16
•
by
Why'd he turn it down?
(unregistered)
|
All global variables live in the heap, but not all heap variables are global. A global variable refers to a static, a singleton, a variable where every function/class refers to the same value. This is contrasted to a member variable, a local variable or a function argument. This definition, by convention, tends to exclude global constant primitives. An excess number of global variables is typically a sign something could be redesigned. |
|
I may be confused here. You have a global db connection that everything seems to be using. In several places it is switched to a testdb and then back. Is this for testing the code against a test environment vs a production environment (which the global variable should be changed to point to the test db) or is there some other reason for this?
|
|
TRWTF is that "fred" is used in the comment block, but not used as a temporary variable name.
(one of my CS professors was in the habit of using "fred" as a temp/nonsense variable name in the same manner as "foo" is often used) |
FTFY |
Re: Globally Coupled
2012-01-23 12:45
•
by
michael
(unregistered)
|
|
All global variables live in the heap, but not all heap variables are global.
Global variables do not live in the heap. A compiler places them into a static section that is loaded straight into memory at load time. No malloc, no free, no heap. I was asking about what was meant by "variables that are allocated globally" but which are not global variables. I suspected, perhaps incorrectly, that this was a reference to heap variables, which can be made globally accessible (as opposed to stack and member variables, which can only be used in context). |
Re: Globally Coupled
2012-01-23 12:50
•
by
Boog, I Am Your Father! (aka Behold The Return Of Zunesis!)!
(unregistered)
|
Hear, Hear! |
|
"What I did was to swap out the link identifier"
so the real WTF is his/her solution to the problem imho. what would hinder him/her to create another global var for db2? |
|
Globals can be declared INSIDE FUNCTIONS???
|
Re: Globally Coupled
2012-01-23 13:15
•
by
Rcxdude
(unregistered)
|
|
depends on the language. what you said is true for C and C++ but I suspect is not true for PHP, python, etc
|
Re: Globally Coupled
2012-01-23 13:18
•
by
Melnorme
(unregistered)
|
|
This is implementation dependent.
"Global variable" is a description of semantic scope, not of generated code. |
|
$GLOBALS['db2'] = ...;
and its done -.- |
If you want to access a global variable from inside a function in PHP, you first have to run the statement global $variableName. If not, $variableNameis treated as a local variable. There is also a supoerglobal array called $GLOBALS that would let you access it as $GLOABLS['variableName']. Good stuff, huh? |
Re: Globally Coupled
2012-01-23 13:26
•
by
Not Jimmy Wales
(unregistered)
|
|
No, that is a comment signed by someone named fred, who apparently worked on the code. It's not the name of a variable.
Ob captcha: WTF is a laoreet? Can I buy one at a petstore? Or is something I shouldn't mention in polite company? |
|
Global variable increase window of vulnerability. This is well known fact. They are necesary evil in our trade.
|
|
Is it just me that is shaken by the database calls directly in the page? Separation of concerns anyone?
Someone in this thread mentioned something about PHP supporting OO concepts and all these are bad examples of PHP, and that PHP really is good, really honestly... Please, show an example of what "good" PHP would look like... Also, PHP is TRWTF, amirite? </obligatory PHP bashing> |
Re: Globally Coupled
2012-01-23 13:57
•
by
Dazed
(unregistered)
|
I do sometimes use more than that. But only in stand-alone run-to-completion applications, where I initialise them at the beginning and never change them after that. In server-side applications I generally reckon I can count the global variables on the fingers of one foot. |
Anything that frustrates morons such as yourself is a good thing. |
|
What madness is this?! How can someone *design* an enterprise-y system with a whole mess of globals?!
This reeks like a simple application became a general application became a cross-functional business corporate scorecard analytical engine... |
|
TRWTF is how many idiots think that they are clever or sophisticated because they bash PHP.
|
Re: Globally Coupled
2012-01-23 14:14
•
by
fuckingCommServerForgotMuUsername
(unregistered)
|
You could have a look at the symfony framework code, most of it is quite clean and dandy. |
Re: Globally Coupled
2012-01-23 14:25
•
by
geoffrey
(unregistered)
|
I could not have said it better myself. When the job needs done, a can-do programmer understands that sometimes everything can't be pretty and perfect, and must resort to these necessary evils. |
Re: Globally Coupled
2012-01-23 14:27
•
by
Darkstar
(unregistered)
|
|
Errhh __FILE__, anyone?
|
|
Without discussing the pitfalls of globals, doesn't this have a direct refactoring pattern? replace the code of the function which uses globals with a function call to a new function passing in the globals as parameters. Implement the new function using the original code, replacing the global references with the parameters.
This would work for all old invocations and the new code could just call the new function. Metro. |
And where is budget for code come from? Remember everything need money. |
|
Search results in the screenshot seem to talk about instances of '$sql' ?
|
Re: Globally Coupled
2012-01-23 14:56
•
by
The name
(unregistered)
|
Selling sex. |
We knew that! ;-) I'd take it beyond "could be" and "typically" but most often have seen "as if" and "rarely is" |
|
Not a single comment has pointed out that Amber is female????
|
Ambar mean sky in Sanskrit. It is boy's name. |
Not to best of my knowledge and my knowledge is best as far as I know. |
|
I once read an article that stated that some companies make a mistake of "redesigning something from scratch" when the should have just fixed what was broken, and that there is rarely a reason to redesign from scratch.
This I believe falls into the "redesign from scratch" catagory. |
Re: Globally Coupled
2012-01-23 15:45
•
by
Nag-Geoff
(unregistered)
|
Surely, you live in fantasy world. |
|
TRWTF is not PHP, TRWTF how we allow armies of incompetent grunts to work as programmer.
Im pretty sure one can create an enterprisey Fecosystem in any langage. |
Oh, so you're not actually declaring new ones, you're just importing existing ones... that makes sense... sort of... |
Re: Globally Coupled
2012-01-23 16:27
•
by
Gibbon1
(unregistered)
|
I often think that I'm choosing between two evils. Sometimes one is an orthodox evil, global's, goto's, functions with side effects, all these are evil, but sometimes to avoid them brings on worse evils. |
Re: Globally Coupled
2012-01-23 16:50
•
by
Matt Westwood
(unregistered)
|
In the UK (England in particular), "Fred" is used as a generic joke name. From what I understand from the lyric sheets of a certain Jefferson Airplane album, the same applies to a greater or lesser extent in the US too, yeah? |
Re: Globally Coupled
2012-01-23 16:51
•
by
Matt Westwood
(unregistered)
|
I take it you're a code monkey? |
Re: Globally Coupled
2012-01-23 17:03
•
by
frotl
(unregistered)
|
Someone could do significantly better than the above without using OOP. Bad programmers are bad whether its procedural programming or object oriented programming. |
Re: Globally Coupled
2012-01-23 17:06
•
by
LOADING
(unregistered)
|
Make sense. Javascript opts for var to declare a variable locally. PHP opts for global to import from the global scope. They are opposites... |
Re: Globally Coupled
2012-01-23 17:26
•
by
Jack
(unregistered)
|
"Amber" means fossilized tree resin in English, and it is a girl's name. But why should someone want to point that out? |
Re: Globally Coupled
2012-01-23 17:31
•
by
anon
(unregistered)
|
...and the bugs that stem from such ridiculous code cost money too.... it's a pretty easy argument to forge IMHO. You could also implement changes bit by bit, that is the true way of getting old code improved, don't try to justify doing it in one big hit... most of that can be done "out of scope" with other development too |
|
Seems many languages permit global variables and few languages prevent global variables. Is that because we are using really old languages from before anybody knew how to structure code? Or are new languages still designed with support for global variables?
|
| « Prev | Page 1 | Page 2 | Next » |