-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use static typing where available #216
base: main
Are you sure you want to change the base?
Conversation
c5a0b64
to
f922c4d
Compare
Whilst I'm a big fan of external typing tools like MyPy, I'm a little more cautious about this proposal. Firstly, I think we need to differentiate a little between how we deal with:
I'd be interested to hear any thoughts @matthewpassmore and @serena-piccioni about how we might apply some of the thoughts in this draft to GovPress work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this!
I would go as far as saying any non-trivial Javascript app MUST use typescript but in the interest of keeping this RFC as broad as possible I think SHOULD is fine.
We should probably be explicit about per-language choices, even if they are only recommendations. |
| ---------- | -------------------------------- | | ||
| C# | N/A | | ||
| Kotlin | N/A | | ||
| PHP | N/A | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RobjS @matthewpassmore do you have any thoughts on this? I think we probably haven't always been consistent about how we use annotations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left PHP as N/A here because (unlike Ruby/Python/JS) the typing is actually integral to the language rather than needing you to run an extra set of tools to make it work, although because it's interpreted there's probably a good way to include it in CI. If there's a handy PSR for it then it should probably be included in the same vein as PEP 484 though!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've used Psalm for static analysis on some projects. It does more than enforcing typing, but that's a big part of it, and we may be able to configure it to only worry about typing.
I've tried using static typing in PHP before and found it a bit of a mixed bag, as the tools don't always exist within the language to do it properly (although that has improved with PHP8), which means you end up with a combination of types declared in language and types declared in docblocks, which can feel a bit clunky.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mypy for Python isn't strictly speaking only for typing (although that's certainly its main purpose), and it can surface some other "this is obviously not right" stuff so I don't think recommending Psalm is necessarily a bad idea.
I think my preference would be for in-language type declarations, but that's only really because that's the way PEP 484 does it and consistency is good. No strong feelings if people actually working with PHP every day feel something else is better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR no longer recommends specific typing tools -- I believe we can resolve this conversation.
290335d
to
808423e
Compare
tl;dr: we should try use static typing where it exists, because it helps protect us from easy mistakes and makes us more fully consider the data our code is using.
Bikeshed for this at https://bikeshed.dxw.com/2023/02/24/just-my-type-why-we-should-start-using-more-static-typing/