Hacker News new | past | comments | ask | show | jobs | submit login

The code is so clean and simple. This is great PR for the company. I want to work there.



I think so too!

I have done a fair bit of Ruby a few years ago but I'm new to python CRUD apps and trying to improve my knowledge here. Is defining all models in the same file[1] conventional in python apps? Rails used to have separate files for each model. And most Ruby apps that I have seen advocate the one-class-one-file convention.

[1] https://github.com/airbnb/caravel/blob/master/caravel/models...


All models in one models.py file is common for Flask and Django.

If you use multiple apps within one Django project or the equivalent in Flask (Blueprints), that extends to one models.py per app (where a "project" is a collection of "apps").

Sometimes you'll see one file model per (with a models/__init__.py that imports them for use). While I think it keep dependency imports for each model very cleanly separated, you end up having a lot of redundancy importing the same basic pieces in every model file.


It depends how many models but usually 1 app models == 1 file (taking the app structure from django) unless they are expected to grow.

For example you have a comment app that could contain several models: Comment, Thread, Report, etc those can be in the same file. To continue on the django example, I would personally prefer having a models folder in the comments app and one file per model as some can get really big.

I also do 1 file / model in Flask, minus some specific cases where it just makes sense to have them in the same file


It depends on the project.

If you have a small number of models (e.g. <= 5), then it's fine to have them all in one file, as you will not benefit from multiple files, really.

When your application is growing, you have split the models into multiple files, grouped by features, etc (e.g. users.py, content.py, etc).

I prefer this as models usually a very small, and switching from one file to another can become quickly annoying when working on related models. However, it may be different for large classes.


Not from the number of lines of code. Some of them exceeds 1000.


# of lines does not indicate good or poor coding




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: