Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yep, although I do like not having clashing names.

But I mean... somehow every other language solved this.



> But I mean... somehow every other language solved this.

Did they? C, Lisp, Rust, Python, Ada, Go, Java, C#, ...

They all require you to qualify conflicting names if some other characteristics (for instance the number or types of arguments) don't provide enough information, or outright don't permit it (C, since it has no notion of name spaces).

Can you point to the "every other language[s]" which have solved this problem?


It's certainly not every other language, but Unison has a novel approach to solving the problem of name clashes: function names are just local aliases for a content hash of the function's AST. Compiling involves replacing function names with those hashes, and putting the names back is a matter of pretty-printing. I'm sure there's an arsenal of footguns lurking in Unison's system, but for sure it opens up interesting opportunities (distributed code becomes "grab this function out of cache").


Does that actually solve name clashes? If I have two functions compiled at the same time:

  def foo(n):
    return n + 2
  def foo(n):
    return n * 2
  foo(3) # which one is called?
(I don't know Unison syntax so using Python for the example)

It's still a name clash at compile time.


TBH I've only dipped my toe into Unison, but I don't believe it would let you re-bind the same identifier in the same scope in the same compilation unit. It's more that `foo(3)` becomes a call to the hashed version `#e0ca5f(3)` forevermore. Once a function has been compiled, it doesn't care what the names of any functions it uses are afterward, until you explicitly recompile them to use the new names. So it really has more to do with preventing versioning conflicts ... others can explain it much better than me, sorry.


Most languages you mention let you import the individual names that you want, and you can resolve potential clashes at the point of import. In C++ you basically ```#include``` a file and with it comes a flood of names that are often times unpredictable.


C++ has had namespaces for a very long time (since the beginning? not sure, I wasn't using computers when it was created), just like those other languages. The name collision issue that it has is the same as them.

And with those C++ namespaces you can do `using some_namespace::some_specific_name;`. Which resolves the issue just like in those other languages.


If C++ was JavaScript you would do:

import {vector} from 'std';

Which I think is a reasonable compromise, you're only bringing vector into scope rather than all of the standard library.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: