Why I Love BQN So Much! (vs Python)

Sdílet
Vložit
  • čas přidán 27. 06. 2024
  • A short video comparing a Python and BQN solution to a simple LeetCode problem.
    Solutions on GitHub: github.com/codereport/LeetCod...
    ADSP Podcast: adspthepodcast.com/
    Array Cast: www.arraycast.com/
    APL Seeds: www.dyalog.com/apl-seeds-user...
    Contest: 336
    Problem Name: Rearrange Array to Maximize Prefix Score
    Problem Link: leetcode.com/problems/rearran...
    Problem Type: Greedy
    Chapters:
    0:00 Intro
    0:20 Problem Description
    1:40 Python Solution
    3:29 BQN Solution
    5:18 Solution Comparison
    6:45 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 • 90

  • @codetothemoon
    @codetothemoon Před rokem +31

    I don’t even understand BQN, and I agree it is objectively better than the Python solution. Seems like the extra time learning the glyphs is well worthwhile for these sorts (pun intended) of elegant solutions

  • @TigerWalts
    @TigerWalts Před rokem +56

    The alternatives for sorted(nums)[::-1] are either:
    sorted(nums, reverse=True)
    reversed(sorted(nums))
    These also return iterators whereas the slice notation does not.

  • @trespaul
    @trespaul Před rokem +51

    Once again, for me, Haskell strikes the perfect balance between readability and conciseness:
    length . filter (> 0) . scanl1 (+) . reverse . sort
    (sort from Data.List)

    • @noomade
      @noomade Před rokem +3

      although, I think
      scanr1 (+) ... instead of ... scanl1 (+) . reverse

    • @0LoneTech
      @0LoneTech Před 8 měsíci +2

      For bonus madness, we do not need to sort the positive elements, nor do we need to process negative elements after the value drops below 0.
      length . takeWhile (> 0) . scanl1 (+) . sortOn (negate . min 1)

  • @woncoh1
    @woncoh1 Před rokem +19

    Love BQN!
    Looks like a bridge between “functional” and Iversonian languages.
    import pandas as pd
    pd.Series(nums).sort_values(ascending=False).cumsum().gt(0).sum()

  • @kahnfatman
    @kahnfatman Před 10 měsíci +5

    I told you already, the Egyptians built the great pyramids, invented APL and vanished.

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

      i’m pretty sure Egypt still exists

  • @noomade
    @noomade Před rokem +5

    Your videos are so good ... I mean like ... EVERY ONE of them!

  • @LetrixAR
    @LetrixAR Před rokem +5

    BQN feels like Regex but as a language

  • @c4tubo
    @c4tubo Před rokem +11

    BQN FTW again. IMO, the best counter to the "it's hieroglyphics" complaint is to imagine doing math in "natural" language. For example "x plus 2 times y divided by 1 minus x plus the square root of y". Is that really more readable? Obviously not, and yet that is essentially the argument. Also what is "natural" language is a bias towards a specific set of symbols (typically a Latin alphabet) and a specific vocabulary (typically English) that people forget took them years in their youth to fully comprehend.

    • @darrylkid210
      @darrylkid210 Před rokem

      good argument

    • @NEO97online
      @NEO97online Před 8 měsíci +2

      there is a big difference between symbols that are pervasive throughout human life from kindergarten, of which there are only a handful, versus a set of alien wingdings that encapsulate complex procedures.

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

      ​@@NEO97online True, but the glyphs can vary drastically in clarity as well. An example here is the descending sort being the vertical mirror of the ascending sort. The reduction and scan are also related, albeit not as clearly. Meanwhile, "phi combinator" is just an awful name; phi is just a glyph from another context. Some of those gain traction, like pi for a circle constant or c for the speed of light. You may even be more familiar with capital sigma as a sum operator than as a letter.

  • @KenHarvey9
    @KenHarvey9 Před rokem

    Love these videos! Thanks

  • @pinkorcyanbutlong5651
    @pinkorcyanbutlong5651 Před rokem +8

    Would be nice a video on Nial, it seems like a nice language for introducing array programming without the 'scare' of such a terse syntax, and the function atlas feature seems like an interesting way of function composition using the array themselves (i.e doing `[f, g] x` results in '[f(x), g(x)]')

  • @CielMC
    @CielMC Před rokem +1

    I just realized BQN is the next letter for APL... oops. (Your channel is my first interaction with array programming, though I seem to struggle to find much resources on YT abt it, I just get taught what arrays are again and again)

  • @greggr1591
    @greggr1591 Před rokem +1

    Been programming in python and I just started learning J, so this vid is a perfect step-by-step of array language concepts. (A YT search for 'j language' showed many of your vids up top, easily the best produced of the lot IMHO). I love the conciseness of array languages; a possible quick-n-dirty J version of the BQN solution might be:
    +/ 0< +/\ (\: nums) { nums
    No doubt you could improve it (I'm still fuzzy on forks, hooks, etc.). Great stuff 👍🏻

  • @tauraamui
    @tauraamui Před rokem +3

    It's only readable once you understand how to read it or what they mean. That's like when Ruby advocates used to say (used to because no one uses that language for anything new anymore) that their random operator symbols were oh so easy to pick up and read. Only if you don't learn them first you have no idea what they mean.

    • @julians.2597
      @julians.2597 Před 3 měsíci

      or when english speakers insist that programming languages need to be in english using only the english alphabet

  • @NEO97online
    @NEO97online Před 8 měsíci +3

    its incredible how ungrounded from reality this type of programming is.

  • @asdqwe4427
    @asdqwe4427 Před rokem +4

    I really don’t see how you could argue that it’s more readable. Sure accumulate is not a great name, but the bqn solution looked like a curse word in a comic book.

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

    New trend unlocked: Array languages.

  • @pmcgee003
    @pmcgee003 Před rokem

    Does BQN easily produce std::partition and std::stable_partition ?

  • @valengo9468
    @valengo9468 Před 8 měsíci

    It takes 0 thought to remember what sorted(nums) does in python, its literally in the name. [::-1] is dumb and requires memory though, you are right there.

  • @simjans7633
    @simjans7633 Před rokem +1

    Hey I've come across a problem that required me to implement the flood fill algorithm and it got me wondering how a flood fill could be done in APL/BQN.
    I came up empty-handed. How would you implement flood fill in BQN?

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

      My first thought would use a convolution to grow a mask recursively until it stopped growing. Hardly efficient, but this series focuses on terse source over anything else, it seems. It would also translate easily to GPUs.

  • @angeloj.willems4362
    @angeloj.willems4362 Před rokem +2

    sorted takes the arg "reverse=True"

  • @DylanMatthewTurner
    @DylanMatthewTurner Před rokem +2

    What does accumulate/+` do exactly?
    EDIT: Nevermind I figured it out lol

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

    for a fair comparison with Python, I suggest to implement a web-server in BNQ. I hope, there is no ready made glyph for that, lol.

  • @PythonPlusPlus
    @PythonPlusPlus Před 8 měsíci

    in python you should be doing sorted(nums, reverse=True)

  • @bzboii
    @bzboii Před 10 měsíci

    missing your videos ! plz release more (your life nonblocking)

  • @hardknockscoc
    @hardknockscoc Před rokem +66

    I disagree with your argument that it's readable. I think having short English names will be useful in larger programs. There are lots of functions. You're not going to be able to have an op for all of them. Aside from this, whitespace delimiting is good practice as well because when looking at the BQN source, it's not immediately obvious how the op apply semantics works just from the syntax. Imo other languages make this more explicit. This could be familiarity, but I doubt that very much. A good way to test this would just be to write one reasonably sized project in both languages using the same algorithms and see if you're struggling more to understand what you've written in one than the other.

    • @Evan490BC
      @Evan490BC Před rokem +1

      Why have a function (operator) for all of them? You can *compose* operators in APL-type languages. I agree about the white space. I'm not a fan of BQN, to be honest.

    • @abrudz
      @abrudz Před rokem +2

      You may prefer Q, which is a "cousin" of BQN. With Q, you'd write this as MaxScore: sum 0< sums desc @

    • @Evan490BC
      @Evan490BC Před rokem

      @@abrudz Nial is also nice.

    • @hardknockscoc
      @hardknockscoc Před rokem +3

      @@Evan490BC Even with composition, you're not going to get all the functions you'd want into some op or composition of ops. I personally prefer languages that keep the ops list short and similar to the ordinary arithmetic ops everyone already knows.

    • @Evan490BC
      @Evan490BC Před rokem

      @@hardknockscoc I lost you there... Why not? APL is a Turing-complete language. Can you explain what you mean?

  • @seethruhead7119
    @seethruhead7119 Před rokem +2

    mr code_report
    can you solve this in BQN in a video?
    "You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "outlier" N."

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

    I like the BQN solution, but what I feel is difficult isn't just learning the glyphs, but also the semantics of the trains. I don't quite understand why you need to add a nothing at 4:37, what are the regular precedence semantics?

  • @ondskabenselv
    @ondskabenselv Před rokem +1

    You should try this in numpy or pandas which implements array programming.

  • @joaq-almeida
    @joaq-almeida Před rokem

    Hey!
    Have you heard about Standard ML(SML)?
    Could you someday solve a problem using this language, please?
    I'd appreciate that.

  • @freedom_aint_free
    @freedom_aint_free Před 9 měsíci

    Without using the itertools:
    def maxScore(nums):
    prefix_sum = 0
    return sum(1 for num in sorted(nums, reverse=True) if (prefix_sum := prefix_sum + num) > 0)

  • @TheLogvasStudio
    @TheLogvasStudio Před rokem +1

    Could someone please explain, why we need to sort that array?
    Why couldn't we just do:
    sum(num for num in nums if num > 0)

    • @PythonPlusPlus
      @PythonPlusPlus Před 8 měsíci

      Because this won’t solve the problem. In order to maximise the prefix you want the numbers arranged in reverse order. We are essentially creating the optimal arrangement of numbers then calculating the length of the prefix.

  • @soracc_
    @soracc_ Před 9 měsíci

    The BQN solution is cute, however, why should we have sort as a primitive? Even the APL-likes can't agree on the set of combinators/other primitives to include. The equivalent Haskell/Factor solution would be much more readable.

  • @kellymoses8566
    @kellymoses8566 Před 11 měsíci

    Which gives one more nerd cred? BQN or Haskell?

  • @FinlayDaG33k
    @FinlayDaG33k Před 9 měsíci

    I'm sitting here, sober and awake... Understanding very little of BQN.
    I can't wait to see what kind of whack stuff drunk and tired me will come up with.

  • @lextr3110
    @lextr3110 Před rokem +6

    Would be nice if you would use dark mode on all your views/webpage.. black on white is hard for the coder eyes

    • @code_report
      @code_report  Před rokem +2

      I totally agree, LeetCode dark mode doesn't apply to the problem statement pages atm.

    • @abrudz
      @abrudz Před rokem +1

      @@code_report Maybe you can add a user-style saying :root{filter:invert(1)hue-rotate(180deg)}

  • @zohnannor
    @zohnannor Před rokem

    APL is no longer your favorite language? :)

  • @woncoh1
    @woncoh1 Před rokem

    APL : Math = Python : Natural language = C : Assembly ?

  • @norude
    @norude Před rokem

    Do fizzbuzz

  • @ddddddddd345
    @ddddddddd345 Před rokem +2

    One one hand I enjoy this youtube channel...
    ... on the other hand I can't help but to think that no one should care about how short (as measured in the number of characters) a code like this is.
    No only software development consistents maybe in .1% (max) of writing code doing computations like this, but also the Python example here is easily much more readable for an average human being or an average software developer.
    After watching couple of these BQN related videos, I really see no point in it, other then a novelty of sorts.

  • @justinlloyd3
    @justinlloyd3 Před 9 měsíci

    Bro I don't have those on my keyboard

  • @steveh4595
    @steveh4595 Před rokem +2

    Connor, don't know how to leave feedback with you through ArrayCast (not going to send an email through "Contact") so I'm leaving a comment here. Why did you invite Nick Psaris to go on about Q and Python integration when it's not available to the free personal license edition of Q? No one in your audience is going out to purchase a kdb Insights license to use that facility and a 30 day "free trial" doesn't cut it. Please stop promoting pay to play because this kind of tech space is way out of anyone's personal affordability.

  • @sahiljindal
    @sahiljindal Před rokem +9

    I would disagree with the argument that it makes it readable. Even though I know why you love BQN and especially "tight and concise" represenation of functions. But Reality is that when it comes to industry adoption and hiring people, "verbose languages" will always come on the top of the chart. Also, even after this much "verbosity", most people don't know how to program. And if we start using BQN in front of them, they would thought that we are some sort of aliens 😂😂. You could understand if I took a different example. Most people who have degree in Maths, don't use concise mathematical language while teaching. And there are some books, who are actually thick and still uses concise language.
    Ultimately, While we respect for your choice of programming language, the reality is no language is better than another. And they are just tools.

    • @welcomb
      @welcomb Před rokem +6

      Exactly. Perl used to have lots of shorthand operators which leads to very short codes. But they don't call it write once read never for nothing. I can look at my self written Perl scripts now and have zero idea how they work.
      I'd never go back to shorthand symbology again. Give me verbose, easy to understand code anytime.

  • @tauraamui
    @tauraamui Před rokem +1

    Would anyone actually use BQN for large code bases that do more than solving interesting problem sets? I mean I wouldn't use Python for that either, but still.

  • @norude
    @norude Před rokem

    In python 3.10+ you can replace 'List' with 'list'

  • @casualpasser-by5954
    @casualpasser-by5954 Před rokem +2

    BQN stuff is cool, but I personally prefer Python solution cause for me understanding verbose code is much easier than code composed of symbols. Though, I am just rookie in programming and it is very possible that my opinion will change in the future.

  • @Mentox2
    @Mentox2 Před rokem +6

    I mean, BQN sounds cool and all, but this syntax feels way too much like regex to my liking.

  • @kian5146
    @kian5146 Před rokem

    With Python it would be much better to use a module which provides array-programming.
    With nums being a pandas.Series for example the solution is:
    nums.sort_values(ascending=False).cumsum().gt(0).sum()

  • @xslvrxslwt
    @xslvrxslwt Před rokem +1

    Just use Julia s 💀

  • @foobar69
    @foobar69 Před rokem

    what is this monstrosity!!!

  • @deepfakescoverychannel6710

    BQN is just unreadable

  • @voncth5791
    @voncth5791 Před 8 měsíci

    Must be the most unreadable language i have ever seen

  • @PEGuyMadison
    @PEGuyMadison Před rokem

    Wait, I thought APL was your favorite language? Don't tell me you are one of those fly by night language guys that can't commit to a language and never find a long term working relationship.

  • @SwordQuake2
    @SwordQuake2 Před rokem +2

    6:11 it IS hard to read. It's like learning kanji as opposed another alphabet (let's say Cyrillic if your native language uses Latin).

  • @TankorSmash
    @TankorSmash Před rokem

    I sent you a message on Twitter the other day, not sure if you saw it or not!

  • @woncoh1
    @woncoh1 Před rokem

    import itertools
    import toolz
    from typing import List
    def max_score(nums: List[int]) -> int:
    return toolz.pipe(
    nums,
    sorted,
    reversed,
    itertools.accumulate,
    lambda xs: (x > 0 for x in xs),
    sum,
    )

  • @user-rr6my1lo2k
    @user-rr6my1lo2k Před rokem

    Julia:
    findfirst(

  • @pnr
    @pnr Před rokem

    Julia: sort(nums,rev=true) |> cumsum .|> >(0) |> sum
    This looks way more readable in a font that has a ligature for |>

    • @pnr
      @pnr Před rokem

      Or even better, again in Julia: nums |> sort |> reverse |> cumsum .|> >(0) |> sum
      Produces exactly the same assembly code as the previous one. Supreme readability, at least to my eyes. Someone who does not know Julia may find only the second-last function confusing. Apart from that, the data flows through smoothly.

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

    𓀃𓈬𓋏𓉮𓀠𓆘 We are so back