Rust vs Java: A Staff Engineer's perspective

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ค. 2024
  • Are you trying to decide between Rust and Java for your next project? Look no further! In this video, Dario Lencina, staff engineer compares the two programming languages in terms of concurrency, syntax, licensing, and tooling. Whether you're a seasoned developer or new to the scene, this video has something for everyone. So sit back, relax, and let us help you make an informed decision on Rust vs Java.
    If you're wondering if Rust is a good language for you, or if Java is still the king of the hill, then this video is for you! I'll share my thoughts on the different languages, and let you know which one I think is the best for certain scenarios. So what are you waiting for? Watch the video and make your decision!
    I am doing this, because you, my dear subscribers requested it.
    Here's my cheatsheet so that you can follow along! security-union.github.io/rust...
    Code: github.com/security-union/rus...
    00:00 Java vs Rust Intro
    00:14 Apple Pay uses Java
    00:21 AWS wants to contribute to Rust
    00:56 Rust vs Java motivation and methodology
    01:36 How not to compare java and rust
    02:00 Table of contents
    02:28 Java language goals
    03:54 Java Licensing
    04:50 Rust Security
    05:32 How Memory Management works in java
    06:15 How Memory Management works in rust
    07:07 Dangling pointer in Java
    08:23 Dangling pointer in Rust
    09:10 Null pointer in Java
    09:33 There are no null pointers in Rust
    09:38 Making rust panic using refcell
    10:00 Compilation
    10:46 Blocking Concurrency
    10:57 Deadlock in java
    12:10 Deadlock in rustlang
    13:19 Non Blocking concurrency
    13:30 Create multithreaded mpmc channel with java vs rust
    18:21 Tooling
    19:00 Install java sdk with sdkman
    19:13 managing rust toolchain with rustup
    19:54 Using sdk man to install gradle
    20:49 create rust project with cargo
    21:14 Spring boot vs actix memory and cpu comparison
    23:49 Conclusions: both are awesome, (but Rust is newer and better)
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 62

  • @hamdysaadpersonal
    @hamdysaadpersonal ปีที่แล้ว +10

    💞💞 this is the real full comparison.
    And Thank you Dario for the shoutout 💞🔥

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว +1

      Thank you my friend, I hope you have an awesome 2023!!

  • @ReedoTV
    @ReedoTV ปีที่แล้ว +9

    I write Rust so I can keep my passion alive and I write Java so I can stay employed

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว

      The market is ready for rust developers! Checkout all the positions on LinkedIn

    • @gmodrules123456789
      @gmodrules123456789 ปีที่แล้ว +2

      Java can be fun if you write it intuitively rather than following some strict guideline

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว

      I agree! I remember the Java EE enterprise beans stuff, it makes me sad!

  • @olexandrkostiuk9653
    @olexandrkostiuk9653 8 หลายเดือนก่อน +4

    There is a little mistake in mpmc section related to Java assumptions. You must pass the final or effectively final variable to lambda but not to thread. And behavior for primitives and objects are the same. In Java, all parameters are passed by value. In the case of an object, the value is a reference to that object, so the reference still keeps the final props. But anyway, it's a great video!

    • @dario.lencina
      @dario.lencina  8 หลายเดือนก่อน

      Thanks for the feedback mate 👀👀

  • @RealViPdude
    @RealViPdude 4 หลายเดือนก่อน +4

    people who complain about the main method in java have no idea what theyre talking about.

    • @dario.lencina
      @dario.lencina  4 หลายเดือนก่อน

      That is exactly right, nowadays you do not even have to type it, the use will do it for ya

  • @kuqmua755
    @kuqmua755 ปีที่แล้ว +2

    great video! about dead locks - is there any abstraction around rust Arc to prevent it? like all of your values must implement some trait to use it between threads - and throw error on compile time if you trying to do so

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว +2

      Hey @kuqmua! I found RwLock so that you can only get one write lock at the time which helps! doc.rust-lang.org/std/sync/struct.RwLock.html
      This type of lock allows a number of readers or at most one writer at any point in time. The write portion of this lock typically allows modification of the underlying data (exclusive access) and the read portion of this lock typically allows for read-only access (shared access).

  • @karimjedda
    @karimjedda ปีที่แล้ว +4

    Great video and thanks for going into the details. I've grew up with Java/C++/Python and been learning some Rust for a year as an additional tool to get things done. It's been a pleasure to work with.

    • @dario.lencina
      @dario.lencina  หลายเดือนก่อน +1

      glad to hear my friend!!

  • @Taurdil
    @Taurdil 10 หลายเดือนก่อน +5

    Compilation times would be nice to compare. Say, Spring Boot vs Actix or smth. That would be the place Java shines, especially because it doesn't need to recompile all your dependencies even once.
    But the real difference would be in the possibilities. In Java, you can change byte code during loading (per class basis) so you can write your "agent" which would instrument client's code with whatever logic you need. It is utilised heavily by telemetry libraries such as DataDog , OpenTelemetry, etc. In Rust, I think, you have to instrument your code manually.
    And Java has pretty good Reflexion API. Haven't seen any in Rust
    These could be a real dealbreakers for some projects I think.

    • @dario.lencina
      @dario.lencina  10 หลายเดือนก่อน +2

      Yes! Compile time is still terrible in Rust! Also Java Agents are awesome! I completely forgot about them.
      I love how mature the Java echo system is!

  • @computerfan1079
    @computerfan1079 11 หลายเดือนก่อน +3

    I laughed out loud multiple times. I see your channel growing a lot

    • @dario.lencina
      @dario.lencina  11 หลายเดือนก่อน

      even as I was editing the video the part with the for loop "benchmark" had me laughing!!

  • @kuqmua755
    @kuqmua755 ปีที่แล้ว +1

    and yes, would like to talk about async programming. is there implicit timeout for async functions in rust and what happens if you reach it - and how handle timeout error for async functions without panic - with Result.

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว +1

      You got it chief!! I just added it to the queue, I'll include timeouts and some other common pitfalls!!

  • @professornumbskull5555
    @professornumbskull5555 ปีที่แล้ว +13

    There is null in rust, std::ptr::null

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว +5

      Yikes, thanks for pointing this out, how do you use it?

    • @professornumbskull5555
      @professornumbskull5555 ปีที่แล้ว +8

      ​@@dario.lencina You don't. Null pointer should not be used in application, in any form, unless you're working with Systems development. You can get a null pointer by invoking function, ptr::null(), which gives you a raw pointer, pointing to null, which to do anything with, you need to be in an unsafe block.

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว +1

      Makes sense, 👏🤗 thank you so much

  • @Gennys
    @Gennys 2 หลายเดือนก่อน +3

    I have one tiny nitpick about around 17:10 and in a couple other instances. If you want to compare the libraries of the languages to one another that's one thing. But it should be explicitly stated that you keep saying "Rust" and "Java" interchangeably with "Rust's libraries" and Java's libraries.
    I see people do this a LOT when they're comparing two languages but in fact they are just comparing the libraries for the language.

    • @dario.lencina
      @dario.lencina  2 หลายเดือนก่อน +1

      Thank you for bringing this to my attention. I appreciate your careful listening and your point is well-taken. I intended to compare the libraries available in Rust with those in Java, which indeed are distinct and should not have been referred to interchangeably. It’s important to be precise when discussing the characteristics and capabilities of different programming languages, and I’ll make sure to be more specific in future discussions. Thanks again for your feedback!

  • @morgomi
    @morgomi ปีที่แล้ว +2

    Ironically, I searched "Rust vs Java" and the first video was 1:36. I immediately closed it after seeing the while loop. :D Then youtube recommended this video on my homepage and here I'm. Such a cool channel.

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว +1

      Welcome to the party brother !! 🥳🎉

  • @RhinoInfo
    @RhinoInfo ปีที่แล้ว +4

    hi . a great video man . actually i would love to switch to rust . but i don't wanna dive wrong to the lang . could you please make a roadmap vid . so you share u'r experience with us . thanks for the vid again

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว +4

      Hey @Rhino, I'll definitely do this, the most common pitfall (imo) is to try to learn smart pointers and lifetimes in too much detail as opposed to copying objects around just to get started. In the mean time I recommend that you read doc.rust-lang.org/book/ it should take less than 4 hours and it provides a great "getting started" guide.
      Thank you so much for your feedback!

    • @v01d_r34l1ty
      @v01d_r34l1ty ปีที่แล้ว +2

      @@dario.lencina This is definitely an underappreciated comment. I've tried time and time again for about 3 years now to learn Rust. Kept giving up on it very quickly because ultimately every book gets right into the nitty gritty. On New Years, I was alone with my little bro, so I decided to try Axum again and successfully built a static web server with various API handlers! I learned more doing that than anything else so far.

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว +1

      @@v01d_r34l1ty neat!! 🤗👏 good for you, is it a public GitHub project that you can share?

    • @v01d_r34l1ty
      @v01d_r34l1ty ปีที่แล้ว +1

      ​@@dario.lencina Not yet! It will be once I get JSON web tokens and authentication implemented. I'm trying to make a very basic chat application (demo video on my channel).

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว +1

      @@v01d_r34l1ty sweet!!

  • @krellin
    @krellin 4 หลายเดือนก่อน +1

    Good video, and you are on point that everything is a tool, good engineers do not fanboy over one or the other just know what is better to use in which situation.
    Performance is not a perk of the language but your knowledge of how hardware works and how to write code that takes advantage of it. You can have insane performance with both.

    • @dario.lencina
      @dario.lencina  4 หลายเดือนก่อน

      That’s right my friend! Both are awesome tools!

    • @dario.lencina
      @dario.lencina  4 หลายเดือนก่อน

      Being analytical as opposed to fanboys is always better

  • @kobibr9362
    @kobibr9362 4 หลายเดือนก่อน +1

    Could a boxed value in Rust help create that dangling pointer?

    • @dario.lencina
      @dario.lencina  4 หลายเดือนก่อน

      You are saying that we could use Boxes to create dangling pointers? Wouldn’t the borrow checker prevent it?

  • @dr.rainereschrich1549
    @dr.rainereschrich1549 3 หลายเดือนก่อน +1

    You should also compare rust to Java + GraalVM Native image!

    • @dario.lencina
      @dario.lencina  3 หลายเดือนก่อน +1

      Wow 👀👀👀I need to look into that!! Thanks for sharing

  • @loophole3763
    @loophole3763 4 หลายเดือนก่อน +1

    so , first c, then java then rust,
    then life is set if the brain is good?

    • @dario.lencina
      @dario.lencina  4 หลายเดือนก่อน

      🤗🤗yes, it is the only way to illuminate and achieve nirvana

  • @coffee-is-power
    @coffee-is-power 11 หลายเดือนก่อน +1

    crossbeam is not necessary, it's already inside the std library on std::sync::mspc

    • @dario.lencina
      @dario.lencina  11 หลายเดือนก่อน

      Nice!! Good to know 🤗🤗🤗

  • @dario.lencina
    @dario.lencina  ปีที่แล้ว +1

    Here's my cheatsheet so that you can follow along! security-union.github.io/rust-vs-java/

  • @Razpirato
    @Razpirato ปีที่แล้ว +3

    Nice video but you need better mic etiquette. Constantly getting “plosives”.

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว

      Point taken, I’ll add a pop filter to deal with this, thanks for watching

    • @dariolencina3709
      @dariolencina3709 11 หลายเดือนก่อน

      Is this better th-cam.com/video/LWwOSZJwEJI/w-d-xo.html&ab_channel=SecurityUnion (added a pop filter)?

  • @Gabriel-zr4kz
    @Gabriel-zr4kz หลายเดือนก่อน +1

    Java is the best language in my Opinion (at least for learning), everything is literal and verbose. I hate programming languages like Python and Ruby, they seem to complicated for me and I don't know why (perhaps abstraction).
    My first language was Js/Ts but once you deal with maps, reduces it gets kinda weird. I'm a SDE nowadays and I only learned to program after I learned java. In my opinion the annoying boilerplate makes sense in my head.

    • @dario.lencina
      @dario.lencina  หลายเดือนก่อน +1

      Java does have its merits with explicit verbosity, which some find reassuring like a well-detailed map.
      Yet, isn't it thrilling to sometimes navigate the programming jungles with just a compass?
      Python and Ruby are like that, offering a concise syntax - it’s less about the roads taken and more about the adventure.
      Admittedly, Java's boilerplate can feel like a safety harness, but maybe after scaling the cliffs with JavaScript's flexibility, that harness just feels a bit too snug?
      As an SDE, you've mastered different terrains, so why not enjoy the view from all perspectives?

    • @Gabriel-zr4kz
      @Gabriel-zr4kz หลายเดือนก่อน +1

      ​@@dario.lencina What a comment! Yes .map in JS are pretty useful, but they only made sense when I made them in Java HAHA. like every other data structure One example is when I do Hackerrank/LeetCode challenges I do them in Java because it's easy for me and I'm a fullstack with strong frontend side and don't know why.
      I do well with C and C++ codes seems more well, but easier than Ruby/Python.

  • @codeman99-dev
    @codeman99-dev 5 หลายเดือนก่อน +1

    My guy. Turn off the dynamic zoom. Very distracting.

    • @dario.lencina
      @dario.lencina  5 หลายเดือนก่อน

      Thanks mate, I’ll consider it. Believe or not some people actually like it ?

    • @codeman99-dev
      @codeman99-dev 5 หลายเดือนก่อน +1

      @@dario.lencina interesting.
      I guess someone must. I can't watch Networkchuck because of his dual camera setup. He has quite the following though.

    • @dario.lencina
      @dario.lencina  5 หลายเดือนก่อน

      @99codemister I’ll make sure to make them less distracting

  • @doylemcguire1588
    @doylemcguire1588 ปีที่แล้ว +1

    Promo sm 😩

    • @dario.lencina
      @dario.lencina  11 หลายเดือนก่อน

      What's promo sm?

  • @ahuramazda9202
    @ahuramazda9202 ปีที่แล้ว +2

    A nonsensical and trivial comparison, and of course wrong.

    • @dario.lencina
      @dario.lencina  ปีที่แล้ว

      Lol, thanks for your feedback son, time to go eat your Java Beans 🫘