You are here: Re: OOP PHP with MySQLi « PHP Programming Language « IT news, forums, messages
Re: OOP PHP with MySQLi

Posted by Erwin Moller on 02/01/06 18:15

Jerry Stuckle wrote:

> Erwin Moller wrote:
>> Jerry Stuckle wrote:
>>
>>
>>>
>>>Yes, bad programming. It binds all of your code to the variable
>>>$connection, among other things.
>>
>>
>> No, I use it only in functions that need the connection.
>> If a script needs the connection it gets the connection by means of a
>> include at top of the script.
>>
>
> Yes, and declaring something global has its own overhead.

Like putting the reference into the global-array?
Wow, THAT is overhead.

Let's double the memory in the server right away!

>
>>
>> If you need to change that you have a
>>
>>>huge amount of code to change.
>>
>>
>> Why should somebody want to change the connection-object?
>> It is needed for database-access.
>> If I need to change that I am really making a new program.
>>
>
> Well, lets say you change hosting companies - and the new one uses
> PostGres. Or you want to use the code on something which requires
> Oracle access. Or any number of things.

In that case I change my connectstring IN ONE PLACE.

Just as you do in your connection-object.

Your point being?


>
>>
>> It also makes the code less portable.
>>
>>>Also, if $connection gets changed someplace, you'll have a hell of a
>>>time trying to debug it.
>>
>>
>> Sorry, thanks for replying, and I do not want to pick a fight with you,
>> but this doesn't make sense.
>> I can say the same for your object-oriented approach, look:
>>
>> - If you use an (singleton) Object to deliver the connection, you bind
>> all your code to that object.
>> and
>> - If the connection in the object somehow get changed, all code breaks.
>> and
>>
>
> First of all, it was not MY singleton object. But it's a heck of a lot
> more portable than yours is.

That is what you keep claiming.
Now give some argumentation please, because I know what your opinion is, and
honestly, it is NOT getting any more convincing by repeating it.


>
> Yes, you bind your code to that object. But that object itself can
> change. Right now it uses MySQL. Later it can use Postgres, Oracle or
> even flat files. No change to the code using it.

That depends solely on the fact if you use a databaseabstractionlayer or
not.
You cannot just 'change database' without one, and you know that.
A lot of SQL-functionality is implemented differently on different
databases.

You need some ODBC or ADODB or another approach to reach that flexibility,
and it has zero to do with how some connection-object is found in a script.

If you do not agree, tell me why.


>
>> You know where you need a databaseconnection and get it delivered
>> somehow, singleton Object or global connection.
>> Both are lines of code, and both deliver the same in the end: a working
>> connection.
>>
>
> But an object is a lot more than a line of code.

Really?

My eyes are opening....


>
>>
>>>Globals in general are bad ideas.
>>
>>
>> Not if you need an outside variable inside a function.
>> It is perfectly legal.
>>
>
> And this one statement tells me that you've never worked in a commercial
> programming environment. What's "legal" is not necessarily "good
> programming practice".

I think you don't see the difference between a global in PHP and a global in
other many other languages.

Globals in PHP last for the duration of the script whereas the more usual
global means something is available to all processes running.
for example: In J2EE you can store stuff in ServletContext, In IIS/ASP in
Application, and that is where they stay, can get corrupted, etc.
But that is not how things work in PHP.

Go study the subject a bit more, then come back and try to insult me.
Ok?

About the commercial programming environment: Don't worry. Been there.
Did that. They pay me well. :P
I run my own softwarecompany now for years.
Mainly so I do not have to cooperate with zealots with low coding-experience
that resonate with each and every hype they hear about.

OOP?
Learned it, liked it, use it when appropriate.

Once again: I have 0 problems with somebody using a singleton database
connection design. 0 problems.

I DO have problems with your arrogant attitude.

If you were speaking with any authority, I might learn a thing or two, but
so you only repeated your invalid arguments.
Back them up.

>
>> I could also deliver the connection by refrence every call to every
>> function that needs the connection.
>>
>> No big diff.
>>
>
> Huge difference. But you obviously have made your mind up. Just please
> - don't promote your poor programming practices on naive new programmers!

I haven't made my mind up.
I can live easily with both approaches as I told you.
The problem is you seem to think for some reason the object-oriented
approach of delivering a connection is superior, which is not true.


>
>> Please remember that we are NOT talking about globals as in ASP
>> (Application), but just globals for the duration of the script.
>>
>
> Yes, I know EXACTLY what we're talking about!

So please explain all the fuss you make.
I haven't seen any argument yet.
(I am serious)

>
>>
>>
>>
>>>Citrus's design is much better. There is a little overhead - but not
>>>all that much.
>>
>>
>> Yes, Citrus claimed the same.
>> Also without any argumentation that made any sense.
>>
>> If you are so sure of the superiority of the Object approach, why can you
>> not tell us why?
>>
>
> I tried. You obviously aren't listening!

I responded in the earlier thread with to your and citrus' claims, but you
didn't bother to respond yourself.
Get a mirror man.
It is you who isn't listening.


>>
>>
>>>And I find objects almost always improve the structure of my code. It
>>>also makes it more flexible and configurable. For instance - I can
>>>easily change databases simply by changing the database object. No
>>>changes in my code are necessary.
>>
>>
>> No changes in your code needed?
>> Of course you need to change something in your code, the Object that
>> makes the connection is changed by you.
>>
>
> No, the OBJECT code changes. MY CODE does not!

Aha, now I get it.
The Objectcode is not part of the application in your view?

Get real.


>
>> Now compare this to an include that delivers the connection: I also have
>> 1 place to change the connection, and it is included everywhere.
>> Then everywhere where 'global $connection;' is used, the connection is
>> up-to-date.
>>
>> Don't try to sell nonsense to me.
>> I developed years and years in Java, and do not fall for laymans
>> arguments.
>>
>
> I've been programming since 1967 (in Fortran I). I've written C++ for 18
> years, some of them as a programmer for IBM. I've been writing Java for
> over 10 years. And since then I've been a successful consultant,
> writing code and managing projects.
>
> Hardly a layman.

Ok, great credentials.

Now show them off and write a decent response.

>>
>> Another thing: In PHP Objects are only halfhearted and last only for the
>> duration of the script. They are not persistent. (Unless of course you
>> serialize and deserialize them from script to script, but that is not
>> exactly persistent.)
>
> So? The same is true for any program!

Nonsense.
In Java Objects happily exist in memory (or swapped for that matter) for
months and months.
If memory servers me well I have a few around for some years now.

PHP has to serialize them, generating a string, and revive them where
needed.
Really, that IS something else than being in memory and in-process.
PHP is not really OOP. They just added the possibility to use objects. Good
move by the way.


>
>> Object in PHP are nothing more than a bundling of some functions
>> together, and their own namespace. Really that is all there is to it.
>>
>
> And you obviously don't want to understand.

Well....

Where did I hear that before?
Hmm, let me see....
I remember! It was some guy telling me I could find peace if I followed his
God. Yeah that was it.
I asked him why I should follow his God while so many others are around too.
I didn't want to listen, so he told me.

Well, I DO listen. Give me something reasonably to think about!

>
>> Don't try to make more of it than that.
>>
>>
>> Heck - I can even use flat files when
>>
>>>necessary!
>>>
>>
>>
>> So can I, but what has that to do with this issue?
>> Are you suggesting that Objects are the next step in evolution of the
>> $connection in scripts? Haha.
>>
>
> The fact is - I can do it without any changes to my code!
>

We have been over that before.
You DO have to change your code, how else will the object know its
connectstring or databaseserver or whatever changed?

When using a connection that is included above every php-script you also
have only 1 place to change that.

Really, I do not see any advantage here.
If you do, tell me.

>>
>> Regards,
>> Erwin Moller
>>
>
> But this conversation is at an end. I don't argue with close-minded
> idiots.

As you can see: I DO agrue with idiots.

>
> Here's a tag line for you:
>
> "My mind is made up. Don't confuse me with the facts!"
>

Sounds very kinky and cool, really!
The kind of line you can use everywhere to make your argument sound more
worthwhile. Readers Digest?

Erwin

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация