Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Review #1

Closed
wants to merge 2 commits into from
Closed

Code Review #1

wants to merge 2 commits into from

Conversation

isovector
Copy link
Collaborator

I just deleted everything so that I could revert it and use the PR code review tools. GH is not so helpful at reviewing code that already exists :)

Copy link
Collaborator Author

@isovector isovector left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all, this is a great project, Chris. My comments are mostly around library functions you should know about, some stylistic things, throwing type-safety at the problem, and how to avoid partiality. Based on what I've seen here, I'd happily hire you for any team I was working on!

README.md Show resolved Hide resolved


-- | An angle as measured in degrees (rather than radians)
type Degree = Number
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type synonyms (via the type keyword) provide no type safety, and client code doing math is the exact sort of place you'd expect people to accidentally use rads instead of degrees or vice versa.

Using a newtype here would differentiate Degree from Number at the type level (rather than just changing the word used in the documentation.) I like to think of this analogously defensive driving --- assume someone (possibly you?) is going to make a mistake down the line, and you want to be ready for it.

src/Graphics.purs Show resolved Hide resolved
src/Main.purs Show resolved Hide resolved
src/Main.purs Show resolved Hide resolved
CenterSouth -> anchorCenterSouth s
Bottom -> anchorBottom s
LogicalOrigin -> s{pos=s.pos :-: s.originOffset}
_ -> s
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No wildcards! Enumerate all the cases!

src/Core.purs Show resolved Hide resolved
updateSprites :: (Sprite -> Sprite) -> ApplicationState -> ApplicationState
updateSprites f state = state{sprites=map f state.sprites}

updateWhen :: (Sprite -> Boolean) -> (Sprite -> Sprite) -> SpriteMap -> SpriteMap
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More composable to write this function as: updateWhen :: (Sprite -> Bool) -> (Sprite -> Sprite) -> Sprite -> Sprite. This thing admits a monoid instance via Endo, and now you can change predicates and transformations.

src/Core.purs Show resolved Hide resolved
src/Core.purs Show resolved Hide resolved
@isovector
Copy link
Collaborator Author

isovector commented Aug 5, 2021

Closing this (but not deleting!) because it keeps popping up in my list of open PRs and I am momentarily confused about why! Hope it was helpful :)

@isovector isovector closed this Aug 5, 2021
@chriskiehl
Copy link
Owner

Hey! Yeah, seriously, super helpful! A very ill-timed death of my (admittedly ancient) computer right after I emailed you took a bit of steam away from my working on this (thus the sudden stop in movement). However, I've legit read your comments multiple times. Tons of useful info that I'm excited to dig into now that I've got my dev machine stood back up!

Thanks again!

@isovector
Copy link
Collaborator Author

My offer still stands if you have more questions --- I legitimately get a blast out of this stuff. Hope the new dev work goes swimmingly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants