Move semantics in Rust, C++, and Hylo
What Hylo Is and Surface Syntax
- Hylo is a niche “C++ successor”-style language (formerly called Val), not yet widely used.
- Some dislike its
funkeyword and the article’s inconsistent capitalization of “rust”; others see this as trivial bikeshedding. - Hylo is associated with well-known C++ figures, which raises interest despite its immaturity.
C++ Move Semantics and POD/String Details
- Several comments say the article oversimplifies C++ moves, especially around
std::stringand POD. - Clarification: the
Personexample is not POD because it contains a non-POD (std::string); defaulted move constructors call member move constructors. - Moving a
std::stringusually transfers internal pointers; the moved-from string remains valid but in an unspecified state (often empty, but not guaranteed). - For aggregates and POD-like types, move and copy can be identical in cost (flat copy).
Undefined vs Implementation-Defined and “Use After Move”
- Disagreement: one side claims accessing a moved-from
std::stringis undefined behavior; others assert it’s implementation-defined/unspecified but still valid. - Consensus: standard library types must remain destructible and safely observable after move; user types can be written poorly and violate invariants, but then that’s a bug, not mandated UB.
- Tools like clang-tidy warn about “bugprone use-after-move” because it’s usually a logic error even if technically allowed.
What std::move Really Does
- Multiple comments stress that
std::moveis just a cast to an rvalue reference used to select overloads (e.g., move vs copy constructors). - It does not “force” a move; the target type decides whether moving is cheap or just a copy.
- Overuse of
std::movecan harm performance; some link to examples where it blocks optimizations or adds overhead.
Rust Ownership, Initialization, and Comparisons
- Rust has similar “move” behavior: ownership transfer copies the struct shell but reuses heap allocations.
- Literals are
&str;to_string()creates an ownedString. You only need it when ownership/mutation is required. - To keep using a value after a function call, you pass a reference (
&Tor&mut T), not ownership. - Rust’s
MaybeUninitis mentioned as the “separate type” modeling (un)initialized memory, versus Hylo baking initialization into call conventions.
APIs, Syntax, and Standard Library Evolution
- Several note the article compares Rust’s
println!to old-style C++ streams, ignoring newerstd::printlnandstd::formator the long-existingfmtlibrary. - Others respond that C++23/20 features are very new, not widely available, and can significantly increase compile times in practice.
Complexity, Footguns, and Hylo’s Pitch
- Some argue C++ move semantics are overly complex, with experts disagreeing on details; this raises doubts about their suitability as “everyday” features.
- Others view confusion as mostly educational or “skill” issues once you internalize ownership patterns.
- There is interest in Hylo’s “mutable value semantics”: aiming for functional-style reasoning (no aliasing surprises) with in-place mutation performance, via richer call conventions (
let,set,sink,inout).