Quick Sample
I consider this an ideal language to work with, but I`m not entirely sure if a compiler or preprocessor could handle it.
The basic ideas are as follows:
- Static typing
- The compiler should prevent all the stupid I see with duck typing
- Constants are declared with
let
, and are immutable. - Variables are declared with the type, or
var
if assigned.
- Minimalist syntax
- I like Python`s white-space block definitions
- No damn semi-colons
- Why should I need to type "def" or "function" ?
- Scope
- prevent myself from accessing stuff I forgot I shouldn't
- prevent others from accessing stuff they never should've
- public, protected, and private using naming semantics instead of keywords (_, __)
- shit declared in a method stays in the damn method
- Accessors/Mutators
- Massive time savers, and nicer syntax.
- Why do I need to say
obj.set_number(val)
instead ofobj.number = val
- Garbage Collection
- It's 2015, 'nuff said.
Example directory structure
Let .foo
be the file extension for this theoretical language.
run.foo my_module/ numgetter.foo numgetter_prude.foo
Example code
In run.foo
using my_module // "main", like some other languages, // is a method that automatically runs // when the module is executed main() var mytest = numgetter_prude("new name", 69) log(mytest.name) // logs "new name" log(mytest.number) // logs 0 because of the accessor override in numgetter_prude // Call a static module "method" numgetter_prude.print_stuff(mytest) // prints "Name is new name\nNumber is 0"
In numgetter.foo
public int add_num = 10 // variables with getters/setters // automatically create a private variable // such as _number and use it when appropriate int number: get get_number; set set_number // Allow sub-modules to override "public" methods public get_number() int return number public set_number(int val) void number = val
In numgetter_prude.foo
// module level inheretance inherets numgetter public string name // allow this to be read publically // but still set privately int other_number: public get // Methods with the module name are constructors numgetter_prude() // Constructors without explicit return assume "return this" return test("foo", 123) // Method overloading which is pretty much standard these days numgetter_prude(string new_name, int new_number) name = new_name number = new_number // Static methods do not require constructing the module // to call, nor do they have access to module namespaces // that are not static public static print_stuff(test test_instance) void // string concatenation is simply a space print("Name is " test_instance.name) print("Number is " test_instance.number) public get_number() int return add_num + base.number public set_number(int val) void if val in [69, 666] // too vulgar to allow val = 0 _number = val
Equivalent C-Sharp
In Run.cs
using console; class Run { // Comment // Comment // Comment static void Main() { var mytest = new NumgetterPrude("new name", 69); log(mytest.name) // logs "new name log(mytest.Number) // logs 0 // Call a static module "method" NumgetterPrude.PrintStuff(mytest) // prints "Name is new name\nNumber is 0" } }
In Numgetter.cs
public class Numgetter { public int add_num = 10; int _number; int Number { public get { return GetNumber(); } public set { SetNumber(value); } } public virtual int GetNumber() { return _number; } public virtual void SetNumber(val) { _number = val; } }
In NumgetterPrude.cs
public class NumgetterPrude : Numgetter { public string name; // Comment public NumgetterPrude() { name = "foo"; Number = 123; } // Comment public NumgetterPrude(string newName, int newNumber) { name = newName; Number = newNumber; } public override int GetNumber() { return add_num + base.GetNumber(); } public override void SetNumber(int val) { if ({69, 666}.Contains(val)) { // too vulgar to allow val = 0; } _number = val; } // Comment // Comment // Comment public static void PrintStuff(NumGetter ng) { console.writeln("Name is "+ng.name); console.writeln("Number is "+ng.Number); } }