Recent

Author Topic: Please make your language more freedom  (Read 37043 times)

giahung1997

  • Full Member
  • ***
  • Posts: 113
Please make your language more freedom
« on: June 21, 2018, 04:18:54 am »
A little struggle to register, take of me many minutes since I'm not speak English, I've to go to a online text reverse site to correctly backward spell the word 'Lazarus'  %)

And now the real problem I want to say. I used to think Lazarus (FreePascal) is the only free and modern Pascal language ecosystem. It turn out to be wrong. There's PascalABC.NET too. I liked it more from Object Free Pascal, not because it can use the full power of .NET but because I found their Pascal Dialect to be more modern and freedom than yours (just my own opinion). For example, I could declare varible everywhere on the procedure's body, don't have to declare it all on var:

Code: Pascal  [Select][+][-]
  1. // "Решето Эратосфена" - вычисление простых чисел
  2. const n = 100000;
  3.  
  4. var primes: set of integer;
  5.  
  6. begin
  7.   primes := [2..n];
  8.  
  9.   for var i:=2 to round(sqrt(n)) do
  10.   begin
  11.     if not (i in primes) then
  12.       continue;
  13.     var x := i*i;
  14.     while x<=n do
  15.     begin
  16.       Exclude(primes,x);
  17.       x += i;
  18.     end;
  19.   end;
  20.  
  21.   writeln('Простые числа < ',n,':');
  22.   writeln(primes);
  23.   writeln;
  24.   writeln('Время вычисления: ',Milliseconds/1000);
  25. end.

It's OK for you disciplined Pascal lover. I'm used to familiar with TP too but it's only a short time in school (Vietnam school still teach programming using Pascal, but College teach C/C++/Java). I choose to be a farmer and not go to college, programming for fun at my free time using a language (dynamic) called Fantom (I choose it because it's ':=' like Pascal  :-[). Now I come back I found it's something tricky about having to declare anything at var. Thanks.

PascalABC.NET's GUI Designer is noway comparable to Lazarus despite it using Windows Form Components of .NET. That's the reason I want to go to Lazarus but afraid. Another downside of PascalABC.NET is, these guys from Russian, their documents are not yet translated to English. I'm a later generation of Vietnamese, no longer can read Russian  :'(

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Please make your language more freedom
« Reply #1 on: June 21, 2018, 04:51:18 am »
There's PascalABC.NET too. I liked it more from Object Free Pascal, not because it can use the full power of .NET but because I found their Pascal Dialect to be more modern and freedom than yours (just my own opinion). For example, I could declare varible everywhere on the procedure's body, don't have to declare it all on var:
Free Pascal is rather "purist" and your request is I believe has been discussed previously and rejected. Decision regarding importing language features need to be taken carefully because once done, it's a responsibility to maintain. You can take a look at various ideas ever proposed here, in which some of them have been implemented. In case you don't know, DelphiWebScript dialect in SmartPascal also implements that inline declaration feature, among others.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Please make your language more freedom
« Reply #2 on: June 21, 2018, 09:08:19 am »
There's PascalABC.NET too. I liked it more from Object Free Pascal, not because it can use the full power of .NET but because I found their Pascal Dialect to be more modern and freedom than yours (just my own opinion).

(I still fail to see what "modern" has to do with imitating 1970s C syntax. The two years that Pascal is older than C can't matter that much?)

 

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Please make your language more freedom
« Reply #3 on: June 21, 2018, 09:14:17 am »
Code: Pascal  [Select][+][-]
  1.   for var i:=2 to round(sqrt(n)) do
  2.  
That "feature" has been discussed many times and it was decided against it. (imho for all the good reasons
Not because it is hard to implement, but because of other reasons:
- The strict separation of declaration and actual use is deemed more important and more in line with true Pascal Philosophy
- For example it makes it easy to introduce hard to find bugs
- It also makes the program less readable to others: you are more or less hiding the use of a variable inside its implementation.

To summarize, although this C style "feature" seems attractive to some, it actually hurts the Pascal style of readability and separation.
Note FreePascal has many, many modern features that are unique. And many are way more useful.

But if somebody cares to implement it!, there is a slight change it could be accepted under a modeswitch that is OFF by default.
That has been discussed too, if I remember correctly.

As an aside: personally I think the feature has the wrong syntax: from a language point of view there should be no declaration at all, because assignments to e.g. loop variables can use type inference like:
Code: Pascal  [Select][+][-]
  1.   for i:=2 to round(sqrt(n)) do // "i" can be type inferred from its use as an ordinal type and its scope is also known
Not in (easily) in this case, but in other cases even the range of the ordinal can be determined, both probably not in LL(1), which is also a Pascal feature/property.
So if one implements it, it is better to skip the "var" at all, it is useless. (And IMNSHO thoughtlessly implemented!! to look like C.)
That is a better still solution but I am just as against it as using var syntax in loop implementations.

To summarize the next is possible, but not recommended:
Code: Pascal  [Select][+][-]
  1. //non-working demo code
  2.   for i:=2 to round(sqrt(n)) do  // inferred ordinality "var" is superfluous
  3.   begin
  4.     if not (i in primes) then
  5.       continue;
  6.     x := i*i; // inferred ordinality: "var" is superfluous
  7.     while x<=n do
  8.     begin
  9.       Exclude(primes,x);
  10.       x += i;
  11.     end;
  12.   end;

Note that a similar mechanism is already used in the for in do, where the indexing ordinal is even completely hidden and only values are used..

 
« Last Edit: June 21, 2018, 11:37:23 am by Thaddy »
Specialize a type, not a var.

giahung1997

  • Full Member
  • ***
  • Posts: 113
Re: Please make your language more freedom
« Reply #4 on: June 21, 2018, 01:08:49 pm »
There's PascalABC.NET too. I liked it more from Object Free Pascal, not because it can use the full power of .NET but because I found their Pascal Dialect to be more modern and freedom than yours (just my own opinion).

(I still fail to see what "modern" has to do with imitating 1970s C syntax. The two years that Pascal is older than C can't matter that much?)

Because all other languages support this (declare variables everywhere in function body) nowaday. Only Borland C++ 5.5 has the same behavior when the C language not yet standardized, and this product is old (around 2000), that is what I mean when I said "outdated" and "modern"  :-*

@Thaddy: Thanks. FreePascal is really strict  :)
« Last Edit: June 21, 2018, 01:11:40 pm by giahung1997 »

RayoGlauco

  • Full Member
  • ***
  • Posts: 176
  • Beers: 1567
Re: Please make your language more freedom
« Reply #5 on: June 21, 2018, 01:23:14 pm »
When I was 20, many years ago, I liked the C style code because you can do many things with very few code. But now, I appreciate more readability, clarity and avoiding mistakes. I prefer a little more code if it's easier to maintain. That's why I like freepascal.  :)
« Last Edit: June 21, 2018, 01:25:00 pm by RayoGlauco »
To err is human, but to really mess things up, you need a computer.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Please make your language more freedom
« Reply #6 on: June 21, 2018, 02:11:10 pm »
Because all other languages support this
@Thaddy: Thanks. FreePascal is really strict  :)
Well the former is not quite true: they are either C derived languages or are scripting languages. And as I demonstrated, in pascal like languages, the "feature" is not well thought out.
Also note that many (if not almost every) team leaders or CTO's simply forbid the more frivolous features of C style languages like inline declaration of variables in a company's codebase, because it has been proven to be counter-productive. Hence I always insist on code reviews to prevent the programmer "who knows better" from using this in our C or C++ or .Net code. The larger the codebase, the larger the team, the less likely inline vars are allowed. E.g. you hardly see it in Mozilla or Google code! Not even in serious open sourced Microsoft code. Study the Linux kernel code....

There is a reason for that....Better prevent it, or at best do it like I described.

The number of defects in C/C++ style written code - in teams - far exceeds the number in Pascal style written code. (I am really experienced with both, as a teacher, Borland certified trainer, team leader, CTO and director of development +38 years)
« Last Edit: June 21, 2018, 02:24:04 pm by Thaddy »
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Please make your language more freedom
« Reply #7 on: June 21, 2018, 03:02:30 pm »
Because all other languages support this (declare variables everywhere in function body) nowaday.

Most languages (java, C# etc) have a syntax that is C in principle. We don't.
 

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Please make your language more freedom
« Reply #8 on: June 21, 2018, 03:11:02 pm »
Most languages
I would rephrase that to "Some popular languages"... Most languages have to my knowledge a differing syntax from curly brackets.
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Please make your language more freedom
« Reply #9 on: June 21, 2018, 03:16:38 pm »
Most languages
I would rephrase that to "Some popular languages"...

Javascript, java, C#, C, C++, that is half the top 10 of the tiobe index.
 

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: Please make your language more freedom
« Reply #10 on: June 21, 2018, 03:21:21 pm »
Because all other languages support this (declare variables everywhere in function body) nowaday.

Well, not all... "whitespace" doesn't. ;)

But seriously, take javascript. The results of being able to declare your var wherever you want became so complex (
http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html ), that they needed a linter https://eslint.org/docs/rules/vars-on-top


rick2691

  • Sr. Member
  • ****
  • Posts: 444
Re: Please make your language more freedom
« Reply #11 on: June 21, 2018, 05:01:53 pm »
Quote
for var i:=2 to round(sqrt(n)) do

Looking at the code example, I wonder how the program or programmer knows what variable type it is. It seems like a problematic method.

Rick
Windows 11, LAZ 2.0.10, FPC 3.2.0, SVN 63526, i386-win32-win32/win64, using windows unit

Trenatos

  • Hero Member
  • *****
  • Posts: 535
    • MarcusFernstrom.com
Re: Please make your language more freedom
« Reply #12 on: June 21, 2018, 05:15:59 pm »
I work with dynamically and statically typed languages.

The longer I code the more I prefer static typing and clarity.

It's not worth the headaches for the small gains to declare things all over the place.

Forget a var or const keyword somewhere and the whole thing shifts scope with not warning. Yay.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Please make your language more freedom
« Reply #13 on: June 21, 2018, 05:44:08 pm »
Javascript, java, C#, C, C++, that is half the top 10 of the tiobe index.
And only because Kernighan and Richie were too lazy to type begin/end and preferred forth order for parameters... :D :D :D ..... (true!)
Curly brackets.... Oh, well... I - and you - am just as proficient in curly brackets as I am in Pascal. But that is not that we like it..? I like Python, though, and ADA and Fortran and Cobol and even (Power/Turbo) Basic...

Note, that since a very short time somebody edited away the influence of Pascal on the C language on Wikipedia. That's not acceptable. K&R  were always very aware of their influences and stated that in almost all real publications including some seriously humorous and deliberately provoking "hate-mails"....(before there was email, just BBS, and some crude precursor...)
« Last Edit: June 21, 2018, 09:17:42 pm by Thaddy »
Specialize a type, not a var.

BeniBela

  • Hero Member
  • *****
  • Posts: 905
    • homepage
Re: Please make your language more freedom
« Reply #14 on: June 21, 2018, 10:13:39 pm »
Thr inline var should not be there to be like C, but to improve readability and prevent bugs caused by uninitialized variable.

After a for loop the loop variable must not be used without being reinitialized. "for var" makes sure you do not accidentally use the variable. Using a loop variable after a loop must be a compile error. It makes no sense that fpc compiles code that accesses a variable it knows to be invalid

And other inplace "var .. := .."  make sure the variable is initialized at its declaration. No one  needs a variable that is  uninitialized.

 

TinyPortal © 2005-2018