CodeAhead
CodeAhead
  • Видео 1
  • Просмотров 177 773
Rust: When C Code Isn't Enough
When companies have gigantic code libraries written in C and filled with technical debt, they look to Rust to save them.
Points of reference:
martin.ankerl.com/2019/04/01/hashmap-benchmarks-01-overview/
ruclips.net/video/XdMgH3eV6BA/видео.html
www.youtube.com/@NoBoilerplate
github.com/motion-canvas
#programming #code #software
Просмотров: 177 829

Видео

Комментарии

  • @turdwarbler
    @turdwarbler 5 часов назад

    Go look at the TIOBE index, C and C++ have been in the top 1,2,3,4 positions basically forever. Rust is currently 14 but getting more popular as it becomes the in-vogue language to be using at this moment in time. Most large specialised projects will implement their own bespoke data structures to suit their use cases and are nearly always faster than the containers in the std library. The C++ standard does not specify the underlying data structures to be used but does specify various criteria which they must meet. Hence implementors can use whatever they like. I started writing device drivers in assembler. I then moved to assembler/C as C was the "high level assembler" and less error prone. Then C++ arrived and everybody jumped on the band wagon as to how it was going to solve all the problems with C. (It didnt, it just created new ones). Then Java arrived and everybody jumped on the band wagon as to how it was going to solve all the problems with C++ (it didnt, it just created more). Then Go arrived and to date hasnt really shone yet. Now we have Rust and everybody jumped on the band wagon as to how it was going to fix all the problems the C++, and C, and basically the whole world). It hasnt, and it wont and it will just have its own set of issues if and when it gets established. And I imagine in a couple of years we might have Zig getting more popular. I program in C and C++ for over 40 years, and I have never ever had any problems with the language or memory issues, sure everybody has bugs but these are discovered in testing and removed. C is a lovely language, but C++ has just become a fucking syntatic and semantic mess and getting worse, the C++ committe made up of various industry lobbists just want to add feature on feature on feature and less and less people are even attempting to learn and use it. Designing a language by committe doesnt work, and Rust is starting to have that problem as well. Nothing gets close to C to being a lovely language to program at the hardware level. I stopped watching this video, its a complete wate of my life.

  • @StEvUgnIn
    @StEvUgnIn 17 дней назад

    It would be interesting to benchmark the performance of C++ Boost in the same manner

  • @StEvUgnIn
    @StEvUgnIn 17 дней назад

    Most Rust implementations suck

  • @anthonyglaser929
    @anthonyglaser929 21 день назад

    after watching this video I am quite certain I will not be moving to Rust.

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

    dude placed cobol near to c/c++ in popularity ☠☠☠

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

    i love rust

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

    dude made one video and then ditched, shame

  • @ioexec
    @ioexec 2 месяца назад

    Such an excellent summary of what rust brings to the table. Whenever people ask me "Why rust?" I'll send them here.

  • @czarsonxd2093
    @czarsonxd2093 2 месяца назад

    just use the const keyword???????? these first two examples are so bad im sorry, just another video trying to sell the language

  • @WabuhWabuh
    @WabuhWabuh 3 месяца назад

    twitter...was completely botted...

  • @PFnove
    @PFnove 3 месяца назад

    Rust is faster than C++ if you don't know how to write good code in C++ Having to check that the location of an array you're accessing isn't out of bounds means bad code (unless the user is involved, the user will find all possible bugs) Even division by zero checks (again, unless the user is involved) means bad code

  • @peterkilian9100
    @peterkilian9100 3 месяца назад

    Unfortunately it looks like you have it backwards. C is the opposite of ambiguous. It is as soundly designed as a language can be in the functional sense since every line of code is explicit. The code you don’t work with is not a compiler issue, it’s a developer one. You are responsible for your code, not the compiler.

  • @jasonkusi2373
    @jasonkusi2373 3 месяца назад

    Thank you for this info

  • @adityaagarwal3010
    @adityaagarwal3010 3 месяца назад

    This is a stupid video. So a single builtin data structure is faster in one language than another. What does this prove? This is like saying a cow runs faster than a cheetah because you saw an adult cow compete against a newborn cheetah.

  • @siddharthupadhyay6347
    @siddharthupadhyay6347 3 месяца назад

    First upload and that too good quality? Fabulous.

  • @yrncollo
    @yrncollo 3 месяца назад

    How is that hard? I don't understand why everyone is saying Rust is hard

  • @therandomsomeone.
    @therandomsomeone. 3 месяца назад

    [𝐄𝐗𝐓𝐑𝐄𝐌𝐄𝐋𝐘 𝐋𝐎𝐔𝐃 𝐈𝐍𝐂𝐎𝐑𝐑𝐄𝐂𝐓 𝐁𝐔𝐙𝐙𝐄𝐑]

  • @blacksundarkskies
    @blacksundarkskies 3 месяца назад

    rust troons again

  • @mateuszabramek7015
    @mateuszabramek7015 3 месяца назад

    If C is slower it's just skill issue. Besides Rust still doesn't have own ABI...

  • @dmitrykim3096
    @dmitrykim3096 3 месяца назад

    Rust is enforcing the good practices developed in other languages so idiots dont write bad code, and 96 prrcent of people are idiots

  • @x2net
    @x2net 3 месяца назад

    so the "rust" compiler created in c / c++. So I think C is more than enough :3

  • @artbll9
    @artbll9 3 месяца назад

    This guy is not an expert, talking for talking

  • @ygypt
    @ygypt 3 месяца назад

    The frist example is weird and bad because it illustrates a user's ineptitude, instead of just focusing on how rust requires a few more keystrokes. Nobody would use clone() before using &borrow. Also, you wouldn't be using "more and more" memory for each clone(), because each cloned variable would drop at the end of the greet() call, you would just be wasting cycles by creating and dropping the same variable. The point still stands, the fact that you need to put a little more effort in but your code is more manageable over the long term, but it's a strangely made point.

  • @asher05
    @asher05 4 месяца назад

    Is this a sign for me to learn Rust? What exactly can I do with it?

  • @ChandTaare-c9i
    @ChandTaare-c9i 4 месяца назад

    Your explanation is great. Here is my doubt, I have written a program that has 4 threads between every thread busy waiting on the segment queue. We are creating a packet in one thread and passing via queue to another and processing something in every thread and that packet processed in the last thread and we time stamp at every thread. Total 1million packet processed. We have written a similar program in c++ also. Performance : MACOS: rust : 2.9sec c++ : 2.7sec LINUX rust : 15sec C++ : 3.3sec Why rust is too slow in Linux. Can anybody help me to solve my problem, I have used every compiler optimization of everything, still nothing happens.

  • @Ali-ls5px
    @Ali-ls5px 4 месяца назад

    No I won't switch to rust.

  • @ttt69420
    @ttt69420 4 месяца назад

    Terrible and, as usual, deceptive implementation. Do not recommend channel. Thanks!

  • @Byynx
    @Byynx 4 месяца назад

    Does C and C++ have comments? // This comment has zero irony.

  • @Byynx
    @Byynx 4 месяца назад

    With the 1st and 2nd cases the word "biased" immediatly poped up in my mind, how you use silly things to pretend that rust is better. The simple fact you ommit things like references "&" and " the "const" keyword in C++ that not only tell us if the contents of a pointer will be changed but also tell us if the contents of where is pointing too will be changed.

  • @Kiyuja
    @Kiyuja 5 месяцев назад

    I'm relatively new to Rust but I'd say in this example there is no "real" difference between C or Rust in terms of writing the implementation. The Rust code was easily readable to me, even as a beginner, because I am familiar with the syntax (I was screaming "just pass a reference" like 20 times) because thats what I am used to. And tbh the C code seemed to do the same (char *). The difference likely lies within a lack of dedicated Rust libraries C/ C++ had for decades and being forced to handle Results / Options, Err etc. whereas C will let you do whatever. This will be a negative for short POCs but in large code bases you will implement the exact same things that are standard in Rust anyway

  • @sledgex9
    @sledgex9 5 месяцев назад

    "Rust is more modern than C and C++ thus is able to have faster default implementations of data structures" -> Oh come on. This has nothing to do with Rust being modern/new. There are currently (if I am not mistaken) 3 implementations of the C++ stl (msvc, gcc, clang) The C++ STL usually describes the data structures in general and doesn't force a specific algorithmic implementation for containers. Moreover, you just tested one data structure. Lastly, one can find very good C++ implementations of any data structures one desires if the STL ones don't fit their needs.

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

    C code @3:20 is incorrect. The divide function definition has an integer pointer as first parameter. So when calling the divide function, you pass with & a normal variable not a pointer to the divide function. int a = 20; int return_value = divide(&a, 4); printf("%d ", a);

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

    For Rust i recommend using .to_owned() instead of .to_string(). It's faster but use &str if you can.

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

    because you don't know how to do it because of lack of actual knowledge don't blame it on the language 😂

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

    Outside of the code writing I believe that Rust is great for teamwork because of the config file, the toml I think. Just type in whatever dependencies you need in there and cargo will do it all for you, all the correct pakages, the correct version of Rust you want and then cargo run, kinda like Python venv. So not only does Rust code is explicit and precise, but the way Rust manages itself is just so good, any team member with Rust installed can just take that toml file and run it, and they are set.

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

    U must do that in cpp too

  • @NoBoilerplate
    @NoBoilerplate 8 месяцев назад

    When's the next video my dude? You've got everything here that makes a great channel, what are you currently passionate about? Tell us about it! 😄 (My only feedback, if I may, would be to use a better mic, don't buy one, just use your phone's microphone like I demo in my "how to sound great" video) Looking forward to seeing more!

    • @CodeAhead
      @CodeAhead 8 месяцев назад

      Thank you, that means so much coming from the best! I will definitely follow that advice if I end up making another video. I was having a lot of trouble with my adsense account which was killing my motivation, but hopefully the situation can be resolved in the future. Until then I will learn as much as possible to have some material for the future! ;)

  • @lepidoptera9337
    @lepidoptera9337 8 месяцев назад

    C is always enough. ;-)

  • @AnimeGIFfy
    @AnimeGIFfy 9 месяцев назад

    pov strongest rust propaganda (it's weak).

  • @DungVu-di7dz
    @DungVu-di7dz 9 месяцев назад

    no, is c++ > rust

  • @James-l5s7k
    @James-l5s7k 10 месяцев назад

    Simply untrue. Can't wait to see your zero days because rust can be fast or safe; never both :)

  • @nevokrien95
    @nevokrien95 11 месяцев назад

    U can't just say "when we benchmark" show an actual benchmark and compiler details... I would bet c usually wins if u choose a good hashmap especially if u optimize for ur data distribution

  • @xcoder1122
    @xcoder1122 11 месяцев назад

    The speed of Rust depends a lot on what your code actually does. I have a small test benchmark that performs fractal calculations, no fancy objects or structures are involved except arrays, and this code runs 10% faster in Rust than in C, who would have expected that? However, if I modify the benchmark to compute many more fractal values that all need to be held in memory, the Rust code is suddenly 20% slower than the C code. Sure, in the end it's all LLVM, but there are certain operations that are faster in LLVM than others, and certain combination patterns cause more code than others (e.g. because of extra checks or more cleanup at the end of a function). Rust is neither guaranteed faster nor guaranteed slower, it all depends on what your code actually does and how your code does it, and how well the compiler can optimize away the things that would otherwise make Rust slower, or how much the compiler can benefit from making assumptions about data or code flow that it can only make in Rust but not in C, where those assumptions end up leading to better CPU code. Since Rust is much more complicated under the hood than C, the final speed will always be a kind of gamble ("Oh, if I change this, my code will be 60% faster... I didn't expect that"), whereas speed in C is predictable most of the time ("It was clear that this will be faster than that"), but that still doesn't mean that C will always end up with the best performance, as C simply provides less meta-information for compilers to work with, so compilers can't always figure out the best optimization path, as they simply have less understanding of what's really going on, or they have to be prepared to deal with exceptional cases, which may be guaranteed not to happen with comparable Rust code. The takeaway is that for a way safer and way better typed language, Rust is often comparable fast, but in most cases it will still be slightly slower, so you are trading a tiny bit of speed for way more safety. My biggest grief with Rust is that I already disliked C++ just because it's syntax is so ugly but the syntax of Rust is even worse.

    • @lepidoptera9337
      @lepidoptera9337 8 месяцев назад

      There is nothing unsafe about C. People simply don't know how to use it. I also doubt that Rust can beat properly optimized C code if the compiler optimizations are the same. It might not even be the code. Individual results might have something to do with cache hit/miss rates or pipelines rather than the actual code. Even LLVM can not optimize that since it's strongly data dependent.

    • @xcoder1122
      @xcoder1122 8 месяцев назад

      ​@@lepidoptera9337C is unsafe because its memory model is unsafe. Unless you use C11 atomics (which didn't even exist prior to 2011), C provides no guarantees about memory access at all. The problem is that every platform/CPU has its own memory rules and you would have to make sure to write C code that follows those rules but since those rules vary by platform/CPU, it's actually not truly possible to write C code that is guaranteed to work correctly on more than one platform. If it does, that's plain luck. Modern programming languages like Rust, Swift, Go and even Java and C# do define a memory model as part of the language that is valid for all platforms the language supports. It's up to the compiler/interpreter to ensure that this memory model works as defined by the language on the platform, no matter what is required to make that happen. The programmer doesn't have to adopt his code to any platform for those, the programmer can rely on what is defined in the language standard. Here's a very simple example: You have a global variable of type int, whose value is currently 0 and you change its value to 10 in thread A. 30 minutes later, the variable has never been touched ever since, you read the value of the variable on thread B, what will the value be? 10? Show me where the C standard makes that guarantee. Fact is: It doesn't. Prior to C11 C didn't even acknowledge the existence of multiple threads. But even without threads: You only have one thread, that runs on CPU 1 and you write a value, 30 minutes later the SAME thread runs on CPU 2 and reads the value. Again, where does the C Standard guarantee that CPU 2 will see the value that CPU 1 has written? It doesn't, because C does not acknowledge the existence of systems with more than one CPU. And what applies to CPUs also applies to cores of a single CPU. Only when using atomic variables as defined by C11, there now is a memory model and you as programmer can even choose between 6 different memory models but for everything that is not atomic, nothing is defined. Without atomics, the way you think C works in fact only works if all your code is always running on a single thread only and your system only has one CPU core or if you are lucky and the CPU does make that guarantee in hardware; like x86 does most of the time but PPC, ARM, Alpha, RISC-V, etc. doesn't make those guarantees. That's why so much C code that worked flawless on x86 CPUs fore decades suddenly breaks when it has to run on other CPUs. The code was never correct in the first place but x86 is very forgiving and gives a lot of memory access and ordering guarantees that other CPUs don't. So you basically had C code, that was valid for x86 in particular but that doesn't make it universally valid, as there is no such thing as universally valid C code, because C leaves most definitions to the system, instead of defining it to the language. This is also true for plenty of other situations. E.g. what happens if a signed int overflows? Not defined in the C standard. What happens when you de-reference NULL? Not defined in the C standard. What happens when you shift a 32 bit integer right by 32? Not defined in the C standard. Of course, on every platform the behavior is defined but the definition varies by platform, that's why modern languages define it as part of the language. As for performance, I have a C code sample, that calculates a Mandelbrot set. It's as basic as this calculation can get (three for loops, an array of float values, some simple int and float calculations, one static function being called from within the main for loop). When I compile it with clang using -O3, the code runs slightly slower as when I take the code as is, convert it to Rust (which almost requires no adoption, except for the data types and the function definitions) and compile it with the Rust compiler. Reproducible on x86 and on ARM CPUs. If RUclips would allow external links, I'd show you the code and I take any bet, you cannot make the C code run faster than than the Rust code, as there is nothing you could optimize about that code and there is no better optimization than -O3.

    • @xcoder1122
      @xcoder1122 8 месяцев назад

      ​@@lepidoptera9337If I could post links here, I could show you a simple Mandelbrot calculation code that will run faster in Rust than in C and I bet that there is nothing you can do to make this code run faster in C, as this code is minimalistic and there is nothing you could optimize that the compiler cannot optimize 100 times better than you and still Rust always wins on x86 and ARM with both compilers set to maximum optimization. And C is unsafe because it does not define a memory model (only for atomics which only exists since 2011) and it also has tons of undefined behavior, where the C standard simply does not define what the outcome of an operation will be. This makes it very easy to port C to any platform but it also means that the same code will not behave the same on different platforms. Modern languages have a well defined memory model and well defined behavior and it is the task of the compiler to ensure this behavior on all supported platforms, no matter what is required to make that happen, so you can rely that the same code will produce the same results on any platform.

  • @ItsCOMMANDer_
    @ItsCOMMANDer_ 11 месяцев назад

    Rust may be a goid language, but i dont like it. I'll just stay with c

    • @Phantom-lr6cs
      @Phantom-lr6cs 8 месяцев назад

      rust without llvm and gcc doesn't even exists and this people are morons XD all their code works with or thru c++ yet they don't like c++ and c cuz they are just bunch of looser typescript developers who never heard of memory managinG XD their brain cannot just process the new info about compuer science : D

  • @sepio_
    @sepio_ 11 месяцев назад

    would be nice for the next video to see the performance and productivity comparison that doesn't involve 3rd party libraries

  • @faysoufox
    @faysoufox 11 месяцев назад

    Nice video, looking forward to others like this

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

    2:49 "...we are after all the programmers and we know exactly what we want to be doing..." We do???????

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

    "Segmentation fault (core dumped)" is the message c programmers fear the most

    • @lepidoptera9337
      @lepidoptera9337 8 месяцев назад

      It is trivial to avoid that. If it happens to you, it's basically just a feedback from the compiler that you don't understand what you are doing. Nothing to fear. You just have to start learning.

    • @Phantom-lr6cs
      @Phantom-lr6cs 8 месяцев назад

      segmentation fault came from OS not from c lang kid . it has nothing to do with c . its comes when some morons code and they don't know what they are doing XD

    • @amuldoodh556
      @amuldoodh556 3 месяца назад

      ​@@lepidoptera9337do you even know what you are talking about? It's not even a compiler error

    • @lepidoptera9337
      @lepidoptera9337 3 месяца назад

      @@amuldoodh556 True. It's a system error originating from the MMU that tells you that you are poking around in the wrong memory location. Ye shall not write random numbers into a pointer. No big deal. ;-)

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

    3:40 In bigger coding projects you should always specify function parameters as they are intended to be used. For example making param1 in your div() function a pointer to a constant value. int div(const int *param1, ...) if it is read-only

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

    Interesting video with interesting comments, thanks for the upload.