05-10-2009, 10:14 PM
|
#5 (permalink)
|
|
The Contributor
Join Date: Dec 2007
Posts: 60
Thanks: 5
|
Quote:
Originally Posted by xenon
My question is: why? As long as the constructor doesn't take any parameters it's safe to use any variant. It's only a matter of preference.
|
Yep, purely preference.. Don't be lazy, just add the damn brackets and make it look formidable
Quote:
Originally Posted by xenon
No, that would be a performance issue. You are talking about performance in variable names (which btw, I think it's bs, unless you give me a good reason for why your statement is true), but you can't see the difference in performance between calling a function and using a language construct?
|
I actually benchmarked this.. I had mixed thoughts about your comment, but I was right. If you benchmark it yourself (I did it over 1000 iterations with 12 objects in a test array), you will see that my method is actually a hair better. What makes my theory even more prominent is that he's incrementing a variable of a class (++$this->head_count is slower than ++$head_count).
Look at it this way: you're setting $this->head_count every time that foreach loops.. if it looped 1000 times, that variable would be set 1000 times, which is also 1000 mathematical calculations since he's incrementing it.. You can't honestly tell me that one function call seems like a bad idea. But then again, this argument is stupid -- both methods work, both methods are near equal in performance. There's nothing really to argue about I guess, it comes down to what you think is best. To get down to the nitty gritty, you would have to see how count() works internally.
Quote:
Originally Posted by xenon
But that's the worst method that could be used and does not implement the singleton pattern (which says that only a limited number of instances should be allowed to be created from a class). With your implementation, nothing stops me from creating a thousand instances of the class (each of which will overwrite the static variable $CreateTable with the last instance created).
|
I'm speechless. I'm trying to help the guy, and you're mocking me. Instead of mocking, why don't you criticize? I'm sure people would actually respect your opinion if you didn't come on as so hostile.
|
|
|
|