Building a Clear Programming Language for Newcomers
This is a joke
Introduction
Many new programmers are often confused about a very important concept in programming: the variable lifespan. For example, one could not understand why the variable "a" is "not defined" when it's clearly there:
int x=3;
{
int a=4;
}
a; //Compile Error
Another problem newcomers face when they are first presented callback functions are that they are not able to convert sequential code into callback functions. When the program gets complicated, it is common for a professional programmer to combine the callback functions and sequential coding. When this happens, newcomers may not know the correct order of execution, leading to frustration.
One more problem comes from the "impossible" mission for coding: naming things. Professional coder might use what are called "defensive programming" by naming variables weirdly, like just calling them q
fa
wps
sht
etc.
In order to make programming more accessible to beginners, we have developed the latest programming language: CLang
!
Naming things
To solve the problem with naming things, in CLang we force the variable name to include its type at the beginning (for int, long long, bool, byte, etc) or at the end (for complex types). Instead, you do not need to explicitly write out its type:
iAge #int32 age
llAnswer #int64 answer
myBook #Book my
newObject #Object "new"
Program Structures
In a standard program, we might write program in a sequential order:
int main(){
int a;
cin>>a;
if(a<0){
int out=-a;
cout<<out;
}else{
int out=a;
cout<<out;
}
}
However in CLang we force everything to have a callback function and the scope is defined explicitly using {}
! So no more sequential and the order of execution has no worries!
mainFunc(){ //define Func called main
ia{ //int a. in the {} is where this variable 'a' exists
inputF(function(data){ //signature: inputF/inputFunc(callback)
(ia=data).then(function(){
if(a<0,function(){ //if(cond,true_callback,false_callback)
iOut(-ia){ //give iOut an initial value
outputF(iOut,function(){})
}
},function(){
iOut(ia){
outputF(iOut,function(){})
}
})
})
})
}
}{}
The function are defined using the following syntax:
nameF/nameFunc(parameters):returnType{
codeBlock
}{
defined scope
}
For example:
absF(ia):int{
return ia>0?ia:-ia;
}{
//you can use absF here
mainF(){
ia{
input(function(data){
(ia=data).then(function(){
output(absF(ia),function(){})
})
})
}
}{}
}
Defining a class is weird but understandable:
class Animal{
public{
iAge,nameString;
barkF(contentString){
output(nameString+" says "+contentString,NF) //wow you can use NF for empty functions!
}
}
}{
class Dog:Animal{
private{
typeString;
}
public{
barkF(contentString){
output(nameString+" barks "+contentString,NF)
}
}
}
}
版权声明:
作者:XGN
链接:https://blog.hellholestudios.top/archives/1574
来源:Hell Hole Studios Blog
文章版权归作者所有,未经允许请勿转载。
共有 0 条评论