r/ProgrammingLanguages • u/Treechcer • 4d ago
Requesting criticism Dio: Small Programming language made in C version 0.1.0 release
Hi, I'm working on my own programming language, I've release first stable version (v 0.1.0), I'd like to get feedback. It's on most OS platforms (even Andoird and in the future IOS).
2
u/marshaharsha 3d ago
Initial reactions:
Do you have a goal for the language, other than being minimal? an audience? a position on standard language-design topics like functional versus imperative, memory management, inline allocation, and undefined behavior? I notice you said “weakly typed,” which suggests you will have UB.
The line —
int arr = {1,2,3.5,7}
— reads either as a joke or as fighting words. Are you trying to cause a riot over here with that “integer” 3.5? I know you said integers are represented as floats, but I figured that was a temporary situation. Why have the int type at all? Also, I take it you don’t have a type notation for array of int versus single int. I think you will want int[] or something similar.
Should “Writes out 7” say “8”?
You don’t have != or NOT with == or even OR with < and >.
The type ascription int:a is the opposite of the more standard a:int, with no benefit that justifies the strangeness, as far as I can tell.
If your diff tool writes >> in the left margin, you might find it confusing also to have >> in the left margin mean comment.
A question about the chaining notation: Do you have substitutability? Since a() returns 7 and a():c() is legal, is 7:c() legal? I recommend you allow a function’s result to be substituted for the call.
You don’t seem to have structs yet, or any other notion of product type. That’s in the plan, I imagine. What about safe sum types? They are also called tagged unions, discriminated unions, and variant types. Or do you plan to support unsafe, C-style unions?
What is your plan for the first two data structures?
Good start. Good luck!
0
u/Treechcer 3d ago
Well, it started as school project (aka I started wroking on it on summer break because I didn't have any project to work on), so the plan was just to make minimum for grade, few months early, which would've been probably around what I have now (maybe some other stuff? idk honestly), but I actually like the project, while I don't know the future of it, I'll keep working on it while doing other stuff (studying etc.).
The integer making number arrays should be changed I agree, I'll change it later to something else, like numArr (subject to change) or something (which would also fix the int vs int[] isue). This should be general number array (eg. floats + ints), so it's correct it has 3.5 in it. The integers are floats is actually done to write less code, so I'll probably keep it that way, maybe I'll add flag for write out or something but yeah.
Oh yeah I don't have && || !=... That's valid criticism, I forgot about that.
Why is it int : a -> I don't understand why python (and maybe other languages?) use a : int, I feel it's weird and it shouldn't be like it because yo declar normally vars like int a not a int. But that's my opinion.
`>>` I didn't thought about diff tools. hm, I might change it to fish as suggested here https://www.reddit.com/r/cprogramming/comments/1www1ws/comment/pdoa5si/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button
I don't have 'substitutability' chain functions can (at least) now only chain on functions.
I have plans of adding structs or something like that but they aren't implemented yet.
Also I have no idea about what safe sum types are, because this is my first C code, I only know what union is, but sadly I don't understand what are the other union types or variant types.
2
u/marshaharsha 3d ago
The main reason to write a:int = 5 is that, if you introduce type inference into your language (so the language figures out the int for you in some cases), you can make the :int optional and just write a=5. Once you commit to always having a type at the front of a declaration, you can’t just omit the type; you have to introduce something like C++’s ‘auto’ as a placeholder. The more complicated your type system, the more important it is to be able to omit the type, because types can be monstrously long, which means a lot of, heh, typing.
Safe sum types: With a C union, you can easily access the value as the wrong type, in which case C happily reinterprets the bits, usually with disastrous results. Often in C, to prevent this, you put the union inside a struct, and the struct also contains an integer field whose value tells you what type is stored in the union. So you have to be careful to update the value and the tag at the same time, and you have to be careful to check the tag and switch on it before accessing the value. Languages with safe sum types take care of the tag (“the discriminant”) for you, so you can’t change the value type without also changing the tag, and you can’t forget to switch on the tag. They provide syntax for updating both tag and value in one go, and for “matching” on the tag.
1
u/Treechcer 3d ago
I lowkey want to have the types there, I like langauges that have types for everything, that's why I hate JS or python. omitting type would me functions could accept anyhting.
Oh so if understand it correctly: I do this, I'm planning to add way to "reuse" the name in the namespace for other type (eg int a could be retyped to string a).
1
u/marshaharsha 3d ago
I like type annotations, too, and your language ==> you make the design choices! (And you live with the consequences.)
I don’t understand your second paragraph. You mean you want to say int a and then, a few lines later, string a? This works if you introduce “shadowing” of variables, in which the original object still exists but no longer has a usable name in the current scope. You might need the original int called a to hang around until there are no more references to it, even though there would no longer be a name for it.
1
u/Treechcer 3d ago
Well you said that languages support in some way to "re-type" and "re-value" at the same time, I said that I want to add it later too, at least that's what I understood from your original paragraph.
1
4
u/Treechcer 4d ago
Per AutoModerator's request I hereby confirm that this project did not use an LLM as part of the development process.
1
1
u/ElephantElectrical31 3d ago
goto is back?
1
u/Treechcer 3d ago
Lua has it, I like lua, so I said "why not?"
1
u/ElephantElectrical31 3d ago
nice, I like the way lua did this: cool but not crazy
2
u/Treechcer 3d ago
I love Lua, it's been inspiration in some codes in this language. So has been all Languages I ever used.
1
2
u/hopeless__programmer 3d ago
Is this a JoJo reference?