Re: Do you currently use namespaces?
- Posted by Jeremy Cowgar <jeremy at c?wgar.com> May 26, 2008
- 1030 views
Matt Lewis wrote: > > ken mortenson wrote: > > > > Jeremy Cowgar wrote: > > > [SNIP include example] > > > ---- This is proper coding. > > > > Ah, Jeremy, this is a grand statement. Especially when demonstrating the > > 'include everything' school of programming. I see this same problem in > > Microsoft programmers which is why they have a zillion constants for the > > definition of true and false (all with very precise names) in their code. > > > > Including fileA and fileB twice is only a little bit of nails on the > > chalkboard for me, but I can get past that because the language allows it. > > It's not a matter of including it twice. His point was that your code should > include what it needs. Your statement is actually the antithesis of modular > programming, IMHO. Each module should explicitly declare its dependencies. > Euphoria has never required this, though it will at least generate a > warning in 4.0. > In addition, if you use namespaces, you can forget the fact 100% that anything is global throughout the entire program. For instance: FileA.e. FileB.e, FileC.e, FileD.e, ...., FileAA.e, ...., FileZZZZZZZ.e
global function hello()
MyProg.ex
include FileA.e as a include FileB.e as b ... include FileZZZZZZZ.e as zzzzzzz a:hello() b:hello() aaa:hello() zzzzzzzzzz:hello()
In side of the namespace, the *only* functions/procedures/variables are those within the file defining the namespace. It does not matter if there are 1,000 hello() functions. In side your declared namespace there is only 1. That's the same as a module: -- Fake Language FileA.fake module FileA export sub hello() { ... } sub goodbye() { ... } -- Fake Language FileB.fake module FileB export sub hello() { ... } sub goodbye() { ... } -- Fake Language MyProg.fake use FileA use FileB FileA.hello() FileB.hello() -- Jeremy Cowgar http://jeremy.cowgar.com