PascalABC.NET: Difference between revisions

Content deleted Content added
Differences between Delphi and PascalABC.NET: Little bit more about history
Added history section, removed redundant code samples, restructured the article
Line 26:
PascalABC.NET is implemented for the [[.NET Framework]] platform, so that it is compatible with all .NET libraries and utilizes all the features of [[Common Language Runtime]], such as [[Garbage collection (computer science)|garbage collection]], [[exception handling]], and [[Generic programming|generics]]. Some language constructions, e.g. tuples, sequences, and lambdas, are based on regular .NET types. PascalABC.NET is ideologically close to [[Oxygene (programming language)|Oxygene]], but, unlike it, provides high compatibility with [[Delphi (programming language)|Delphi]].
 
== DifferencesHistory between Delphi andof PascalABC.NET ==
PascalABC.NET was developed by a group of enthusiasts at the Institute of Mathematics, Mechanics, and Computer Science in Rostov-on-Don, Russia.<ref name=":1">{{Cite book |last=Osipov |first=Alexander V. |title=PascalABC.NET: Vvedenie v sovremennoe programmirovanie [PascalABC.NET: Introduction to Modern Programming] |publisher=Southern Federal University |year=2019 |pages=28}}</ref> In 2003, a predecessor of the modern PascalABC.NET, called Pascal ABC, was implemented by associate professor Stanislav Mikhalkovich to be used for teaching schoolchildren instead of [[Turbo Pascal]], which became outdated and incompatible with morden operating systems but was still used for educational purposes. Pascal ABC was implemented as an [[Interpreter (computing)|interpreted programming language]], that led to a significant lack of performance. Four years after that it was completely rewritten by students Ivan Bondarev, Alexander Tkachuk, and Sergey Ivanov as a [[Compiled language|compiled programming language]] for the .NET platform. In 2010, PascalABC.NET started to be actively used for teaching high school students. By 2015, the number of users of the language had increased significantly. It began to be actively used throughout Russia in schools and at programming contests, surpassing [[Free Pascal|FreePascal]]. Since then, the PascalABC.NET developers have set themselves the goal of actively incorporating modern features into the language. In the same year, PascalABC.NET became an open source project distributed under the [[GNU Lesser General Public License|LGPLv3 license]].<ref>{{Cite web |date=2021-03-30 |title=Twisted Pair Podcast, #389 |url=https://tpair.org/podcast/tp-389/ |website=Twisted Pair Podcast |language=ru-RU}}</ref><ref>{{Cite web |last=Bondarev |first=Ivan V. |last2=Belyakova |first2=Yulia V. |last3=Mikhalkovich |first3=Stanislav S. |date=2013-04-24 |title=PascalABC.NET programming system: 10 years of development |url=https://pascalabc.net/downloads/Presentations/10letPABC.pdf |access-date=2023-04-09 |website=PascalABC.NET}}</ref>
 
In 2017<ref>{{Cite web |date=2017-03-29 |title=Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio |url=https://pvs-studio.com/en/blog/posts/csharp/0492/ |website=PVS-Studio |lang=en}}</ref> and 2022,<ref>{{Cite web |date=2022-02-11 |title=Re-checking PascalABC.NET |url=https://medium.com/pvs-studio/re-checking-pascalabc-net-f8bfc94aba3c |website=Medium |lang=en}}</ref> independent audit of [https://github.com/pascalabcnet/pascalabcnet PascalABC.NET public repository] was conducted. Based on the results of the static check, potentially dangerous code fragments were listed that require additional analysis by developers. It was also noted that the overall quality of the code could be improved. To do this, code duplication and redundant checks should be eliminated, and refactoring should be performed more carefully.
=== New features ===
 
== Use in school and higher education ==
Designed for education, PascalABC.NET remains the most common programming language in Russian schools and one of the recommended languages for passing the [[Unified State Exam]] on informatics.<ref>{{Cite web |title=Metodicheskie rekomendacii po podgotovke i provedeniyu edinogo gosudarstvennogo ekzamena po informatike i IKT v komp'yuternoj forme v gorode Moskve v 2021 godu [Guidelines for the preparation and conduct of the unified state exam in computer science and ICT in the city of Moscow in 2021] |url=http://rcoi.mcko.ru/resources/upload/RichFilemanager/documents/2020-2021/org_metod/11/mr_kege_inf_2021.pdf |publisher=Departament obrazovaniya i nauki goroda Moskvy [Department of Education and Science of Moscow] |page=110 |language=ru-RU}}</ref><ref>{{Cite web |last=Polyakov |first=Konstantin |title=Doklady na konferenciyah i seminarah [Reports at conferences and seminars] |url=https://kpolyakov.spb.ru/school/doklad.htm |language=ru-RU}}</ref><ref>{{Cite web |last=Bogdanov |first=Alexey |date=2022-10-04 |title=PascalABC.Net or Python/ C#/C++ |url=https://www.youtube.com/watch?v=RulhCYnbRAA |access-date=2023-04-05 |website=YouTube |language=ru-RU}}</ref> In the Southern Federal University, it is used as the first language for teaching students majoring in computer science, and for teaching children in one of the largest computer schools in Russia.<ref>{{Cite news |last=Popova |first=Ekaterina |date=2022-09-06 |title=Kak v Rostove gumanitarii uspeshno obuchayutsya IT-special'nostyam [How humanitarians successfully study IT specialties in Rostov] |language=ru-RU |work=Komsomolskaya Pravda |url=https://www.rostov.kp.ru/daily/27441/4643617/}}</ref> PascalABC.NET is widely used as a basic programming language in pedagogical universities for the training of computer science teachers.<ref name="MathAnim">{{Cite journal |last1=Dzhenzher |first1=V.O. |last2=Denisova |first2=L.V. |year=2019 |title=Mathematical animation in computer simulation at school |url=https://www.sciencegate.app/document/10.32517/2221-1993-2019-18-6-51-54 |journal=Informatics in School |language=ru-RU |issue=6 |pages=51–54 |doi=10.32517/2221-1993-2019-18-6-51-54 |s2cid=203704481}}</ref><ref name="HammingCode">{{Cite journal |last1=Dzhenzher |first1=V.O. |last2=Denisova |first2=L.V. |year=2021 |title=Implementation of the Hamming code on PascalABC.NET while studying the theoretical foundations of informatics |url=https://www.sciencegate.app/document/10.32517/2221-1993-2021-20-9-27-36 |journal=Informatics in School |language=ru-RU |volume=1 |issue=9 |pages=29–38 |doi=10.32517/2221-1993-2021-20-9-27-36 |s2cid=245473319}}</ref><ref name="SciGraph">{{Cite journal |last1=Dzhenzher |first1=V.O. |last2=Denisova |first2=L.V. |year=2020 |title=Scientific graphics in PascalABC.NET: plotting function graphs in a rectangular cartesian coordinate system |url=https://www.sciencegate.app/document/10.32517/2221-1993-2020-19-1-31-39 |journal=Informatics in School |language=ru-RU |issue=1 |pages=31–39 |doi=10.32517/2221-1993-2020-19-1-31-39 |s2cid=215844807}}</ref><ref>{{Cite journal |last=Kulabukhov |first=S.Yu. |year=2021 |title=Mathematical modeling in informatiсs lessons using numerical solution of differential equations |url=https://school.infojournal.ru/jour/article/view/528/528 |journal=Informatics in School |language=ru-RU |issue=2 |pages=14–21 |doi=10.32517/2221-1993-2021-20-2-14-21 |s2cid=235541530}}</ref> It also serves as a tool for scientific computing.<ref>{{Cite journal |last1=Khazieva |first1=R.T. |last2=Ivanov |first2=M.D. |year=2020 |title=Selection of optimum device parameters for permanent magnetic field generation |url=https://www.energyret.ru/jour/article/view/1625/696 |journal=Power Engineering: Research, Equipment, Technology |language=ru-RU |volume=22 |issue=6 |pages=176–187 |doi=10.30724/1998-9903-2020-22-6-176-187 |s2cid=233658494}}</ref><ref>{{Cite journal |last1=Lukyanov |first1=O.E. |last2=Zolotov |first2=D.V. |year=2021 |title=Methodological support for the training of UAV designers and operators |url=https://journals.ssau.ru/vestnik/article/view/8633/pdf |journal=VESTNIK of Samara University. Aerospace and Mechanical Engineering |language=ru-RU |volume=20 |issue=1 |pages=14–28 |doi=10.18287/2541-7533-2021-20-1-14-28 |s2cid=236617894}}</ref> PascalABC.NET is also built into a number of validation systems used for programming competitions.<ref>{{Cite web |title=ACMP Olympiad System |url=https://acmp.ru/article.asp?id_text=120 |url-status=live |archive-url=https://web.archive.org/web/20230327035528/https://acmp.ru/article.asp?id_text=120 |archive-date=2023-03-27 |access-date=2023-04-05}}</ref><ref>{{Cite web |title=Yandex Contest Compilers List |url=https://contest.yandex.ru/compilers/ |url-status=live |archive-url=https://web.archive.org/web/20230314174434/https://contest.yandex.ru/compilers/ |archive-date=2023-03-14 |access-date=2023-04-05 |website=Yandex Contest}}</ref>
 
In 2020, during anti-COVID lockdowns and home schooling period, PascalABC.NET website was ranked 3<sup>rd</sup> in Yandex rating in the "Programming" category, and the number of downloads of the installation kit exceeded 10000 a day.<ref>{{Cite web |last=Kubysheva |first=Olga |date=2020-04-17 |title=PascalABC.NET: Sajt sistemy programmirovaniya, razrabatyvaemoj na mekhmate YUFU, podnyalsya v rejtinge YAndeksa na tret'e mesto [PascalABC.NET: Site of programming system developed at SFedU MMCS faculty climbed up to the third place in Yandex ranking] |url=https://www.rostov.kp.ru/online/news/3839814/ |website=Komsomol'skaya pravda |language=ru-RU}}</ref>
 
Though the core PascalABC.NET community is located in Russia, the language is also known in other countries such as Belarus<ref>{{Cite journal |last=Kutysh |first=Aleksandr Z. |year=2018 |title=Razrabotka soderzhaniya vzaimosvyazannogo obucheniya budushchih uchitelej informatiki tekhnologiyam programmirovaniya [Development of interconnected training content for future computer science teachers in programming] |url=https://www.adu.by/images/2019/05/PedNauka_3(24)_2018.pdf |journal=Pedagogical science and education |language=ru-RU |issue=3 |pages=44-52}}</ref>, Romania,<ref>{{Cite web |date=2020-01-21 |title=Practică în Pascal |url=https://www.youtube.com/playlist?list=PLP11T_LhFxPlQoxbZ1ZTlrv6AXDQjJJqB |website=YouTube}}</ref> Indonesia,<ref>{{Cite web |title=Mengenal PascalABC.NET |url=https://www.pascal-id.org/news/357/mengenal-pascalabc.net |url-status=live |archive-url=https://web.archive.org/web/20220810114037/https://www.pascal-id.org/news/357/mengenal-pascalabc.net |archive-date=2022-08-10 |access-date=2023-04-08}}</ref> Algeria.<ref>{{Cite web |date=2022-06-12 |title=PASCAL AND DELPHI TUTORIAL |url=https://www.youtube.com/playlist?list=PLmFVPmv0ntGNq-mu4vCT68I5ekJQj-Ocn |website=YouTube}}</ref>
 
== Language syntax ==
 
=== Differences between Delphi and PascalABC.NET ===
 
==== New features ====
'''•''' <code>loop</code> statement<syntaxhighlight lang="delphi">
loop 10 do
Line 67 ⟶ 81:
Println(m); // [[1,2,3,4],[2,3,4,5],[3,4,5,6]]
Println(m[:2,1:3]); // [[2,3],[3,4]]
</syntaxhighlight>Some other features such as inline variable declarations, type inference, and <code>for</code> statement with a variable declaration are standard in the current version of Delphi. However, PascalABC.NET pioneered these features in 2007,<ref name=":2">{{Cite web |title=PascalABC.NET. What's New |url=https://pascalabc.net/chto-novogo |url-status=live |access-date=2023-04-09 |website=PascalABC.NET |language=ru-RU}}</ref>, while in Delphi they were implemented in 2018.<ref>{{Cite web |last=Embarcadero Technologies |date=2018-11-21 |title=See What's New in RAD Studio 10.3 |url=https://www.youtube.com/watch?v=RreUFdxaR20&t=44s |website=YouTube}}</ref><ref>{{Cite web |title=Help for RAD Studio 10.3 Rio. What's New |url=https://docwiki.embarcadero.com/RADStudio/Rio/en/What%27s_New |url-status=live |access-date=2023-04-09 |website=Embarcadero. Product Documentation Wikis}}</ref>.
 
=== Changed features ===
 
==== Changed features ====
* strings in <code>case</code> statements
* sets based on arbitrary type: <code>set of string</code>
Line 77 ⟶ 90:
* modules can be defined in a simplified form (without <code>interface</code> and <code>implementation</code> sections)
 
==== Not implemented features ====
 
* records with variant parts
* open arrays
Line 84 ⟶ 96:
* [[Inline assembler|inline assembly code]]
 
=== Functional style features ===
In PascalABC.NET, functions are [[First-class citizen|first-class objects]]. They can be assigned to variables, passed as parameters, and returned from other functions.<ref name=":1" /> Functional type is set in the form <code>T -> Res</code>. An [[anonymous function]] can be assigned to the variable of this type:
<syntaxhighlight lang="delphi">
## // denotes that the main program will be written without enclosing begin-end
Line 116 ⟶ 128:
Print(f(2)(3));
</syntaxhighlight>
 
== Use in school and higher education ==
 
Designed for education, PascalABC.NET remains the most common programming language in Russian schools and one of the recommended languages for passing the [[Unified State Exam]] on informatics.<ref>{{Cite web |title=Metodicheskie rekomendacii po podgotovke i provedeniyu edinogo gosudarstvennogo ekzamena po informatike i IKT v komp'yuternoj forme v gorode Moskve v 2021 godu [Guidelines for the preparation and conduct of the unified state exam in computer science and ICT in the city of Moscow in 2021] |url=http://rcoi.mcko.ru/resources/upload/RichFilemanager/documents/2020-2021/org_metod/11/mr_kege_inf_2021.pdf |publisher=Departament obrazovaniya i nauki goroda Moskvy [Department of Education and Science of Moscow] |page=110 |language=ru-RU}}</ref><ref>{{Cite web |last=Polyakov |first=Konstantin |title=Doklady na konferenciyah i seminarah [Reports at conferences and seminars] |url=https://kpolyakov.spb.ru/school/doklad.htm |language=ru-RU}}</ref><ref>{{Cite web |last=Bogdanov |first=Alexey |date=2022-10-04 |title=PascalABC.Net or Python/ C#/C++ |url=https://www.youtube.com/watch?v=RulhCYnbRAA |access-date=2023-04-05 |website=YouTube |language=ru-RU}}</ref> In the Southern Federal University, it is used as the first language for teaching students majoring in computer science, and for teaching children in one of the largest computer schools in Russia.<ref>{{Cite news |last=Popova |first=Ekaterina |date=2022-09-06 |title=Kak v Rostove gumanitarii uspeshno obuchayutsya IT-special'nostyam [How humanitarians successfully study IT specialties in Rostov] |language=ru-RU |work=Komsomolskaya Pravda |url=https://www.rostov.kp.ru/daily/27441/4643617/}}</ref> PascalABC.NET is widely used as a basic programming language in pedagogical universities for the training of computer science teachers.<ref name="MathAnim">{{Cite journal |last1=Dzhenzher |first1=V.O. |last2=Denisova |first2=L.V. |year=2019 |title=Mathematical animation in computer simulation at school |url=https://www.sciencegate.app/document/10.32517/2221-1993-2019-18-6-51-54 |journal=Informatics in School |language=ru-RU |issue=6 |pages=51–54 |doi=10.32517/2221-1993-2019-18-6-51-54|s2cid=203704481 }}</ref><ref name="HammingCode">{{Cite journal |last1=Dzhenzher |first1=V.O. |last2=Denisova |first2=L.V. |year=2021 |title=Implementation of the Hamming code on PascalABC.NET while studying the theoretical foundations of informatics |url=https://www.sciencegate.app/document/10.32517/2221-1993-2021-20-9-27-36 |journal=Informatics in School |volume=1 |language=ru-RU |issue=9 |pages=29–38 |doi=10.32517/2221-1993-2021-20-9-27-36|s2cid=245473319 }}</ref><ref name="SciGraph">{{Cite journal |last1=Dzhenzher |first1=V.O. |last2=Denisova |first2=L.V. |year=2020 |title=Scientific graphics in PascalABC.NET: plotting function graphs in a rectangular cartesian coordinate system |url=https://www.sciencegate.app/document/10.32517/2221-1993-2020-19-1-31-39 |journal=Informatics in School |language=ru-RU |issue=1 |pages=31–39 |doi=10.32517/2221-1993-2020-19-1-31-39|s2cid=215844807 }}</ref><ref>{{Cite journal |last=Kulabukhov |first=S.Yu. |year=2021 |title=Mathematical modeling in informatiсs lessons using numerical solution of differential equations |url=https://school.infojournal.ru/jour/article/view/528/528 |journal=Informatics in School |language=ru-RU |issue=2 |pages=14–21 |doi=10.32517/2221-1993-2021-20-2-14-21|s2cid=235541530 }}</ref> It also serves as a tool for scientific computing.<ref>{{Cite journal |last1=Khazieva |first1=R.T. |last2=Ivanov |first2=M.D. |year=2020 |title=Selection of optimum device parameters for permanent magnetic field generation |url=https://www.energyret.ru/jour/article/view/1625/696 |journal=Power Engineering: Research, Equipment, Technology |language=ru-RU |volume=22 |issue=6 |pages=176–187 |doi=10.30724/1998-9903-2020-22-6-176-187|s2cid=233658494 }}</ref><ref>{{Cite journal |last1=Lukyanov |first1=O.E. |last2=Zolotov |first2=D.V. |year=2021 |title=Methodological support for the training of UAV designers and operators |url=https://journals.ssau.ru/vestnik/article/view/8633/pdf |journal=VESTNIK of Samara University. Aerospace and Mechanical Engineering |language=ru-RU |volume=20 |issue=1 |pages=14–28 |doi=10.18287/2541-7533-2021-20-1-14-28|s2cid=236617894 }}</ref>
[[File:Turtle Dawing Unit of PascalABC.NET.png|thumb|An example of a geometric figure drawn with the TurtleWPF unit]]
PascalABC.NET has built-in units aimed at teaching children of primary and secondary school age: GraphWPF (raster graphics), WPFObjects (vector graphics), Graph3D (3D graphics and animation), Robot, Drawman and TurtleWPF (for beginners).These units represent a higher abstraction level allowing beginners not to focus on technical aspects of drawing.
The figure shown is drawn with the following code:<syntaxhighlight lang="delphi">
uses TurtleWPF;
 
begin
Down; // prepare turtle's pen
SetSpeed(11); // set turtle's movement speed
SetColor(Colors.Red); // set pen color
for var i:=1 to 450 do
begin
SetColor(RGB(128+i,0,i)); // change pen color
Forw(i); // move turtle forward
Turn(96); // rotate turtle clockwise
end;
end.
</syntaxhighlight>PascalABC.NET is also built into a number of validation systems used for programming competitions.<ref>{{Cite web |title=ACMP Olympiad System |url=https://acmp.ru/article.asp?id_text=120 |url-status=live |archive-url=https://web.archive.org/web/20230327035528/https://acmp.ru/article.asp?id_text=120 |archive-date=2023-03-27 |access-date=2023-04-05}}</ref><ref>{{Cite web |title=Yandex Contest Compilers List |url=https://contest.yandex.ru/compilers/ |url-status=live |archive-url=https://web.archive.org/web/20230314174434/https://contest.yandex.ru/compilers/ |archive-date=2023-03-14 |access-date=2023-04-05 |website=Yandex Contest}}</ref>
 
== Programming styles and code examples ==
PascalABC.NET is a multi-paradigm programming language. It allows one to use different coding styles from oldschool Pascal to functional and object-oriented programming. The same task can be solved in different styles as follows:
 
=== Oldschool style ===
<syntaxhighlight lang="delphi">
var a,b,i,sum: integer; // variables definition preceeds the main program body
begin
Read(a,b);
sum := 0;
for i:=a to b do
sum := sum + i*i;
Write('Sum = ',sum)
end.
</syntaxhighlight>
 
=== Equivalent PascalABC.NET style ===
<syntaxhighlight lang="delphi">
begin
var (a,b) := ReadInteger2; // read input into tuple of two variables
var sum := 0; // type auto-inference
for var i:=a to b do
sum += i*i;
Print($'Sum = {sum}') // string interpolation
end.
</syntaxhighlight>
 
=== Procedural style ===
<syntaxhighlight lang="delphi">
function SumSquares(a,b: integer): integer;
begin
Result := 0;
for var i := a to b do
Result += i * i
end;
 
begin
var (a,b) := ReadInteger2;
Print($'Sum = {SumSquares(a,b)}')
end.
</syntaxhighlight>
 
=== Functional style ===
This solution uses .NET extension methods for sequences and PascalABC.NET-specific range <code>(a..b)</code>.<syntaxhighlight lang="delphi">
begin
var (a,b) := ReadInteger2;
(a..b).Sum(x -> x*x).Print // method chaining with lambda expressions
end.
</syntaxhighlight>
 
=== Object-oriented style ===
This solution demonstrates PascalABC.NET-specific short function definition style.<syntaxhighlight lang="delphi">
type Algorithms = class
static function SumSquares(a,b: integer) := (a..b).Sum(x -> x*x);
static function SumCubes(a,b: integer) := (a..b).Sum(x -> x*x*x);
end;
 
begin
var (a,b) := ReadInteger2;
Println($'Squares sum = {Algorithms.SumSquares(a,b)}');
Println($'Cubes sum = {Algorithms.SumCubes(a,b)}')
end.
</syntaxhighlight>
 
=== Close to regular C# style ===
It is possible to write programs without usage of PascalABC.NET standard library. All standard .NET Framework classes and methods can be used directly.<syntaxhighlight lang="delphi">
uses System; // using .NET System namespace
begin
var arr := Console.ReadLine.Split(
new char[](' '),
StringSplitOptions.RemoveEmptyEntries
);
var (a,b) := (integer.Parse(arr[0]),integer.Parse(arr[1]));
var sum := 0;
for var i:=a to b do
sum += i*i;
Console.WriteLine($'Sum = {sum}')
end.
</syntaxhighlight>
 
== Source code audit ==
In 2017<ref>{{Cite web|lang=en|url=https://pvs-studio.com/en/blog/posts/csharp/0492/|title=Analysis of PascalABC.NET using SonarQube plugins: SonarC# and PVS-Studio|website=PVS-Studio|date=2017-03-29}}</ref> and 2022,<ref>{{Cite web|lang=en|url=https://medium.com/pvs-studio/re-checking-pascalabc-net-f8bfc94aba3c|title=Re-checking PascalABC.NET|website=Medium|date=2022-02-11}}</ref> independent audit of [https://github.com/pascalabcnet/pascalabcnet PascalABC.NET public repository] was conducted. Based on the results of the static check, potentially dangerous code fragments were listed that require additional analysis by developers. It was also noted that the overall quality of the code could be improved. To do this, code duplication and redundant checks should be eliminated, and refactoring should be performed more carefully.
 
== See also ==
* [[Object Pascal]]
* [[C Sharp (programming language)|C#]]
 
== References ==