Some feedback for the language I'm designing

Community Forums/General Help/Some feedback for the language I'm designing

ziggy(Posted 2012) [#1]
As some of you know, I'm designing a programming language in Monkey, called Harpl. I'm designing its syntax and my idea is that the language syntax is as much verbose as possible and I want to use real words where possible instead of symbols (I really don't like C++ syntax, so I'm more looking for a Basic-like aproach). Having a decent IDE does not force you to write all the commands, and also, you write code once, but read it lots of times, so my idea is to make a language that is easy to understand and read and maintain.

with this in mind, I'm designing the variable declaration sentence.
It's more or less like this right now:
Define VariableName As DataType = Expression

Expression is optional, as there are default data types for variables, but the As clause is not optional (no default datatype to Int as in BlitzMax or Monkey).
With this readability in mind, and with the idea to make the code as easier to maintain as possible, I've decided to not use the same symbol for different operations. As instance, string concatenation has its own operator, instead of using + or & like in other languages, it is using ++. This makes code clean:
Output "Your socore divided by 10 is: " ++ Score / 10

With this idea in mind, I find that when setting a default value for a boolean variable, the whole idea of having a single symbol for each task gets a bit wrong:
Define MyBooleanVar as Boolean = X = Y

So, I was thinking if it would be a better idea to use another operator or, even better, a word, to set default values on variable declarations, so it could be something like:
Define MyBooleanVar as Boolean value X = Y, MyInt as Integer value 5, MyString as String value "Hello world!"

Or:
Define MyBooleanVar as Boolean default X = Y, MyInt as Integer default 5, MyString as String default "Hello world!"


What do you think? Maybe a speciffic operator to set values to variables would do the thing too:
Define MyBooleanVar as Boolean: X = Y, MyInt as Integer:5, MyString as String: "Hello world!"
But I find this a lot less readable.

Don't know wich is the right decision here. If anyone insterested this is the Harpl language project page at googlecode: http://code.google.com/p/harpl-project/ It's an open source project.

Any suggestion in this syntax mather will be welcome.

Last edited 2012


Yasha(Posted 2012) [#2]
OK...

On verbosity: well, I happen to disagree, but that's also entirely a matter of taste. You will find a lot of people who love this style, so it's not a bad choice at all. Rock on.

Your current style of declaration is certainly serviceable, as it's close to standard BASIC syntax. However, there are a lot of things to get picky over...


> no default datatype to Int

Good! However, may I suggest default-to-type-of-expression as a potential replacement? You may think it's unnecessary now, but wait until you have to start writing code about "myContainer As List Of Dict Of (Hash, Set Of (Int, Int, Int))" - there's no need to write that twice! It would suit your language's style to make this explicit, so you could have it be something like "As Val".


> to not use the same symbol for different operations

Also good... although you might make a few enemies if you take this to its logical conclusion and copy e.g. OCaml, with its separate "+" and ".+" for integer and float addition!

(Aside note: where does Harpl fall on the continuum of "fast, compiled, static" vs. "scripting, interpreted, dynamic"? If it's more towards the latter, have you considered ditching ints/floats and having a universal unlimited-precision number type? This is great for users, and can still be made to be "fast enough" by a decent compiler/runtime that can switch representation behind the scenes - you only need the distinction if you really want to think in terms of hardware math operations, and most people don't need that.)


As for variable setting, the established conventions of many other languages are ":=" for "set" and "==" for "compare", and the one used more frequently can be simplified back to a single "=". I would suggest the Pascal way over the C way, and make "set" an explicit statement with a different symbol, which may as well be ":=".


However, I note that you're using "Define" as your variable keyword. So going by the words you're using, you're not creating a variable and then immediately setting it; you're defining a variable as something. This means it is logically perfectly OK to use "=" in this situation even if "=" means comparison, because the keyword implies you are setting a truth value, not inserting something into a variable slot.

Of course, you could even extend this: assuming you intend to make assignment a statement, as it is in Blitz, and not an expression (which has its uses in C, but would be totally out-of-character for this language), why not introduce a new leading keyword for that? Go really old-school and bring back "Let"! That way, you can keep the "=" for all assignment operations, as you're maintaining the same "setting a truth value" idiom established by the "Define" keyword.


Either way, I would recommend against "value" as the operator. With the exception of very-well-known ones like "And", text infix operators are a bad idea in this style of language and will make it harder to read as it becomes less immediately clear what the various parts of an expression/statement actually are (or at least, limit them to words that are also "infix operators" in English, e.g. "is" for identity comparison).

Last edited 2012


ziggy(Posted 2012) [#3]
However, may I suggest default-to-type-of-expression as a potential replacement?
Yes, I would love to add this, and I don't think it would be very complicated.

although you might make a few enemies if you take this to its logical conclusion and copy e.g. OCaml, with its separate "+" and ".+" for integer and float addition!
I was thinking on OCalm design, BUT I'm allowing automatic conversion between Integers and Floats in all marithmetic operations. When you mix floats and integers,the result is always a float. So a single operation for addition, no mather if it is a float or an integer.

where does Harpl fall on the continuum of "fast, compiled, static" vs. "scripting, interpreted, dynamic"?
I'm trying to make it fast and strong typed. I also will be looking to LLVM in the long run.

As for variable setting, the established conventions of many other languages are ":=" for "set" and "==" for "compare", and the one used more frequently can be simplified back to a single "=".
That's usual in languages that allow assignation in the middle of an expression, wich is something I really dislike as I think it make code harder to maintain, so not sure if it's the best approach, while I understand it makes sense to have different operators for differents tasks.

However, I note that you're using "Define" as your variable keyword. So going by the words you're using, you're not creating a variable and then immediately setting it; you're defining a variable as something. This means it is logically perfectly OK to use "=" in this situation even if = means comparison, because the keyword implies you are setting a truth value, not inserting something into a variable slot.
Yes, maybe I'm over complicating things and it is clear enough, but when I add the explicit expression declaration, it can get a bit unelegant:
Definle MyVar = X = Y
This is not very nice, isn't it?

Either way, I would recommend against "value" as the operator. With the exception of very-well-known ones like "And", text infix operators are a bad idea in this style of language and will make it harder to read as it becomes less immediately clear what the various parts of an expression/statement actually are.
I see, maybe you're right here. And what about not having an operator?
Define MyVar As Integer 45, MyName as String "Manel", MyBoolean as Boolean X = 6;
Maybe this is the easiesat approach?

Last edited 2012


Yasha(Posted 2012) [#4]
This is not very nice, isn't it?


No, but is it really any worse than the ugly-but-legitimate
If (X = Y) = (A = B) Then ...

...? If you were to decide that the = in variable declaration/assignment were a boolean (using the above logic that they define truth values rather than set value slots), it would essentially be the same things as the above: the coder's own darned fault.


what about not having an operator?


Potentially a good idea. I would again suggest bringing back "Let" though, and doing the same thing with it.


ziggy(Posted 2012) [#5]
Potentially a good idea. I would again suggest bringing back "Let" though, and doing the same thing with it.

So to modify a variable:
Let MyAge MyAge+5
Not sure about this.
Let MyAge = MyAge+5
Looks better

Let MyAge := MyAge+5
Looks like Pascal, wich is not bad...
I think I'll go the C# way here, and just use the variable name, but I'm not sure yet. Still refining all the syntax.

Last edited 2012