Functional vs Array Programming

preview_player
Показать описание
My unofficial Strange Loop 2021 Conference Talk where I compare the functional and array programming paradigms.

Array Languages:

Functional Languages:

Chapters:
0:00 Introduction
0:11 About Me
1:24 5 Favorite Programming Languages
1:48 List of Functional / Array Languages
2:24 Problem Statement
3:15 Problem Examples
4:40 Imperative Solution Walkthrough
6:30 C++ Solution
7:12 Python Solution
7:58 Functional Solution Walkthrough
9:47 Scala Solution
11:20 Haskell Solution
13:23 Combinatory Logic Digression
17:28 S Combinator Explanation
18:34 Understanding the S Combinator in Haskell
20:10 APL Solution
20:48 APL vs Haskell Solution Comparison
22:35 S' Combinator Explanation
23:22 C Combinator Explanation
24:15 SKICW Combinators in Haskell & APL
25:20 Haskell vs APL Language Comparison
26:45 Haskell vs APL vs BQN Language Comparison
27:00 APL vs BQN Solution Comparison
27:50 Functional Programming / BQN Blog Post
28:05 Final Summary
29:47 Outro

Рекомендации по теме
Комментарии
Автор

Dude I'm high as f watching random cs videos and I see we returned to hieroglyphs

gardendado
Автор

APL is how coding looks like for non-coders

yeicore
Автор

Me: oh c++ thats pretty verbose but I can somewhat understand it
*changes to python*
Ah! I really get the idea now, yeah this is fairly intuitive
*switches to scalla and haskel*
uhhh huh...
*digression*
im trippin balls dude
*switches to APL*
WHAT THE F-

shekels
Автор

what programming looks like to non programmers

telnobynoyator_
Автор

Honestly, from the video you made me prefer Haskell over APL. It really doesn't matter if the code is shorter if you need someone specialized on the language to make sense of it, while on Haskell after you explained the S operator and that was all I needed to get a rough ideia of what the code was doing.

guilhermegigeck
Автор

Great talk. For reference, this is how you could solve the problem in the Wolfram Language:

(nums - FoldList[Min, nums]) // DeleteCases[0] // Prepend[-1] // Max

skratky
Автор

APL feels like Chinese in that there is a single symbol per concept. The learning curve is steep but it's beautifully rewarding when you get there.

halneufmille
Автор

When introducing the Python solution @ 17:12, replaces clear easy to read semantically meaningful variable names with short abbreviations while stating "...change the variable names to make them more concise which, in my opinion makes them a lot more readble" - realizing, oh yeah his fav language is APL! ;-) haha Also nice job on the combinators intro!

benjaminscherrey
Автор

I have an APL book called "APL An Interactive Approach" and you can tell it's old because it asks you to plug your computer into a phone line.

Such a weird and obscure language but it was pretty fun to mess around with.

lane
Автор

Great video! Really interesting. A couple of comments:

1. It seems really redundant to use -1 to signify no solution, since, if you read the problem carefully, nums[i] < nums[j]. This means that nums[j] - nums[i] > 0, if a candidate solution. So, if max of all candidates is 0, there is no solution. This would simplify the Scala especially.

2. I understand that Python was just used as an example language for imperative programming, but it could come off that you were comparing Python and Haskell/Scala's abilities, when Python is capable of solving this in a very functional manner as well. In fact, the implementation can be quite elegant:

max(map(sub, nums, accumulate(nums, min)))

Though Python does not explicitly have scanLeft or zipWith, Python's map auto zips multiple iterables, and the standard itertools library has accumulate, which is essentially the same as scanLeft. Conveniently, if you don't provide an initial value to accumulate, the first value is just the first item of the iterable (which seems similar to Haskells scanl1). Python's operator library provides the sub function. One other nice thing about this, is that it works entirely with iterators, so there are no intermediate results.

If you want to use -1's instead of 0's, I think the most elegant way would just be to use an 'or' operator, since 0 is falsey:

max(map(sub, nums, accumulate(nums, min))) or -1

atrus
Автор

Thank you so much.
This is by far the most accessible intro to combinators and combinatorial logic I've ever seen.
I do admit to never making a true effort to seek out understanding of combinators beyond a very quick skim of Wikipedia, but that doesn't change the fact that what little effort I have put in was never rewarded with conceptual clarity.
For example, all previous videos I've seen making the claim that they are an easy intro to the topic... well, they failed me.

I guess what I'm saying is thank you!
So concise and clear and completely useful!

anthonycousins
Автор

Im pretty sure APL is the code Neo sees as the matrix when he gets revived… the moral of the film is we should all take a page from neo’s book and learn APL 😤

kDrewAn
Автор

I think APL deserves a prize for being more esoteric than assembly.

philiphanhurst
Автор

Personally, I'd take the C++ (or a Rust) implementation. It's more obvious what's going on and all of the intermediate values are easily available for evaluation or logging or whatever during debugging. And it's likely better performing, particularly once you get beyond trivial examples. And of course, you can just put the whole thing in a helper if you need the algorithm more than once, and you never even see the guts unless you need to (at which point it's a lot easier to see the guts.)

I'd also argue that extremely minimal syntax isn't really an important goal of software. Creating products for people to use is the real purpose of software. One problem in software (as in many pursuits) is that too many people become more about the pursuit itself than about the purpose of the pursuit. Nothing wrong with that in and of itself, but it can become an issue. I think C++ is suffering from this currently. It's too driven by people who are into languages and not enough people who just want to create products for people to use.

deanroddey
Автор

This is probably one of the, if not the best, computer science video I have ever watched. This helped me expand my perspective on problem solving as a new programmer. Thank you!

ianbridges
Автор

More practically, APL started out at a time when programming was still regarded by some as an extension of pure mathematics, so a highly symbolic syntax was not totally out of left field. Memory at the time was also at a premium, likely costing over a dollar a bit, so being able to represent core functionality in a glyph represented by just a few bits had practical benefits.

stevemcgrath
Автор

Is it just me, or is the Scala form the most readable? The briefer the function gets, the harder it is for me to read. Even when I know haskell and not Scala.

bimsherwood
Автор

IMO dev teams are diverse and code ideally should be readable for everyone.
I personally liked Scala and Haskell solutions (although I need to learn combinators to fully understand it, so I'll watch your videos about it).

What's nice about this F# solution is that it's clear, concise, and can be run step by step interactively in REPL to see the transformations:

let maximumDifference nums =

nums
|> Seq.scan min System.Int32.MaxValue
|> Seq.tail
|> Seq.zip nums
|> Seq.map ((<||) (-))
|> Seq.filter ((<>) 0)
|> Seq.fold max -1

fsharpdev
Автор

This is going to be a good one, I can feel it

cristian-sigb
Автор

Combinatory logic gameplay:
Combinatory logic lore: "Somebody I Used To Know remix played over this accelerated video"
Thanks for this video, quite interesting introduction to combinatory logic and array programming.

gigabek