The C++ to Rust Phrasebook provides a quick reference for C++ developers transitioning to Rust. It maps common C++ idioms and patterns to their Rust equivalents, covering topics like memory management, error handling, data structures, and concurrency. The guide focuses on demonstrating how familiar C++ concepts translate into Rust's ownership, borrowing, and lifetime systems, aiming to ease the learning curve by providing concrete examples and highlighting key differences. It's designed as a practical resource for quickly finding idiomatic Rust solutions to problems commonly encountered in C++.
This document provides a concise guide for C programmers transitioning to Fortran. It highlights key differences, focusing on Fortran's array handling (multidimensional arrays and array slicing), subroutines and functions (pass-by-reference semantics and intent attributes), derived types (similar to structs), and modules (for encapsulation and namespace management). The guide emphasizes Fortran's column-major array ordering, contrasting it with C's row-major order. It also explains Fortran's powerful array operations and intrinsic functions, allowing for optimized numerical computation. Finally, it touches on common Fortran features like implicit variable declarations, formatting with FORMAT
statements, and the use of ALLOCATE
and DEALLOCATE
for dynamic memory management.
Hacker News users discuss Fortran's continued relevance, particularly in scientific computing, highlighting its performance advantages and ease of use for numerical tasks. Some commenters share personal anecdotes of Fortran's simplicity for array manipulation and its historical dominance. Concerns about ecosystem tooling and developer mindshare are also raised, questioning whether Fortran offers advantages over modern C++ for new projects. The discussion also touches on specific language features like derived types and allocatable arrays, comparing their implementation in Fortran to C++. Several users express interest in learning modern Fortran, spurred by the linked resource.
This paper introduces Crusade, a formally verified translation from a subset of C to safe Rust. Crusade targets a memory-safe dialect of C, excluding features like arbitrary pointer arithmetic and casts. It leverages the Coq proof assistant to formally verify the translation's correctness, ensuring that the generated Rust code behaves identically to the original C, modulo non-determinism inherent in C. This rigorous approach aims to facilitate safe integration of legacy C code into Rust projects without sacrificing confidence in memory safety, a critical aspect of modern systems programming. The translation handles a substantial subset of C, including structs, unions, and functions, and demonstrates its practical applicability by successfully converting real-world C libraries.
HN commenters discuss the challenges and nuances of formally verifying the C to Rust transpiler, Cracked. Some express skepticism about the practicality of fully verifying such a complex tool, citing the potential for errors in the formal proofs themselves and the inherent difficulty of capturing all undefined C behavior. Others question the performance impact of the generated Rust code. However, many commend the project's ambition and see it as a significant step towards safer systems programming. The discussion also touches upon the trade-offs between a fully verified transpiler and a more pragmatic approach focusing on common C patterns, with some suggesting that prioritizing practical safety improvements could be more beneficial in the short term. There's also interest in the project's handling of concurrency and the potential for integrating Cracked with existing Rust tooling.
Summary of Comments ( 57 )
https://news.ycombinator.com/item?id=44140349
Hacker News users discussed the usefulness of the C++ to Rust Phrasebook, generally finding it a helpful resource, particularly for those transitioning from C++ to Rust. Several commenters pointed out specific examples where the phrasebook's suggested translations weren't ideal, offering alternative Rust idioms or highlighting nuances between the two languages. Some debated the best way to handle memory management and ownership in Rust compared to C++, focusing on the complexities of borrowing and lifetimes. A few users also mentioned existing tools and resources, like
c2rust
and the Rust book, as valuable complements to the phrasebook. Overall, the sentiment was positive, with commenters appreciating the effort to bridge the gap between the two languages.The Hacker News post titled "C++ to Rust Phrasebook" spawned a lively discussion with a variety of comments exploring the nuances of transitioning from C++ to Rust, the utility of the phrasebook itself, and broader comparisons between the two languages.
Several commenters appreciated the phrasebook's practical approach, highlighting its usefulness for developers actively making the switch. One commenter specifically praised its focus on idiomatic Rust, emphasizing the importance of learning the "Rust way" rather than simply replicating C++ patterns. This sentiment was echoed by others who noted that direct translations often miss the benefits and elegance of Rust's features.
The discussion delved into specific language comparisons. One commenter pointed out Rust's stricter rules around borrowing and ownership, contrasting it with C++'s more permissive memory management, which can lead to dangling pointers and other memory-related bugs. The complexities of Rust's borrow checker were also discussed, with some acknowledging its initial learning curve while others emphasized its long-term benefits in ensuring memory safety.
The topic of undefined behavior in C++ arose, with commenters highlighting how Rust's stricter compile-time checks help prevent such issues. One user shared a personal anecdote about tracking down a bug caused by undefined behavior in C++, emphasizing the time-saving potential of Rust's stricter approach.
Some commenters discussed the performance implications of choosing Rust over C++, with one suggesting that Rust's zero-cost abstractions often lead to comparable or even superior performance. Others noted that while Rust's memory safety features can introduce some runtime overhead, it's often negligible in practice.
The thread also touched upon the cultural differences between the C++ and Rust communities. One commenter perceived the Rust community as more welcoming to newcomers and more focused on modern software development practices.
While many commenters praised the phrasebook, some offered constructive criticism. One suggested including examples of unsafe Rust code, arguing that it's an essential part of the language for interacting with external libraries or achieving maximum performance in specific scenarios. Another commenter wished for more guidance on translating complex C++ templates into Rust.
Overall, the comments on the Hacker News post reflect a general appreciation for the C++ to Rust Phrasebook as a valuable resource for developers transitioning between the two languages. The discussion highlights the key differences between C++ and Rust, emphasizing Rust's focus on memory safety, its stricter compiler, and the benefits of its idiomatic approach. While acknowledging the learning curve associated with Rust, many commenters expressed confidence in its long-term potential and its ability to address common pain points experienced by C++ developers.