As some of you know, I'm in the process of designing/implementing my own language right now (and unless I'm mistaken, I believe there's two others on these forums also doing similar things). I'm curious, what kinds of features have you seen that you would want to see in a new language, and what kinds of tasks do you find tedious with existing languages that you feel should be easier? What kinds of features should definitely not be present?
Syntax is not a feature. My language is stored as nothing more than abstract syntax trees (it looks like some especially cryptic lisp if you open a file in a text editor which doesn't recognize my language). Users define what the syntax should be, and the AST is displayed with that syntax by their editor. When they save, it's converted back from their preferred syntax to the AST. This should put an end to pointless style and syntax fights and force people to think about the actual features, algorithms, and data structures.
Some ideas I have:
- Only for-in loops, no for loops. For loops have the potential for logic mistakes to be made and no actual benefit over for-in loops.
- Default values for parameters.
- Parameters can be passed by position or keyword.
- Functions can also take flags, in addition to parameters. This is something frequently seen in command line programs but I've never seen it any of the languages I'm familiar with, so I'll offer a quick example of what I have in mind (with Python style syntax):
- All code must go in functions - you can't have code outside of functions.
- All functions must have some documentation specifying the intended input, the output, exceptions that could occur, etc.
- No mandatory functions (IE, "main" in C and Java). Instead, when run your code from the command line, you specify the function you're running, and you pass your parameters in exactly as if you were calling the function from within the language. This does away with argc/argv and the nonsense of having to parse them and write special usage messages and help messages and whatnot. If the user passes bad parameters, they're automatically shown the documentation for the function.
- Identifiers are constants by default - must explicitly be made variables.
- The language is interpreted, with checks of your code done after it's changed to AST but before it's written to disk. If you don't have valid code, it doesn't save (this is in contrast to Python, where you don't find about mistakes you've made until after you're already running the code. An IDE could point the issues out to you, but I'm under the impression that most Python code is written in a text editor - similarly, I'd like my language written in your editor of choice, so the plugin which does the text -> AST conversion will do the checking.)
- Named return values. Python allows for multiple return values, but it's confusing what each value is. An example of what I have in mind:
Sets the local constants x and y to the returned values named x and y. For extra clarity about which is which, assignment always goes from right to left, so:
Of course you could wonder, why isn't a datastructure being used? That would be the proper solution in most cases - indeed, in the above example, you would probably have some type Coordinate or Point which stores X and Y, but I just shared that for simplicity. I guess a better example might be something like:
Hopefully you can imagine some scenarios where this is a good idea.
Anyways... enough from me. I'm interested in hearing what kinds of features you've come across (or have never seen) that you'd want a new language to have. I'm also hearing what you think about my ideas.
Syntax is not a feature. My language is stored as nothing more than abstract syntax trees (it looks like some especially cryptic lisp if you open a file in a text editor which doesn't recognize my language). Users define what the syntax should be, and the AST is displayed with that syntax by their editor. When they save, it's converted back from their preferred syntax to the AST. This should put an end to pointless style and syntax fights and force people to think about the actual features, algorithms, and data structures.
Some ideas I have:
- Only for-in loops, no for loops. For loops have the potential for logic mistakes to be made and no actual benefit over for-in loops.
- Default values for parameters.
- Parameters can be passed by position or keyword.
- Functions can also take flags, in addition to parameters. This is something frequently seen in command line programs but I've never seen it any of the languages I'm familiar with, so I'll offer a quick example of what I have in mind (with Python style syntax):
Code:
# Defining a function which takes a parameter (defaults to 0) and a flag.
def getCoordinates(offset: 0, :2D|3D):
if 2D:
return x, y
else:
return x, y, z
# Calling the function defined above:
x, y: getCoordinates(offset: 10, :2D)
- All code must go in functions - you can't have code outside of functions.
- All functions must have some documentation specifying the intended input, the output, exceptions that could occur, etc.
- No mandatory functions (IE, "main" in C and Java). Instead, when run your code from the command line, you specify the function you're running, and you pass your parameters in exactly as if you were calling the function from within the language. This does away with argc/argv and the nonsense of having to parse them and write special usage messages and help messages and whatnot. If the user passes bad parameters, they're automatically shown the documentation for the function.
- Identifiers are constants by default - must explicitly be made variables.
- The language is interpreted, with checks of your code done after it's changed to AST but before it's written to disk. If you don't have valid code, it doesn't save (this is in contrast to Python, where you don't find about mistakes you've made until after you're already running the code. An IDE could point the issues out to you, but I'm under the impression that most Python code is written in a text editor - similarly, I'd like my language written in your editor of choice, so the plugin which does the text -> AST conversion will do the checking.)
- Named return values. Python allows for multiple return values, but it's confusing what each value is. An example of what I have in mind:
Code:
x: x, y: y: getCoordinates(:2D)
Sets the local constants x and y to the returned values named x and y. For extra clarity about which is which, assignment always goes from right to left, so:
Code:
localX: returnedX, localY: returnedY: getCoordinates(:2D)
Of course you could wonder, why isn't a datastructure being used? That would be the proper solution in most cases - indeed, in the above example, you would probably have some type Coordinate or Point which stores X and Y, but I just shared that for simplicity. I guess a better example might be something like:
Code:
files: files, folders: folders: listContents(path)
Hopefully you can imagine some scenarios where this is a good idea.
Anyways... enough from me. I'm interested in hearing what kinds of features you've come across (or have never seen) that you'd want a new language to have. I'm also hearing what you think about my ideas.