• 0 Posts
  • 113 Comments
Joined 1 year ago
cake
Cake day: August 8th, 2023

help-circle
  • gerryflap@feddit.nlto196@lemmy.blahaj.zoneRule
    link
    fedilink
    English
    arrow-up
    0
    ·
    4 days ago

    Using Haskell you can write it way more concise:

    iseven :: Int -> Bool
    iseven 0 = True
    iseven 1 = False
    iseven 2 = True
    iseven 3 = False
    iseven 4 = True
    iseven 5 = False
    iseven 6 = True
    iseven 7 = False
    iseven 8 = True
    ...
    

    However, we can be way smarter by only defining the 2 base cases and then a recursive definition for all other numbers:

    iseven :: Int -> Bool
    iseven 0 = True
    iseven 1 = False
    iseven n = iseven (n-2)
    

    It’s having a hard time with negative numbers, but honestly that’s quite a mood








  • Sometimes I look at the memes around here and wonder wtf y’all are doing. Like, neither my code nor the code at the place I work at are perfect. But I don’t think I’ve ever seen a merge do this. Maybe some of the most diverged merges temporarily had a lot of errors because of some refactoring, but then it was just a few find + replaces away from being fixed again. But those were merges where multiple teams had been working on both the original and the fork for years and even then it was usually pretty okay.