loading...

I need your feedback about a new programming language idea to improve its design.

mak12776 profile image Mohammad Amin Khakzadan Updated on ・3 min read

Hello, I want to create a new programming language named codescript. It will be open source and free. This repository is where I started.

I need your feedback about it. So I can improve the design of the language.

It will be a scripting language and will be compiled into its own byte code.

DISCLAIMER: I'm not very well at speaking the english language, but I am an experienced programmer, so I can do a better explanation of it by code examples.

ok, let's start.

imagine you opened a file named main.code for writing codescript.

At the first you start writing a file, there is no variable or function defined, and there is no if, else, else if, for or while token that can be understood by compiler. program flow and other stuff will be written just by symbols. Also, there is no print or puts function for writing text to stdout. (they can be accessed by [# system] module). So there's no limit for your variable names except that they should match the Regex pattern [_a-zA-Z][_a-zA-Z0-9]* and also they can't be T, F or N constants.

Now, data types that can be stored in the variables:

// comments start with two slashes.

char = 'a'
int = 10
float = 2.3

bool = T                 // or F
none = N

// `;` can be used to separate statements, but aren't mandatory.

array = [1, 'a', T];
string = "abcd";
code = #(a = 10);

object =
{
    name = "jack"
    age = 10
};

function num => 10 * num;

// `function` is not a keyword. you are defining a function named `function`.

char, int, float

char,int, float are simple data types that you may know.

english_first_letter = 'a'
seconds_in_a_year = 60 * 60 * 24 * 365
pi_number = 3.14159265

bool, none

bool and none are for boolean, and none, respectively. you can't and (&&), or (||) between bool and none data types:

boolean = T || N            // error: `bool` and `none` can't be Or-ed.

also between other data types:

boolean = "Hello" && 5      // error: `string` and `int` can't be And-ed.

They were allowed only between bool data types:

true = F || T
false = true && F

// we can also xor between booleans

var = T ^^ F            // var = T

array, string

array and string data types just exist because of the computer memory data model. I want to design codescript as simple as possible. And let the developer do the extra work with his own creativity. the only difference between string and array is that string data type can only store char.

name = "John"
name_len = name.len            // name_len == 4

numbers = [2, 4, 6]
numbers_len = numbers.len      // numbers_len == 3

code

code data type is just a piece of code. that means when you type:

code = #(a = 10)

you are storing a variable definition statement into another variable.

Ok, let me give you examples:

define_var = #(var = "Hello");

define_var;                      // it's the same as: var = "Hello"

hello_world = var + " World";    // hello_world == "Hello World"

We can also store calculation statements:

var1 = #(2 * 3);
var2 = 2 * 3;
// type of var1 is `code`, but var2 contains `6`, which is an `int`.

a = var1;
b = var2;
// now, `a` and `b`, both are of the type `int`.

or store multiple statements:

code_object = #(name = "Jack"; age = 20;);

code_object;
// now, `name` and `age` are defined.

Or defining a variable based on previous definitions:

define_b = #(b = a * 10);
a = 3;

define_b;
// now, b == 30

It's worth that we can store code statements into a variable, and I will show you the advantages of this later.

object

object data types are just like namespaces, or maybe classes. you can define variables inside them, and you can access them or assign them by . member access.

object = 
{
    name = "Jack"
    age = 20
}

// object.name == "Jack"
// object.age == 20

// assign color member of object, not previosly defined:
object.color = "white"

objects can be used for a block of code, for example:

array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

ten_times_array_len = 
{
    result = 10 * array.len;
}.result;

// you might have guessed that ten_times_array_len is equal to 100.
// and there is no variable defined named `result`.

function

function data types are just functions. They can be called, and return any type of data.

I'm not very sure about the function definition style, I'm thinking of some styles:

// --- style 1 ---

// function declaration:
sum a b => a + b;

// anonymous declaration:
sum = (a b) => a + b;

// --- style 2 ---

// function declaration:
sum a b = a + b;

// anonymous declaration:     
sum = (a b) = a + b;

// or anything else...

if you want to create a new programming language, which style you prefer? In my opinion, the lack of use of semicolons between arguments is less costly. they can be separated by spaces.

This post is not over and I try to complete it over time.

Posted on by:

Discussion

markdown guide
 

I have a very nit-picky suggestion: changing .len to .length.
I have a few reasons:
Number one, it's that tiny bit more clear. A beginner might not immediately understand len, but length is very intuitive.
Number two is that you've adhered to this "longer" style before with the keyword function. I like that a lot, because of its expressiveness, and I think it should carry through.

I have one question left: what's this language for?😇 Is it for fun, or does it actually serve a specific use-case? That might help with giving suggestions what could be changed/added/improved!

 

Yes, a beginner might not immediately understand len, but a profession wants short sentences to spell less time to write. So, it's better to teach the beginner what we mean by len.

function is not a keyword, it's a variable. you are defining function as being a function. what I said at the beginning of the article is that there's no keyword that will be understood by the language compiler, the compiler will just understand symbols. that is another way of writing a short sentence for speed efficiency.

It will be a language like python or javascript, a general purpose language. I did not explain it completely. So it's hard to understand the purpose of the language.

 

I don't think the "less time to write" argument is so valid, because auto-complete is a thing, and it will probably complete a simple l to length if it's good. Does require more tooling though.

But I'm always the person who'd rather have long words and avoid all abbreviations. :D

Function being a variable is interesting! Didn't get that/remember it correctly.

Have fun and good luck with the language!😇

yea, function is a variable. it's not like python, ruby or whatever else.

def = 1;
module = 1;
func = 1;
lambda = 1;
something = 1;

all of them are variables, we have no limit for choosing our variable names.

 

It seems that a language like that could be a nice use for statistics (remembering horrible courses on that...), but there should be a way to import algorithms of some sort, I suppose.

How is the language interpreted ? Is it interpreted by another language (c or python) or transformed into another language ? I'm asking this because ES6 javascript can transpile into ES5 with babel, JS gets updated a lot, and for the better. I think that python could have something like this as well, and in fact, your code looks a lot like python without the hassle (in my mind, at least, I'm not a professional:) )

 

there is a way to import algorithms: we have jumping branches.
let's explain by example:

// check whether a number is even or not

print = [# io].print

(int % 2 == 0): 
(
    print "even"
    -> end
)
print "old"
end:

the interpreter can be written in python or C, but the virtual machine that wants execute byte code must be written in c for speed efficiency.
and yes, this a scripting programming language like python, javascript, TypeScript, ruby.