Recent

Poll

What missing 'modern' language feature would you like to see implemented first in Pas2JS ?

Interfaces
26 (32.1%)
Anonymous functions
11 (13.6%)
Attributes
2 (2.5%)
Generics
15 (18.5%)
Type helpers
11 (13.6%)
I do not care, start on any feature...
6 (7.4%)
First make the compiler more strict in what it allows now (stuff like range checking etc.)
10 (12.3%)

Total Members Voted: 40

Voting closed: February 28, 2018, 09:22:09 am

Author Topic: Pas2JS missing language features ?  (Read 33535 times)

MvC

  • New Member
  • *
  • Posts: 25
    • Free Pascal Core team member
Pas2JS missing language features ?
« on: January 16, 2018, 05:15:09 pm »
Hello,

Pas2js is still missing some of the more "modern" language features.
Currently we're at Delphi 7 compatibility (more or less), minus interfaces.

We'd like to know what language features we should work on first, according to the users.
You can vote 3 times, so we can have an idea of 'ranking' of the features.

Please vote, tell us what you think!

Michael.




Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Pas2JS missing language features ?
« Reply #1 on: January 16, 2018, 05:24:31 pm »
There's no place for democracy in software develpment  ;D
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Sergionn

  • New member
  • *
  • Posts: 8
Re: Pas2JS missing language features ?
« Reply #2 on: January 16, 2018, 05:43:36 pm »
Please vote, tell us what you think!

For me anonymus functions would be preffer - then i will be ready to translate to pas2js my ui/autolayout/bindings&ect  framework!
Wait for implementation very mach!
And thanks to you for very important work, which SmartMobile team didn't do:( - they took the wrong way...
« Last Edit: January 16, 2018, 05:45:20 pm by Sergionn »

mdbs99

  • Full Member
  • ***
  • Posts: 121
  • Software Engineer. Husband. Trader.
    • website
Re: Pas2JS missing language features ?
« Reply #3 on: January 16, 2018, 05:45:22 pm »
Well, to be more Delphi 7 compatible we need Interfaces for sure.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Pas2JS missing language features ?
« Reply #4 on: January 16, 2018, 06:44:31 pm »
Interfaces, type helpers, whatever, anything....
What lacks are two features, one of which I deem important:that is anonymous methods.
But that would be for FPC itself to have first.
After I saw an actual demonstration of what can be achieved with pas2js I have been playing with it all day.

Note that it may be of interest to explain why certain language features are not possible in pas2js.
Specialize a type, not a var.

zburns

  • Newbie
  • Posts: 1
Re: Pas2JS missing language features ?
« Reply #5 on: January 16, 2018, 07:18:34 pm »
Thaddy - do you have a demonstration - I'm also trying to figure out where/what I can use pas2js for and always looking for ideas.

Zack

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: Pas2JS missing language features ?
« Reply #6 on: January 17, 2018, 08:45:49 am »
I'm also interested in the use-case of PAS2JS. Why use Pascal instead of JavaScript (with its ecosystem)?

In the wiki I've read that it has support to generate nodejs modules. But does it allow to interact with existing modules? (the Haxe language for example does this with 'externs' - you describe the API to an external JavaScript library / module, so the compiler does know about the external structure)

For me the biggest point would be the possibility to write the classes of my application logic only once: native Free Pascal classes which can be used for the server part of a web-application and to-JavaScript-compiled classes that I can use client-side in my own JavaScript code.

Sorry if my questions are too naive, but I had no time to seriously try PAS2JS ;-) ...btw, I would prefer a better name for the project! :-)
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Pas2JS missing language features ?
« Reply #7 on: January 17, 2018, 09:23:59 am »
I'm also interested in the use-case of PAS2JS. Why use Pascal instead of JavaScript (with its ecosystem)?
Mainly because Pascal is strongly typed as opposed to JavaScript: that means that the transpiler can generate more accurate code, less prone to errors, even if it outputs eventually JavaScript.
So you have the advantages of a strongly typed language while generating code for a weakly typed language. That includes e.g. debugging, type safety, etc. Pascal is often less verbose too.
Note that pas2js also supports inserting Javascript directly if you need it, through asm blocks, where the asm code is actual javascript.

Simply install the packages in Lazarus and you are good to go.

In reference to other questions: I will add some node.js examples to the wiki and a simple database application with client-side forms. Maybe Michael and Mattias can add even more: they are the experts.
I need to clean up the code so I can't do it today.
Specialize a type, not a var.

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: Pas2JS missing language features ?
« Reply #8 on: January 17, 2018, 09:31:18 am »
Thanks Thaddy, more examples would be really great!

A little offtopic, but:
I was playing with Haxe lately - and although it also has strict type checks during compilation, the generated JavaScript code was not safe! I was a little bit disappointed by that fact, you could, for example, declare an object property as string, but the generated JS code did not declared that property with the help of Object.defineProperty and a related setter, which checks the type at runtime. Thus you can assign every type to that property of an instance of that type! So you can write type-safe-code, as long as you write the whole application in Haxe (because all the code gets compiled with type checking), but as soon as you write modules, which you want to use in other JavaScript code, the compiled code is even worse than hand-written code. Adding JavaScript type checking via setters for properties would be a real benefit of using PAS2JS!
« Last Edit: January 17, 2018, 10:03:11 am by dubst3pp4 »
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
Re: Pas2JS missing language features ?
« Reply #9 on: January 17, 2018, 09:32:50 am »
What lacks are two features, one of which I deem important:that is anonymous methods.
But that would be for FPC itself to have first.

There isn't any reason why Pas2JS couldn't have anonymous functions before FPC.

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: Pas2JS missing language features ?
« Reply #10 on: January 17, 2018, 09:59:08 am »
There isn't any reason why Pas2JS couldn't have anonymous functions before FPC.
Well, no maybe, but it would confuse me (just like writing Delphi code using it confuses me when I switch back to FPC.... :o %))

Maybe, because pas2js goal is afaik to be a large subset (meaning all applicable features) of FPC, not a superset  :D
Anyway..
« Last Edit: January 17, 2018, 10:03:21 am by Thaddy »
Specialize a type, not a var.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Pas2JS missing language features ?
« Reply #11 on: January 17, 2018, 01:52:38 pm »
What would an anonymous function (method?) allow that cannot be done with a procedural type?

mattias

  • Administrator
  • Full Member
  • *
  • Posts: 184
    • http://www.lazarus.freepascal.org
Re: Pas2JS missing language features ?
« Reply #12 on: January 17, 2018, 02:23:36 pm »
Note that pas2js supports closures, so for example instead of using an anymous function you can use a sub function:

Delphi:
Code: Pascal  [Select][+][-]
  1. function MakeAdder(y: Integer): TFuncOfInt;
  2. begin
  3.   Result := function(x: Integer)
  4.     begin
  5.       Result := x + y;
  6.     end;
  7. end;
  8.  

Pas2js:
Code: Pascal  [Select][+][-]
  1. function MakeAdder(y: Integer): TFuncOfInt;
  2.   function Adder(x: Integer): integer;
  3.   begin
  4.     Result := x + y;
  5.   end;
  6. begin
  7.   Result:=@Adder;
  8. end;
  9.  

mattias

  • Administrator
  • Full Member
  • *
  • Posts: 184
    • http://www.lazarus.freepascal.org
Re: Pas2JS missing language features ?
« Reply #13 on: January 17, 2018, 02:38:57 pm »
In the wiki I've read that it has support to generate nodejs modules. But does it allow to interact with existing modules? (the Haxe language for example does this with 'externs' - you describe the API to an external JavaScript library / module, so the compiler does know about the external structure)

Same in pas2js. It supports external classes, functions and variables. See unit js for examples.
You can even descend a new Pascal class from an external JS class.

And you can use asm-blocks to insert JS directly. But the external classes are so powerful, that even the RTL hardly use asm blocks.

dubst3pp4

  • Jr. Member
  • **
  • Posts: 86
  • Retro computing ~ GNU/Linux
    • me on Mastodon
Re: Pas2JS missing language features ?
« Reply #14 on: January 17, 2018, 02:52:40 pm »
@mattias
Can I use this also in native Free Pascal code? I've tried your interesting closure example, but in my version the value of y is initialized to the same value as x at every call:
Code: Pascal  [Select][+][-]
  1. program example;
  2. {$mode objfpc}{$H+}
  3. {$modeswitch nestedprocvars}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. type
  9.   TFuncOfInt = function(x: integer): integer is nested;
  10.  
  11. function MakeAdder(y: integer): TFuncOfInt;
  12.   function Adder(x: integer): integer;
  13.   begin
  14.     WriteLn('adding ' + IntToStr(y) + ' to ' + IntToStr(x));
  15.     Result := x + y;
  16.   end;
  17. begin
  18.   Result := @Adder;
  19. end;
  20.  
  21. var
  22.   SomeResult: integer;
  23.  
  24. begin
  25.   SomeResult := MakeAdder(2)(5);
  26.   WriteLn(IntToStr(SomeResult));
  27. end.
  28.  

Result:

adding 5 to 5
10


Sorry if this is way too offtopic, but how do you archieve y to stay in the scope (like I would expect from JavaScript)? Or does it only returns the expected result when compiling with PAS2JS?
« Last Edit: January 17, 2018, 03:19:00 pm by dubst3pp4 »
Jabber: xmpp:marc.hanisch@member.fsf.org -- Support the Free Software Foundation: https://my.fsf.org/donate

 

TinyPortal © 2005-2018