
Python Vs Php  - iamelgringo
http://wiki.python.org/moin/PythonVsPhp
======
some
> There are no namespaces, so functions often have prefixes to denote their
> source

Can somebody tell me, how namespaces work?

Say, without namespaces you would do it like this:

    
    
      function isBig($Number)
      {
       return ($Number>1000);
      }
    
      if (isBig(50)) echo '50 is big';
    

How would this look like when namespaces are used?

~~~
voldern
Something like this:

    
    
      namespace yo 
      {
        function isBig($number) {
          return ($number>1000);
        }
      }
    
      if (yo::isBig(50)) echo '50 is big';

~~~
some
We do this thing in PHP with classes. See below. What is the advantage - if
any - of namespaces?

    
    
      class yo 
      {
       function isBig($number)
       {
          return ($number>1000);
       }
      }
    
      if (yo::isBig(50)) echo '50 is big';

~~~
ks
isBig(50) is more readable than yo::isBig(50) in my opinion.

~~~
ardit33
because colons are ugly. yo.isBig(50) is much more readable.

Now, assuming somebody else decides to have a function called isBig(), which
does something very different.

The only way to use both in php, would be if they had different names (hence
the countless of functions that do very similiar things, but have different
names).

While in languages that have a propper namespace you can do:
numModule.isBig(50) floatModule.isBig(50) --etc

Also, in java you can import a class directly.

You can use com.mycompany.numClass.isBig(50)

or import com.mycompany.numClass;

and use numClass.isBig(50)

if there are two classes with the same name, from totally different packages
(namespaces), then you will have to use one of them the long way (
com.mycompany.numClass.isBig(50) ) in order to avoid namespaces conflicts.

Java does a decent job in all this. Python is even less strict (you can import
a module with (import as)a nd name it something different, when you use it),
which allows for great flexibility, but also more confusion if you don't know
what you are doing. But if people adere to the python mantra to keep things
flat, than it should not be a problem.

So, overrall namespaces are very useful, especially in any large app. But, you
haven't seen them on php yet, as the php crowd could care less for them. Plus
Php was ment just for simple page processing and apps, and nothing too
complicated.

------
imp
Lots of retorts and counter retorts. It read almost like a forum posting.

