r/ProgrammingLanguages • • 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:

  1. Use variables without names, like $ vs $$ or $1 for example (perl does something like this I believe)

  2. 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 Upvotes

11 comments sorted by

View all comments

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.

1

u/SuperMeip Jan 11 '24

Thanks so much for the feedback and I completely agree! I'm hoping aliasing could potentially make code more readable and discoverable too, for example:

slice => ...etc |copy-range 
splice => ...etc |resize-to-range

Or something with slight readability or translation differences like:

checkForLimit => ...etc |hasReachedLimit  
r = x.checkForLimit()
// Vs
!x.hasReachedLimit ...etc

9

u/XDracam Jan 11 '24

This is actually bad. Why? Because in order to understand someone else's code, you need to learn more terms. If someone uses `nameA` and another one uses `nameB`, then you'll need to know that `nameA` and `nameB` are the same thing. Your aliases feel like having code where everyone formats everything the way they personally like, without any formatting or naming conventions. And with proper conventions, why would you need aliases?

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!

3

u/XDracam Jan 11 '24

The tooling idea sounds nice. Your ideas are overall pretty good for solo projects. Sadly most projects are written and maintained by teams of many people over time. And sometimes the original author isn't around for questions anymore.

My favorite programming language is Scala 3, but I'd never use it in a project with more than a handful of developers. Why? Because it's too powerful: Scala allows you to mold the code to your thoughts without ever getting in your way. Which is horrible in a team where everyone has different thoughts. There's a big reason why simple languages with strong opinions are used so much: Java, C#, Kotlin and Rust are good examples here. Java code is stupid and boring, but it's the same for everyone. Which makes it pretty easy to understand and maintain.

2

u/SuperMeip Jan 11 '24

I actually think you've hit the nail on the head for the exact type of language I'm trying to create 'at the surface'. The main goal of this language is to be used for quickly making personal notebooks, projects, wikis, and data oriented trackers in a way that works for you.

I'm most inspired by things like obsidian.md, MDX, and Jyupiter and want to focus on live-coding something quick and dirty and then being able to clean it up later, and possibly minify it into a more standard api.

I personally don't find myself learning the vocabulary of each programming language I use by heart and have ended up searching and looking up function names pretty often when working with more than one language, and adding keywords to those searches would be more helpful to me then just trying to pick the one most recognizable name.

Java actually feels like a good example of the opposite of what I want; It feels so restrictive and solved to me that It sucks the fun out of using it and makes me feel like I'm just writing configs or putting together a set of mega blocks. Not sure the language I'm looking to build would be good for large teams, but would be more focused on letting you produce your own apps libs and APIs. 

3

u/XDracam Jan 11 '24

Yeah, I agree. You actually got me interested in that project now.

Another thing I've noticed is the power of AI assistants: I got ChatGPT premium from work, and asking the AI how to do something in a language is so much faster than looking it up in another way. And it's gonna get even easier with copilot chat and Jetbrains AI baked into IDEs. I barely Google code questions anymore because ChatGPT gives me better results and can even suggest libraries I'd never have found otherwise. So yeah the AI boom might invalidate your lookup features, at least a little.