Functional style - examples

React.js is functional …

IObservable … ReactiveX : Bart de Smet

D language …

Maybe if you create part of Unix you can take a poke at Donald Knuth … :slight_smile:

John Carmack - American computer programmer and video game developer. He co-founded the video game company id Software and was the lead programmer of its 1990s games Commander Keen, Wolfenstein 3D, Doom, Quake, and their sequels.

John Carmack in 2012 …

If this is supposed to be a step forward in programming syntax, then I’ll respectfully disagree.

ps: Unrelated to my comment above, code blocks (also above) are appearing to me with mid-gray text (except for the first line) on a black background which is almost impossible to read :confused:.

There is an issue with syntax highlighting on the forums at the moment - the events plugin is breaking things - I have reported them to the author in 3 places but no joy so far (looking into whether we can remove the plugin).

Edit - should be better now, I found it’s not the events plugin - it’s the plugin we use to select the highlighting color scheme - removed it for now and reported the issue.

1 Like

Yay! Looks fine now. :+1:

My aim is to put ideas out there, and maybe get people to start thinking in this direction.
There are an enormous range of good resources online regarding more functional styled code.

And … I wouldn’t expect anyone to be convinced from an initial look at something.
The code you quoted wasn’t a recommendation, really.
The point of it was to transform a familiar loop into a format that could be recognised as a map over a container.
The ‘step forward’ idea is :

map( range, fn) . sum

The advantages being … short, easily reasoned about, less code to write therefore less bugs to write, and it can be broken up and run as parallel operations.

In the C++ world, there has been encouragement building for a decade or so for developers to more frequently utilise their standard algorithms library.

This is a great talk … (2013) C++ Seasoning. GoingNative 2013 C++ Seasoning - YouTube

Sean Parent is from Adobe and Google, and was a boss to Alexander Stepanov.
In part of the talk he shows some “normal” not-so-readable code from the Chromium code base, and progressively transforms it into two algorithm calls. I would suggest any developer to watch it, it is not c++ dependent at all.

Same guy, Sean Parent, on the same subject …

My aim is to put ideas out there, and maybe get people to start thinking in this direction.

@Paul_McGee. It’s just occurred to me from your comment that this wasn’t someone else’s idea but your own. If that was the case then please accept my apologies for the bluntness of my own comment. Had I realised that before I would have been far more diplomatic. And I agree that first looks can indeed be deceiving. Cheers.

@angusj No problem, it didn’t come across as blunt at all.
(Also, I have given my frank assessment of an article to someone I didn’t realise was the author.
… we all survived. :sweat_smile: )

1 Like

I seem to have not mentioned that Craig Stultz talked about Functional Programming in 2009, in Coderage 3 :
Functional Programming in Delphi 2009
Video:
https://cc.embarcadero.com/Item/26395

Code:

“Delphi 2009 includes several new features well suited to a functional style of programming.
We’ll explore the use of generics, anonymous methods, and new RTL types while introducing concepts from functional programming.”

2015 … Boian Mitov

2017 … Glen Kleidon presented to Melbourne ADUG … @Glen_Kleidon2
Adopting a Functional programming approach in Delphi “.

I hope we might see a recording of it sometime, if it exists ( @Geoff ?)

https://www.adug.org.au/meetings/melbourne-meeting-april-2017/

2021 … I spoke to our Perth members, and then Melbourne, in an attempt to describe some basic Category Theory and the relation to FP.

2022 … Kevin Bond @drbond presented at Delphi Boot Camp 2022

“Delphi and functional programming using anonymous methods”

Unfortunately @Paul_McGee, We don’t have recordings prior to the start of COVID for Melbourne meetings.

Related to this query : SQL formatter library wanted

People might like to take a squiz at how the datatypes in Haskell are used in this library
to capture the structure of SQL statements.
source : queryparser/Query.hs at master · uber/queryparser · GitHub

Product types are like our Record and Class.
eg A single type might contain integer AND string AND enum.

image

Sum types (co-product types) are the opposite of product types.
eg A single type which is integer OR string OR enum.

‘Select r a’ and ‘Expr r a’ are type constructors.

Just like a generic type in Delphi, eg TSelect< R,A > or TExpr< R,A >
they need to be provided with two types in order to form a concrete type, like eg TExpr< string, string >