BB_C

joined 1 year ago
[–] BB_C@programming.dev 2 points 3 hours ago

Also:

A short post on how variable names can leak out of macros

I don't think you understood the blog OP!

[–] BB_C@programming.dev 1 points 3 hours ago (1 children)

Maybe a good idea for a post. But the amount of reaches required makes this icky.

  • Pretending people write:
    let Ok(x) = read_input() else { return Err(Error) };
    
    instead of
     let x = read_input().map_err(|_| ...)?;
    
  • Pretending people write:
     const x: &str = "...";
    
    instead of
     const X: &str = "...";
    
  • Pretending there exist people who have such knowledge of rust macros hygiene, ident namespaces, etc, but somehow don't know about how macro code expands (the "shock" about the compile error).

Maybe there is a reason after all why almost no one (maybe no one, period) was ever in that situation.

[–] BB_C@programming.dev 1 points 2 days ago (1 children)

you’re not supposed to immediately reach for macros

correct

for small things you don’t quite like about the language.

incorrect

Excessive macro use makes it impossible for others (including your future self) to read your code

N/A. the macro above is trivial.

impossible for others to read your code and there’s often good reasons why it’s designed like it is.

fiction

[–] BB_C@programming.dev 2 points 2 days ago* (last edited 2 days ago) (3 children)

There is a general mechanism in Rust that allows language users to add their own sugar. It's called macros 😉

macro_rules! keep {
    (let $id:ident = $expr:expr => $($tt:tt)+) => {
        let $id = $expr;
        let $id = $id$($tt)+;
    }
}

fn main() {
    keep!{ let path = std::env::current_dir().unwrap() => .as_path() };
    println!("{path:?}");
}

You can remove let from the macro's fragment specifier and invocation.

[–] BB_C@programming.dev 1 points 3 days ago

mastering_rust

Maybe wait until you're actually good at it.

[–] BB_C@programming.dev 3 points 5 days ago

Bringing vimperator/pentadactyl back! That would be the dream.

Anyway, last time I tested it (~3 weeks ago), servo was not very usable still with the few websites I tried. Hopefully it gets, at least partway, there in a few months.

[–] BB_C@programming.dev 14 points 5 days ago (1 children)

Neither.

  • make new() give you a fully valid and usable struct value.
  • or use a builder (you can call it something else like Partial/Incomplete/whatever) struct so you can't accidentally do anything without a fully initialized value.

Maybe you should also use substructs that hold some of the info.

[–] BB_C@programming.dev 7 points 1 week ago (2 children)

If you're not into tiling, install openbox and a panel of your choosing. You will quickly find that you don't need a DE at all.

[–] BB_C@programming.dev 5 points 1 week ago
  • C++ offers no guaranteed memory safety.
  • A fictional safe C++ that would inevitably break backwards compatibility might as well be called Noel++, because it's not the same language anymore.
  • If that proposal ever gets implemented (it won't), neither the promise of guaranteed memory safety will hold up, nor any big C++ project will adopt it. Big projects don't adopt the (rollingly defined) so-called modern C++ already, and that is something that is a part of the language proper, standardized, and available via multiple implementations.

would you argue that it’s impossible to write a"hello, world" program in C++

bent as expected


This proposal is just a part of a damage control campaign. No (supposedly doable) implementation will ever see the light of day. Ping me when this is proven wrong.

[–] BB_C@programming.dev 4 points 1 week ago (3 children)

The only (arguably*) baseless claim in that quote is this part:

it’s theoretically possible to write memory-safe C++

Maybe try to write more humbly and less fanatically, since you don't seem to be that knowledgable about anything (experienced in other threads too).

* It's "theoretically possible" to write memory-safe assembly if we bend contextual meanings enough.

[–] BB_C@programming.dev 8 points 1 week ago* (last edited 1 week ago)

If lock-ergonomics^ⓒ^ is as relevant to you as indexing, you're doing it wrong.

I would rather take indexing returning Results than the other way around.

One can always wrap any code in {||{ //.. }}() and use question marks liberally anyway (I call them stable try blocks 😉).

[–] BB_C@programming.dev 1 points 2 weeks ago

..and that's how you drive up metrics.

view more: next ›