Functional vs Array Programming

Sdílet
Vložit
  • čas přidán 3. 06. 2024
  • My unofficial Strange Loop 2021 Conference Talk where I compare the functional and array programming paradigms.
    Array Languages:
    APL: www.dyalog.com/
    J: www.jsoftware.com/
    BQN: mlochbaum.github.io/BQN/
    Functional Languages:
    Haskell: www.haskell.org/
    Scala: www.scala-lang.org/
    ADSP The Podcast: adspthepodcast.com/
    ArrayCast: www.arraycast.com/
    Programming Languages Virtual Meetup: www.meetup.com/Programming-La...
    Functional / BQN Blog Post: mlochbaum.github.io/BQN/doc/f...
    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
    Follow me on Github: github.com/codereport
    Follow me on Twitter: / code_report
    Follow me on LinkedIn: / codereport
  • Věda a technologie

Komentáře • 402

  • @gardendado1999
    @gardendado1999 Před rokem +629

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

    • @vaap
      @vaap Před rokem +25

      I love this so much

    • @willmcpherson2
      @willmcpherson2 Před rokem +17

      bro 💀

    • @swyveu
      @swyveu Před 7 měsíci +3

      420 likes .... coincidence?

    • @arshamshayan
      @arshamshayan Před 6 měsíci +3

      my exact reaction when I saw APL for the first time 😭

  • @yeicore
    @yeicore Před 2 lety +575

    APL is how coding looks like for non-coders

    • @everyhandletaken
      @everyhandletaken Před 2 lety +35

      Looks like emojilang & mindf$ck had a baby & they named it APL. 🤯

    • @NStripleseven
      @NStripleseven Před rokem +81

      Most coding languages look like gibberish to non-coders, APL looks like gibberish to everybody. Equality.

    • @everyhandletaken
      @everyhandletaken Před rokem +11

      @@NStripleseven lol
      I like that analogy!

    • @torarinvik4920
      @torarinvik4920 Před rokem +1

      This comment is epic, it's so accurate!

    • @viridianite
      @viridianite Před rokem +3

      So are you saying APL programmers are above coders? lol

  • @telnobynoyator_6183
    @telnobynoyator_6183 Před 2 lety +347

    what programming looks like to non programmers

    • @yardez5990
      @yardez5990 Před 2 lety +78

      APL looks like minecraft enchanting table language

    • @saidkorseir192
      @saidkorseir192 Před 2 lety +19

      I am .net developer for 6+ years. I didn't understand anything not a jot.

    • @TRVQ2
      @TRVQ2 Před rokem +6

      @@saidkorseir192 Then just start from Python first ;)

    • @espana86
      @espana86 Před rokem +1

      Doesn't APL look very similar to just Greek?

  • @15shekels
    @15shekels Před 2 lety +400

    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-

    • @monad_tcp
      @monad_tcp Před 2 lety +5

      "WHAT THE F-" F\omega is a programming language too.

    • @monad_tcp
      @monad_tcp Před 2 lety +8

      After APL and Haskell blew your mind. You are read for ......
      .....
      Forth

    • @15shekels
      @15shekels Před 4 měsíci

      @@user-tx4wj7qk4t dawg I wrote this 2 years ago. Recently dabbled with C / Raylib and can confirm what you say is true

  • @halneufmille
    @halneufmille Před 2 lety +86

    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.

  • @lane1313
    @lane1313 Před 2 lety +71

    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.

  • @guilhermegigeck5946
    @guilhermegigeck5946 Před 2 lety +285

    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.

    • @hongnken
      @hongnken Před 2 lety +33

      I totally agree. Haskell nails both readability and simplicity

    • @batlin
      @batlin Před rokem +16

      Many would take that further and justify Scala over Haskell, then Java over Scala, then C over Java, then assembly over C. The question is whether the value you get is worth it in exchange for initial understanding barrier. Personally I'm intrigued enough to try APL and BQN out.

    • @casperes0912
      @casperes0912 Před rokem +33

      @@batlin How on Earth did you get to assembly being more readable than C or Java?

    • @batlin
      @batlin Před rokem +5

      @@casperes0912 I didn't. Please read the thread again.

    • @smurfo4221
      @smurfo4221 Před rokem +13

      APL isn't meant to be read, its a write it once and then recreate it if you need to change it later kind of thing. This is at least what everyone i've been learning from has said. This might seem stupid, but the language is meant to be easily written out so you can focus on the thing that needs to be done instead of how to do it.

  • @skratky
    @skratky Před 2 lety +76

    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

    • @telnobynoyator_6183
      @telnobynoyator_6183 Před 2 lety +20

      Readable AND short ? Looks like a great language to me !

    • @raianmr2843
      @raianmr2843 Před rokem +19

      my normie ass automatically assumed everything after // to be comments, spent a solid 10 secs thinking about where the rest of the logic was

  • @kDrewAn
    @kDrewAn Před 2 lety +58

    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 😤

  • @benjaminscherrey1124
    @benjaminscherrey1124 Před 2 lety +106

    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!

    • @johannestafelmaier616
      @johannestafelmaier616 Před 2 lety +6

      It's 7:12

    • @voxelfusion9894
      @voxelfusion9894 Před 2 lety +48

      Yeah I was like, this has to be sarcasm, making fun of unreadable code and mystery names. Later I realized he's simply nuts.

    • @saltrocklamp199
      @saltrocklamp199 Před 2 lety +10

      Yeah, this is a style that I strongly disagree with. Also, the Python algorithm is a linear scan, while the functional version seems like it might end up making 2 passes over the data, unless I misunderstand how Haskell and friends can optimize code. I would have assumed the Haskell version was just the imperative version translated to recursion.

    • @austininflorida
      @austininflorida Před 2 lety +20

      My least favorite part of programming is figuring out what everyone's abbreviations mean. They are never as obvious to the reader as they are to the writer.

    • @imadetheuniverse4fun
      @imadetheuniverse4fun Před 2 lety +10

      @@austininflorida Also when they abbreviate words by a single letter to make it just that bit shorter. It's like... why? "low" becomes "lo"... just write "low"!

  • @stevemcgrath4040
    @stevemcgrath4040 Před 2 lety +34

    APL (A Programming Language) has been the source of jokes in the programming community for nearly 50 years! I couldn’t readily find good references beyond en.wikipedia.org/wiki/Write-only_language?wprov=sfti1 , but there used to be fun competitions on who could write the shortest and most indecipherable code in APL.
    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.

    • @FaranAiki
      @FaranAiki Před 2 lety +4

      I thought it was, "Array Programming language".

    • @foxoninetails_
      @foxoninetails_ Před rokem +10

      Iverson's decision to keep APL functionality to single glyphs was far less a product of chance or circumstance than of intention. While it may have helped save on memory incidentally, programming was by no means considered "an extension of pure mathematics" in the 60s; these were the days of FORTRAN and COBOL, when programming was still in its infancy but was largely verbose and strictly procedural, and was beginning to be more and more seriously used for day to day business rather than simply mathematics. Even at the time, APL's syntax was very much out of left field to most programmers.
      It was no mistake or happenstance that he chose notation so dense. Rather, he considered the dense notation of APL to be a feature and selling point in itself, as once you get past the learning curve of understanding the notation, its density shifts into clarity and ease of expression, similar to how exceptionally complex concepts can be expressed in very small amounts of mathematical notation. I highly recommend reading through his paper "Notation as a Tool of Thought" for more insight on why he chose to lean in the direction of the more "mathematical" appearance of APL.

    • @swikle
      @swikle Před 7 měsíci +1

      @@foxoninetails_ That sounds like a reasonable explanation. I would guess that, based on the fact that he wrote that paper, it is the correct one. I may try to track the paper down now. One of the first books I owned was APL/360: An Interactive Approach. In 1972, in high school, the only terminal I had access to was based on the IBM Selectric Typewriter. That was a very successful typewriter for IBM and it had swappable character balls. At the time, I did know Iverson worked for IBM and I had assumed the "weird character" approach was because at IBM Research, they might have been encouraged to help sell Selectric based technology. I don't think the language became as mainstream as IBM might have hoped. However, there are a lot of people my age, those who leaned towards math anyway, who learned that language right after FORTRAN and were quite taken by it. I think APL taught me more about how to think as a programmer than any thing I learned in my high school and college careers. I have run into many people since in the tech world who also fell in love with APL. And I would say, to some extent, it taught me how to think about matrix math in general.

  • @atrus3823
    @atrus3823 Před 2 lety +113

    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

    • @MrMeszaros
      @MrMeszaros Před 2 lety +4

      Thanks - just wanted to say that functional solutions can be written in Python!

    • @geeshta
      @geeshta Před 2 lety +7

      @@a2sbestos768 Also I don't think variable names as "lo" and "e" should be used in Python, as explicit is better. Also I'm a huge fan of type annotations so I'd prefer
      def maximum_range(nums: List[int]) -> int:

    • @rikschaaf
      @rikschaaf Před 2 lety +2

      @@geeshta It is the trade-off between code readability and code "elegance". Some people like it when there is as little as possible boilerplate and redundant code. Long variable names are therefore a no-no if a shorter one conveys its purpose well enough. Lo for "the lowest number so far" is good enough in this case. I do think that this does increase the size of your function documentation though, because you need to define more specifically what a variable means.
      Same goes for the "elegant" uses of the combinators to combine multiple statements into one line to not repeat the use of a variable for instance. Sure it saves characters, but you now need to spend more characters in the documentation to help future code refactorers decipher what the piece of code does.

    • @gloverelaxis
      @gloverelaxis Před rokem +3

      this is *infinitely* better code than every example in the video. self-describing and simple

    • @jumbo_mumbo1441
      @jumbo_mumbo1441 Před rokem

      You swapped i and j in your first point, just fyi

  • @anthonycousins853
    @anthonycousins853 Před 2 lety +44

    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!

    • @TimothyJesionowski
      @TimothyJesionowski Před 2 lety +3

      I never even knew these existed. I barely understand basic FP tools like map/zip...

  • @ianbridges6040
    @ianbridges6040 Před 2 lety +54

    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!

  • @fsharpdev
    @fsharpdev Před rokem +9

    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

  • @laughingvampire7555
    @laughingvampire7555 Před rokem +3

    APL is also functional programming, the main difference is that arrays are the main data structure while in Lisp the Single Linked List is the main data structure.

  • @gigabek
    @gigabek Před 2 lety +13

    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.

  • @zachb1706
    @zachb1706 Před 2 lety +10

    I was shocked when I first saw the APL version of the gave of life, a game that took me ~100 lines to code in python written in a single line

  • @c4tubo
    @c4tubo Před 2 lety +11

    APL was the very first programming language that I learned at the age of 8, taught to me by deaf friends. The next was BASIC. Imagine that!

  • @voxelfusion9894
    @voxelfusion9894 Před 2 lety +47

    One one hand I'm awed at the deep mathematics on display, on the other hand I want to never use it myself.
    All of these highly formal functional languages are so ridiculously complex and unmaintainable, I can't imagine anyone using them in a serious setting.

    • @15shekels
      @15shekels Před 2 lety +4

      I figured the same. Coming from a python background I cant live without intuitive programming design that kinda makes comments not necessary
      In the grand scheme of things, all thats important to me is:
      *can i read it off the bat and come back to it later and remember what this function does and what created that call back?"
      *is it efficient?
      Ironically having said this youd probably laugh at me since i mentioned efficient and python in the same comment but i digress, something like python with a little more control over variable instantiation would be nice.

    • @leftaroundabout
      @leftaroundabout Před 2 lety +6

      You may well find Haskell complex, but it's certainly not _unmaintainable_ - in fact, IMO the biggest advantage of Haskell is that its strong type system makes it almost impossible to break code that's worked before, without the compiler detecting the problem. Thus one can confidently change APIs without the risk that some dependency then ends up with bugs in production.
      And ultra-compact, point-free code is actually rather frowned upon in the Haskell community. This video strongly overstates the similarities in practice to APL.

  • @BeansEnjoyer911
    @BeansEnjoyer911 Před 2 lety +8

    In my opinion, in imperative languages, branching into loops and conditional blocks really benefit from braces.
    I agree they add noise, but I feel like it helps sort out what the blocks of code are doing.
    Which is a main reason I find python infuriating, it's still imperative, but relies on a lot of tabbing to generate structure, which can get annoying to read in large parsing sections of code.
    For context Haskell is my favorite language, with C# being my professional language

  • @srijanpaul
    @srijanpaul Před 2 lety +6

    Great talk as always.
    The slides were much smoother this time around, loved it.

  • @joaquinbarrientoscr
    @joaquinbarrientoscr Před 2 lety +4

    Wow, just amazing!
    You are just the programming channel I was looking for. Thanks for your content, keep it up!
    Cheers!

  • @deanroddey2881
    @deanroddey2881 Před 2 lety +176

    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.

    • @lorenzrosenthal119
      @lorenzrosenthal119 Před 2 lety +33

      it's all fun and games until you need to reason about side effects and concurrency...

    • @deanroddey2881
      @deanroddey2881 Před 2 lety +20

      @@lorenzrosenthal119 Whether a piece of code has side effects isn't a function of the language it's written in. You can of course write plenty of C++ code that is without side effects, in those areas where it's a benefit, but not have to jump through hoops to deal with mutable shared state, which is something that you often really need. Sometimes everyone needs to agree on the state of the state right now.

    • @mbartelsm
      @mbartelsm Před 2 lety +4

      I agree, when programming we are programming for other people, and that usually means that elegant code is probably not what you want to write. Take the haskell S-combinator, it'd probably be just as readable, if not more, to just define an argument and pass that to the function.

    • @alexanderrowe1042
      @alexanderrowe1042 Před 2 lety +5

      @@deanroddey2881 it sort of is based on language though. Sure I can write c++ with no side effects but there's not many language level constructs to guarantee it. As a mutable / effectful language by default, the burden is put onto the developers to opt into it, which means i don't really trust any c++ code to do what it says haha. When working in a large code base I have to hope they aren't doing anything funky and have to read the implementation of code more than I would like to. When a language supports it from a more basic level I can KNOW when something is a pure function which saves me a lot of effort / time debugging and digging.

    • @deanroddey2881
      @deanroddey2881 Před 2 lety +4

      @@alexanderrowe1042 I would never argue that C++ is SAFE of course. I've spent my life writing a huge amount of C++, so I know that isn't the case. It CAN be safe but it is of course on the writer to do so, and most writers are going to take the easier route in a lot of cases.
      My own C++ code base, which is 1M+ lines, is as good as it gets, because it was written in as close to optimal conditions as possible. Hardly any serious code base even comes close to enjoying those kinds of circumstances, and that's were C++ gets particularly dangerous. In my case, it's all one writer, and everything is uber-consistent, and nothing was ever hacked into place.
      In that kind of situation, C++ is awfully nice. And it helps that I don't use the STL, or any other third party code, I have built my own entire world, so it's more like working in C# or Java in a lot of ways, in the sense of being built as a completely unified system from the ground up with a comprehensive runtime library that is all designed to work together.

  • @ssfrr
    @ssfrr Před 2 lety +3

    it's worth noting that the problem being solved has a real-world interpretation: If the numbers are a time series of prices (like daily prices for a stock), this gives the maximum profit you could make if you bought and sold at the optimal times (assuming you can't short-sell). So if you are evaluating some trading algorithm this gives the upper bound on performance.
    This is also solved in one of the "Q for mortals" videos.

  • @rikschaaf
    @rikschaaf Před 2 lety +17

    Imperative programming is like a recipe. You follow the steps and out comes the result at the end.
    Functional programming is like an assembly line for your data, where each step computes, recombinates or combines the data, to get to the endproduct.
    I feel that the recipes of imperative programming are easiest to read and follow, because you can easily digest it step by step and see the intermediate results.
    If you do simple things like map, filter and reduce and an occasional zip, functional programming can still be very readable for most programmers, but it becomes way more complex once you start using the combinators. And I don't mean that those can't be understood. I mean if you can see at a glance what it does without too much effort, which helps maintainability.

    • @utof
      @utof Před rokem +4

      Well as everything i think one becomes good at doing a thing with practice. After some time u probably will be able to quickly think, read and type with combinators, but the problems arise as soon as you need to show it to someone. Pretty high chance it will take quiiite some time to understand. If it was a thing taught in schools/uni, then probably there would be no problems

    • @curlyfryactual
      @curlyfryactual Před rokem +2

      ​@@utof the beauty of industry: you will need to show it to someone as you cannot maintain code forever, and your boss will not pay for that person to sit around learning a new way to think.

  • @bimsherwood7006
    @bimsherwood7006 Před 2 lety +149

    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.

    • @bimsherwood7006
      @bimsherwood7006 Před 2 lety +3

      Yeah, after thinking about it, I'd use the haskell Let expression to name the lists, just like how you explained the algorithm at the start.

    • @alexanderhurst1998
      @alexanderhurst1998 Před 2 lety +45

      I don't know why we are caring so much about how concise the function can get by adding more symbols.
      Like he mentions how you might not want to spell flip and use parentheses yet the APL solution has symbols that I have no idea how to type. Typing flip() is easier and it's plain English so it's easier for me to read.

    • @RaukGorth
      @RaukGorth Před 2 lety +6

      Yes very. Like when I read "tail" the first thought is "oh, this is going to remove the first element!"

    • @hoggmann7217
      @hoggmann7217 Před 2 lety +13

      Haskell was the most readable for me. Scala looked bloated. People that know math tend to go towards concise solutions and languages because symbols make it shorter to write and read. Once you know what the symbol means it's tedious to grok more and more expanded versions of it. That said I'd rather read the Scala than the Python.

    • @monad_tcp
      @monad_tcp Před 2 lety +1

      Its not, F# and Ocaml are better. Actually APL is more readable after you learn the symbols.

  • @pspicer777
    @pspicer777 Před 2 lety +3

    My moment has finally come! _I used APL before you were a glint in your father's eye_ . 👍. Great video. Enjoy the journey it's everything.

  • @deudaux
    @deudaux Před 6 měsíci

    Just the first video I watched on this channel, and looking at other videos... this is probably the best channel I found over the last ~10 years

  • @KR-uc9ei
    @KR-uc9ei Před 2 lety +5

    clojure solution:
    (defn maximum-difference [nums]
    (->> nums
    (reductions min)
    (map - nums)
    (filter pos-int?)
    (cons -1)
    (apply max)))
    i like it better than the skala solution and clojures map fn forgoes the need to zip, which is always nice. But point free solutions like these tend to fall apart when you don't have a consistent placement for argument (notice my use of cons instead of conj). But that can happen in haskell and apl too, if it werent for combinators to save the day. clojure just solves this with more macros which has it's own tradeoffs.

  • @philiphanhurst2655
    @philiphanhurst2655 Před 2 lety +120

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

    • @henriquefinger935
      @henriquefinger935 Před 2 lety +23

      Assembly isn't esoteric at all.

    • @charlesthompson9395
      @charlesthompson9395 Před 2 lety +8

      Assembly is at least remotely useful when it comes to retro games

    • @FaranAiki
      @FaranAiki Před 2 lety +13

      @Charles Thompson, and APL is OP at array manipulating. APL is not esoteric at all, it serves a cool purpose, not like "Brainfsck".

    • @chouaibsam4381
      @chouaibsam4381 Před 2 lety +1

      I had a headache

    • @batner
      @batner Před 2 lety +3

      Why you consider asm esoteric?

  • @ravimaithreyregulagedda2158

    Man I really really loved this video. You convinced me to look into combinatory logic. I'm gonna check out To Mock a Mockingbird.
    Thanks for the great video!

  • @jms019
    @jms019 Před 2 lety

    Thank you. I finally get what combinators are _for_ not having seen it explained in a way I have understood as an engineer until now.

  • @cristian-si1gb
    @cristian-si1gb Před 2 lety +34

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

    • @echoptic775
      @echoptic775 Před 2 lety +1

      Was it?

    • @LyricWulf
      @LyricWulf Před 2 lety

      @@echoptic775 I think they are still recovering from the digression

  • @codebitcookie8053
    @codebitcookie8053 Před 2 lety +4

    Oooooh a very interesting comparison! Love your channel

  • @allenmaudiln
    @allenmaudiln Před 2 lety +1

    I love your podcast! I didn’t realise this was your channel.

  • @lesfreresdelaquote1176
    @lesfreresdelaquote1176 Před 2 lety +1

    Thank you, this is the first time I have a good idea of what the S Combinator is all about...
    Sharing the same argument again, without being forced to mention it twice... Neat...

  • @andreiiaz2097
    @andreiiaz2097 Před 2 lety +13

    I can't wait to see this showdown. 😁
    Thanks in advance for making this!

  • @harshrathod50
    @harshrathod50 Před 2 lety +5

    This is the first time I came to know of combinators. Interesting.

  • @monad_tcp
    @monad_tcp Před 2 lety +1

    I love APL . It helped me so much with Linear Algebra and Calculus.

  • @casperes0912
    @casperes0912 Před rokem +9

    What people like this guy often forget, is that code is read a lot more than it's written

    • @user-sv7fo4ps3k
      @user-sv7fo4ps3k Před 10 měsíci +8

      I assume to people who live in APL, it's very readable. Those ten people can probably read this immediately.

    • @lpi3
      @lpi3 Před 5 měsíci

      From my experience it's not true.

    • @0LoneTech
      @0LoneTech Před 5 měsíci

      It's often very fast to get the gist of an expression, but a little slower for me to confirm the exact workings of the chain. In comparison, C syntax is very noisy with redundant terminators, separators, names etc. Haskell is a fairly sweet spot, but forking of data often involves some awkward back and forth parsing.

    • @user-tx4wj7qk4t
      @user-tx4wj7qk4t Před 3 měsíci

      Do you say that when you see Chinese and tell them they need to rewrite their language so people who don't speak Chinese can read it?

  • @alexxx4434
    @alexxx4434 Před 2 lety +3

    Such a great presentation!

  • @walrustrent2001
    @walrustrent2001 Před rokem

    I think the very idea that only collections (aka arrays) of things should exist is brilliant, kudos to APL to introduce that.

  • @Nellak2011
    @Nellak2011 Před 2 lety +13

    I'm pretty sure APL was developed by our alien overlords.

    • @cranknlesdesires
      @cranknlesdesires Před 2 lety +1

      Nah, Ken just wanted a version of maths that made sense, like why does summing everything have its own symbol but subbing everything doesn't? Why does min and max have no symbol even though we use often? Why do we need to remember Bedmas/Pedmas, what about if a expression has a Sigma, when do I do that? So Ken made something more consistent, with more symbols and less rules, and it was found that it can be made a programing language easily enough.

  • @carstenrasmussen1159
    @carstenrasmussen1159 Před 2 lety +1

    I like your run through. Very good example and good work. Personally I like languages which are multi paradime. I our team we use D and try get my colleagues to use other part of the D language. Specially the OOP or OOOP (Over Object Oriented Programing)

  • @ivanivanovich4778
    @ivanivanovich4778 Před 2 lety +7

    How does changing variable names from clear words to random meaningless syllables make the code more readable

  • @mlliarm
    @mlliarm Před 2 lety

    Smullyan's bird book will arrive most likely on 2021-12-18. I'd ordered it well before I saw this video. I'm happy to see that you recommend it too :D!

  • @oraqlle
    @oraqlle Před 2 lety

    What's your thoughts on the C++ standard trying to becoming more expressive like the inclusion of the ranges-v3 and I've seen a proposal for C++23 for a new composition operator for I think regular (imperative) functions as well as the range, view and lambda functions. I believe the proposed operator was operator |> (x, f(y)) where f is a function and y is its input and x is a value or function that is passed to f through y. I was curious on your thoughts. Awesome video though.

  • @vivekkaushik9508
    @vivekkaushik9508 Před 2 lety

    I hardly understand 5% of what's going on here but I feel amazed and quite smart after watching these vids. LMFAO. Seriously the world of computing is mind blowing. The so called "developers" like me don't even know 1% on what goes behind the scenes when we call an in-built function or use any tooling like Git or SDKs etc. Thanks mate for keep making these vids. Hope you're keeping backups we don't know when WW3 ends everything.

  • @ninguhosaptot
    @ninguhosaptot Před 2 lety +2

    Please could you comment how do you do those smooth text code transtions? Thanks in advance.

  • @jtetrfs5367
    @jtetrfs5367 Před 2 lety +1

    Excellent production!

  • @ShadyE
    @ShadyE Před 2 lety +5

    I wonder if Clojure's macros can be used to introduce combinators 🤔

  • @robertpeszek6892
    @robertpeszek6892 Před 2 lety +1

    Very nice presentation!

  • @garklein8089
    @garklein8089 Před 2 lety +24

    The parentheses aren't even needed in the APL solution, making a cool looking function with the max reduce at one side and the min scan at the other

    • @code_report
      @code_report  Před 2 lety +12

      Sigh :facepalm: I definitely should have noticed that

  • @joaoholanda3021
    @joaoholanda3021 Před 2 měsíci

    Honestly I am far from understanding it but congratulations for the great presentation and thank you for taking the time to explain it. There's a lot I still have to learn tô fully appreciate it.

  • @HOWTO-sf6sy
    @HOWTO-sf6sy Před 2 lety +5

    Waiting⏳also your sicp course is insane

  • @RajeshPandianM
    @RajeshPandianM Před 2 lety +3

    I wanted to ask this in the last video. Did you create a logo for APL? If so, this looks cool! 😁😁

  • @0dWHOHWb0
    @0dWHOHWb0 Před 2 lety +32

    How do you even produce those characters on your keyboard? Is typing a function call really so taxing that reducing it to a single character is the difference maker? I don't understand how this kind of language can be easier to read/write or reason about.

    • @ravimaithreyregulagedda2158
      @ravimaithreyregulagedda2158 Před 2 lety +6

      I think you missed the point. The guy is talking about why he thinks a certain language is amazing in his opinion. He thinks that way because he loves the math and all behind combinatory logic.
      I agree with you that it might not be practical, but the guy thinks it's cool and he likes the concept and loves that an existing langauge has all this combinatory logic in it. That's why he made this video.
      At least that's how I understood the video anyway ¯\_(ツ)_/¯

    • @0dWHOHWb0
      @0dWHOHWb0 Před 2 lety +1

      @@ravimaithreyregulagedda2158 It's possible, yeah. We're left to guess at the motivations of the author since they weren't clearly stated.

    • @stevemcgrath4040
      @stevemcgrath4040 Před 2 lety +3

      @@0dWHOHWb0 Back in the days when APL was cool, you had special keyboards and unique encodings (well before Unicode). So you probably just use a custom keyboard mapping. I don’t remember the count, but there aren’t that many glyphs in APL. Conceptually, it’s most like the broad use of symbols in mathematics in general; you’re writing a mathematical expression, not a story.

    • @orkhepaj
      @orkhepaj Před 2 lety +3

      hipster lang , they dont use this for anything

    • @jamieg2427
      @jamieg2427 Před 2 lety

      it's not that difficult to have certain key presses produce other characters. vim, for example, makes setting up this type of scheme pretty trivial, but it can be done at a system level very easily on linux and windows.
      also, J, made in the 90s by the creator of APL, uses ascii characters, so fear not. (:

  • @otmanm4095
    @otmanm4095 Před 2 lety

    You broke my brain ! Great vidéo ! Subed'

  • @madsteeez
    @madsteeez Před 2 lety

    MATLAB:
    res = max(nums (2:end)-nums(1:end-1))
    If all(res

  • @imadetheuniverse4fun
    @imadetheuniverse4fun Před 2 lety +1

    What are the pros and cons of writing the algorithm in one paradigm vs the other? For example the pros and cons of the Haskel implementation vs the Python one? For context, Python is my main language but I'm kind of interesting in learning Haskel.

  • @markwvh
    @markwvh Před 2 lety +13

    Your strategy is overly complex, no?
    maxDiff :: [Int] -> Int
    maxDiff = snd $ foldl' go (maxBound, -1)
    where go (lo, diff) x = (min lo n, max diff (x - lo))

    • @henriquefinger935
      @henriquefinger935 Před 2 lety

      I'm a Haskell beginner, this was my solution:
      maxDiff [] = -1
      maxDiff (a:as) = mD as a
      mD [] _ = -1
      mD (a:as) m = if a > m
      then max (a-m) (mD as m)
      else mD as a

  • @henriquefinger935
    @henriquefinger935 Před 2 lety +3

    Before the functional language section I tried to solve the problem with Haskell myself. What surprised me is that my solution was completely different from yours.
    I only used recursion and ifs, no fancy functions like scan, map, filter, reduce and combinators, but my code is still O(n).
    It made me wonder which is faster for larger input arrays, I might check it out later.

    • @guptadagger896
      @guptadagger896 Před rokem +1

      Scan was new to me, but map and folds should be very standard haskell toolset

  • @Baterodalo
    @Baterodalo Před 2 lety +2

    APL is the Doctors handwright of programing

  • @peerhenry
    @peerhenry Před 2 lety +1

    The S combinator explained at 17:32 reminds me of functions as monads: you can chain a binary function x onto a unary function y, so in Haskell it would be something like y >>= x. I believe the same is achieved by treating functions as applicatives with x y (solution of this video).

    • @explosionspin3422
      @explosionspin3422 Před 2 lety

      You probably already treat functions as monads. That's what Reader is. Reader a b is pretty much the same as a -> b, under the hood

  • @MultiJaxk
    @MultiJaxk Před 2 lety +2

    What's your opinion on J programming Language vs APL? honestly I've been giving both a bit of review, and seem to like J language more. What would you say - which one is "more powerful", if you could/can compare them?

  • @amj864
    @amj864 Před 2 lety +5

    Would you do a Julia over view? It looks like a jack of all trades and master of few.

  • @mikivanousek1030
    @mikivanousek1030 Před rokem

    Did you use Manim to create the slides? It looks great.

  • @HenrikMyrhaug
    @HenrikMyrhaug Před 2 lety

    About the example problem:
    I believe it might be faster to store two variables of the highest number and highest difference, and instead of comparing the difference between the min and the current number to the current biggest difference on every single step, we just compare the current number to the highest number.
    Each time we find a new min, we compare the highest difference to the different between the current max and min, and store the largest of those as the largest difference, then set the min and max to the new min we found.
    So instead of doing a subtraction for every element in the array, we only do a subtraction each time we find a new minimum.
    I have no idea how fast variables can be accessed and stored, so I don't know wether the increased number of variables used increases compute times more than the reduction from fewer subtractions.

  • @diegofloreschavez8420
    @diegofloreschavez8420 Před 2 lety +1

    You can do it one-liner in Python like this:
    def solve(*args: int) -> int:
    return max(args[min(args):]) - min(args) if min(args) != args[-1] else -1
    But I think it would be better if you store "min(args)" first in a variable.

  • @rjameslower
    @rjameslower Před 2 lety +1

    What do you think about GNU APL for a beginner?

  • @hebozhe
    @hebozhe Před 11 dny

    Smullyan and Priest write some of the most accessible logic books.
    I don't study much in this area of logic, but I'd definitely pick through the Smullyan text if I wanted a quick comprehensible dive. Good recommendation.

  • @shmendusel
    @shmendusel Před 7 měsíci

    Are functional and array orthogonal paradigms? Could you theoretically have a programming language that is both functional and array based?

  • @reda29100
    @reda29100 Před 2 lety

    5:00 doesn't it make more sense to assume the max_dif to be n[1]-n[0] if positive, otherwise -1, such that .we increase the difference as we find a larger one, instead of assuming it to be MAX_INT?

  • @korigamik
    @korigamik Před rokem

    Your videos are cool! Can I ask what you use to create these amazing slides and animations?

    • @code_report
      @code_report  Před rokem

      I have a tutorial here: czcams.com/video/Vh3y1ela-_s/video.html

  • @amanbolat
    @amanbolat Před 2 lety +1

    So, how to open a file using APL?

  • @mymacaintwag
    @mymacaintwag Před 2 lety

    Nice 👍 really informative

  • @jongeduard
    @jongeduard Před rokem +1

    Hi, personally many of these languages are not my cup of tea. APL cannot even be typed on a normal keyboard. But I liked to see what I could do in C# here.
    I am both able to go the imperative way as well al the functional way which is called LINQ.
    I had to write the ScanLeft part myself, of which my yield return version turned out to be the nicest, because in that way you still benefit from Linq it's lazy execution efficiency.
    But the rest was quite easy. For Map you use Select and for Filter you use Where.
    The nicest thing is that Zip is available as well and it accepts and extra input array as direct input, so that I basically get something simular to that S combinator solution from Haskell, even though the code looks more like the Scala code in the video.

  • @asteriskman
    @asteriskman Před 2 lety

    "The expressivity of the single glyphs"? oh yea, totally sold me...I'm switching to APL, where do I buy a keyboard with all these expressive symbols?

  • @tubeincompetence
    @tubeincompetence Před 2 lety +4

    Well. This video made me happy to stay with C++ I guess. :D
    Or I guess I just won't go for APL.

  • @alpers.2123
    @alpers.2123 Před 2 lety +1

    11:00 Scala code, python equivalent:
    max(-1,*(n-m for m,n in zip(list(reduce(lambda x,y: x+[min(y,x[-1])], nums, [sys.maxsize]))[1:], nums) if n-m))
    19:30 haskell code, python equivalent (no INT_MAX, yet python doesnt have S combinator, so this is best I can):
    max(-1,*(n-m for m,n in zip(reduce(lambda x,y: x+[min(y,x[-1])], nums[1:], nums[0:1]), nums) if n-m))
    Update: Just saw atrus' comment. here is pythonic way:
    max(map(sub, nums, accumulate(nums, min))) or -1

  • @bjk837
    @bjk837 Před rokem

    I would love to know how you manage your time. Would love to start doing more outside of work, but I you’re like 10X and I’m struggling

  • @amalirfan
    @amalirfan Před 2 lety

    what font do you use?, It looks nice.

    • @code_report
      @code_report  Před 2 lety

      For the code Consolas, for titles Rockwell

  • @loutragetadk453
    @loutragetadk453 Před 2 lety +3

    I would like to learn more about this combinatory logic stuff.

  • @rmschindler144
    @rmschindler144 Před 7 měsíci

    Wow, APL and BQN are gorgeous.

    • @jacoblockwood4034
      @jacoblockwood4034 Před 2 měsíci +1

      Try them out! They look intimidating but you can learn array programming concepts pretty quickly and get the specifics of each language as you learn. Also try Uiua, which approaches array programming using a stack-based flow (think Forth).

  • @prawnydagrate
    @prawnydagrate Před 7 měsíci

    7:55 - for the python example, isn't it better to use math.inf instead of sys.maxsize?

    • @0LoneTech
      @0LoneTech Před 5 měsíci

      Possibly, but not type consistent. sys.maxsize is like Haskell's maxBound::Int, except Python's int has no max value (it's arbitrary precision like Integer). It's not great as Python code goes anyhow; I might e.g. write max(max(nums[i:])-min(nums[:i]) for i in range(1,len(nums)-1)), which may not be as algorithmically efficient but avoids naming new magic values and probably runs faster.

  • @MB-rc8ie
    @MB-rc8ie Před 2 lety +1

    7:08 What is the point of returning auto in that function?

    • @josee.ramirez4305
      @josee.ramirez4305 Před 2 lety

      It is not returning "auto", that is not a function is actually a lambda. The lambda is defined as the "name(...inputs..) -> return_type { body} }. Thus, "maximum_difference" is a variable of type lambda and to avoid writing the whole type as in any other C++ variable declaration he used the "auto" keyword".

    • @MB-rc8ie
      @MB-rc8ie Před 2 lety +1

      @@josee.ramirez4305
      ?? Lambda must have capture list so it would be [] () -> int { return 10}.
      Besides, this functin returns the result of std::max, so it returns int.

  • @blehbleh9283
    @blehbleh9283 Před 2 lety

    How do you even type APL on a keyboard????

  • @taylors1545
    @taylors1545 Před 2 lety +7

    Anyone ever open a door out of curiosity and instantly regret it? Time for another mug of coffee...

  • @BeansEnjoyer911
    @BeansEnjoyer911 Před 2 lety +1

    You've earned a sub

  • @0dWHOHWb0
    @0dWHOHWb0 Před 2 lety

    Why auto maximum_difference(std::vector nums) -> int, instead of int maximum_difference(std::vector nums)? Why by value instead of by const-ref?

    • @0dWHOHWb0
      @0dWHOHWb0 Před 2 lety +1

      Also, you probably should do for (const auto& elem : nums), even though the copy here doesn't make a difference... Also, how's performance with those "min scans", differences and other transformations? You could implement those with e.g. std::transform but I figure it'd be slower compared to the explicit loop to do all that.

  • @benjidaniel5595
    @benjidaniel5595 Před 2 lety +2

    Elegance !== Legibility

  • @pauhull
    @pauhull Před 2 lety +3

    imagine you have to check a pull request and see this: 20:12

  • @red13emerald
    @red13emerald Před 2 lety +13

    7:40 100% disagree. Even though I knew what the variables were originally, I got immediately confused by these short variable names. It’s maybe to do with parsing mathematical formulas, which I am super bad at, but I feel like 1-3 word variables are much more readable than 1-3 letter variables. Except for i in a loop, but even there, index, position or location may be more appropriate depending on what you’re actually iterating over.

    • @saltrocklamp199
      @saltrocklamp199 Před 2 lety +5

      I have a lot of experience parsing math formulas and I still think the short variable names are worse!

    • @31redorange08
      @31redorange08 Před 2 lety

      Wasn't this whole video a joke?

    • @red13emerald
      @red13emerald Před 2 lety

      @@31redorange08 I… don’t know. Maybe? I guess, yeah, when you think about it like that, it makes sense, but I can also see how people do find beauty in pure languages like this. I just thought that it wasn’t for me?

  • @walrustrent2001
    @walrustrent2001 Před rokem +1

    Data-oriented algorithms should use reverse notation so that the reading order matches the application of functions.
    Elm has really smart notations that lead to easier reading than Haskell, since it provides operators for both function composition and function application in both directions)
    Namely |> and > and ( zipWith (-) scanl1 min )
    |> filter(/= 0)
    |> foldl max (-1)
    Of course you loose the pointfree notation but I think it is largely worth it

    • @0LoneTech
      @0LoneTech Před 3 měsíci

      What do you mean about losing point free notation? x is the only point in your example, so each operation is written point free. Just change "maxDiff x = x |> " with "maxDiff = " and |> with >>, and you're fully point free. |> is also used in Futhark, and internally in GHC, and is named & in Data.Function. Protolude and Relude both expose & by default.

  • @thinker2273
    @thinker2273 Před rokem +3

    I am convinced this guy is insane. His main argument for APL and related languages is that... they use less symbols? Like... what? There is no world in which that is a worthwhile argument for or against any language. Being able to express a function in terms of a single obscure unicode character as opposed to four standard ASCII characters is not an inherent benefit. Not to mention the fact that both Haskell and APL have the same issue when it comes to readability and attitude towards newcomers to each respective language - they both have an unbelievably academic and elitist community which favors mathematical names and concepts over more readily understood equivalents. You can express the S-combinator both in terms of an abstract mathematical concept, or in terms of a simple C-like function signature, and I hazard a guess that the C-like function will be a lot more readable and understandable to a lot more individuals. However, I will agree that there are tasks that languages like Haskell and APL excel at, particularly related to data processing.

  • @christianbenesch1
    @christianbenesch1 Před 4 měsíci

    Is Conor Hoekstra the child of Edward Haskell and Edsger Dijkstra?

  • @wowzers1237____
    @wowzers1237____ Před 2 lety +7

    If BQN also had all the type theory stuff Haskell does, I'd be sold. Without it, although the glyph notation is cool, it's just a limited version of Haskell not worth learning (imo) - just learn Haskell at that point.
    Or I guess I can ask: Other than the fact that it's more succinct on account of the glyphs, what does BQN offer that Haskell doesn't?

    • @0LoneTech
      @0LoneTech Před 5 měsíci

      It's not just the glyphs, but also the syntax and chosen data types and polymorphisms. For instance, CBQN will happily build byte arrays rather than Double arrays to improve memory access patterns, simply because the data fits. When they advertise context free syntax (really, only local context), it's to assist both human and automatic readers.
      It really isn't a version of Haskell. If anything, it's a version of APL, and the array oriented programming is a useful paradigm to learn, which you could translate to some degree into Haskell Massiv.
      It does bug me that people keep comparing Haskell lists to arrays. There are arrays even in standard Haskell (Data.Array), though not in base.

  • @bzboii
    @bzboii Před rokem +1

    20:35 Twin Algorithms secret reference (and 21:58)
    could have sniped his conference talk while he waited to give it in person

  • @virkony
    @virkony Před 2 lety +1

    23:26 use of uncurry (zipWith (-)) . (id &&& scanl1 min) might match APL better, I think.