* * *

Author Topic: FreePascal made it to project of the month on Sourceforge  (Read 27761 times)

jwdietrich

  • Hero Member
  • *****
  • Posts: 927
    • formatio reticularis
Re: FreePascal made it to project of the month on Sourceforge
« Reply #15 on: April 16, 2014, 08:44:58 am »
Hello Florian, actually I have seen you before (I have seen your icon)
I thought that FPC is made by team of high school students, until I read the interview yesterday.
I was following this project since 1999 or before

Do you ernestly think that people, who you thaught to be high school students in 1999 are still at high school?  ;)
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

Lazarus 1.6.4 | FPC 3.0.2 | PPC, Intel, ARM | macOS, Windows, Linux

motaz

  • Sr. Member
  • ****
  • Posts: 497
    • http://code.sd
Re: FreePascal made it to project of the month on Sourceforge
« Reply #16 on: April 16, 2014, 11:40:14 am »
Quote
Do you ernestly think that people, who you thaught to be high school students in 1999 are still at high school?  ;)

No, I meant there were a team, not only one person :)
« Last Edit: April 16, 2014, 03:15:02 pm by motaz »

taazz

  • Hero Member
  • *****
  • Posts: 3992
Re: FreePascal made it to project of the month on Sourceforge
« Reply #17 on: April 17, 2014, 07:00:10 am »
Quote
Do you ernestly think that people, who you thaught to be high school students in 1999 are still at high school?  ;)

No, I meant there were a team, not only one person :)

So if it is a person then he graduated from high school, if it is a team they are still in high school? :P

Grats to the team excelent work.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

edwinyzh

  • New member
  • *
  • Posts: 15
Re: FreePascal made it to project of the month on Sourceforge
« Reply #18 on: April 17, 2014, 10:54:58 am »
This is a great news, FPC definitely deserve it!

In the interview it mentioned "The next big thing for FPC will be the 3.0 release: Besides a lot of new language features...", doesn't anybody know if the upcoming FPC 3.0 will support anonymous method?

I've done some search, the newsletter archives of 2013 show that it's been discussed and someone's been working on it in a branch, but couldn't find any definite info.

Anonymous method 's "local variable capturing" allows us write more clean code logics, and you'll gonna love it if you use it in practice :)

hinst

  • Sr. Member
  • ****
  • Posts: 303
Re: FreePascal made it to project of the month on Sourceforge
« Reply #19 on: April 17, 2014, 11:07:19 am »
FPC forever

•_•)
( •_•)>⌐■-■
(⌐■_■)

We have so many people trolling each other on this forum every day; no wonder FPC got most votes
Too late to escape fate

Leledumbo

  • Hero Member
  • *****
  • Posts: 7610
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: FreePascal made it to project of the month on Sourceforge
« Reply #20 on: April 17, 2014, 12:00:27 pm »
I've done some search, the newsletter archives of 2013 show that it's been discussed and someone's been working on it in a branch, but couldn't find any definite info.

Anonymous method 's "local variable capturing" allows us write more clean code logics, and you'll gonna love it if you use it in practice :)
I forgot the branch name, but it does exist. Just browse svn archive.
IMHO, other than Delphi compatibility, I've found that anonymous function does have its drawback. I'm used to it when I code in Haskell, and the executable gets bloated in size. I believe this would be the same in Pascal, because I've found out that I was repeating a similar code pattern again and again. For simple use, however, such as inline callback (without access to outer variables), this feature could be useful to reduce typing for the lazy :P

edwinyzh

  • New member
  • *
  • Posts: 15
Re: FreePascal made it to project of the month on Sourceforge
« Reply #21 on: April 17, 2014, 12:23:15 pm »
I forgot the branch name, but it does exist. Just browse svn archive.
We'll, that'll be too much of a hassle for an average to figure out how to use that FPC branch with the official Lazarus, while being uncertained and worried about it not including the latest bugfixes in the latest trunk.

IMHO, other than Delphi compatibility, I've found that anonymous function does have its drawback...... the executable gets bloated in size......
I don't believe that by providing anonymous methods will result in executable size increment to a level that overweighs the benefit of anonymous methods.

...this feature could be useful to reduce typing for the lazy :P
It's about lazy, but it's much much more about code readabilities. :P

taazz

  • Hero Member
  • *****
  • Posts: 3992
Re: FreePascal made it to project of the month on Sourceforge
« Reply #22 on: April 17, 2014, 12:44:07 pm »
It's about lazy, but it's much much more about code readabilities. :P

I'm lazy enough to thing about using them, can you provide an example that makes the code more readable? As far I understand it it will make code harder to read not easier.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5536
Re: FreePascal made it to project of the month on Sourceforge
« Reply #23 on: April 17, 2014, 02:03:13 pm »
In the interview it mentioned "The next big thing for FPC will be the 3.0 release: Besides a lot of new language features...", doesn't anybody know if the upcoming FPC 3.0 will support anonymous method?

As said, sb worked on it for a while, and progress is unclear, and so is the exact 3.0 timeframe. So this is not known at this point.

edwinyzh

  • New member
  • *
  • Posts: 15
Re: FreePascal made it to project of the month on Sourceforge
« Reply #24 on: April 17, 2014, 03:23:34 pm »
I'm lazy enough to thing about using them, can you provide an example that makes the code more readable? As far I understand it it will make code harder to read not easier.

My program executes JavaScript using the Google V8 engine which executes js asynchronously in another process, so if you want to do something after the js code you submitted to the V8 engine is executed and returns a value, you have to provide a call back procedure to it.

Check the example code below, since Delphi has anonymous method, I am able to keep the logic together so it's very clear to see what will happen after the js code returns a value, otherwise I'll have to define the call back in another method. 
Code: [Select]
  js :=
    '(function(){' +
    '  /*...*/' +
    '  srcCode = doSomethingWith(srcCode, options);' +
    '  hostApp.SendStringValueToHostApp("%s", srcCode);' +
    '})();';

  FJsEngin.ExecJavaScriptInSeparatedProcess(js,
    (*The anonymous method to be executed once the JS code is executed asynchronously in another process and returns the value.
   *)
    procedure(aStrValue: string)
    begin
      doSomethingInTheMainProcess;
    end);

Apart from the code cleanliness, another benefit that anonymous methods makes it easy to use local variables, this part I don't go further here, but it's also a great benefit.

It also applies to multi-threading programming.

A good read on anonymous method by Joel Spolsky.
« Last Edit: April 17, 2014, 03:46:11 pm by edwinyzh »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5536
Re: FreePascal made it to project of the month on Sourceforge
« Reply #25 on: April 17, 2014, 04:45:55 pm »
so it's very clear to see what will happen after the js code returns a value, otherwise I'll have to define the call back in another method. 

The trouble is that that is a matter of personal preferences. I think it also complicates overviewing what a method does in one glance.
 

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4286
    • wiki
Re: FreePascal made it to project of the month on Sourceforge
« Reply #26 on: April 17, 2014, 04:59:20 pm »
Apart from the code cleanliness, another benefit that anonymous methods makes it easy to use local variables, this part I don't go further here, but it's also a great benefit.

Actually that is called a closure isn't it? And you do not need an anonymous method for a closure. You could use a nested named procedure instead, if closures were implemented (and if they were implemented using nested procs)

I noted that in every thread about anonymous methods. Half of the time (at least half of the time) what people were speaking about are closures.

It may well be that most (maybe all) other languages combine those 2 features. But that does not mean that one is the other.
- It is possible (ignoring if it is desirable or not) to have anonymous methods, that are not closures
- It is possible to have closures without anonymous methods.

So if asked about the benefit of anonymous methods, do not answer with the benefits of closures. That does not answer the question. If it is closures you want, then it can be done using a nested proc/func that is used to create the closure.

And using nested proc for closure, you would have 99.9% identical code, with the only difference:
- the source of the closure needs a name  (that should not be a problem)
- the source will be declared a bit further up (as nested proc, instead of closure)
All else is identical.


So where is your code more clean, than the same code but using a nested procedure (from which, if fpc supports it, you create your closure)?

Code: [Select]
procedure Foo;
var
  // locals, that can be used in closure

  procedure CallBackFordoSomethingInTheMainProcess; IsClosure; // some modifier fpc needs to add
  begin
      doSomethingInTheMainProcess;
  end;

begin
  //...
  js :=
    '(function(){' +
    '  /*...*/' +
    '  srcCode = doSomethingWith(srcCode, options);' +
    '  hostApp.SendStringValueToHostApp("%s", srcCode);' +
    '})();';

  FJsEngin.ExecJavaScriptInSeparatedProcess(js,
    (*The anonymous method to be executed once the JS code is executed asynchronously in another process and returns the value.
   *)
   @CallBackFordoSomethingInTheMainProcess
   );

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5536
Re: FreePascal made it to project of the month on Sourceforge
« Reply #27 on: April 17, 2014, 06:55:58 pm »

And using nested proc for closure, you would have 99.9% identical code, with the only difference:
- the source of the closure needs a name  (that should not be a problem)
- the source will be declared a bit further up (as nested proc, instead of closure)
All else is identical.

Closure vs anonymous method yes.  Nested proc vs closure/anonymous no. The nested proc passed as closure only has validity as long as the frame of its parent on the stack is intact.  Anonymous methods are afaik implemented as an under the hood interface that allocates dedicated space on the heap for what it captures in, and is freed when no longer need.
 

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4286
    • wiki
Re: FreePascal made it to project of the month on Sourceforge
« Reply #28 on: April 17, 2014, 07:31:37 pm »
Closure vs anonymous method yes.  Nested proc vs closure/anonymous no. The nested proc passed as closure only has validity as long as the frame of its parent on the stack is intact.  Anonymous methods are afaik implemented as an under the hood interface that allocates dedicated space on the heap for what it captures in, and is freed when no longer need.

But that is a question of what what the compiler implements.
Except for a "nested" procedure, that should be used as closure, may be named different. So the name "nested" may then be wrong. (and it would technically not be "nested" as it would not have all the properties that a current nested has /but it would be declared in a very similar way)

Assuming for the sake of this argument only, that it was/would be accepted, and a volunteer for implementation existed:
A procedure declared in the same manner like a nested proc (marked with an appropriate modifier / or otherwise marked/declared as "to be used as closure") could do the same as an anonymous procedure.

« Last Edit: April 17, 2014, 07:33:35 pm by Martin_fr »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 4286
    • wiki
Re: FreePascal made it to project of the month on Sourceforge
« Reply #29 on: April 17, 2014, 07:48:11 pm »
Just a note: I am not trying to advertise a specific way of implementing this. (Though I would have personal preferences of course).

I merely wanted to point out, that a lot of the past arguments are massively flawed, because they reason for one feature by showing what can be done with an other feature.

For that point, I stated that one was not bound to the other, and that alternatives exist (or could be made existent) where one comes without the other.
« Last Edit: April 17, 2014, 07:50:42 pm by Martin_fr »

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus