News for hackers. Stuff that matters.
Re:Erlang inventor: Why do we need modules and files? by Todd on Tuesday May 24, 2011 @01:14PM (#2580692)
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.

Re:Erlang inventor: Why do we need modules and files? by ohyes on Tuesday May 24, 2011 @01:29PM (#2580736)
I 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).

Re:Erlang inventor: Why do we need modules and files? by bartonfink on Tuesday May 24, 2011 @01:53PM (#2580836)
You'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.

Re:Erlang inventor: Why do we need modules and files? by pavpanchekha on Tuesday May 24, 2011 @10:43PM (#2582642)
Furthermore 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.

Re:Erlang inventor: Why do we need modules and files? by pwpwp on Tuesday May 24, 2011 @02:40PM (#2581012)
Is misc.foo better than misc_foo?

My point being - a point also raised by Joe - is that just "adding dots" doesn't solve anything.

Re:Erlang inventor: Why do we need modules and files? by falcolas on Tuesday May 24, 2011 @02:59PM (#2581091)
I 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.

Re:Erlang inventor: Why do we need modules and files? by d0m on Tuesday May 24, 2011 @03:25PM (#2581207)
From 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

Re:Erlang inventor: Why do we need modules and files? by bartonfink on Tuesday May 24, 2011 @05:20PM (#2581707)
<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; }

Re:Erlang inventor: Why do we need modules and files? by seiji on Tuesday May 24, 2011 @03:25PM (#2581206)
The function names would still be user readable. The compiler and/or runtime would translate what you say to what you mean (think c++ mangling).
Re:Erlang inventor: Why do we need modules and files? by haberman on Tuesday May 24, 2011 @05:26PM (#2581732)
> 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.

Re:Erlang inventor: Why do we need modules and files? by lelele on Tuesday May 24, 2011 @07:37PM (#2582165)
> Also, It lets symbols inside the module call their friends by quux instead of foo_bar_baz_quux.

This is the main point in support of modules: they make you use names just like you are used to in real life. In a given context, shorter names suffice. When more contexts are involved, then you need qualifiers.

Re:Erlang inventor: Why do we need modules and files? by joelangeway on Tuesday May 24, 2011 @07:26PM (#2582134)
The 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.

Re:Erlang inventor: Why do we need modules and files? by damncabbage on Tuesday May 24, 2011 @07:44PM (#2582188)
> 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.)
Re:Erlang inventor: Why do we need modules and files? by joelangeway on Tuesday May 24, 2011 @08:08PM (#2582279)
OK, 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.