I'm working on a new programming language (Flogram) and largely behind the scenes it automatically allocates memory using Rust ownership and automatically threads the code for the programmer.
The ownership rules I'm using are:
-
When calling a function you can pass without any modifier and it passes by value (or perhaps under the covers by immutable ref depending upon what the compiler guesses would be faster). Or you can use the 'mut' modifier to pass by mutable ref allowing the object to be modified.
-
If you create objects or structs using 'new', you can pass them into functions and modify them by ref but you cannot return them from functions. If you use 'gc' then they will be created using the garbage collector and are allowed to be returned from functions.
-
You can create arrays or hashmaps or memory pools or other data structures and pass those into functions as objects and populate them and in this manner also pass new objects up the stack.
-
If one object is pointing to another by reference, the one being referred to must have been created at the same time or before the other one (or belong to the same collection data structure.. array, etc). Or it must be garbage collected. I don't like this rule but seems nessecary to guarantee memory safety.
That right there seems like it should cover everything related to Rust ownership but be a little bit easier to digest and beginners can always use 'gc' to create garbage collected objects and not think about it, then optimize the parts that need it later.
Alternatively maybe get rid of gc rules. And for consistency, don't allow returning anything from function, everything returned is returned by mut.
But I came up with it, understand it well, so maybe it seems simpler to me than it would a beginner programmer. Thoughts? Can you think of any ownership edge cases that this doesn't cover? Would you consider using this language?