I recently completed my first fullstack project. Well, I still think it is far from completion as I keep getting ideas about new features I can add to my project but now for the least I can be proud of it.
The project was a real estate dealing site. The purpose of the site was to help people look for houses they want to buy and also help real estate agents to sell any houses they have by listing them on the site. Once a person likes a house and want to buy/rent it, the person can contact the real estate agent and talk about it and make a deal.
While the idea seemed pretty simple to me at first but as I started coding, then I realized that it is not the case as I kept stumbling upon design problems, database deadlock situations, concurrency issues and many more.
I will write about the project in greater details in future post, for now I want to share the lessons I learned while doing the project and which can be prevented with some precaution.
Well, the technology stack I used in my project are:
For frontend:
- HTML
- CSS
- Bootstrap framework
- Javascript
FOr backend:
- Node
- Express.js framework
For database:
- MySQL
Before starting the project, I had the knowledge and experience of working with HTML,CSS,Bootstrap and MySQL extensively while Javascript, Node and Express.js were completely new to me and I had no previous knowledge of them.
By doing the project, I learned a lot of new things and also I made a lot of mistakes which I only came to realize at the end of the project.
1. Plan everything before you start programming
One of the grave mistakes I did was I didn't plan what I needed for the project, what are the features that needed to be present and I didn't put too much thought into the database schema design. All of this led to a lot of trouble in the later part of the project. As I didn't plan the features to be added to the project in the beginning, I kept adding new features on the go as I kept getting the idea about them. But this created a lot of hassle for me!
As the kept adding new features, I had to change my database design a lot. I kept on adding new tables, sometimes deleting current ones and many times changing the schema of the current relations. All of this led to a whole lot of frustration and confusion which clearly disturbed the smooth flow of the project.
2. Design your database schema before you start programming.
Although, this point is part of the first point but I want to put more emphasis on it. One of the big mistakes I did in the beginning of my project is I didn't put much thought or work in the schema design of my database. This led to a huge pile of problems in later part of the project. One of the main problems I faced was while creating triggers in the MySQL database. Due to no previous planning of my database schema, I stumbled across database deadlock situation while creating one of the triggers. Since, I was already near the end of my project, changing my database schema at this point felt a lot tough with a huge data population. Thus, I was not able to resolve the deadlock situation and had to drop the idea of adding a feature which was dependent on the trigger. Also, at the end of the project, I realized how no planning of the database schema led to a poorly constructed and highly inefficient database. The database was not at all scalable and if it was not a personal project but a product to be used by people, it would have caused a lot of trouble as number of users increased. So, it is better to design the database properly at the beginning of the project than to go through all the trouble later on.
3. Know the framework/language in depth before you start doing some project.
I coded the backend bit of my project in node. Node was completely new to me before starting the project. Before starting the project, I spent a lot less time than it was needed to learn node and it surely created a lot of problem while doing the project. While doing the project I didn't know that Nodejs is asynchronous in nature. While I primarily have experience with C,C++ which are synchronous in nature, the asynchronous nature of node came as a big shock to me. I learned about the asynchronous nature when I was sending query to my database from the server using node. The flow of the code was not the one I was expecting. So after sending a query to the database, node didn't wait for the result and simply started executing the next line of code. It created a lot of errors and unexpected results. I struggled to understand the problem when it occurred and it took up a lot of my time to figure out the reason behind the unexpected behavior of the code. How I solved this problem has also taught me a lesson.
4. While taking each decision, always consider the long term solution.
In the above point, I mentioned the problem I faced due to the asynchronous nature of node. While I recognized the problem after some time, I realized I lacked the knowledge of promises and async/await which are able to solve the problem more efficiently. Soon I started to read about them and I realized if I implement them, I have to modify a huge chunk of my code. So, instead of doing that I took the short term solution which is executing each query in nested form. Although this solution worked perfectly, it created a problem of it's own. This problem is something known as the callback hell. It basically means is that I kept nesting my function calls and the nesting got so deep that my code became somewhat cumbersome and unreadable.
Even for me, the code became somewhat cumbersome and I can imagine how difficult it would be for someone other to read the code and understand it. As I kept nesting, the lines of code kept shifting rightwards and soon it became difficult to code in the editor itself. So, it is wise to plan everything always consider the long term solution.
5. Choose the appropriate framework before starting the project.
In my first attempt of building the site, I chose to do the server side code using pure node. Soon I realized it was a wrong decision and had to restart the whole project. It was because as humongous the project was, coding it with pure node led to lot of programming from scratch and created a lot of frustration. I basically had to code a lot of the components from scratch as pure node don't have them in the native library. It took a lot of time and if you are under time constraint, it would be better to use a framework such as express.
6. Always make your code modular
I always had a bad habit of coding all of my methods, structures and everything in a single file.Although this worked for small projects but while working on somewhat large projects, it created a lot of trouble. If the code is not modular, first it creates a lot of confusion during debugging and secondly it makes the code unreadable. To be able to write a clean code, it in necessary to make the code modular. It not only helps to deliver your intent, idea to the other person reading your code clearly and effectively but it also helps you to have a smooth flow during the coding process and be less frustrated while debugging.
Top comments (5)
Well, unless you're working on a project that must go into production, you don't really have to know the language/framework you're going to use in depth. In my experience I've learned a lot more by getting my hands dirty and for me it's better than trying to know everything before starting.
That's true. One can't possibly know everything about a language/framework before starting a project but I believe it is necessary to have a strong and deep knowledge of the language/framework in which the project is to be done.
Personally, I have stumbled while starting a project with half knowledge of the required language/framework and it usually leads to very bad code as well as design. One can surely learn a lot by getting their hands dirty and learn on the go but sometimes it is risky to make mistakes on certain project which are going to impact a lot of people due to broken or inadequate knowledge of the required language/framework.
Hey Soumyajit I'm looking forward to know about the application. As a beginner node developer I did face similar issues and would love to share some of my thoughts that could be of some help.
Thank you Rikesh for the tips. Yes, I will surely share more information about my application in future blog.
Thank you for this meticulous article.