My fourth week at DigitalLabs and first week of development, take a read.
Programming Starts
One of my passions in life is to code, learning languages from Javascript to C++. Programming has enabled me to take my ideas and bring them to life, from video games to recursive solutions using dynamic programming, sharing them across the world. As Gabe Newell, the founder of Valve said: “The Programmers of today..are the wizards of tomorrow”.
The first 3 weeks of the project consisted of design and features, providing a complete understanding of the project. On the other hand this week I built the initial building blocks of the system utilizing my knowledge of NodeJS and asynchronous programming flow. The reliance on my technical knowledge has increased each week, NodeJS, AngularJS, and MongoDB all had to be fully understood before this week even started. Fortunately, I have used both NodeJS and AngularJS in the past and used my SQL knowledge and documentation to gain a grasp on MongoDB. Surprisingly I thoroughly enjoyed working on the design and features fully fleshing out the system but, it has been splendorous to start to program.
Building the Backend
The objective for this week was to implement the system’s backend which includes authentication, the Import and Browse APIs, the database and connections to the file storage. The first part I tackled was authentication, which was relatively simple to implement. In previous weeks I thoroughly investigated and tested how authentication would work, to implement I simply copied and pasted the code I had written and stitched together with the single page web app (SPA). The file storage authentication was a similar story, stitching previously written code with the SPA. To construct the Import and Browse APIs, akin to authentication, formerly written code was used. Using the work from previous weeks was especially satisfying, reinforcing the significance of design and features, without it both authentication and the APIs would have stolen a considerably larger amount of time.
Constructing the connections to the file storage and the MongoDB database had I read a vast amount of documentation. For this specific build of the system the file storage used will be OneDrive thus the native API is needed. This was my first time working with the OneDrive API, initially, I read the API documentation learning the limitations and features.
Additionally, I read tutorials from various sources, once I felt I understood how the OneDrive API functioned, I implemented it connecting it the import API. When predicting the time each task would need, I thought the database construction would take much longer. Constructing the database was relatively straight-forward since the documentation was clear and concise.
Asynchronous Flow
More traditional languages, for example, C++ and Java are synchronous meaning that each line is executed in-order. NodeJS is asynchronous, permits other lines of code to execute before others have finished. Asynchronous flow is a difficult paradigm to work with, it requires a full understanding of ‘promises’ and ‘async tasks’.
In previous projects to deal with NodeJS asynchronous nature, I used NodeJS promises. Promises allow you to turn asynchronous code to synchronous by waiting for the eventual completion of an asynchronous operation. Once an asynchronous task has been completed the returning value can be checked to lead to other tasks to fire. One situation where promises are used is downloading data from an API. The time it takes to download data from an API is highly variable thus promises where used to wait for the download to complete then perform tasks on the downloaded data.
Working with DigitalLabs I have learned a second superior way to deal with asynchronous tasks, ‘async/await’. Async/await is very similar to promises, they wait for eventual completion of an asynchronous operation but in a syntactically simpler way. Using promises can be very convoluted and hard to track async/await solves this problem by providing a simpler syntax to solve the same problem
Conclusion
This week I learned a great deal especially about asynchronous programming in NodeJS continuing to improve my programming skills. It feels good that the backend system is now fully implemented allowing me to concentrate on the SPA for the rest of the development time.