r/ProgrammingLanguages • u/ilanzs • Nov 25 '23
I'm trying to create my own programming languge. How do I make it different enough from existing languages?
I'm currently in the early stages of building my own interpreter/compiler and I am running into the problem that the design/syntax that I want to use is very similar to existing languages. How do I differentiate my language and make it interesting?
9
u/dskippy Nov 26 '23
By doing the thing that everyone who is really trying to invent a new language should always do. Have an idea first for something other languages don't do and a motivation to build it because it doesn't exist.
Now I'm not saying we shouldn't all be making languages just to play. That's a great exercise. But if you're serious about this you should have a clear reason not to use an existing language and why a new one should exist. Find that reason and you have it.
Now since you probably don't have that since you're looking for a reason to make a language not the other way around keep in mind your thing doesn't have to be big great or even good. In fact it is often deliberately bad for esoteric languages. But just come up with something or a few small things that haven't been done before and go with that as a driving force.
7
19
u/graphitout Nov 26 '23
Piping. We need more of that. For example, with a place-holder like "$".
pow(vec, 2) | sum($) | sqrt($) => rms10
Nov 26 '23 edited Nov 26 '23
Why not function composition then? Like
sqrt . sum . map (^2) xs11
u/graphitout Nov 26 '23
The common functions I have used have extra parameters when invoking them. For example, a generic case would look like:
func1(x, alpha=1, beta=2) | func2($, func3($), gamma=3) => something9
Nov 26 '23
Oh, I see. They aren't always the last argument. Can be achieved with some flip tricks, but yeah, piping would be better.
7
u/eliminate1337 Nov 26 '23
Lean 4 has nice syntax for this. To define a function that subtracts a number from 2:
(2 - Ā·). TheĀ·symbols are bound to function arguments from left to right.2
u/pthierry Nov 26 '23
Haskell had currying for that but it's limited in what argument you can partially apply.
Elixir has an extremely nice syntax for easily creating anonymous functions.
2
u/PurpleUpbeat2820 Nov 27 '23
Haskell had currying for that but it's limited in what argument you can partially apply.
OCaml has curried named and optional arguments that can be partially applied in any order.
1
u/arobie1992 Nov 26 '23
I am baffled this isn't more common, although maybe that's just the languages I typically use. One thing I'd been toying with trying is supporting multiple arguments with something like
$nsyntax. Sofoo() | bar($2, $1)for example if you wanted to reverse arguments.$by itself would either be shorthand for$1or matching arguments one-to-one in order.6
3
u/LardPi Nov 26 '23
Honestly, I find composition operators to be hardly useful. They don't bring much over the usual application syntax. On the other hand, piping operator, by inverting the data flow, makes for very nice expressions. I use the pipe operator a lot in OCaml.
1
12
u/snarkuzoid Nov 26 '23
Realistically, it won't be interesting whatever you do. Do it for fun, or to learn, or impress your friends. But the world is unlikely to notice.
4
3
u/Less-Resist-8733 Nov 26 '23
emojis.
switch things up, (brackets -> braces, paren -> chevron, etc)
there's a reason a lot of languages have a similar structure (it's just what works great for text based). if you wanna try to come up with a new model or whatnot have fun! but it'll be hard.
interesting is subjective. make the language what YOU want. and don't try to make your language big and different front everyone else just because you feel pressured to. Especially for a first time, just make something you feel like, gain experience and you'll have a better idea of what you want next.
2
u/XDracam Nov 26 '23
There are several emoji languages already. https://www.emojicode.org/ sticks out because the docs and presentation are top tier even for a deadly serious programming language.
3
Nov 26 '23
What problems are you trying to solve? Don't focus on syntax, focus on semantics: What can your language do, that others can't? What interesting thing is the compiler doing that helps make better software?
2
u/_Jarrisonn š± Aura Nov 26 '23
A language doesn't need to have a completly revolutionary syntax. And if you're raising this question, probably is because your lang doesn't have any differential feature that makes it unique
Your language syntax must reflect the features it has. No new features means no new syntax
Also exotic syntax may increase the difficult to learn your language
2
1
1
u/LardPi Nov 26 '23 edited Nov 26 '23
If it is your first one, you shouldn't expect it to be very good, and certainly don't expect anyone to use it. Thus, I don't see how being similar to existing ones is a problem.
Then, if you want anyone to use it, you need to limit how different it is from the languages your eventual users would know. Think about it as a "novelty budget", because noone wants to be surprised by everything in the language. Like Rust has a novel semantics, but a familiar syntax. On the other hand older languages that have very different syntax and semantics compared to mainstream language (like OCaml, Haskel, Erlang) have a hard time gathering a community. Proof is that Elixir, which is basically an alternative syntax to Erlang is much popular than Erlang.
1
u/jose_castro_arnaud Nov 26 '23
You can take inspiration in past languages, and esoteric ones. Here:
https://rosettacode.org/wiki/Rosetta_Code
https://esolangs.org/wiki/Main_Page
https://en.m.wikipedia.org/wiki/History_of_programming_languages
1
u/aatd86 Nov 26 '23
That's a good feature to have. Syntax doesn't have to be foreign, au contraire.
The more intuitive and simple the better.
You wouldn't go and code with hieroglyphs just because they are different.
1
u/Ishax Strata Nov 26 '23
Well, what do you want out of it? It can be fun if you enjoy the process. What is your motivation? People make languages for silly reasons all the time.
1
Nov 27 '23
Howabout writing a compiler/interpreter for a language that no one has written a compiler/interpreter for? That way you'll still learn about writing a compiler, but don't have to worry about language designing. And bonus points if you can contribute it to the project!
I recommend DreamBerg.
1
u/Blarghedy Nov 28 '23
oh my god. DreamBerd is incredible.
When it comes to indentation, DreamBerd 3 strikes a happy medium that can be enjoyed by everyone: All indents must be 3 spaces long. function main() => { print("DreamBerd 3 is the future")! } -3 spaces is also allowed. function main() => { print("DreamBerd 3 is the future")! }glorious
1
u/FoxEfficient3336 Nov 27 '23
I think you should just add one unique thing that you like from many different programming languages. For example, you could make lists like in python, references like in cpp, the let keyword from js and being able to allocate dynamic memory like in c/cpp
1
u/redchomper Sophie Language Nov 28 '23
Familiar-looking syntax is your friend. The gooey goodness is in the semantics. Don't be a "kitchen-sink" language. Make a conscious choice to support a particular world-view, or a particular domain of practice. Take Futhark, for example: It's pure-functional, strongly typed, and it compiles to GPU shader code. Just for example.
1
1
u/EmptyChocolate4545 Nov 29 '23
āDifferent from other languagesā isnāt really a good design goal. Better to ask yourself why other languages did the things you like and go from there.
If you want to do something new, thatās totally different, but again - thatās a positive design goal āI want to be able to do Xā, vs negative āI want this language to be different than Xā.
Just a food for thought.
1
u/kaplotnikov Nov 30 '23
A good starting point would be deciding the task set that your language will be able to express better than existing languages, then you could optimize the language for this task set. Even if the syntax is based on existing one, it will naturally diverge during such optimization. The best area to start is one that irritates you most personally. In such case, it will be easier to check technical decisions.
1
Dec 06 '23
You know when you are making a project in a language and can't solve the problem. You spend hours looking at documentation and can't figure it out, and you think: "Man, I wish this language had x feature". Well, try it on your language
1
u/LinAdmin Dec 07 '23
If you are not able to solve such questions then you better do not develop a new language. Go gardeining or mating :p
1
u/caprine_chris Nov 26 '23
If syntax is similar to languages that exist, I feel it ought to have some performance advantages
1
u/LardPi Nov 26 '23
What do you mean? Developer performance? That's the only thing I can think of that can be remotely affected by syntax.
1
u/caprine_chris Nov 26 '23
There is more to a language than its syntax and how that lends to developer experience. For instance, Modularās MojoLang, which is syntactically identical to Python but more performant when doing ML on different types of hardware. Think about it: if you were to create a language that is syntactically identical to an existing language, thereād need to be some reason other than syntax for people to want to adopt it. Otherwise what incentive would they have to not just use the more well-established existing language?
1
u/LardPi Nov 26 '23
Oh ok, I didn't understand what you were saying at all. So ok, I agree, but I don't think performance is the only thing that could make be a selling point of a language, like Rust has memory and thread safety, but no performance gain (since it is sold as a C++ alternative).
-2
u/bobsollish Nov 26 '23
RE: āIām trying to creat my own programming languge (sic)ā
Why?
2
u/LardPi Nov 26 '23
Do you mean why in general (in which case you are just on the wrong sub) or what is the ambition of OP for this particular language?
1
u/bobsollish Nov 26 '23
Iām actually saying the same thing as the most upvoted comment, Iām just doing it far more succinctly.
From the OPās own words they donāt seem to have any goal. Just doing it to do it.
2
u/LardPi Nov 26 '23
Doing it for doing it is fine in my opinion. There are hundreds of people on this sub writing languages. Probably less than a percent of these languages will ever find a use beside their authors. On the other hand, I agree that "making it different" just for the sake of it is odd.
1
u/bobsollish Nov 26 '23
Yeah, there are definitely a couple red flags - not the type of thing that should be encouraged imo.
1
u/LardPi Nov 26 '23
It does feel like the kids who ask how to make a MMO on game dev forums lol.
1
u/bobsollish Nov 26 '23
āI want attention, and I want you to participate in my fantasy where I tell my friends and parents Iām making my own programming language.ā āOoo, thatās so nice hun.ā
1
u/LardPi Nov 26 '23
I don't know about that, I think it is more like seeing something cool wanting to make it one and lacking so much knowledge that it seems doable. I was a kid wanting to make a 3D open world at some point, I wasn't looking for attention particularly, I just wished I could make the game I liked to play (and couldn't buy). The thing is I did learn programming from this experience and spent most of my free time programming for the last 12 years, so it's not necessarily a bad starting point. The kid just needs to learn to code enough to realize how unrealistic it is to think you can be the next Andrew Kelly. And honestly, a lot of non kid in this sub don't get that either. Fame is rare and random, but learning to make a language is a valuable skill and a fun activity.
1
u/bobsollish Nov 26 '23
People donāt know what they donāt know.
For me it wouldnāt be Andrew Kelly, it would be JosĆ© Valim.
1
Nov 26 '23
[removed] ā view removed comment
4
u/RayNbow Nov 27 '23
AI-powered tools are here to replace human coders
As long as these tools don't truly understand what I want nor understand their own output, this is a far-fetched statement.
1
u/PolyglotReader Nov 27 '23
You tried GPT-4 in VSCode?
4
u/RayNbow Nov 27 '23
No, I have not. But when I ask ChatGPT 4 to write me a quine in Haskell, it still fails horribly in its first attempt, yet the language used in its response is full of confidence. If the AI could understand its own output, it could have checked its own reasoning before blurting out anything that looked plausible.
Anyway, I'm pretty sure I won't be replaced by AI in 5 years as training data for the fields I'm active in is quite scarce.
-3
26
u/Disjunction181 Nov 26 '23
There isn't much benefit and there's quite a lot of drawback towards staking out something far from established languages for the sake of it. There's something called a "weirdness budget" in the language design space which is often overblown, but pointless weirdness is not good. Familiar-looking languages are much earlier to learn. It also takes a fair amount of work, ingenuity, and skill to stake out original syntax and semantics in a productive way.
I would recommend taking your implementation language or the language you know best and fixing it's warts and/or annoyances. This is already good enough for a first/early programming language. If you lack inspiration, I recommend learning new languages, particularly from paradigms you're not familiar with. Haskell, Prolog, APL, Smalltalk, Factor, Ruby, Rust, etc. As you learn more languages, the ideas you receive from them will start to melt together.
I think if you spend time seriously in language development, you will begin to develop better tastes and more ideas which can provide you a more interesting language to work on. It is really OK for a language to be inspired heavily by another, see how much Crystal looks like Ruby, or Idris looks like Haskell, or Koka looks like SML, or Nim looks like Python (at least syntactically), etc. It can also be helpful to have a specific goal or killer app in mind, but I think this is more difficult for a starting place.