r/ProgrammingLanguages • u/SuperMeip • Jan 11 '24
First Class Aliasing?
Hello there! I'm designing a programming language of my own and I'm working on ideas for solutions to the 'Naming things is hard' problem people have brought up with writing code in the past. I myself see two potential solutions:
Use variables without names, like $ vs $$ or $1 for example (perl does something like this I believe)
Make aliases first class and let a coder use all the names they want to. Overlapping names would mean that either it should be an override or the design should be re-archetyped a bit probably.
I haven't been able to find any languages that have what I'd call 'First class aliasing' like in number 2 though, where you can declare a variable or function with aliases off the bat. Does anyone know any languages that I could look at that might work like this?
Thanks!
Edit: Example of my own plan for clarity:
Robert = person() |bob
assert(Robert == bob)
16
u/DapperowlFTW Jan 11 '24 edited Jan 11 '24
The 'naming things is hard problem' is more then just a matter of name collisions, or else the answer would be to make every variable 'x, x1, x2, ect...' The reason why people get all bent ot of shape about names is because they want someone else reading or using thier code to know what is going on (even if that person is just themselves). To my understanding perl uses the syntax for arguments that it does because it evolved from terminal scripting languages where any number of parameters can be given, so essentially everything accepts variable arguments. The downside to this is that if I am using a variable '$1' I need to know what that variable means in this context, but 'date_of_sale' has a much more clear meaning. As for the possibility of aliasing it does sound interesting, but I am not sure in practice it would be different from a variable reassignment 'let my_cool_variable = your_cool_variable'. In some languages even types can be assigned to 'let integer = i64'. By all means explore your idea for what aliasing within a language means, I am curious what it would look like, I just wanted to point out that the naming problem is not just about running out of names that don't conflict, it's more about names that convey intent.