Rust-Based, Memory-Safe PNG Decoders "Vastly Outperform" C-Based PNG Libraries

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • duby229
    Senior Member
    • Nov 2007
    • 7780

    Originally posted by rabcor View Post

    Rust is supposed to be like c++ but with training wheels for imbeciles. Competent c++ devs tend not to like it because it's not actually in any meaningful way better than c ++ for competent devs. But getting to that level takes a lot of time which makes rust attractive for lazy scrubs and fresh faced devs.

    C when correctly utilized should be faster than both of these, however as you said, 30 years of technical debt and 30 year old code that was made before the days of multithreading.
    Have you ever tried multithreading in C? It is hard, coherency is really difficult. There are some APIs now to help, but still it's very difficult. It's incredibly easy to write code that corrupts it's own self. C itself was never designed for it. It can be done, but incredibly hard to do right. You can easily write code that doesn't work at all and then never be able to figure out why.

    Comment

    • duby229
      Senior Member
      • Nov 2007
      • 7780

      Originally posted by YBoy360 View Post
      The problem is how to use this lib in real world, if it cannot be linked. C can be linked everywhere.
      Rust has bindings for pretty much every other language in existence. And if you know C then you can easily overwrite the default bindings and make your own.

      Comment

      • TheMightyBuzzard
        Senior Member
        • Sep 2021
        • 416

        Originally posted by iq-0 View Post

        Code:
        use strict;
        use warnings;
        use AnyEvent::HTTP;
        use JSON;
        
        sub fetch {
        ​​​	my ($url, $cb) = @_;
        	http_get($url,
        		headers => { accept => 'application/json' },
        		sub {
        			my ($data, $hdr) = @_;
        			die "Failed to fetch $url" if $hdr->{Status} !~ /^2/;
        			return $cb->(decode_json $data);
        		}
        	);
        }​
        edit: 🍺
        I would have gone with some error handling one step up instead of a die in code non-trivial enough to be using a callback but otherwise I approve.

        Comment

        • TheMightyBuzzard
          Senior Member
          • Sep 2021
          • 416

          Originally posted by duby229 View Post

          Have you ever tried multithreading in C? It is hard, coherency is really difficult. There are some APIs now to help, but still it's very difficult. It's incredibly easy to write code that corrupts it's own self. C itself was never designed for it. It can be done, but incredibly hard to do right. You can easily write code that doesn't work at all and then never be able to figure out why.
          Like most everything else in programming, it's only hard if you don't know how to do it. You have to learn how to do it in Rust as well or your code won't even compile. The only difference is Rust tries to hold the hands of people who didn't bother to learn before they started writing.

          Comment

          • TheMightyBuzzard
            Senior Member
            • Sep 2021
            • 416

            Originally posted by smitty3268 View Post
            Seriously, which parts are confusing?
            How experienced are you? Because the answer is "any and all of them may be if you're dealing with a fresh graduate". But if you are a fresh graduate (or a fanboi to the point of self-delusion) you'll deny this.

            Comment

            • duby229
              Senior Member
              • Nov 2007
              • 7780

              Originally posted by TheMightyBuzzard View Post

              Like most everything else in programming, it's only hard if you don't know how to do it. You have to learn how to do it in Rust as well or your code won't even compile. The only difference is Rust tries to hold the hands of people who didn't bother to learn before they started writing.
              That's not entirely true actually. Multithreading is built into the structure and syntax of rust. It's a fundamental part of rusts standard library. Coherency is built into rust at a fundamental level. But in C you have to literally do it all manually. Nowadays there are APIs you can use like a template, but you still have to do your own memory management. Coherency is really hard in C.

              Comment

              • sdack
                Senior Member
                • Mar 2011
                • 1724

                Originally posted by back2ζœͺδΎ† View Post
                [ just for completeness, same functionality with Cpp:
                Code:
                ...
                // Callback function to handle data received from libcurl
                size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* out) {
                size_t totalSize = size * nmemb;
                out->append((char*)contents, totalSize);
                return totalSize;
                }
                ...
                (thx) ]
                *lol* Thanks for that. I hope it was meant as a joke! ... No null-pointer checks, no check whether size is 0, no memory check, ... and contents should have been char* per cURL docs. Lots of missed opportunities to write good code.

                Comment

                • Mordrag
                  Junior Member
                  • Nov 2017
                  • 28

                  Originally posted by TheMightyBuzzard View Post

                  And that right there is a major reason why I'm not a fan of so many Rust projects or Rust fanbois. They like to call something "production-ready" as soon as they think they're done writing the code (or even before in many cases). Production-ready actually means something though. I know that's easy to overlook in a time when changing definitions to suit your desires is so common but it's important to remember that it's only you and your equally deluded friends that actually believe that crap when you do it.
                  Tell me you haven't written Rust without telling me you haven't written Rust. Please go to crates io and lookup some popular crates. It is ridiculous how many are still not 1.0.0 with great documentation and dx overall. I've never seen that kind of quality control in any ecosystem except Rust's.

                  Comment

                  • sdack
                    Senior Member
                    • Mar 2011
                    • 1724

                    Originally posted by Mordrag View Post
                    Tell me you haven't written Rust without telling me you haven't written Rust. Please go to crates io and lookup some popular crates. It is ridiculous how many are still not 1.0.0 with great documentation and dx overall. I've never seen that kind of quality control in any ecosystem except Rust's.
                    Popularity does not imply quality. And yes, it is ridiculous when people do not know when to move past version 0.something.

                    Comment

                    • Mordrag
                      Junior Member
                      • Nov 2017
                      • 28

                      Originally posted by sdack View Post
                      Rust was created because people are having skill issues.
                      I was being sarcastic obviously this example is super simple. Anybody with a bit of Rust experience or even other languages with generics and async can understand this if they know that '?' is error propagation.

                      Comment

                      Working...
                      X