teacherc / spheri-app

Spheri is a simple web app that recommends a song based on your local weather
https://www.spheri.app
GNU General Public License v3.0
18 stars 3 forks source link

Validator pattern #1

Open BurningSquid opened 2 years ago

BurningSquid commented 2 years ago

https://github.com/teacherc/spheri-app/blob/696ff65cdb4322fa59829698f400f0b34a07e121/main.py#L15

For data validation there are a few object oriented patterns that are helpful. Check out Pydantic's validator pattern. Essentially you store the information in a dataclass (in pydantic's case it inherents from base model) with the validation logic.

teacherc commented 2 years ago

Will do. I was also thinking of using Flask WTF's forms and validators now that I understand Flask WTF a bit more.

BurningSquid commented 2 years ago

Will do. I was also thinking of using Flask WTF's forms and validators now that I understand Flask WTF a bit more.

Not as familiar with that as the FastAPI - Pydantic pattern but it looks fine

teacherc commented 1 year ago

@BurningSquid I've been reading Miguel Grinberg's Flask book and trying to understand these patterns. When I start my next project, I'll make it a goal to use Pydantic or FlaskWTF validator patterns for my forms.

BurningSquid commented 1 year ago

Great! Just wanted to highlight that this is a great example of what a lot of people call "technical debt" if you've heard that term before. It's totally acceptable to "kick the can down the road" for specific items as long as you can capture your thoughts on the "correct/ideal" way to do it now so that you can circle back later.

Management of technical debt is extremely important as a project matures and eventually becomes (at least in my experience) one of the primary concerns with dev planning later on