On Friday 07 December 2007, Robert Cummings wrote:
> On Fri, 2007-12-07 at 15:55 -0500, Sam Barrow wrote:
> > Very good point
> >
> > namespace stuff ;
> > {
> >     function myfunction() {
> >             return true ;
> >     }
> > }
> >
> > That would actually work, but it's not quite the same as you have the
> > semicolon after the namespace declaration, which looks kind of stupid.
> > Overall i dont think braces are a bad idea.
> >
> > People say multiple namespaces per file are confusing, but braces would
> > partially solve this. If using braces makes multiple namespaces per file
> > more likely, I say that's the way to go, as I am very much in favor of
> > multiple namespaces per file.
>
> As I've said previously, I'm neutral to the namespace thing. I imagine
> I'll realize advantages in the future, but given that I try to keep my
> code backward compatible until the death of a version, I don't think
> I'll be using them until about 2012. However, having said that, I would
> also have to say I'm in the braces camp. The above example while
> perfectly valid, is an obvious hack and throws a little WTF factor at
> anyone viewing it :)

Probably silly thought that I am going to throw out anyway:

<SillyIdea>

I've seen three different arguments for braces over a bare keyword:

1) Visually easier to read.

2) More logical for multiple namespaces per file (relates to #1).

3) Easier for code-assistance programs to pick up and make use of in various 
ways.

The arguments against that I've seen are:

1) It makes the engine a bit slower.  (I will take the word of the C coders on 
that one.)

2) Multiple namespaces per file is a bad thing, don't encourage it.

3) It supposes nested namespaces, which this isn't.  (Although as Greg pointed 
out, you can effectively use them almost that way anyway.)

Ignoring points #2 for the moment, the main pro-brace arguments come down to 
usability, both human and IDE.  As the last few posters in this thread have 
pointed out, random braces are a no-op to the compiler as long as they 
balance so if one is so inclined.  So aside from a weird-looking semi-colon, 
we can visually have our cake and eat it too with a common coding convention 
of:

namespace Foo; {
...
}

To the compiler, it's a keyword.  To the reader, it's a brace with an extra 
semi-colon in it.  I've only played with the tokenizer a little bit, but 
would that also be sufficient meta-data for code-assistance programs (vim, 
Zend, Eclipse, Komodo, or whatever) to do their magic, much the same as 
@return Foo in phpDoc can be used to code-complete objects returned from a 
function/method?  

That would, I think, involve no changes to the engine.  It would be strictly a 
documented trick in the manual somewhere.  "PHP only cares about the keyword.  
A common convention for extra visual clarity is to wrap the body of the 
namespace in un-tagged braces.  Although the compiler ignores them, some IDEs 
may make use of them for improved code assistance."  Or something like that.

That is, of course, predicated on the extra braces actually having no effect 
on the parser or compiler.  

Thoughts?

</SillyIdea>

-- 
Larry Garfield                  AIM: LOLG42
[EMAIL PROTECTED]               ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to