Rust vs 7 Other Languages You Probably Haven't Tried

Sdílet
Vložit
  • čas přidán 6. 01. 2023
  • Take a quick tour of 7 languages that most people probably haven't tried. We write a simple program in Rust, then write the same program in each of those 7 languages in an effort to get a feel for them.
    Check out Sidekick, an incredible debugging tool: www.runsidekick.com/
    -
    Stuff I use to make these videos - I absolutely love all of these products. Using these links is an easy way to support the channel, thank you so much if you do so!!!
    Camera: Canon EOS R5 amzn.to/3CCrxzl
    Monitor: Dell U4914DW 49in amzn.to/3MJV1jx
    Keyboard: Keychron Q1 amzn.to/3YkJNrB
    SSD for Video Editing: VectoTech Rapid 8TB amzn.to/3hXz9TM
    Microphone 1: Rode NT1-A amzn.to/3vWM4gL
    Microphone 2: Seinheiser 416 amzn.to/3Fkti60
    Microphone Interface: Focusrite Clarett+ 2Pre amzn.to/3J5dy7S
    Tripod: JOBY GorillaPod 5K amzn.to/3JaPxMA
    Mouse: Razer DeathAdder amzn.to/3J9fYCf
    Computer: 2021 Macbook Pro amzn.to/3J7FXtW
    Lens: Canon RF24mm F1.8 Macro is STM Lens amzn.to/3UUs1bB
    Caffeine: High Brew Cold Brew Coffee amzn.to/3hXyx0q
    More Caffeine: Monster Energy Juice, Pipeline Punch amzn.to/3Czmfox
    Building A Second Brain book: amzn.to/3cIShWf
  • Věda a technologie

Komentáře • 381

  • @codetothemoon
    @codetothemoon  Před rokem +47

    ERRATA: Many of the examples are more verbose than necessary. This is partially due to my lack of expertise in many of the languages, and partially due to the desire to show equivalent constructs in each of the languages. In many cases, the most concise version of the program in that particular language would negate the need to use some of those constructs.

    • @adicide9070
      @adicide9070 Před rokem +4

      do you know if maybe someone has rewritten the Zig example more idiomatically and succinctly? I'd love to see that.

  • @kintrix007
    @kintrix007 Před rokem +134

    I am very surprised you didn't do map and fold in Elixir, and instead opted for a more verbose implementation, basically just doing a fold and a map by hand.

    • @adamhenriksson6007
      @adamhenriksson6007 Před rokem +14

      Yeah, figuring out all the fun and funky things one can do with fold is half the fun of functional programming.

    • @codetothemoon
      @codetothemoon  Před rokem +63

      Thanks for pointing this out! Sadly, I don't think the Elixir implementation was the only one that was more verbose than necessary...

    • @zzzyyyxxx
      @zzzyyyxxx Před rokem +11

      @@codetothemoon you might wanna redo this video then

    • @andrewdunbar828
      @andrewdunbar828 Před rokem +22

      @@zzzyyyxxx A followup rather than a redo would be of interest.

    • @MegaSascuach
      @MegaSascuach Před rokem +2

      At least there was only one list enumeration in the elixir program. 😅 I’m sure other language experts are picking apart the other examples too. Either way it was fun to look at elixir code keep it up @Code to the Moon

  • @Circl3s
    @Circl3s Před rokem +26

    Your local Crystal fan here. Not only does it have a really comfy syntax, but the standard library is insane. More people should give Crystal a try!

    • @codetothemoon
      @codetothemoon  Před rokem +6

      Nice! Crystal is definitely one of the languages I was most impressed with when preparing this video.

    • @tsimom
      @tsimom Před rokem +6

      yeah man been using crystal for quite some time and kinda gotten addicted... wait do you mean the programming language? /s

    • @Skidoodle18
      @Skidoodle18 Před 20 dny

      Late reply, but what are the main applications for Crystal? Does it have good documentation?

  • @woozy_deer
    @woozy_deer Před rokem +23

    I think a notable absence is Vale, it's more akin to Rust than any since it has it's own borrow checker and similar performance while claiming to be more concise and flexible.

    • @codetothemoon
      @codetothemoon  Před rokem +17

      I agree, Vale looks super interesting! I was actually going to include it in the video, but I ran into a roadblock trying to read stdin to a String. I asked the lead about it on the Vale Discord, and they said it was something they were going to implement. So I figured I'd do a separate video about it - Vale is actually the language I'm hinting about at the very end

  • @swdev245
    @swdev245 Před rokem +15

    For Julia, you could also have replaced the body of the function 'sum_fn' with the line:
    parse.(Int, splits) |> sum
    The dot after parse lets the function operate on an array and it pipes the resulting array into the sum function

    • @codetothemoon
      @codetothemoon  Před rokem +6

      thanks for pointing this out! several of the solutions in this video are suboptimal, Julia seems to be one of the more egregious cases of that

    • @mskaarupj
      @mskaarupj Před rokem +2

      @@codetothemoon I would also use Vector{

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

      Ahh .. more language syntax that I have no idea what it does.

  • @karlwaugh30
    @karlwaugh30 Před rokem +34

    The pipe operator also appears in F# and it's such an amazing language feature. I miss it.

    • @codetothemoon
      @codetothemoon  Před rokem +11

      Ahh I didn't know F# had it too, I do hope it becomes more commonly implemented in new languages

    • @Michal_Peterka
      @Michal_Peterka Před rokem

      ♥|> F#

    • @metaltyphoon
      @metaltyphoon Před rokem +2

      @@codetothemoon believe it or not but c++ 20 has it 😂

    • @emoutraspalavras-marloncou4459
      @emoutraspalavras-marloncou4459 Před rokem +5

      @@codetothemoon If I am not mistaking the functional programming language OCaml introduced that pipe operator. That was both Elixir and F# have drawn inspiration from. There are very good video series by a professor from the UK on youtube, the series has more than 100 videos and he shows you have to try the code online on the browser, no need to install anything. I got to OCaml when I after falling in loved with F# I was disappointed to find out that F# is roughly totally based on OCml, they look the same when it comes to the functional style, since F# also accept the OOP approach with imperative style. So now I am sticking to OCaml, since it is where F# came partially from. OCml, Haskell, Erlang the Common Lisp are quite a challenge, but these are really interesting programming languages. I am very surprised how many implementation are so concise in these 4 languages.

    • @pinkorcyanbutlong5651
      @pinkorcyanbutlong5651 Před rokem +2

      @@emoutraspalavras-marloncou4459 as someone who is also learning some OCaml and F#, would still say F# is more 'usable' as it can use/be used alongside C# projects, with C# itself bing quite popular; While OCaml is quite niche and honestly just less practical, with it only recently being able to do async and multi-thread without hacks

  • @JStevenAR
    @JStevenAR Před rokem +19

    Nim is a really awesome language. I started learning it a few months ago but I keep finding cool stuff about this language, like the macro system, so easy to use and powerful to make very cool things with metaprogramming. If you haven't used yet, Nim is worth giving a try.

    • @codetothemoon
      @codetothemoon  Před rokem +4

      I was impressed by nim as well! Seems like it has a bright future

    • @agustinpizarro
      @agustinpizarro Před rokem +2

      check "sugar" module!

    • @JStevenAR
      @JStevenAR Před rokem +2

      @@agustinpizarro That module always blow my mind!!! 🤯

    • @bluedark7724
      @bluedark7724 Před 9 měsíci +1

      Meta programming is above my mental ability. I had some excitement for Nim last year, nothing came off it.

  • @mageprometheus
    @mageprometheus Před rokem +25

    Thanks, this was great. I love playing with Rust. After years of watching Jon Gjengset's videos I got his book, Rust for Rustaceans, It's so rare to find intermediate to advanced stuff. I learned erlang and Haskell long ago and have started looking at Elexir. I got into Lua to write pluging in Reaper DAW, it 's faster to knock out than C++, and then fell in love with the wonderful Lua metaprogramming. Take care.

    • @codetothemoon
      @codetothemoon  Před rokem +5

      Thanks, I really enjoyed making it. I got Rust for Rustaceans recently as well, it's a fantastic book! I didn't realize Reaper supported Lua as well, seems like everyone is fixated on Neovim's support for it these days

    • @lardosian
      @lardosian Před rokem +4

      Reaper is a great DAW, love it!

    • @terryriley6410
      @terryriley6410 Před 10 měsíci +1

      lua 'end syntax' and 1 based indexing is annoying to me

    • @bluedark7724
      @bluedark7724 Před 9 měsíci +1

      Lau is a scripting language... I didn't mind that. It's another level of abstraction. There is a major difference between scripting and programming - one needs a run time, the other doesn't. I think Lua is great as a tool, if your Hong to learn lua, then python, which can be semi-compiled.
      I find that a language that has support everywhere is easier for me. Rust on everything for example, Python is everywhere... of course the C's are everything, but they are a pain.

  • @moumous87
    @moumous87 Před rokem +62

    0:53 Rust
    2:04 Nim
    3:14 Julia
    3:58 Elixir
    4:01 - 5:05 sponsor break: Sidekick
    5:06 Elixir resume
    5:50 Zig
    7:06 Haskal
    8:02 Lua
    8:35 Crystal

    • @joshbarghest7058
      @joshbarghest7058 Před rokem +5

      *Haskell

    • @curio78
      @curio78 Před měsícem

      Skipped d Lang? Seems like tge best designed clean and best of all worlds lsnguage

  • @flashas
    @flashas Před rokem +23

    Haskell can be even more concise, but no need to (in production code).
    main = getLine >>= print . sum . map read . words >> main
    or use interact

    • @codetothemoon
      @codetothemoon  Před rokem +6

      wow, nice! thanks for pointing this out!

    • @pdr.
      @pdr. Před rokem +1

      With interact:
      main = interact $ unlines . map (show . sum . map read . words) . lines
      This is longer but I think more understandable.

    • @opposite342
      @opposite342 Před rokem

      @@codetothemoon the >> and >>= are Haskell's monad binding operators, and from my research it is quite similar to elixir's pipe as well

    • @Axman6
      @Axman6 Před rokem

      You can also just use forever instead of the explicit recursion.

    • @steffahn
      @steffahn Před rokem +1

      @@Axman6 I want to second this. Using "forever $ do …" (or "forever do …" with {-# LANGUAGE BlockArguments #-}) reads very much just as well as "loop { … }" in Rust.

  • @NickWindham
    @NickWindham Před rokem +57

    Yay, somebody finally mentioning Julia! Might be the best kept secret in all of programming.

    • @PaulSebastianM
      @PaulSebastianM Před rokem +11

      There is no such thing. If something is good in programming, it won't stay a secret.

    • @mndtr0
      @mndtr0 Před rokem +9

      So young but beautiful lang with lua-like syntax and LuaJIT speed(and even faster). Who knows maybe if Julia may be older NeoVim devs use it instead of LuaJIT...

    • @codetothemoon
      @codetothemoon  Před rokem +9

      It does seem under-appreciated!

    • @trulyUnAssuming
      @trulyUnAssuming Před rokem +3

      I have such a love-hate relationship with julia. But it is becoming my go-to language, so it is doing something right 😅

    • @valdemarkjaer
      @valdemarkjaer Před rokem +5

      I’ve chosen Julia to be my general purpose / ML / DS language for the near future. Hope to work with both RUST and JULIA in health informatics. Let’s see what the future will show.

  • @Kruglord
    @Kruglord Před rokem +16

    Julia supports the exact same pipe operator as Elixir! You also don't need the begin\end in the map of sum_fn, but I'm pretty sure you only included that as a demonstration of a begin block. There's also the `eachline()` function, which if not passed any args, creates an iterator over stdin. Thus, you can write `for line in eachline()` rather than `while true; readline()`

    • @codetothemoon
      @codetothemoon  Před rokem +2

      oh nice I didn't realize this! I'm learning a ton hearing from practitioners of all of these languages - thanks for pointing these things out!

    • @sharos404
      @sharos404 Před rokem

      Edit: I just realized someone gave this comment before me.
      ​​@@codetothemoonIn addition you could do:
      ```
      ints = parse.(Int, splits)
      sum(ints)
      ```
      Instead of having sum_fn at all. Here the . (dot) is shorthand for broadcast, so it just creates a vector of Integers from the get-go.

  • @tian5185
    @tian5185 Před rokem +20

    Would love to see a follow-up with idiomatic code from experts of these languages!

  • @nullpointer1755
    @nullpointer1755 Před rokem +25

    The Julia version could be implemented like this:
    # No need to write type annotations since at runtime Julia will look at the type of the argument and compile the function for that type
    sum_fn(splits) = sum(parse(Int, x) for x in splits)
    # Putting the code inside a function makes more performant because of how the Julia compiler works
    function main()
    line = readline()
    splits = split(line, " ")
    result = sum_fn(splits)
    @show result
    end
    main()

    • @sashaabramowitz8440
      @sashaabramowitz8440 Před rokem +5

      Also wanted to add that Julia has the pipe operator too, not only Elixir

    • @Kruglord
      @Kruglord Před rokem +3

      Yes, I came here to say that, plus it supports the pipe operator too. I actually tend to write my code using a lot of `Base.Iterators.map` and `Base.Iterators.filter` so that they'll be lazy in their execution lol.
      ```julia
      parse_Int(x) = parse(Int, x)
      function main()
      # Rather than the infinite loop, you can use eachline() to create an iterator of the lines from stdin
      for line in eachline()
      line |>
      split .|> # Broadcast pipe, applies the subsequent function to the elements of the input, rather than the whole input
      parse_Int |>
      sum |>
      println
      end
      end
      main()
      ```

  • @jasongoldberger1
    @jasongoldberger1 Před rokem +11

    As an Elixir expert I deem this code to be not quite idiomatic, but it showcases pattern-match destructuring and recursion which is, IMO, a better show and tell than using the Enum module to map and sum.

    • @codetothemoon
      @codetothemoon  Před rokem +1

      Thanks, I'm learning a ton from experts such as yourself in each of these languages. I believe there is representation for every single one in the comments, which is really cool

  • @SianaGearz
    @SianaGearz Před rokem +9

    I'm gearing up for a larger project in Rust, and depending how it goes, I might chose Nim for another medium size but much smaller project. Nim looks like SO much fun!

    • @codetothemoon
      @codetothemoon  Před rokem

      nice!! yeah I was really impressed with nim. Somebody mentioned in the comments that they were working on a borrow checking option - now that would be a game changer

  • @aNotoriousPhD
    @aNotoriousPhD Před rokem +7

    Idk if anyone has mentioned it, but for elixir, one easier way of running that code could've been using a .exs file (elixir script) instead. And then just do `elixir .exs` to run it. It's pretty nice

  • @intelqa5334
    @intelqa5334 Před rokem +5

    Crystal program can be made even more compact.
    loop do
    line = gets || "0"
    puts line.split.map(&.to_i).sum
    end

  • @the_mastermage
    @the_mastermage Před rokem +3

    Julia is not just optional type annotation, it is optional type checking. If you anotate a variable with a type you cannot assign it another type, the compiler will throw you an error there.

    • @codetothemoon
      @codetothemoon  Před rokem

      thanks for pointing this out! the distinction is subtle but probably important to be aware of

  • @XerosOfficial
    @XerosOfficial Před rokem +7

    Great video! I would love to see a video about Haxe. One of my favourite languages, with an incredible balance for utility and performance. It also has quite a mature ecosystem for how unknown it is.

    • @codetothemoon
      @codetothemoon  Před rokem +1

      Thanks, I've put Haxe on my "to check out" list - which is swelling in size quite rapidly (I see that as a good thing)!

  • @BohdanTrotsenko
    @BohdanTrotsenko Před rokem +1

    That was very concise, thanks.

    • @codetothemoon
      @codetothemoon  Před rokem

      you're welcome, thanks for watching - brevity is one of my core tenets 🏎️

  • @cyanophage4351
    @cyanophage4351 Před rokem +2

    Crystal is the one I was most interested in here. Thanks for informing me about it. I will be checking it out

    • @codetothemoon
      @codetothemoon  Před rokem

      nice, yeah I was really impressed with Crystal. Definitely worth a look imo!

  • @Tablis0
    @Tablis0 Před rokem +4

    The Julia example is written in a very unJulia way which does not make good use of features of the language. All the reading and summing can be written very concisely:
    sum(s->parse(Int,s), split(readline(), " "))
    or
    sum(parse.(Int,split(readline(), " ")))
    or
    sum(split(readline(), " ") do s
    parse(Int,s)
    end
    You can divide it somehow to make it more readable, but the version presented for me seem to only make the language look more ugly and confusing.

  • @glennmiller394
    @glennmiller394 Před rokem +3

    Good subject matter. You used languages I've never heard of. Thanks for the video.

    • @codetothemoon
      @codetothemoon  Před rokem +1

      Thanks, part of me was worried folks would say something to the effect of "we've already tried all of these", glad to hear that's not the case!

  • @juancarlospaco
    @juancarlospaco Před rokem +2

    Nim has memory safety with no garbage collector.

    • @codetothemoon
      @codetothemoon  Před rokem

      I should have qualified that statement a bit more - all of its mechanisms for memory safety involve some kind of runtime overhead - ie reference counting or garbage collection

  • @ChristopheTroestler
    @ChristopheTroestler Před rokem +7

    Thanks for a fun comparison. Note that you do not need to collect the elements of split_whitespace() just to transform them back to an iterator after. Of course the signature of *sum_fn* then becomes slightly longer:
    fn sum_fn) -> i32 {
    n.map(|e| e.parse::().unwrap()).sum()
    }
    fn main() {
    loop {
    let mut buffer = String::new();
    stdin().read_line(&mut buffer).unwrap();
    println!("{}", sum_fn(buffer.split_whitespace()));
    }
    }

  • @modolief
    @modolief Před rokem +1

    Superb video!!

  • @bluedark7724
    @bluedark7724 Před 9 měsíci +2

    Rust you might want use the Buffer String type - it strips out the /n /r raw data from the keyboard entry, also your parsing() isn't capturing the Return type, which handles errors.

  • @TeamPuzel
    @TeamPuzel Před rokem +5

    Swift implementation, with error handling :)
    while true {
    print("input: ", terminator: "")
    print((readLine() ?? "0")
    .split(separator: " ")
    .compactMap { Int($0) }
    .reduce(0, +)
    )
    }
    It's a really cool language, has extremely good C and C++ interoperability too :)
    It's often seen as "the Apple language" sadly, but just ignore the obj-c classes and use structs, it's even adding Rust like ownership soon

    • @v01d_r34l1ty
      @v01d_r34l1ty Před rokem

      I won't even lie to you, I didn't know Swift worked on anything but Apple products until this comment. Guess it's in the same boat as C# now in the sense that it was originally for a proprietary system but expanded compatibility. Interesting.

    • @TeamPuzel
      @TeamPuzel Před rokem +1

      @@v01d_r34l1ty Yeah, the connection to Apple makes the language look bad; actual Swift code looks completely different from the decades old object oriented apis, but that's what most people will see when they look up Swift on google or CZcams.
      It also looks really high level, so at first I assumed it must be slower than Rust; there's no semicolons after all 🙂

  • @gabriellasso8808
    @gabriellasso8808 Před rokem +11

    Actually ORC, one of Nim's memory management strategies, is memory safe without a garbage collector, it has a deterministic performance due to its nature, so it can work like Rust if you annotate your data structures as acyclic and don't mess up (if you mess up, the compiler identifies that and insert cycle detection code to free the memory when needed)

    • @codetothemoon
      @codetothemoon  Před rokem

      In this documentation I see "ORC" referred to as a "full blown garbage collector" nim-lang.org/blog/2020/10/15/introduction-to-arc-orc-in-nim.html

    • @deadvirgin428
      @deadvirgin428 Před rokem

      Reference counting IS garbage collection (even if very lightweight), that's what the "RC" in ORC stands for. Cycle collection is also garbage collection, which is what the "O" in ORC represents. Not to say that there is anything wrong with it, Nim is wonderful and so is ORC. ORC is great because it allows you to prototype your code very easily without being forced to think about memory, you can always come back and optimize later (which IMO is the optimal workflow), you can still use memory pools or whatever memory management scheme you would want to use in Rust, you are just not required to worry about such things from the get-go and just leave it to the GC until you require better performance.

  • @jsonkody
    @jsonkody Před rokem +5

    Julia synax is inspired more by Ruby than Python.
    Thx for nice video :D

  • @benitoe.4878
    @benitoe.4878 Před 5 měsíci

    Thanks for presenting an example of Julia code as well.

  • @Gelo2000origami
    @Gelo2000origami Před rokem +5

    This should be made into a repo and take in PRs so we get the best of the best in each language

    • @codetothemoon
      @codetothemoon  Před rokem +2

      it's all here! will gladly accept PRs. github.com/Me163/youtube/tree/main/RustVsSevenLanguages

  • @lawrencejob
    @lawrencejob Před rokem +3

    I would love to see Roc in the next one

    • @codetothemoon
      @codetothemoon  Před rokem

      that's one i hadn't heard of, thanks for putting it on my radar!

  • @BosonCollider
    @BosonCollider Před rokem +15

    Just a heads up that Elixir's pipe operator is from F# and that Julia has it as well
    My overall experience from delving deeper into the languages mentioned here is:
    1) Julia, Elixir, and Crystal are both incredibly beautiful and well designed languages that deserve more attention, and by this I do not just mean having a short basic syntax but that their underlying semantics are really well designed. Also they have a great macro system.
    2) Nim and especially Zig are incredibly disappointing and trying to use them without gc is a royal road to segfaults. With that said,
    Zig is easier to write than C or unsafe Rust in the sense that its compiler has less UB, but that also means the compiler is less free to optimize code.
    3) Haskell is great, but apart from maybe being a bit further from mainstream languages, I really wish its standard library could be rewritten from scratch with the benefit of hindsight and new language features, and that texts teaching it took algorithms seriously and made data structures like finger trees more prominent
    4) Lua could have been the perfect scripting language in the 90s instead of python/ruby/js/php, if its standard library was more batteries-included and if netscape could have picked it.

    • @astroid-ws4py
      @astroid-ws4py Před rokem

      And F# took that from OCaml, F# is basically "Microsoft's OCaml" or ".Net OCaml"

    • @batlin
      @batlin Před rokem

      Interesting insights. I used to use Elixir quite a lot and really liked it, although it's not the most performant language for compute-heavy work. We used it to replace a Python-based image-processing system in my old job and it not only produced a MUCH more efficient system, but we ended up with far less code to the same job better and with fewer bugs (immutability by default helped here too).
      I've used Haskell and Nim for fun, and did pretty much all of the 2020 and 2021 Advent of Code challenges in Haskell, and all the 2022 challenges in Nim (and a few in Crystal too). I'd have to disagree with your second point and say that Nim rarely got in my way or crashed, except when I tried to do some invalid casting of bytes to UTF-8, which did produce an unpleasant segfault. Apart from that it's been great. That said, I wasn't using it without a GC, and relied upon the newish "orc" system which is quite frugal.
      I really enjoyed working with Haskell too, although the purity of the type system started to get kinda heavy when I wanted to use dynamic programming and other mutation-heavy coding styles. Using mutable arrays with the ST monad was okay but occasionally confusing and very difficult to debug (you can't just throw in a print statement anywhere), and there doesn't seem to be a mutable hashmap type in the stdlib, so I had to do weird things like manually mapping keys into an integer space and using a vector/array instead.

  • @tintindb
    @tintindb Před rokem +3

    Zig? I keep learning even when I don't expect to.
    And btw the comments are also interesting.
    Oh yeah, there's also Pharo?
    Great post.

    • @codetothemoon
      @codetothemoon  Před rokem +1

      nice! I agree the comments are really insightful - I think I've heard from at least one expert in each of the languages covered in the video which is amazing. Also many point out tech that I hadn't heard of before, this one is a good example. I've put Pharo on my "to look into" list!

  • @frittex
    @frittex Před rokem +5

    defo gonna try out crystal, thank you

    • @codetothemoon
      @codetothemoon  Před rokem +2

      Crystal does seem like a great language - thanks for watching!

  • @jpVoltDeveloper
    @jpVoltDeveloper Před rokem +1

    Thanks!

  • @bocckoka
    @bocckoka Před rokem +15

    That Rust implementation made me screech autistically a bit. split_ws -> parse -> sum, no collect.

    • @codetothemoon
      @codetothemoon  Před rokem +4

      Wow yes, thanks for pointing this out! Sadly I don't think it's the only version of this program that I implemented sub optimally...

  • @deadvirgin428
    @deadvirgin428 Před rokem +1

    Here is an idiomatic version of the sum procedure in the nim program:
    proc sum(arr: seq[string]): int =
    for x in arr:
    result += parseInt(x)

  •  Před rokem +2

    other nim version
    import std/strutils
    import std/sugar # Syntactic sugar for several things, in this case anonymous functions "=>"
    import std/sequtils
    proc sum_fn(the_arr:seq[string]): int =
    the_arr
    .map(x => x.parseInt)
    .foldl(a+b)
    while true:
    stdin
    .readline
    .split
    .sum_fn
    .echo
    in nim, sum(mult(x)) is the same that x.mult().sum() or whitout paramters x.mult.sum

  • @agustinpizarro
    @agustinpizarro Před rokem +2

    nim callback can be made simpler with "sugar" module

  • @Speykious
    @Speykious Před rokem +2

    For the Haskell solution, you can also write sum_fn like this:
    sumFn = sum . map (\s -> read s :: Integer)
    This is function composition and eliminates the need to write the argument that is being taken.

    • @Axman6
      @Axman6 Před rokem +4

      sum . map (read @Integer)
      The whole app can just be:
      main = forever (print @Integer . sum . map read . words =

  • @batlin
    @batlin Před rokem +2

    Nice intro -- it's great to see really nice lesser-known languages like Nim and Crystal get more of a spotlight. BTW, for this type of program in Haskell you can sometimes use "interact", although it can behave surprisingly due to laziness, so I had to use lines / unlines in this example:
    sum_fn = sum . map (\s -> read s :: Integer)
    main = interact $ unlines . map (show . sum_fn . words) . lines

  • @navi93243
    @navi93243 Před rokem +2

    Nice, For people who are interested in data science, Julia is a great language to explore! I moved part of my workflow from Python to Julia.

    • @codetothemoon
      @codetothemoon  Před rokem

      I was indeed pretty impressed with Julia. With Mojo coming along, it'll be interesting to see how the landscape evolves in the coming years

  • @matthiasschuster9505
    @matthiasschuster9505 Před rokem +4

    9:40 You declared yourself at the beginning of the video, that Nim has reference counting and manual memory management
    By the way: There you said actually something that could be considered different as you intended
    You said: Nim has manual memory management - like C.
    MM in Nim is actually a lot more concise and simple than in C
    I know you meant its manual in both ways, and this is true
    Its just not manual in the same way ;)
    P.S: Nim has also a borrow checker in the works

  • @jsonkody
    @jsonkody Před rokem +4

    Julia synax is inspired by Ruby, not Python.
    Thx for nice video :D

    • @codetothemoon
      @codetothemoon  Před rokem

      ahh thanks for pointing this out, that makes more sense!

  • @VioletCowelicious
    @VioletCowelicious Před rokem +3

    Haskell has the pipe operator too :)
    It's called (&) and it's in Data.Function.
    Because Haskell lets you define your own operators, it's not built-in syntax, and you could define it yourself.
    You can even write `(|>) = (&)` to get the same syntax as elixir.
    It passes the LHS as to the RHS as its last parameter, instead of its first parameter.
    (Although of course all functions in Haskell only take one parameter because of currying).

  • @raianmr2843
    @raianmr2843 Před rokem +3

    You should've covered Clojure, or any flavor of lisp tbh. Picking a slightly more interesting program next time would be much appreciated. The quicksort algorithm, for example, can have vastly different implementations depending on the paradigm. That said, thanks for the video, really enjoyed the comparisons.

    • @codetothemoon
      @codetothemoon  Před rokem

      Thanks for the feedback, maybe in the next one!

  • @sp.n7401
    @sp.n7401 Před rokem +6

    Do Nim's ARC/ORC memory models compete with Rust's memory safety? My understanding is during compile time it will automatically insert memory de-allocations similar to how Rust does it.

    • @codetothemoon
      @codetothemoon  Před rokem +2

      I'm definitely not a nim expert - but my understanding was that you can opt-in to reference counting or garbage collection if you want to guarantee memory safety, but if you opt out of that, you incur the same memory management risks that you would have with C/C++. Somebody jump in here if this is wrong!

    • @agustinpizarro
      @agustinpizarro Před rokem +1

      @@codetothemoon It is not "safe" as Rust, but ARC/ORC are deterministic memory handling as C++ but with some memory handling done automatically for you, like you'll do with shared_ptr in C++

  • @hipertracker
    @hipertracker Před 11 měsíci +1

    Elixir has loops and reduce (foldr). It does not need to use recursion. E.g you could use:
    def sum_fn(strs) do
    List.foldl(strs, 0, fn s, acc -> String.to_integer(s) + acc end)
    end
    or
    def sum_fn(strs) do
    Enum.reduce(strs, 0, fn s, acc -> String.to_integer(s) + acc end)
    end

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

      thanks for pointing this out, this is much cleaner! I've been learning a ton from the reactions of the experts in each language showcased in this video.

  • @randomthings1553
    @randomthings1553 Před rokem +2

    I would also add clojure for how short code can look, also clojure has very interisting way oh hadling/embracing null/nil intead of avoiding it.
    (->> (s/split (read-line) #",")
    (map #(Integer/parseInt %))
    (apply +)
    (println))

    • @codetothemoon
      @codetothemoon  Před rokem

      oh nice that one is really concise too! I'm still wrapping my head around the Lisps, might have more coverage of them once I find my footing

  • @seanknowles9985
    @seanknowles9985 Před rokem +5

    Zig is next level, will take the crown very soon 👑

    • @codetothemoon
      @codetothemoon  Před rokem

      interesting, why do you think that is?

    • @seanknowles9985
      @seanknowles9985 Před rokem +2

      @@codetothemoon Great question. So off the top, coming in hot.
      - Simple syntax: Zig has a simple syntax comparable to Go, maybe even easier due to it's clever error handling and that it launched with generics.
      - No garbabe collector: The issues with Nim as much of the standard library is already relient on the GC.
      - Easier to code in the Rust, my god, Rust is amazing but imagine coupling the safety of Rust with a Golang Syntax = Zig.
      - Complete compatibity with C libs and C++
      - The cross compilation is super fast and is being used by other languages to hit those targets, other languages are leveraging Zig already for compliation work.
      - C speed, and faster than C with better compiler. Basically if your a C developer you're being advised to use Zig to compile your C code.
      Zig will replace C, that's without a doubt. I even speculate it replacing Golang down the line as the memory management is easy. So why comprimise on speed when you don't need to.
      Zig has about two years of catch up planned to reach 1.0 and for editor tooling to evolve.

    • @nicktreleaven4119
      @nicktreleaven4119 Před rokem +2

      @@seanknowles9985 does zig have a 100% memory safe subset? That's required by the US NSA guidelines.

    • @seanknowles9985
      @seanknowles9985 Před rokem +3

      @@nicktreleaven4119 good question! I'll throw it to the development team :)

  • @DNA912
    @DNA912 Před rokem +1

    I used haskell in a universaty course about programming languages paradigms and general stuff. I haven't used in since, but I really do remember how beautiful and concise the code was

    • @codetothemoon
      @codetothemoon  Před rokem

      yeah it sure is - i had to use ocaml for a course in university, and I remember being really frustrated with it. I was too shortsighted to appreciate the beautify of it back then, but I sure do now

  • @mohanaggarwal4058
    @mohanaggarwal4058 Před 6 měsíci +1

    U can improve ur nim code a bit:
    import strutils, stdutils
    proc sumFn(theArr: seq[string]): int =
    theArr.mapIt(it.parseInt)
    .foldl(a+b)
    while true:
    let
    line = stdin.readline
    arr = line.split
    sum = sumFn(arr)
    echo sum
    # end of program
    Note: No need to use different lines to import different modules, nim compiler removes underscores from indentifiers so it is better to use camelCase instead of snake_case, use mapIt to improve readability and for writing concise code, no need to write return or result at the end of function, function will return that value automatically. Multiple let or var or const statements can be combined into one, thus making code more concise.

  • @frittex
    @frittex Před rokem +4

    love the typing sound

    • @codetothemoon
      @codetothemoon  Před rokem

      Thanks, I actually mic'd up the keyboard for this one thinking folks might like it

    • @frittex
      @frittex Před rokem

      @@codetothemoon it adds a little more "depth" to the typing animation, and overall the sound you got is just nice to the ear

  • @chocolate4212
    @chocolate4212 Před rokem +1

    More concise Crystal version:
    def get_sum(splits)
    splits.map(&.to_i).sum
    end
    loop do
    gets.try do |line|
    puts get_sum(line.split)
    end
    end
    You don't even need the get_sum method:
    loop do
    gets.try do |line|
    puts line.split.map(&.to_i).sum
    end
    end
    Overall, nice video.

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

    In rust I think you need to specify the type for collected because the compiler can't infere it

  • @francisking708
    @francisking708 Před 5 měsíci +2

    If you like the pipe operator in Elixir, you might also like F#

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

      oh nice I'd like to check it out! definitely heard F# mentioned in the context of underrated/overlooked languages....

    • @fsharplove
      @fsharplove Před 3 měsíci

      As of today, one language should be very special to make me ever consider using it. F# is awesome!

    • @fsharplove
      @fsharplove Před 3 měsíci

      @@codetothemoon Yes, this is my takeaway from learning and using F#. It is a very underrated language and popular languages are not always the best ones.

  • @caddr
    @caddr Před rokem +1

    there is function composition operator (.) in haskell that works like pipe operator (|>), but in reverse

    • @codetothemoon
      @codetothemoon  Před rokem

      Actually this one was on my radar, but for some reason I never really thought of it as the reverse of the pipe operator!

  • @guilherme5094
    @guilherme5094 Před rokem +1

    Really nice👍

  • @kellywilson7585
    @kellywilson7585 Před rokem +12

    Zig solution in 15 lines. Use anytype for parameter type inference in sum_nums declaration. The one line while loop in sum_nums is idiomatic (as long as it isn't more than 80 chars):
    const std = @import("std");
    fn sum_nums(it: anytype) !i32 {
    var sum: i32 = 0;
    while (it.next()) |string| sum += try std.fmt.parseInt(i32, string, 10);
    return sum;
    }
    pub fn main() !void {
    var buf: [10]u8 = undefined;
    while (try io.getStdIn().reader().readUntilDelimiterOrEof(buf[0..], '
    ')) |user_input| {
    var splits = std.mem.split(u8, user_input, " ");
    std.debug.print("{}
    ", .{try sum_nums(&splits)});
    }
    }

    • @adicide9070
      @adicide9070 Před rokem +5

      this "while" line is like the most dense matter in the universe :D

    • @recklessroges
      @recklessroges Před rokem +1

      @@adicide9070 oh I thought it was just perl 😀

  • @EdouardTavinor
    @EdouardTavinor Před rokem +1

    In lisps the pipe is called the threading macro btw.
    I get scared looking at that rust code.

  • @fabianthorsen8925
    @fabianthorsen8925 Před rokem

    Which font are you using? Amazing video, keep up the good content!

  • @lunalect
    @lunalect Před rokem +2

    Julia has the |> operator too…

  • @smalltimer666
    @smalltimer666 Před 5 měsíci +1

    Julia also has an excellent pipe operator !

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

    would love to see Gleam in the next edition of this video!

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

      yeah i've been itching to give Gleam a spin, it looks really nice!

  • @Borkolini
    @Borkolini Před rokem +1

    How about Clojure?

  • @SchmidiAUT
    @SchmidiAUT Před 3 měsíci +1

    I feel the Julia version is unnecessary verbose, one could just write:
    while true
    readline() |> split .|> (x -> parse(Int, x)) |> sum |> println
    end
    So in Julia this exercise takes only 3 lines of code.

  • @matroqueta6825
    @matroqueta6825 Před rokem +2

    Julia also has Elixir's |> operator, it does the same thing!
    On behalf of all Julians I demand that the Elixirites share their trophy with us... or give us a copy of the trophy (we respect that functional programmers dislike shared state)

  • @AndrewBrownK
    @AndrewBrownK Před rokem

    excellent compact video that doesn't waste any time

  • @pikachu7748
    @pikachu7748 Před rokem +2

    I think Julia has the same pipe operator as Elixir

  • @thedeemon
    @thedeemon Před rokem +1

    |> is just function application (call), same as $ in Haskell just in opposite direction. Nothing to do with map.

  • @HalfMonty11
    @HalfMonty11 Před rokem +2

    Interesting video... but I like the end "Has my love for rust waned? It hasn't"
    Very good point. Other languages can have maybe better syntax changes or some ergonomics but that's not worth losing memory safety with no garbage collection. If some other language tried to implement memory safety with no garbage collection with better ergonomics... Rust would probably just adopt those ergonomics too because it's constantly improving and gaining ergonomics. It's hard to even fathom something better unless there's some massive rift/scandal in the main contributors and people who manage and use the language which would be surprising because the community is so good.

  • @wlockuz4467
    @wlockuz4467 Před rokem

    Am I missing something or did you miss the split delimiter in Nim example and passed an empty delimiter instead of a space for Julia example?

  • @matthewscott336
    @matthewscott336 Před rokem +6

    Julia is underrated

  • @WhiterockFTP
    @WhiterockFTP Před rokem +2

    Nim certainly is trying hard to have the memory safety of Rust.

  • @kamertonaudiophileplayer847

    I also wrote a blog for the topic.

  • @kcvinu
    @kcvinu Před rokem +2

    There are Odin, C3 & D. Please try them also. Anyhow, I didn't understand a single line from your rust code.

    • @codetothemoon
      @codetothemoon  Před rokem +1

      Thanks for pointing these languages out, I've heard Odin mentioned a few times. Would be happy to walk you through the Rust code if you like!

    • @kcvinu
      @kcvinu Před rokem

      @@codetothemoon Oh, that's great. I would like to use this opportunity to ask some questions.
      1. You declared the buffer as mutable. So the compiler can understands that buffer is mutable. But why we need to use &mut with buffer in next line ? Didn't the compiler already understand that?
      2. What does unwrap() does ?

    • @brdrnda3805
      @brdrnda3805 Před rokem +1

      @@kcvinu 1. Rust is sometimes quite explicit not because the compiler couldn't understand it but to have it explicitly mentioned in the code for the human reader. Something with references. In C++ you define whether something is passed by reference in the function header and you don't see it in the call at all. So it's more like: This is important information for the reader of the calling code / code that uses a function, so it has to be given explicitly. Rust is not very explicit in other cases (type inference is heavily used)
      Edit: That's not a Rust invention, if I remember correctly C# is also already more explicit than C/C++ with these things)
      Edit2: You could also immutably pass a mutable String to a function. So the let mut buffer says it can be mutated (in general) and the read_line(&mut buffer) says it can mutated within read_line.
      2. There are two things, which are very commonly used in Rust: Option and Result. Option is used when you expect a value, but it could also be that there is no value - the "no-value" is called None. It's basically the replacement for Null. Result is you expect a result (from a function) but it could be that you get an error. It's Rust's error handling (instead of try..catch or the different variants of error return values in C). What both have in common is, that you Rust forces you to deal with the "extra" cases (None, Error). The "dirty" way is using unwrap(), which says: I know what I'm doing, there is a value inside this Option/Result, just unwrap it and give it to me. If you're wrong and there is a None or an Error the program will crash.

  • @elau1004
    @elau1004 Před 9 měsíci +2

    Can do a review on the V language? Thanks.

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

      actually already did! if you want the original version it's here: czcams.com/video/jr1EBaLkjfc/video.html
      BUT if you want the version with Primeagen commentary (recommended) you can find that here: czcams.com/video/j47Hk5qE9As/video.html

  • @jenreiss3107
    @jenreiss3107 Před rokem +1

    the haskell implementation would look nicer by using the `interact :: (String -> String) -> IO ()` function as well as using the point free style: `main = interact (print . sum . map read . words) >> main`. I'm surprised your editor didn't say "Hey, eta reduce!"

    • @chaddaifouche536
      @chaddaifouche536 Před rokem

      Good idea, though remember that interact want (String -> String) so no print in your function. You also don't need to recurse, if you want to do "f" line by line, you can always use `interact (unlines . map f . lines)`. Here, with TypeApplications to specify the Read type elegantly, you can do this :
      interact $ unlines . map (show . sum . map (read @Integer) . words) . lines

    • @jenreiss3107
      @jenreiss3107 Před rokem

      @@chaddaifouche536 amazing. love the type application! thanks for the correction too, I didn't think interact automatically recursed

  • @diktomat
    @diktomat Před rokem +1

    Hah! Actually tried all of them last month, when I did Advent of Code using a different language each day 😂

  • @kebien6020
    @kebien6020 Před rokem

    How to get the |> operator in Haskell:
    infixl 1 |>
    x |> f = f x
    Alternatively, it is already in the base library, you just have to import it. It's called & but you can alias it to |> if you want
    import Data.Function ((&))
    (|>) = (&)

  • @kimdilotmane2708
    @kimdilotmane2708 Před rokem +1

    You have such a very good Doom Emacs config can we get the link to it please ?

    • @codetothemoon
      @codetothemoon  Před rokem

      I'm not doing anything special, I just uncommented the relevant programming languages in init.el and switched to the monokai-pro theme. The only real config I had to add was some stuff to get Zig working, since I don't think DOOM supports it out of the box.

  • @shaileshsundram
    @shaileshsundram Před rokem +1

    What app(s) are you using for screencasting, esp the terminal window?

  • @salvadoraugustovitko1396
    @salvadoraugustovitko1396 Před 11 měsíci +2

    Please talk more about crystal, I really love the language but it doesn't have much traction😢

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

      I was really impressed by it too and was also surprised by its lack of popularity. i hope to be able to cover it more!

  • @debasishraychawdhuri
    @debasishraychawdhuri Před rokem +1

    All these languages are just a little collaj of existing language features. Rust is just new. The borrow checker is a completely new feature and it is the best way to statically manage memory.

    • @codetothemoon
      @codetothemoon  Před rokem

      I agree that the borrow checker takes the cake for the most recent language feature that is truly innovative

  • @JaycenGiga
    @JaycenGiga Před rokem +1

    If you really want to see this problem solved concisely, you should look at APL. I’m not sure if my implementation is correct (I am a beginner at APL and I don’t have an interpreter available right now) but it should be something like the following:
    {⎕←+/⍎v ←⎕ ⋄ ∇}
    The braces denote an anonymous function, and ⋄ separates statements. The first statement does IO and all the logic, and the second one is the recursion. It should be possible to do be even more concise (without an anonymous function) but my APL is not good enough to know how to do it.

    • @dalek6779
      @dalek6779 Před rokem +1

      It's even easier than you think, but kudos for learning. Try this +/⎕
      ⎕ (quad) by itself means read a line from standard input and evaluate as an APL expression. So if you type in a bunch of integers it'll turn it into an integer array. Then obviously +/ just sums it up and outputs.

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

    Pony would be another interesting one to compare

  • @dalek6779
    @dalek6779 Před rokem +5

    Here's a surprise you didn't see coming. Let's not forget about functional programming's cousin, array programming. Trivial in APL +/⎕

    • @codetothemoon
      @codetothemoon  Před rokem +1

      heard a little bit about APL, definately one I'd love to look into

  • @jedisct1
    @jedisct1 Před rokem +3

    Zig is so much fun to use.

    • @codetothemoon
      @codetothemoon  Před rokem

      what makes it fun? I got a bit of exposure to it while making this video, but I still don't feel like I have the whole picture...

  • @matthiasschuster9505
    @matthiasschuster9505 Před rokem

    5:35 If you like that feature, you might love FSharp, who come up with this operator and is very cute overall
    Like Elixir, just statically typed with the most accurate type inference you had ever seen
    And dotnet as a platform

    • @terryriley6410
      @terryriley6410 Před 10 měsíci +1

      stop spreading this misinformation, the pipe operator has been around long before f#

  • @TheRealisticNihilist
    @TheRealisticNihilist Před rokem

    I really thought that dark spot on your shirt was a stain until it moved when you moved.

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

    Hey, would have been cool to actually show comparison between 'business' LOC and ones that glue it in-between. I never actually expected zig to be so cumbersome. Anyways here is the same thing in C#, I think it's a mix of both worlds in terms of expressiveness and fast-ness Console.WriteLine(Console.ReadLine().Split(' ').Sum(int.Parse));

    • @rafaelrosa3841
      @rafaelrosa3841 Před rokem +1

      Zig is a simple language as c is. So it can be more verbose but the learning is easier and the code is more predictable.

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

      c# is just wrong, pointless overuse of capital letters and braces.

    • @user-dc9zo7ek5j
      @user-dc9zo7ek5j Před 10 měsíci

      @@terryriley6410 cs is the other name that it has, but still has 2 characters :(

  • @Lambdaphile
    @Lambdaphile Před rokem

    Bo love for Lisp family languages? :( Wish there was Clojure also.

  • @jedediah-fanuel
    @jedediah-fanuel Před rokem +4

    Crystal gang

  • @sbditto85
    @sbditto85 Před rokem +1

    FWIW I believe Haskells & operator in Data.Function is the same as elixirs |> … doesn’t look as cool though.

    • @codetothemoon
      @codetothemoon  Před rokem

      ohh I didn't know about this, I'll give it a spin - but yes I agree |> is much more aesthetically pleasing 🙃

  • @Ratstail91
    @Ratstail91 Před rokem

    So I was gonna post my Toy version here, but then realized that Toy doesn't have any kind of terminal input library yet... It's a good lang, I swear!

  • @X-Dev_lols
    @X-Dev_lols Před 25 dny

    Recursion is GREAT if you know what you're doing, it just requires different syntax and can cause memory uncrease (although I like minimizing vars in functions anyway \_[-_-]_/).

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

    In Haskell instead of using map with a lambda you can use list comprehension. It's significantly more readable imo
    sum_fn ws = sum $ map (\s -> read s :: Integer) ws
    sum_fn ws = sum [read s :: Integer | s > main

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

      After seeing Haskell's `interact` mentioned in the comments, I figured out how to make the Idris version even sleeker:
      import System.REPL
      import Data.String
      main : IO ()
      main = repl "
      " (cast . sum . map cast . words)