πŸ“œ ⬆️ ⬇️

Suggestions for learning programming language

Good time to read, dear readers habrahabr.ru

For teaching programming offered hundreds of languages, including the management of graphic elements. Therefore, the proposal of a new language for learning requires additional justification.

Let me try to describe the advantages of the proposed programming language for programming (the working title is PL / 2) and for the programming of games (the working name for the PL / 2 script), and I suggest finding the shortcomings in the approach.

')
The main paradigms are as follows:
Assembly code to control the processor
Logical programming represented by Prolog, SQL
Functional programming
Imperative programming described by algorithms
Object programming consisting in the transmission and processing of signals

Currently, these techniques are combined in extensions of existing programming languages. An approach is proposed for combining paradigms in a single syntax that resolves conflicts between different approaches in advance, which will reduce the time spent on learning various syntaxes.

So, the key elements of the educational programming language.

Source text



The source text file consists of arbitrary text (comments, algorithm description), which may include [named] fragments in various programming languages ​​- PL / 2, sql, html, text, PL / 2 script.

the beginning of the insertion of the code is indicated by the meta keyword (meta) in the first position of the line

the end of the insertion is indicated by the sequence / meta in the first position of the line

The PL / 2 syntax includes uniform indentation requirements, in particular, the program text is shifted at least 4 positions from the beginning of the line.

Program text structure



The size of the shift between the levels of nesting is 4 spaces. Operator continuation on the next line is shifted by at least 3 spaces relative to the operator level

The main level of the program is shifted by 4 spaces relative to the markup symbol of the source meta file; accordingly, no single character of the program can have an indent of less than 4 spaces

Syntax



For different types of blocks, different types of brackets are assumed:

parentheses (...) are used to describe and pass parameters when calling methods

square brackets [...] are used to describe the dimension of arrays and specify an index when accessing an array element.

curly braces {...} are used to specify various elements of the program structure. For error localization, braces are supplied with additional characters.

{- ... -} - analogue of parentheses - used in the description of the body of the relational class

{# ... #} - used when describing the body of a function block

{$ ... $} - outer framing brackets when describing a structure class constant

{* ... *} - description of the body of the class or interface

{& ... &} - description of the method body

{@ ... @} - namespace body

{| ... |} - concurrent blocks

{% ...%} - controlled block

{= ... =} - class of responsibility

{...} - internal block in the method body

Operators



==    =/=    :=    ++   --   +  -  *  /  -/-   (    ,  ..  IDE) (? boolean ? value_true :: value_false ?) -   


Imperative programming



The following syntax is proposed for structured programming:

Operators enclosed between brackets {& and &} are executed sequentially in the order specified in the program text.

To change the order of execution, use the loop and branch operators

fulfillment of the condition

 if (){ ... } 


block execution when the first condition is met and the else block when none of the conditions is met

 decision{ if (<1>) ... if (<2>) ... else ... } 


numeric value switch with indication of constant or enumeration member

 switch (<>){ case <1>: ... case <2>: ... else ... } 


In expressions, you can also use the ternary selection operator

Cycle operator
 loop [explicit] [] { for <[]  [ := ]>; from <>; while <,     >; next < >; where <   > ... continue; ... break [ ]; ... } 

Here:
loop - loop start operator
explicit - the loop is executed at least once, the condition for leaving the loop before the first pass is not checked
for - list of loop variables and their initialization
while - the condition under which the loop continues to iterate
next - commands executed after iteration
from - the container from which the elements are selected when passing through the cycle
where is the condition for executing the loop body
continue - the operator of early transition to the next iteration
break - early exit operator from the current or specified cycle

Error processing



management of transactions and areas with the possibility of failure

 transaction{ finalize { } catch { } { throw //  catch  finalize revoke //     ,        finalize } } 


Object oriented programming



new - create a new object
drop - delete an object

work with collections

select :: = - getting information about the collection's named objects
insert + = - the inclusion of a new object in the collection
delete - = - remove an object from the collection
update - multiple updates in the collection

management of the rights of object actions over objects of the specified class or its properties / methods

grant + = - assign object permission rights to a class or property
deny + = - assign prohibition rights to an object on a class or property
revoke - remove object rights to the class

Types of classes



Classes are divided into the following types:



Not imperative programming



operators of work with lambda expressions and lists



quantifiers of existence and universality on ordered lists


eg,
head :: = %> (\ true),
tail :: = ~> (\ true)

Assembler



The processor class is used, the arguments of which methods are the arguments of the assembler commands, and the properties are the registers of the processor core.
This approach allows the use of inheritance, as a transition to a new generation of the processor line, as well as using the full names of commands instead of short mnemonics and the possibility of equal description in help systems.

Hallo, world



 hallo.pl2   program     default.Default.Main() meta source="pl2" name="example2" using user.OS.IO; // using OS Console interface program (String arguments[] \execution time command line parameters\ ) {& Console.write_line("Hallo, world!"); &} /meta *** hallo.pl2 *** 


PL / 2 script



The PL / 2 script language provides the ability to describe scripts and extend classes while describing a variable for programming games.

Instead of a functional variable, it is proposed to use a string that (as in Excel) starts with an equal sign.

In this case, the description of classes and objects is conveniently stored in XML, and the code used for active processing.

Class Description:
 <?xml version="1.0" encoding="windows-1251"?> <pl2script> <type id="type.class.Scene" save="true"> <help id="class.Scene.help">pl2script/game/scene.htm</help> <system> <class id="class.Scene" domain="type" save="true"> <name> <ascii>Scene</ascii> <local></local> </name> <tip id="class.Scene.tip"> <ascii>Game class as a main class for a game</ascii> <local>    </local> </tip> </class> <property id="class.Scene..." domain="string" save="true"> <name> <ascii>prop ...</ascii> <local>prop ...</local> </name> <tip id="class.Scene..tip"> <ascii>tip ...</ascii> <local>  ...</local> </tip> </property> </system> </type> </pl2script> 


Description of the object:
 <?xml version="1.0" encoding="windows-1251"?> <pl2script> <scene id="game."> <name></name> <description> </description> <message>    </message> <way id="game.universe" path="Universe/index" enabled="true"></way> <way id="game.solar" path="Solar/index" enabled="true"> </way> <way id="game.earth" path="Earth/index" enabled="true"></way> <way id="game.country" path="country/index" enabled="true"> </way> <way id="game.body" path="body/index" enabled="true"> </way> <way id="game.nature" path="nature/index" enabled="true"> </way> <way id="game.school" path="school/index" enabled="true"> </way> <way id="game.plant" path="plant/index" enabled="true"> </way> <way id="game.university" path="university/index" enabled="true"> </way> </scene> </pl2script> 


I ask to speak about the problems possible when using this syntax

References:
habrahabr.ru/post/136272 What programming language should be the first when studying at school?
habrahabr.ru/post/176243 "National" programming languages

Project - github.com/palexisru/pl2_rus/wiki

Thanks to oeai for the link to the INSTEAD project and the Lua language

Source: https://habr.com/ru/post/219419/


All Articles