Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

One thing that helps at lot with programming is my tendency to visualize branches and dependencies as graphs/trees as I read/write code. This makes aberrations and code smells extremely obvious. A dirty hack makes you go from something that looks like a beautiful fine-toothed comb to a comb with a cancerous tumor on it.


Sounds like something that would make an interesting blog post!


That's a good idea.

Sometimes the domain is already graphical - and I take every opportunity to make the code match the visual layout, ex:

https://github.com/danthedaniel/gameoflife-rs/blob/master/sr...

    /// Count living cells adjacent to a cell in the matrix.
    #[inline]
    #[rustfmt::skip]
    fn alive_neighbors(&self, x: i32, y: i32) -> u8 {
        [
            self[(x - 1, y - 1)], self[(x + 0, y - 1)], self[(x + 1, y - 1)],
            self[(x - 1, y + 0)], /*  selected cell  */ self[(x + 1, y + 0)],
            self[(x - 1, y + 1)], self[(x + 0, y + 1)], self[(x + 1, y + 1)],
        ]
        .iter()
        .fold(0, |total, &neighbor| total + (neighbor != 0) as u8)
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: