Re: ver 4 and ver 3.11 function name conflicts
- Posted by DerekParnell (admin) Sep 03, 2008
- 1079 views
In other words every time I write a program I do all this extra work
of typing a foo:get()
That stinks !
Now you have functions with same name all over the place even in the same
directory.
No Bernie, that is not the case.
You only need to use a namespace if your program uses clashing names.
But consider the alternative. Assume we didn't have namespaces.
include std/map.e include std/regex.e include get.e map m = map_new() regex r = regex_new() ? get() ? map_get(m, "name")
Not much difference is there? If we didn't have namespaces, then each library would have to come up with a special word for each of its routines. For example if we used prefixes, all routines in a library should be prefixed to minimize name clashes (we can never entirely get rid of them). So all map.e routines could have "map_" as a prefix, etc ... In which case, there is little difference between this and namespaces, except that we would be forced to type prefixes but are not always forced to type namespaces.
Another alternative is to use 'unique' names for routines. eg.
include std/map.e include std/regex.e include get.e map m = create() regex r = construct() ? get() ? fetch(m, "name")
We soon run out of synonyms and we add a bit of confusion because if we come across a line of code "a = retrieve(x)" we don't know easily what that does doing or where it comes from. But if we see "a = memory:get(x)" we might get a clue or two. Plus, what do we do if two indenpendant libraries declare the same name anyway?