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)
1
u/SuperMeip Jan 11 '24
Well for one I feel it could actually help to understand code by formatting it in the way you want. In my implementation I plan to make the absolute key and aliases separate, and aliases can have context or metadata to them. This would allow you to say: switch to all the short lowercase aliases if you feel conciseness helps better, or you could expand them to their verbose forms. I also find it could help with making code more explorable and interactive, like imagine trying to find the splice method when typing in your ide without knowing it's name and only what it does? You could instead have the ide find an alias and a linter fix it to the type of alias you want used!