• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Command-Line Rust: Replacement for C++

 
Ranch Hand
Posts: 71
1
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ken,

Congrats on the book. Do you think Rust will eventually replace C/C++ for most system-level type projects? Thanks.
 
Marshal
Posts: 79969
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does Rust work on all platforms as C and C++ do, Carl? It can hardly replace them if it is platform‑specific.
 
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would Rust be platform-specific? In fact, it has just been accepted as another frontend for the next major GCC release. That will ensure a very wide range of platforms on which it can be deployed easily.
 
Saloon Keeper
Posts: 28321
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Does Rust work on all platforms as C and C++ do, Carl? It can hardly replace them if it is platform‑specific.



The real question is "can Rust run in any environment from cold iron up?"

I could not do OS-level programming on IBM mainframes in Fortran, COBOL, or PL/1. They could only run under their respective language environments (which were not friendly to interrupt-level coding, privileged modes, real-time or small-footprint uses.) One cannot extend Java's "write once/run anywhere" to cold iron, as Java needs its JVM environment. Likewise, Python, although an essential part of the Red Hat Linux boot process, cannot run on bare metal.

Granted, there are exceptions. Prime Computer wrote most (but not all) of its OS in Fortran (the hardware was actually optimised for Fortran, as I've mentioned occasionally). They also later adopted a dialect of PL/1, as Fortran was not the best language to do byte manipulation in on a word-addressed machine. I'm fairly certain that the Honeywell GCOS minicomputer systems could do OS-level code in COBOL (!!!).

But the point is, those were exceptions. C and C++ can run OS-level code on virtually any platform. The languages are designed for a very minimal external language environment. Well, C was specifically designed to write an OS in (Unix).

Rust is at heart a safer C and its language environment is, so I understand, to be suitable for even low-level OS code just like C. So much that the Grand Penguin himself (Linux Torvalds) has been looking towards having Rust code in parts of the Linux OS.
 
Author
Posts: 22
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carl Byrd wrote:Hi Ken,

Congrats on the book. Do you think Rust will eventually replace C/C++ for most system-level type projects? Thanks.



I sincerely hope so! I should note that I have spent my entire 25-year career studiously avoiding C/C++ (and Java!), so my criticisms of those languages is entirely as an outsider. That said, I'd recommend you read the O'Reilly Programming Rust book, which was written by veteran C programmers who point out again and again the various ways that C/C++ allow you to write insane code with all kinds of undefined behavior and how Rust will not allow this (except for "unsafe" code).
 
Ken Youens-Clark
Author
Posts: 22
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Does Rust work on all platforms as C and C++ do, Carl? It can hardly replace them if it is platform‑specific.



I believe Rust will compile on every platform as C/C++. You can look at https://doc.rust-lang.org/rustc/targets/index.html for more information. What I adore is that I can *really* write cross-platform code that works on macOS, Linux, and Windows--I tests all the code in my book on all three platforms. I can barely get Python to act the same on all these.
 
Ken Youens-Clark
Author
Posts: 22
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:

Campbell Ritchie wrote:Does Rust work on all platforms as C and C++ do, Carl? It can hardly replace them if it is platform‑specific.



The real question is "can Rust run in any environment from cold iron up?"

I could not do OS-level programming on IBM mainframes in Fortran, COBOL, or PL/1. They could only run under their respective language environments (which were not friendly to interrupt-level coding, privileged modes, real-time or small-footprint uses.) One cannot extend Java's "write once/run anywhere" to cold iron, as Java needs its JVM environment. Likewise, Python, although an essential part of the Red Hat Linux boot process, cannot run on bare metal.

Granted, there are exceptions. Prime Computer wrote most (but not all) of its OS in Fortran (the hardware was actually optimised for Fortran, as I've mentioned occasionally). They also later adopted a dialect of PL/1, as Fortran was not the best language to do byte manipulation in on a word-addressed machine. I'm fairly certain that the Honeywell GCOS minicomputer systems could do OS-level code in COBOL (!!!).

But the point is, those were exceptions. C and C++ can run OS-level code on virtually any platform. The languages are designed for a very minimal external language environment. Well, C was specifically designed to write an OS in (Unix).

Rust is at heart a safer C and its language environment is, so I understand, to be suitable for even low-level OS code just like C. So much that the Grand Penguin himself (Linux Torvalds) has been looking towards having Rust code in parts of the Linux OS.



My formal education is in arts/language/music. I don't have a CS degree. I'm a self-taught hacker who's mostly worked in dynamically typed languages like Perl and Python. All those caveats said, I believe Rust can directly replace C/C++. As you note, it's probably going to become part of the Linux OS. Interpreted languages like Java, Perl, and Python require sometimes large runtimes/interpreters. One thing I note in the preface is that a Docker container with a useful Python runtime environment can run into the 100s of MB whereas I can build a similar Rust program and copy it to a bare-bones Linux VM that weighs in the 10s of MB. I believe some C libraries are needed (please don't hold me to that), but it's not much.
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic