My earlier projects are USA-centric. This time, I decided to focus on China, the world's 2nd largest economy, with 19% of the world's total population.
To compare the top 3 popular web frameworks (Ruby on Rails, Django, Express) in details, I will create a China Emperor (CE) database.
These 3 frameworks have different strengths. If the goal is to build a simple web app (such as this website), I will choose Rails.
I will choose Django if I am building a business where data collection is a priority.
Based on app size, Django is the smallest while Express is the biggest. These images show why I give Django 3 points and Express 1 point.
We can reduce Rails app size to 1MB if we clean up the tmp folder constantly.
NPM is 1 of the biggest strength of Express app, but it appears that it's bloating the app.
After thinking for 10 mins, I decided to create the 3 tables for the CE database: Archetypes, Dynasties, and Emperors
Archetypes and Dynasties are lookup tables. They store all the possible personality archetypes and dynasties details respectively.
When I was building Rails and Django CE web app, I restrict the number of characters for specific columns. Because I am careful and I am not 100% confident with the validation tests.
I shouldn't have done this premature optimization, but I did it because I love lean, mean killing machine. Therefore, Express CE web app doesn't have this restriction:slight_smile:
I created the 3 possible archetypes for emperors: Conqueror, Builder and Mediocre
You can understand what each archetype means from their descriptions.
For all the columns in dynasties table, only Dynasty length column is a calculated field:
Dynasty length = End year - Start year
I stored the value as a column in the database, which I regret now. The idea I have when I design the database is this:
SELECT * FROM dynasties WHERE dynasty_length > 200;
SELECT * FROM dynasties WHERE end_year - start_year > 200;
But now, I have to write the query like this:
SELECT * FROM dynasties WHERE CAST(COALESCE(dynasty_length,'0')) > 200;
because I chose the wrong datatype for the year columns. I should have used datatype INTEGER instead of VARCHAR for the year columns. I used VARCHAR because I was thinking of storing the date in VARCHAR. But I forgot since I already restricted the year columns to 4 digits (YYYY), it is
impossible hard for the users to input the wrong year:stuck_out_tongue:
To ensure data integrity, if I want to store calculated fields, I need to have bullet-proof tests to ensure that the users don't input data that I don't foresee. It will be a cleaner solution if I do the calculation at view instead of the model. At least if the data is wrong, I can see it on the UI. The database will be error free.
What I love about Rails:
What I love about Django:
Express gives me nothing but pain:rofl:
Q1. Ying Zheng (Qin Shi Huang) is the 1st emperor of China, why is he a builder and not a conqueror?
He is born as the prince of Qin kingdom and become the king at the age of 13. He conquered all 6 kingdoms and unified China. He is the 1st emperor of China. He inherited the Qin kingdom, which becomes the foundation of the Qin dynasty. In my opinion, he is a builder and not a conqueror.
Q2. Since when is Cao Cao an emperor?
He has the power of the emperor, even though he doesn't have the official title. As I value actual power over the title, I consider him an emperor. And because I like him.
From this project, you see the mistakes that I have made because I don't spend more than 10 minutes thinking about the database design. Lucky this is a learning project and not an actual multimillion/billion dollar startup. Then again, if this is a real business, I would be 1000 times more careful. It will be a bad joke if you destroy your empire before your enemies come:wink:
So, have you decided which framework is the most suitable foundation for your empire?