Log inOpen app
Eric Fredine
7,217 posts
user avatar
Eric Fredine
@fredine
Principal engineer writing code for fun and profit. Lapsed photographer. Husband. Father. Aspiring fly fisher.
Vancouver, British Columbia
ericfredine.ca
Joined July 2008
3,153
Following
1,255
Followers
user avatar
@fredine

See Eric Fredine’s full profile

Open X

New to X?

Sign up now to get your own personalized timeline!

Create account

By signing up, you agree to the Terms of Service and Privacy Policy, including Cookie Use.

Terms·Privacy·Cookies·Accessibility·Ads Info·© 2026 X Corp.
Don't miss what's happening
People on X are the first to know.
Log inSign up
  • user avatar
    Eric Fredine
    @fredine
    Apr 13, 2024
    In Rust there's a very elegant solution:
    user avatar
    Coding and Cats
    @codingandcatss
    Apr 12, 2024
    This code structure is called an arrow anti-pattern. How to fix this code?
    63
    73
    2.3K
    382K
  • user avatar
    Eric Fredine
    @fredine
    Apr 11, 2024
    Rust is doing this correctly. It’s better to model things as they are rather than requiring a bunch of implicit knowledge. The simplicity of C is dangerously misleading.
    user avatar
    Glitchbyte
    @0xglitchbyte
    Apr 10, 2024
    How hard can strings be? /s
    42
    91
    1.7K
    196K
  • user avatar
    Eric Fredine
    @fredine
    Oct 19, 2024
    Learn Rust the Dangerous Way is a series of articles putting Rust features in context for low-level C programmers — the sort of people who work on firmware, game engines, OS kernels, and the like. … was a delightful Saturday morning read. Link in the reply.
    2
    57
    652
    50K
  • user avatar
    Eric Fredine
    @fredine
    Jul 4, 2024
    In Rust when you see let y = x.clone(); You don’t know if it’s a cheap reference count increment or an expensive allocation and memcopy. You can do this instead: let y = Arc::clone(x); And enforce it with a clippy lint: #![deny(clippy::clone_on_ref_ptr)]
    19
    21
    486
    136K
  • user avatar
    Eric Fredine
    @fredine
    Jul 27, 2024
    Reading large csv files in parallel chunks is tricky because you can’t be sure a line end isn’t in a quoted field. But I found a paper showing how to make a good guess that works most of the time!
    11
    40
    433
    46K
  • user avatar
    Eric Fredine
    @fredine
    Apr 6, 2024
    I think I’m now at a point where I’m more productive in Rust than TypeScript or PHP because I spend almost no time debugging. An expressive type system and pattern matching is a game changer. If it compiles it works.
    22
    19
    364
    53K
  • user avatar
    Eric Fredine
    @fredine
    Oct 26, 2024
    Replying to @GeorgeMayer
    Would work for groups of people trying to decide where to go for lunch at work as well.
    4
    1
    282
    20K
  • user avatar
    Eric Fredine
    @fredine
    Oct 18, 2024
    I know I’m a bit in the Rust bubble but there really does seem to be a lot of new and impressive software being built in Rust? It seems to be accelerating.
    24
    3
    219
    20K
  • user avatar
    Eric Fredine
    @fredine
    Aug 7, 2024
    Async is the final boss in Rust.
    22
    6
    211
    20K
  • user avatar
    Eric Fredine
    @fredine
    Nov 1, 2024
    Rust lifetime misconceptions #5: if it compiles then my lifetime annotations are correct The inferred lifetime for the returned Option<&u8> is the lifetime of &mut self but semantically we want it to be the lifetime of remainder. So it needs to be annotated.
    struct ByteIter<'a> {
    remainder: &'a [u8]
}

impl<'a> ByteIter<'a> {
    fn next(&mut self) -> Option<&u8> {
        if self.remainder.is_empty() {
            None
        } else {
            let byte = &self.remainder[0];
            self.remainder = &self.remainder[1..];
            Some(byte)
        }
    }
}
    struct ByteIter<'remainder> {
    remainder: &'remainder [u8]
}

impl<'remainder> ByteIter<'remainder> {
    fn next(&mut self) -> Option<&'remainder u8> {
        if self.remainder.is_empty() {
            None
        } else {
            let byte = &self.remainder[0];
            self.remainder = &self.remainder[1..];
            Some(byte)
        }
    }
}
    8
    13
    189
    22K
  • user avatar
    Eric Fredine
    @fredine
    Jun 30, 2024
    This clickable diagram from Effective Rust showing all the transforms for Option and Rust is an absolute masterpiece: docs.google.com/drawings/d/1EO… The only other thing you need to know is when to use as_ref.
    docs.google.com
    Rust Result/Option Transformations
    Result Result Result Option T E Option unwrap, expect, unwrap_or[_else], unwrap_or_default ! unwrap_err, expect_err Err(e) Ok(t) Some(t) ok_or[_else] ok err map, and[_then] map_err None or[_else]...
    3
    21
    149
    8.2K
  • user avatar
    Eric Fredine
    @fredine
    Jun 30, 2024
    The arrival of an Effective book for Rust seems like a coming of age thing. Rust has matured to the point where best practice guidelines are established. I’m a fan because it reduces the cognitive load of making things go brrr. lurklurk.org/effective-rust/
    3
    17
    124
    9K
  • user avatar
    Eric Fredine
    @fredine
    May 18, 2024
    I've been implementing a simple binary tree. This has really driven home for me that collections need to implement three different iterators: one for references, one for mutable references and one that consumes the collection - which is the one shown here for my binary tree.
    14
    3
    110
    19K
  • user avatar
    Eric Fredine
    @fredine
    Jan 24, 2024
    Rust has a fear problem. I semi-seriously implied to someone that they could re-write their Typescript lambdas in Rust and save a bunch of money. They were terrified that it would be impossible to find people capable of doing it.
    14
    5
    115
    17K