Become a fan of Slashdot on Facebook

 



Forgot your password?
typodupeerror
×
Programming Python Security

How Rust Can Replace C In Python Libraries (infoworld.com) 304

An anonymous reader quotes InfoWorld: Proponents of Rust, the language engineered by Mozilla to give developers both speed and memory safety, are stumping for the language as a long-term replacement for C and C++. But replacing software written in these languages can be a difficult, long-term project. One place where Rust could supplant C in the short term is in the traditionally C libraries used in other languages... [A] new spate of projects are making it easier to develop Rust libraries with convenient bindings to Python -- and to deploy Python packages that have Rust binaries.
The article specifically highlights these four new projects:
  • Rust-CPython - a set of bindings in Rust for the CPython runtime
  • PyO3 - a basic way to write Rust software with bindings to Python in both directions.
  • Snaek - lets developers create Rust libraries that are loaded dynamically into Python as needed, but don't rely on being linked statically against Python's runtime.
  • Cookiecutter PyPackage Rust Cross-Platform Publish - simplifies the process of bundling Rust binaries with a Python library.

This discussion has been archived. No new comments can be posted.

How Rust Can Replace C In Python Libraries

Comments Filter:
  • But why? (Score:4, Insightful)

    by Anonymous Coward on Saturday July 29, 2017 @12:39PM (#54904313)

    Why use the new language of the month when C has been around for decades, is welll understood and does exactly what we want?

    How long before I start replacing rust with decay? 6 months? A year?

    • Re: (Score:3, Interesting)

      Comment removed based on user account deletion
      • Re:But why? (Score:5, Informative)

        by gweihir ( 88907 ) on Saturday July 29, 2017 @01:19PM (#54904579)

        We actually need to ditch people that cannot handle C. Go be a "business coder" but stay away from real programs.

        • Re:But why? (Score:4, Interesting)

          by Anonymous Coward on Saturday July 29, 2017 @01:22PM (#54904597)

          But using C doesn't allow the SJWs to bikeshed over a buildbot being called a "master" or a "slave." [github.com]

        • If I had mod points. Someone mod this man up.
      • by jovetoo ( 629494 )

        Why? To run after the latest programming language fad, again?

        I liked the feature list of Rust, until I read the book and ran into their chapter on Ownership, I quit right there and then. I'll stick to std::shared_ptr<>, thank you very much. Research in programming languages is all nice and all these things contribute in their own way but in the end, the programming language should not get in the way of whatever algorithm you are trying to express. You need to be able to control your code in every as

        • Re: (Score:3, Interesting)

          Comment removed based on user account deletion
          • by buzmeg ( 889625 )
            Are you daft, ignorant, or am I *completely* missing something. Rust is compiled. And memory management with the borrow checker is front and center even *moreso* than C and C++.
          • by DrXym ( 126579 )
            Rust is not an interpreted language. It compiles to machine code. In fact it compiles to machine code using the same compiler as clang - LLVM. And if you're worried about people learning memory management then you would appreciate the Rust compiler because you won't be compiling anything until you do.

            Performance wise, the code runs about the same as the equivalent in C.

      • Comment removed (Score:5, Insightful)

        by account_deleted ( 4530225 ) on Saturday July 29, 2017 @03:12PM (#54905123)
        Comment removed based on user account deletion
        • by dog77 ( 1005249 )
          Are you sure the tv was not slow because it was running Linux? I have seen a number of Linux based products running on embedded hardware, that take longer than 10 seconds to boot up. Maybe because they were not optimized, under powered, or special hardware bring up but I do see it happen. On the other hand, I don't think using Java or even something slower like python for the user interface would actually make much of a difference for the boot time.
      • Re:But why? (Score:4, Informative)

        by ArchieBunker ( 132337 ) on Saturday July 29, 2017 @03:49PM (#54905293)

        You're part of the problem we face today. Computers are order of magnitude faster than 20 years ago and yet software still never runs any faster. Web pages still render as quick today as they did in 1997. Software still has loading screens and even with an SSD we have to wait for the operating system to boot up and settle down.

        • by johanw ( 1001493 )

          If you want web pages to load faster, use an adblocker. Ads are the worst reason of slow loading.

      • Re: (Score:3, Insightful)

        by Anonymous Coward

        C was never awful, It is and has always been a wonderful language. It is true that it is designed for people who know how a computer works... That might be a bit much to ask from "modern" "coders". If you have zero knowledge of what a computer actually does I can understand that you see it as awful.

        • Thank you for the most insightful comment in the entire thread!
      • Its a fact of life that you have a progressive stack from hardware to microcode to machine code to assembly code to C and to a VM. C has to be there and yes its hard to write securely. CPython is written in C. Whats the alternative? There has to be something outside the VM.

        • by Jeremi ( 14640 )

          Its a fact of life that you have a progressive stack from hardware to microcode to machine code to assembly code to C and to a VM. C has to be there and yes its hard to write securely. CPython is written in C. Whats the alternative?

          There was a time before C existed, and people were able to make their computers function even then. The ubiquity of C is a historical accident, not an inevitable conclusion; the layers of functionality we currently implement in C could just as easily have been implemented in ADA or Pascal FORTRAN or some other language, had history gone down a slightly different path.

          C is definitely useful, but not uniquely so. If Rust can give us the benefits of C (low-overhead computation and low-level control of the ha

          • To do that Ada, Pascal and FORTRAN would have needed more low level features, which make them both useful and insecure. In other words, something like C has to exist. C is in some respect, a super macro assembler. Tied to the machine and the OS if it exists at all.

            Rust would have to exist between C and python.

            A friend of mine who did a lot of Ada programming told me that his project turned off array bounds checking because it was just too slow for their application to function. There is little difference be

            • Rust would have to exist between C and python.

              Rust is a compiled language. Presumably, the first Rust compiler was written completely in C, with newer versions having progressively more Rust source.

              Obviously, Rust, with it's run time checks, can't match the performance of C without those checks.

              A friend of mine who did a lot of Ada programming told me that his project turned off array bounds checking because it was just too slow for their application to function. There is little difference between that and coding the app in C.

              A co-worker told me that early C compilers put bounds checking (and other checks) in to the generated code. He and his classmates routinely disabled the checks, only turning them on to demonstrate their code passed the checks.

              I see no compelling reason to switch

            • To do that Ada, Pascal and FORTRAN would have needed more low level features

              Pascal has the same low level features as C with a better type system and optional bounds checking. Pascal gives you the same power as C with better safety.

              Strings and dynamic arrays are a good example. Strings and dynamic arrays are far easier to work with in Pascal than in C. They're both reference counted in Pascal as part of the core language. It makes things much simpler.

              But equally if you really want to manage memory manually in Pascal then you can choose to do that too.

    • For example Py-CRust.

    • Re: (Score:3, Interesting)

      by slashdice ( 3722985 )
      I can (and sometimes do) compile C code that was written in the 80s or 90s. And it often works with little or no modifications. (And there are people running awk scripts from the 70s, calling me a whippersnapper). With something like rust or go or swift, your code will not compile in 6 months. (which is hilarious in the case of go because it's more 70s than Disco)
      • by mikael ( 484 )

        I remember porting one of my old MS-DOS demos from C to SDL. I had used a simple structure to abstract the VGA framebuffer into a rendering API. Figured it would take me an entire evening to port across. Recompiled and run in 15 minutes. Which left me another 15 minutes before I went out to catch the bus to do my weekly shopping.

    • by Jeremi ( 14640 )

      Why use the new language of the month when C has been around for decades, is welll understood and does exactly what we want?

      If C did exactly what we want, there wouldn't be buffer-overflow exploits in any C code. The fact that we receive security advisories on a regular basis regarding C-based software shows that our C code often does rather more than we intended it to.

    • C has been around for decades, is welll understood and does exactly what we want?

      Because it doesn't do exactly what you want. Decades of C usage has lead to decades worth of security problems. The history of security flaws in programs written in C has been a costly one. Rust doesn't solve the whole security problem but it offers memory safety features that C doesn't.

    • by DrXym ( 126579 )
      Yes C is well understood, as are the multitude of problems that come from programming in it.
  • by Anonymous Coward on Saturday July 29, 2017 @12:42PM (#54904329)

    And wake me up when Rust stop being a cult and becomes an actually useful language.

    • by Anonymous Coward

      What I don't get is why the Rust community lacks diversity, despite them putting so much emphasis on supposedly supporting diversity.

      Years ago, back when I was a Java developer, I would sometimes go to Java conferences. There would be men there. There would be women there. There were probably transsexuals there. There would be old adults and young adults. There would be people representing every possible skin color. There would be somebody from pretty much every major ethnicity. There would be practitioners

      • by 0123456 ( 636235 )

        In my experience, the people who demand 'diversity' the most prefer to live in white ghettos.

    • For tha we would need to know your bitcoin address!

  • by mnooning ( 759721 ) on Saturday July 29, 2017 @12:46PM (#54904345) Journal
    I've read a third of the Rust nightly book and watched many, many Rust videos on youtube. I like Rust very much. However, I believe Rust was invented by, is sponsored by, and gets it's major funding from the Mozilla foundation. There is essentially no more Mozilla Thunderbird, and the Mozilla Firefox browser is getting significantly less usage. We've had articles on such here on Slashdot. If the Mozilla browser itself falters any more, would Mozilla, and hence rust, stay alive?
    • Let's talk about Sun Microsystems...
    • I don't think that existence of Mozilla will be the deciding factor of the success of the language. For example, no particular corporation was supporting C++ initially, and even now core C++ design is done by volunteers. Even if Mozilla goes bankrupt a community can still thrive around the language if it deserves it. If not then it'll eventually wither in any case, even if Mozilla ends up thriving.
    • by Cyberax ( 705495 )
      At this point, probably yes. There's a critical mass of Rust-based projects, enough to continue maintenance and development of new features.
    • by jma05 ( 897351 ) on Saturday July 29, 2017 @02:38PM (#54904971)

      Python and Perl would have never made it, if people filtered by that logic.

      Programming languages don't need a huge company backing them up, as long as there is enough of a community. If Rust folks are as zealous as the Ruby folks were during the Rails era, we will have a neat C++ replacement.

      I have not used Rust yet and have even been critical (as in, just add those semantics to C++ somehow and don't create a whole new replacement) of it. But the community does seem to be building momentum.

      A peek at module counts
      http://www.modulecounts.com/ [modulecounts.com]
      shows that the Rust community is quite active. They are not merely evangelizing it, but rapidly building value. It does not look like Mozilla is significantly driving it on the module front. It only has half the modules as Go (which is impressive for a zero-cost abstraction language compared to a language that is high level application language), but the modules seem to be accumulating at more than twice the speed now. Modules make the language.

      I wish Nim had that kind of momentum though. That is a language better aligned for my purposes.

  • by Anonymous Coward on Saturday July 29, 2017 @01:06PM (#54904489)

    I was interested in learning Rust and perhaps using it for some personal projects, but then I discovered how the community seems to care so much about social engineering.

    We're not allowed to use "Master" and "Slave". https://github.com/rust-lang/rust-buildbot/issues/2

    We're required to rephrase old texts to fit into "gender non-binary" language. https://github.com/rust-lang/rust/pull/25640

    I'm sure they don't have problems "killing child processes" though...

    etc., etc.

    I'm not interested in using a programming language as some kind of social engineering experiment.

  • by gweihir ( 88907 ) on Saturday July 29, 2017 @01:15PM (#54904551)

    Something that gets this much hype cannot be good, or the hype would not be needed. Seems to me some cretins are using Rust as a religion-surrogate.

    • Why do you call the once a year mentioning of Rust a Hype?
      Typical american?
      You know something, which most people don't know, you get news about it "again" and then you call it a hype?
      I would assume that 90% or more "developers" or "programmers" never ever have heard about Rust.
      I only know Rust because it is occasionally mentioned on /.

      This "hype scare" is a quite strange thing for us europeans.

  • Being able to represent the sort of thing you'd use C or C++ for as a data structure within Python, and then turn into binary via LLVM is something I've been wishing for for a long time. I imagine I'll need to keep wishing for a while longer, but things like numba (in python), and application of LLVM like LLVMPipe, and the Synthesis OS project from a few years back suggest the pieces for doing this are gradually appearing.

  • Wake me up... (Score:4, Insightful)

    by maestroX ( 1061960 ) on Saturday July 29, 2017 @01:42PM (#54904683)
    .. when Linus decides the next major release is to be written in Rust.
    Or for argument's sake, Mozilla itself.
    Every language has it pitfalls, at least with ye olde C/C++ I know where to look and what to expect.
    ...
    Suddenly you start to respect and embrace the get-off-my-lawn attitude, you simply want things to work rather than be written in the next greatest language of the moment.
    I think I'm ready to deal with my dad now :)
  • by VAXcat ( 674775 ) on Saturday July 29, 2017 @01:52PM (#54904731)
    They're really enthusiastic, mention that they think it's great at every opportunity, and can't understand when someone is underwhelmed by the object of their admiration....
  • by FutureDomain ( 1073116 ) on Saturday July 29, 2017 @02:07PM (#54904811)
    Rust can go and, well, rust. If you want to get safer C, than add Cyclone [wikipedia.org] support to gcc and use that. No rewrites, no learning a new language, no hitching your project to a SJW converged organization that is slowly dying, no fanboys who pathetically spam puff pieces on Slashdot... Seriously, Cyclone or any of the other safe-C alternatives are better and less intrusive than a Rust rewrite.
    • Rust can go and, well, rust. If you want to get safer C, than add Cyclone support to gcc and use that.

      Why bother? Rust and C++ are much more powerful alternatives to C with similar machine models. Why on earth would I want to use a language where everything has to be micromanaged by hand.

      no learning a new language,

      Oh the horror!

  • Julia! (Score:2, Interesting)

    by Anonymous Coward

    I make money doing embedded C. If I am going to replace C with something else it will be Julia. I get the speed of C, the coding efficiency of Python and real support for computational algorithms.

  • Well,
    C++ might be a bit ugly when it comes to templates, but for that you have typedef.
    Nothing against Rust, it looks like a decent enough language (exept for the name, looks like the inventors like to repeat the subvers-ive/ion failure).

    Anyway: why would one replace C with Rust instead of C++ is beyond me.

    If you write new code, then I would probably agree, but for existing old code I see no justification.

    I wonder if there is a Rust to JVM compiler ... googeling a bit ...

  • by brian.stinar ( 1104135 ) on Saturday July 29, 2017 @06:46PM (#54906061) Homepage

    This is what happens when developers make business decisions. Seriously, why is Mozilla focused on promoting/using/developing Rust, when they could be focused on making their browser suck less? Probably because they have no business concerns, at all, about making a viable product (or company.) I spent two weeks exclusively using Firefox, right when Google was found to be recording everything I said, in the event I happened to say "OK Google" without a way to turn this off. After two weeks, I realized I'd rather be bugged than use Firefox any longer.

    This is exactly what Joel Spolsky wrote about, when Netscape did a complete rewrite here [joelonsoftware.com], or in his awesome book Joel on Software [amazon.com] . Netscape focused on a rewrite, instead of making their browser suck less.

    It sounds like Netscape made this mistake and then became Firefox. Now, it seems like Firefox is making the exact same mistake. This has to be the funniest business case study ever.

    • by Zan Lynx ( 87672 )

      By replacing small pieces of Firefox with new pieces that use Rust, they are avoiding the Netscape problem. They aren't rewriting the whole thing. But one day the whole browser will be Rust, replaced a piece at a time.

      You don't think Microsoft Edge still uses pieces of Spyglass or Mosaic do you? And yet, at no point did they rewrite the whole thing.

He has not acquired a fortune; the fortune has acquired him. -- Bion

Working...