Why I Love BQN So Much! (vs Python)

Поделиться
HTML-код
  • Опубликовано: 4 янв 2025

Комментарии •

  • @codetothemoon
    @codetothemoon Год назад +34

    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 Год назад +55

    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 Год назад +56

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

    • @0LoneTech
      @0LoneTech Год назад +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)

  • @LetrixAR
    @LetrixAR Год назад +11

    BQN feels like Regex but as a language

  • @woncoh1
    @woncoh1 Год назад +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 Год назад +5

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

    • @ed-bl7zk
      @ed-bl7zk 9 месяцев назад

      i’m pretty sure Egypt still exists

    • @rujon288
      @rujon288 6 месяцев назад

      the 111 million Egyptians right now :

  • @NuclearFury8
    @NuclearFury8 Год назад

    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?

  • @tauraamui
    @tauraamui Год назад +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 9 месяцев назад +1

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

  • @TheLogvasStudio
    @TheLogvasStudio Год назад +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 Год назад

      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.

  • @c4tubo
    @c4tubo Год назад +12

    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 Год назад

      good argument

    • @NEO97online
      @NEO97online Год назад +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 Год назад

      ​@@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.

    • @TheBusttheboss
      @TheBusttheboss Месяц назад

      They are not alien after just a little bit of usage and practice.

  • @DylanMatthewTurner
    @DylanMatthewTurner Год назад +2

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

  • @pinkorcyanbutlong5651
    @pinkorcyanbutlong5651 Год назад +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)]')

  • @seethruhead7119
    @seethruhead7119 Год назад +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."

  • @CielMC
    @CielMC Год назад +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)

  • @simjans7633
    @simjans7633 Год назад +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 Год назад

      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.

  • @kellymoses8566
    @kellymoses8566 Год назад

    Which gives one more nerd cred? BQN or Haskell?

  • @greggr1591
    @greggr1591 Год назад +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 👍🏻

  • @hardknockscoc
    @hardknockscoc Год назад +68

    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 Год назад +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 Год назад +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 Год назад

      @@abrudz Nial is also nice.

    • @hardknockscoc
      @hardknockscoc Год назад +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 Год назад

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

  • @freedom_aint_free
    @freedom_aint_free Год назад

    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)

  • @pmcgee003
    @pmcgee003 Год назад

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

  • @joaq-almeida
    @joaq-almeida Год назад

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

  • @KenHarvey9
    @KenHarvey9 Год назад

    Love these videos! Thanks

  • @FinlayDaG33k
    @FinlayDaG33k Год назад

    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.

  • @PythonPlusPlus
    @PythonPlusPlus Год назад

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

  • @justinlloyd3
    @justinlloyd3 Год назад

    Bro I don't have those on my keyboard

  • @angeloj.willems4362
    @angeloj.willems4362 Год назад +2

    sorted takes the arg "reverse=True"

  • @ondskabenselv
    @ondskabenselv Год назад +1

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

  • @asdqwe4427
    @asdqwe4427 Год назад +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 11 месяцев назад

    New trend unlocked: Array languages.

  • @NEO97online
    @NEO97online Год назад +3

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

  • @sergeygoncharov2441
    @sergeygoncharov2441 Год назад

    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.

  • @zohnannor
    @zohnannor Год назад

    APL is no longer your favorite language? :)

  • @woncoh1
    @woncoh1 Год назад

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

  • @lextr3110
    @lextr3110 Год назад +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  Год назад +2

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

    • @abrudz
      @abrudz Год назад +1

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

  • @valengo9468
    @valengo9468 Год назад

    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.

  • @bzboii
    @bzboii Год назад

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

  • @tauraamui
    @tauraamui Год назад +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.

  • @SwordQuake2
    @SwordQuake2 Год назад +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).

  • @soracc_
    @soracc_ Год назад

    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.

  • @norude
    @norude Год назад

    Do fizzbuzz

  • @ddddddddd345
    @ddddddddd345 Год назад +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.

  • @MyriadColorsCM
    @MyriadColorsCM Год назад +6

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

  • @_xeere
    @_xeere Месяц назад

    Complaining about "accumulate" being a poorly named function is intensely hypocritical when you consider that BQN functions are named after random squiggles.

  • @norude
    @norude Год назад

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

  • @MelanieCastillo-x1r
    @MelanieCastillo-x1r 3 месяца назад

    Gibson Streets

  • @steveh4595
    @steveh4595 Год назад +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 Год назад +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 Год назад +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.

  • @casualpasser-by5954
    @casualpasser-by5954 Год назад +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.

  • @FranklinOliver-n7t
    @FranklinOliver-n7t 3 месяца назад

    Christiana Rapids

  • @deepfakescoverychannel6710
    @deepfakescoverychannel6710 Год назад +8

    BQN is just unreadable

  • @xslvrxslwt
    @xslvrxslwt Год назад +1

    Just use Julia s 💀

  • @foobar69
    @foobar69 Год назад

    what is this monstrosity!!!

  • @voncth5791
    @voncth5791 Год назад

    Must be the most unreadable language i have ever seen

  • @kian5146
    @kian5146 Год назад

    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()

  • @PEGuyMadison
    @PEGuyMadison Год назад

    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.

  • @woncoh1
    @woncoh1 Год назад

    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,
    )

  • @彭鈺峯
    @彭鈺峯 Год назад

    Julia:
    findfirst(

  • @pnr
    @pnr Год назад

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

    • @pnr
      @pnr Год назад

      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 Год назад

    𓀃𓈬𓋏𓉮𓀠𓆘 We are so back