Rust features that impress me as a C# developer

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

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

  • @reinux
    @reinux 2 года назад +5

    Funny thing is F# has always had a lot of this stuff since it shares its ML roots with Rust, but since C# has been taking features from F# piecemeal instead of having them from the beginning, C# is now a much harder language to learn than F#.

    • @lindblomdev
      @lindblomdev  2 года назад +1

      I dabbled with F# a couple of years ago. One think in particular that I liked was the erased types, don't remember what they called them. Where I could make a type that only existed during compilation and prevented me from doing something like assigning a kilo number to a gram variable without converting it.
      The thing I didn't like with F# was that it felt alien as everything around it was C#:ey. I could not get over that.

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

      @@lindblomdev Unit of Measures. Nice thing is that some operations with different units are allowed. F.e. 120 / 2 returns 60

  • @arjix8738
    @arjix8738 2 года назад +3

    This looks like a promising channel!
    You sir got my sub.

    • @lindblomdev
      @lindblomdev  2 года назад +2

      Thanks, pressure is on to deliver now 😆

  • @irlshrek
    @irlshrek 2 года назад +11

    Love the rust content! Can you make the text a little bigger?

    • @lindblomdev
      @lindblomdev  2 года назад +4

      Yes I will increase it even more next time 👍 thanks for the feedback 👊

    • @The4valanche
      @The4valanche 2 года назад +3

      @@lindblomdev a huge part of the RUclips audience is watching on phones, so this is a really good idea. Might wanna go overboard and go as big as possible/aesthetic.
      Zen mode + zoom 👍
      Edit: increasing cursor size would be good while you're at it 😉

    • @lindblomdev
      @lindblomdev  2 года назад

      I have made both the font and the cursor bigger on my latest video. If you check it out it would be great if you report back if it works for you. I tested on my iPhone 12 mini and I though it was fine now. If you don't want to watch it or report back, I understand. You don't have too 🙈

  • @PhosphorusMoscu-code
    @PhosphorusMoscu-code Год назад +2

    Well, currently I'm working as Rust Developer, a few times I find some problems doing things.
    To be more exact the problem that I had was creating a Vec, because I needed a Vec to store functions with different arguments and amounts of arguments.
    I was thinking in do something like this: Vec but it's not too easy, currently we have a limitation, besides the language team know it and they are working in give the possibility to do something like that more easily.
    And it's all, the unique real issue that I had using Rust in a year and it was a very specific task and was for something of the university.
    In my work, I suppose that it's the easiest job that I had in my life, because the language prevents a lot of bugs, suggests good practice and things like that.
    I'm absolutely convinced that it's the best language at this moment and it's growing and improving because the devs listen to the community, and are working in be more easily the language without paid in performance.
    In my job we are constantly discovering new things for example the rust analyzer could do refactors, but refactor of context, great refactors, search in all the project this breaking change and replace it for the new solution having in consideration the context, the enums that you are using and the functions! It's like a regex with steroids
    Definitely congrats to the Rust team and its community! They are doing a great language.

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

      If you have a finite number of combinations of args that you know at compile time. Then could make it a list of enums where every enum value contains a different signature lambda (enum MyFns { Onei32(Box ()>), Twoi32(Box ()>),}). Since rust have these powerful enum, this would be cleaner than what you would get in the world of c# using reflection.

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

      thanks for your comment and sorry for the late reply 🙈

  • @DennisHaney
    @DennisHaney 2 года назад +2

    Traits: The corresponding feature in C# is Extension Methods. Enums as shown is easily done by C# records inheriting from a common base record (CurrentUser) . Mutablity and ownership is kinda the whole point in Rust, whereas C# controls it at object declaration level, e.g. you can make a readonly record and then "mutate" it using the "with" keyword which will create a new copy with the changes. Type inference: I don't agree doing it the way Rust does is the better one, that means any change to any parameter anywhere might change my declared variable types, whereas C# infers type from its declaration, thus only changes to return types will change var declarations (or out parameters). Constructors: It is correct you cannot have an async constructor or have a constructor return anything in C#, but nothing prevents you from having a factory method to do so, which is actually exactly what Rust does.

    • @lindblomdev
      @lindblomdev  2 года назад +1

      The problem with extension methods is that I cannot make a method that takes an "implementation" of a static class of extension methods. Whereas I can have a method that takes a trait.
      Record types are neat, I agree.

    • @felixst-gelais6722
      @felixst-gelais6722 2 года назад

      the whole point is that its all more convenient in rust. like, all of it is.

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

      5.Days().Ago().Dump();
      public static class Extensions
      {
      public static TimeSpan Days(this int n)
      {
      return TimeSpan.FromDays(n);
      }
      public static DateTime Ago(this TimeSpan t)
      {
      return DateTime.Now.Subtract(t);
      }
      }

  • @thanatosor
    @thanatosor 2 года назад +3

    With a good intellisense, Rust is way more enjoyable to use than even C# on VSCode.
    It even is safer, faster, more readable than C# with no GC or abstract.
    * Note :
    I have 10 years living with C# but have never been satisfied with anything I made in it, unlike Rust clicked every details when I come to build VM/Compiler again in it.

    • @lindblomdev
      @lindblomdev  2 года назад

      And sometimes the tooling in rust messes up due to some code issue and there are red squiggles everywhere 😅 then it's not fun for a few minutes, until the problem is fixed 🤣

    • @thanatosor
      @thanatosor 2 года назад +1

      @@lindblomdev Rust Analyzer could be lagged sometimes if source code is too big

  • @voney000
    @voney000 2 года назад +3

    I like the video, your verbal explanations are easy to follow but I can’t see the code on a phone screen.
    Would you consider zooming vscode by a point or two? I think the RUclips compression is killing the text.

    • @lindblomdev
      @lindblomdev  2 года назад +1

      Thanks for the feedback. I finished a new video today where I have made improvements around font sizes and cursor sizes. I tried it on my iPhones 12 mini and I thought it looked ok. If you happen to check it out, please let me know if it's OK for you 👍

    • @voney000
      @voney000 2 года назад +1

      @@lindblomdev Much better. Thankyou for switching it up. I can read it just fine on my phone now.

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

      Now, there is pinch zoom option on RUclips video screen to zoom in. 🐯🙏🇵🇰

  • @cchance
    @cchance 2 года назад +3

    Ok while these features are great the error reporting by the compiler is easily the best feature of rust like seriously it’s light years ahead of even high level languages

    • @lindblomdev
      @lindblomdev  2 года назад +1

      That must have come out of a need. As the language was harder to use in its early days, they probably realized that they wouldn't get anybody to use it, if they couldn't get good support from the compiler itself.
      .net doesn't really need better error reporting, right? I mean, if it doesn't build and it isn't obvious. Just delete bin/obj folders and try again 🤪

    • @kevinmcfarlane2752
      @kevinmcfarlane2752 7 месяцев назад

      I think the Help style was borrowed (pun) from Elm. Or at least that’s the only language I’ve seen that has similar.

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

    We could sort of do this if c# would allow extension methods to implement an interface methods.
    Could be useful for putting interfaces on other people’s code especially other people’s sealed stuff

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

      True, that would be a nice addition 👍

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

      You can have extension method to interface in c# too.

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

      That is correct, but you cannot implement an interface on a class you do not own by adding all required methods via extension methods.

  • @AlexanderSuraphel
    @AlexanderSuraphel 2 года назад

    Kotlin has the first feature as "extension functions". The only issue I have with it that the source of truth gets scattered and makes reasoning hard.

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

      Can you make a function that takes an argument that implements an extension method or implement an interface as extensions in kotlin? We have extension methods in c# too, but they cannot be used to implement an interface on a class. Nor can i say that my function accepts arguments that implement a specified set of extension methods.

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

    'new' in rust it's not constructor actually, it's convention that new method should give us the instantiated object because there is no constructor concept there. So saying no async in constructor in c# is incorrect here. You are comparing orange to apples here ie method to actual constructor concept.
    Why rust don't have constructor is because it's being explicite and efficient here. Because it's up to user now to which field of struct it want to initialize and which not unlike in C# where compiler allocates memory to each field in class when the constructor gets called.

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

      Thank you for your clarifying comment. I thought I mentioned that new was a convention and that you could achieve the same thing in c# using extension methods, but it would not be according to what a C# dev expect. Then again, a async factory or builder would also do the trick in a more familiar manner.

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

    As C# developer true, i'm impressed by rust low memory usage and performance, and how there's no null, and ownership & borrowing
    i'm just confused why they went with the horrible syntax, i noticed that C# has the most beautiful syntax among all the languages with human readable methods
    println vs Console.WriteLine, std:: vs System., #[derive(Debug)], lambda expression in rust is straight up horrible {|x| x.do() } vs x => x.do(), = & ( & > are characters that can be typed easily and fast as opposed to | that needs the incorporation of 2 hands to type
    and it piles up because all other 3rd party packages have gone insane and started naming weird shit, tokio is to add async & await
    i don't know why this low level languages doesn't just fucking use human readable naming, rust is something capable of replacing C++ why ruin it with C++ style of syntax

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

      Because it is not replacement of C#, but replacement of c, at least it's trying to be.

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

      Agree about the lambda syntax, I blame the ruby people for that. At least they didn't carry over the "if a lambda is the last argument you can put it after the call" from ruby 😅 tokio is a fun wordplay I think, and it's memorable. You could use async-std instead of you like that name better and it works with our project. I haven't used it, I like what the tokio peeps do and it has never failed me. 🙃

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

      For me it's a replacement for C#. Have not convinced my employer yet to go rust on a major project, but if/when that happens I'll be ready. Until then I'll keep banging out C# while on the clock.

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

      you've never coded in scala