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

I gotta say that, after not having used it in about 4 years, I love looking at Haskell again.

One question: could CurrentTile.hs be DRYed up? https://github.com/egonSchiele/chips/blob/master/src/Chips/C...

This repeating pattern seems ripe for DRYing:

    checkCurTile (Chip _) = do
      liftIO $ playSound (soundDir ++ "collect_chip.wav") False
      tileAt Current .= (Empty def)
    checkCurTile (Gate _) = do
      liftIO $ playSound (soundDir ++ "door.wav") False
      tileAt Current .= (Empty def)
    checkCurTile (KeyYellow _) = do
      yellowKeyCount += 1
      tileAt Current .= (Empty def)
    checkCurTile (KeyBlue _) = do
      blueKeyCount += 1
      tileAt Current .= (Empty def)
    [...]


Sorry for bad formatting and not compile checking the code, but this is an improvement imo:

    checkCurTile b = do
      case b of
       Chip -> liftIO $ playSound (soundDir ++ "collect_chip.wav") False
       Gate -> liftIO $ playSound (soundDir ++ "door.wav") False
       (KeyYellow _) -> yellowKeyCount += 1
       (KeyBlue _) -> blueKeyCount += 1
      tileAt Current .= (Empty def)


Ah yeah, it could definitely be refactored. There's some repetitive code in there.




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

Search: