• 4 Posts
  • 46 Comments
Joined 3 years ago
cake
Cake day: August 5th, 2023

help-circle
  • Maybe they are trying to manifest its death by arranging its funeral over and over. Programming as an art form isn’t more dead than painting as an art form, as long as people want to do it. However, as the blog post hints at, what you produce for work wasn’t perhaps ever meant to be a work of art. You aren’t necessarily going to be able to write code in your favorite style for work anyway, unless you can influence it and decide the conventions. That has been true since forever in larger organisations.

    Props to the blog author for seeking out new experiences in their free time but what they are mourning is either still there (just write your art code) or they have just had to adjust to their new trade-off. Don’t be surprised when it doesn’t feel artistic if you don’t spend any effort on the process.










  • A closure may/will try to capture by reference, so it may hold references to the calling function’s scope. For example, this would want to hold a reference to x:

    let x = 0;
    std::thread::spawn(|| x += 1);
    

    It’s as if you had a struct like this:

    struct MyClosure<'a> {
        x: &'a mut i32,
    }
    

    That makes the closure non-'static, since it holds non-'static references. The usual solution is to use the move keyword, to hint that you want it to move by default, or to use scoped threads. But yeah Send and 'static depend on the captures.

    Am I correct in guessing that you handle is of Gontian origin?

    Yes! 😁 I picked it when I used to play Tibia (15-20 years ago!), and it stuck with me since then. The correct spelling was already taken, so I modified it a bit. This name is usually available.


  • Your guess is correct, it should be understood as

    F: ( FnOnce() -> T ) + Send + 'static
    T: Send + 'static
    

    The FnOnce() -> T is syntax sugar for FnOnce<(), Output = T> and the bounds after apply to F. That’s also why T has separate bounds. They aren’t propagated or inherited. It’s just an ambiguous looking syntax, but T + Trait + 'lifetime isn’t a valid syntax for applying bounds to T (unless I missed something).

    The type F may be a closure over values from the calling thread. It has to be possible to send these values to the spawned thread, hence F needs Send + 'static. When the thread is done with its work, it returns a value of type T that gets passed back via JoinHandle<T>, so T needs Send + 'static too.

    I hope this cleared things up a bit.