Re: PHP global namespace clogged up
From: Tony Marston (tony_at_NOSPAM.demon.co.uk)
Date: 09/06/04
- Next message: Tony Marston: "Re: PHP global namespace clogged up"
- Previous message: Janwillem Borleffs: "Re: XSLT processing instruction to use PHP"
- In reply to: Tim Tyler: "Re: PHP global namespace clogged up"
- Next in thread: Tim Tyler: "Re: PHP global namespace clogged up"
- Reply: Tim Tyler: "Re: PHP global namespace clogged up"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 6 Sep 2004 00:20:21 +0100
"Tim Tyler" <tim@tt1lock.org> wrote in message news:I3KtvH.Dn5@bath.ac.uk...
> Tony Marston <tony@nospam.demon.co.uk> wrote or quoted:
>> "Tim Tyler" <tim@tt1lock.org> wrote in message
>> news:I3FJqG.JKB@bath.ac.uk...
>> > Tony Marston <tony@nospam.demon.co.uk> wrote or quoted:
>
>> >> What's wrong with http://www.php.net/manual/en/funcref.php ?
>> >
>> > The particular page is not what I'm complaining about. It's
>> > PHP's global functions that are the problem - and I've already
>> > stated why I think a single big function namespace is a bad idea.
>>
>> Global fuctions are not a problem except for you.
>
> Ever heard of polluting global namespaces?
No, never.
> This is programmer's 101 here, surely:
>
> ``Namespace pollution -- Global names are available everywhere. You may
> unknowingly end up using a global when you think you are using a local
> (by misspelling or forgetting to declare the local) or vice versa.
That is difficult to do in PHP. Within a function every variable is local
unless you explicitly define global $varname; beforehand, or use
$GLOBALS['varname']. Only a bad programmer would confuse the two.
> Also, if you ever have to link together modules that have the same
> global variable names, if you are lucky, you will get linking errors.
> If you are unlucky, the linker will simply treat all uses of the same
> name as the same object.''
Firstly, PHP does not have linking. Secondly, different modules cannot
reference different sets of global variables, so if they all reference the
same global name they will all use the same object.
> - http://c2.com/cgi/wiki?GlobalVariablesAreBad
That article was not written with PHP in mind, therefore some of its
arguments are totally irrelevant. Besides, it is just an opinion shared by a
small minority so I do not feel obliged to give it any credence.
> Many of the other points there apply to functions as well - see the
> sections on non-locality, lack of access control or constraint checking,
> and implicit coupling.
>
> This is why most programming languages have namespaces - and use them.
None of the languages I have used in the past 30 years have had namespaces.
I regularly program without them so I don't see what the big deal is.
>> >> >> What OO features are missing or unavailable?
>> >> >
>> >> > That's not what I said.
>> >>
>> >> OK then. EWhy should all the functions be OO? What's the advantage?
>> >
>> > The usual ones: abstraction; encapsulation; polymorphism; inheritance.
>>
>> PHP functions do not need all that bloat to work, so again I say "it is
>> not
>> a problem".
>
> It's not bloat - it's mostly a case of organising things into
> heirarchical trees - rather than putting them into big lists.
So what's wrong with having a simple single list of functions? All the
programming languages I have ever used have given me instant access to all
of the functions right from the start. I have never had to load in the
functions I want before I could use them. The very idea sounds totally
preposterous.
>> > Defending the idea makes no sense to me at all. PHP is not some sort
>> > of Holy object - which you need to sacrifice all existing common
>> > sense about language design to protect. Single big global namespaces
>> > are well out fashion these days - and if you think they are in vogue,
>> > you need to WAKE UP.
>>
>> Being fashionable is not a good reason to change the way an entire
>> language
>> works. many many developers are happy with the way PHP works and would be
>> very unhappy if it were change to suit your personal preferences.
>
> If PHP gets into a bad enough mess from being built on too-backwards
> foundations, it will be wiped out by something better than it - and
> then where will they be?
That PHP is a mess is just your opinion. I do not share that opinion, nor do
the authors otherwise they would surely take steps to put it right.
>> >> > It also consequently fails to take advantage of inheritance and
>> >> > polymorphism - but that's not what I was mostly complaining about.
>> >>
>> >> The standard PHP functions do not have to take advantage of
>> >> inheritance
>> >> and
>> >> polymorphism to work, therefore your argument has no merit.
>> >
>> > Noboby *needs* to write programs in high level languages either.
>> >
>> > But what is /necessary/ and what is /desirable/ are not the same thing.
>>
>> Exactly. It is not *necessary* for the standard PHP functions to be
>> objected
>> oriented. There would be no performance improvement to outwiegh the cost,
>> so
>> a cost/benefit analysis would shoot the whole idea down in flames.
>
> I have no idea why you are mentioning performance improvements.
>
> The benefits of OO design mainly show up when building large projects,
> maintaining and managing code - rather than when optimising code for
> speed.
If there is no benefit in performance and there is no benefit is programmer
productivity then there is absolutely no point in changing the language.
>> >> >> > I'm pointing out a serious problem with PHP.
>> >> >>
>> >> >> If PHP had serious problems it would not be the popular language it
>> >> >> is
>> >> >> today. [...]
>> >> >
>> >> > Do you have the same view about Microsoft Windows?
>> >>
>> >> Yes. It meets all the criteria of a virus.
>> >
>> > So, to clarify: do you think it has serious problems?
>>
>> Ask the users whose PC's keep crashing. Ask the user's who find that the
>> XP
>> SP2 upgrade doesn't install. Ask the users who have installed XP SP2 only
>> to
>> find that some of their other applications no longer work.
>
> Though you don't answer the question directly, I think you say enough
> here to undermine your original argument that things that are popular
> can't have serious problems with them.
>
>> >> Just stop saying that PHP has serious flaws because it is not totally
>> >> OO.
>> >
>> > A bit of a paraphrase, there:
>> >
>> > I'm not complaining about PHP the language.
>> >
>> > My beef here is with PHP's library - and how out-of-date and backwards
>> > it
>> > looks.
>>
>> No language can survive if it keeps changing every year or so just to be
>> fashionable. It has to be consistent and provide backwards compatibility
>> otherwise developers would not switch to later versions.
>
> I've never suggested that PHP should change in a manner that breaks
> existing code.
Then who was the moron who said that PHP should ditch all the legacy
procedural functions and replace with fashionable OO alternatives? That is
what this whole thread is about.
>> >> The functions in PHP work perfectly well as they are, and making them
>> >> all OO would not give any improvement.
>> >
>> > We don't agree on that point - and I'm /very/ suprised to find people
>> > defending the design as though it makes sense.
>>
>> What improvement could I expect if PHP's functions were changed from
>> procedural to OO?
>
> PHP would scale to building large projects better - and its standard
> library would be better organised, easier to extend, and easier to
> maintain.
I disagree. It would just be different, not better. Changing the names of
functions, or changing the way they are used would not give tangible
improvements to everybody, only perceived improvements to a meagre few.
>> > PHP's function library is a historical legacy - the product of days
>> > gone by when PHP had no OO features at all - and that we now seem
>> > to be rather stuck with.
>>
>> All languages evolve. The fact that OOP was not in the original design
>> does
>> not matter a jot. It made an apearance in PHP 4 and has been improved in
>> PHP
>> 5. I like the fact that I can use procedural code when I want to and OO
>> code
>> when I want to. I am not forced into one or the other, so I can mix and
>> match to my heart's content. How many other languages give you that
>> option?
>
> Most OO languages let you code in a procedural style if you want to.
> Certainly this is true of languages such as C++, Perl and Java.
So if all those wonderful languages still let you write procedural code then
what is the big deal with insisting that everything should be OO?
-- Tony Marston http://www.tonymarston.net
- Next message: Tony Marston: "Re: PHP global namespace clogged up"
- Previous message: Janwillem Borleffs: "Re: XSLT processing instruction to use PHP"
- In reply to: Tim Tyler: "Re: PHP global namespace clogged up"
- Next in thread: Tim Tyler: "Re: PHP global namespace clogged up"
- Reply: Tim Tyler: "Re: PHP global namespace clogged up"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|