4 ms·
I understand his frustration, but a single global namespace is not the solution. This would be a regression to the place that PHP has been trying to escape from
by Todd 15y ago
I understand his frustration, but a single global namespace is not the solution. This would be a regression to the place that PHP has been trying to escape from.
If modules aren't available, then people will invent pseudo namespace qualifiers (e.g., misc_foo). A global namespace will become like the .com TLD--a few early landgrabbers with the cool names like foo and bar, then a bevy of latecomers with fooo and baaar67.
The module/namespace concept isn't a 100% solution, but it's sufficient. People understand hierarchy. It's simple and effective. And it also solves the global-visibility/encapsulation issue that he sidestepped.
- ohyes 15y agoI don't think its really a single global 'namespace'. It seems that instead of using actual names for the key in the k/v database, you would use something closer to an ip-address. give the function a unique id, and then make it have a really good description. To find the function, you use the description, and then reference the unique id. To reference it in your code, you would bind the unique id to the descriptive name. What I want to know is how you prevent massive duplication of functionality in this k/v database (with slightly different argument conventions or implementation details, for example).
- bartonfink 15y agoYou'd have the duplicate functionality problem anyhow, as function tables essentially work as k/v databases already. The keys are the method signatures (e.g. name, parameters, return type) and the value is the actual implementation. Unless your language syntax specifies that argument conventions (e.g. names or ordering of parameters) are part of the method signature, you're always going to have to deal with the problem of foo(int a, char b) mapping differently from foo(int i, char c) or foo(char b, int a). You could do this, but it's not really widespread as far as I know. I know of no language that deduplicates functions based on implementation details.
- pavpanchekha 15y agoFurthermore it's undoable in general. Equivalence of lambda terms being undecideable and so on. Point being, at some point functions become sufficiently different that it's hard to tell. What if you write one md5 function in Erlang, another in whatever that Ruby syntax for Erlang is called. I'm sure the Erlang they both generate, or bytecode, or what-have-you (I don't know how BEAM or HIPE work on the inside) are very different, to the point that checking that they are truly equivalent is going to be near-impossible, even for a very strictly defined program like MD5.
- pwpwp 15y agoIs misc.foo better than misc_foo? My point being - a point also raised by Joe - is that just "adding dots" doesn't solve anything.
- falcolas 15y agoI would rather have misc.foo (or in python terms, from misc import foo), than this_is_a_unique_function_name_that_does_foo, or '0000100302foo' with a ton of metadata to explain what it does and why it's better than every other similar function. I'm trying to imagine visually parsing a program where the function names are merely unique identifiers that don't necessarily relate to their function, and it's not going well.
- seiji 15y agoThe function names would still be user readable. The compiler and/or runtime would translate what you say to what you mean (think c++ mangling).
- d0m 15y agoFrom what I understand, it'd be more: from global_database import foo291 as foo and you'd have lots of meta information associated to foo291 so you could easily find it by doing: db-search blah
- bartonfink 15y ago<quote> I'm trying to imagine visually parsing a program where the function names are merely unique identifiers that don't necessarily relate to their function... </quote> Just to be pedantic: you're doing this already. int add(int a, int b){ return a - b; }
- haberman 15y ago> My point being - a point also raised by Joe - is that just "adding dots" doesn't solve anything. It's visually much easier to parse foo.bar_baz.quux than foo_bar_baz_quux. Also, It lets symbols inside the module call their friends by quux instead of foo_bar_baz_quux.
- joelangeway 15y agoThe global namespace in PHP is awesome. I don't have to learn a framework to solve a problem, there's a function for it. Namespace qualifiers in names are a fine solution to the collision problem. That's effectively what's there already except every darn function has to be in a module. Names don't have to be treated like property, you can invoke policy on them and change bad names. His dreams about rich metadata probably include version tags and hashes that would prevent this from silently breaking anything or in a way that couldn't be repaired by a tool. Modules don't solve the problem you think they do, they just make the name of all functions longer and harder to figure out. They're not hierarchical. He addressed issues of visibility/encapsulation and gave a great example of where modules fail to solve the problem. Though I don't quite follow his suggested fix, it looks like using lexical scope to encapsulate fib/3 but my Erlang is actually a bit rusty.
- damncabbage 15y ago> Names don't have to be treated like property, you can invoke policy on them and change bad names. A lot of PHP projects involve working with existing components or apps. Some of these use the global namespace with very obvious names, eg. phpBB's User, CodeIgniter's Session. Try and combine two components that use the same obvious names, and everything explodes in a giant mess of E_ERROR. (It's the same deal with globally-scoped constants: define('ACTIVE',1); define('ACTIVE','active'); Makes life very interesting.)
- joelangeway 15y agoOK, I might have change my mind about that. I have been lucky enough not to have had to use multiple selfishly named libraries I guess.