Thursday 17 December 2020

Reflection on my CS50 journey so far

After finishing the Week 5 Problem Set, that's generally the end of learning how to programme using C. From the next week onwards, I'll be using other programming languages such as Python and SQL. From the sound of it, using Python will be a lot easier compared to C (really hope so).

I read from a blog written by someone who has completed this course, that C is an on-the-ground-level programming language, and because of this, understanding what's happening underneath the "hood", understanding what the computer does when it receives a specific code that you typed in would be essential. But for Python, it is a programming language that has integrated programmes that people have wrote, and to use these programmes or functions, we just need to type a shorter and simpler syntax to get the computer to do what we want it to. Not sure if this means that we can just ignore the idea of memory and data structures which gave me a hard time completing the problem sets.

Anyways, I've been thinking about what I'd like to do for my Final Project, although there are still many weeks of lectures and problem sets to complete before I even get there. I've thought of two major ideas.

The first one is making an app to track budgets and spendings. There are probably tons of apps out there that do this, but I wanna make it personal for my own needs and use. I want it to be an app that helps me plan for my future wealth, other than just tracking how much I spend. Up until now, I've been collecting receipts and checking my online bank account for any purchases that I did. I also record from where the receipts are issued to get a sense of the type of item I usually spend on. I also make notes on the large one-off spendings that I make like buying the SAMSUNG Tablet or traveling for leisure. 

Back in undergraduate, I used to have a cap on how much I should spend in a month, and how much I managed to save. But now, not anymore since I don't have a running source of money, just the savings that I have. But once I do, I want to be able to know how much I can spend and how much I should save each month for important things like car insurance, taxes, loans, and wish-list savings. I want to know how much should I save if I want to perform the Hajj ASAP, or if I wanna travel around the world. All without jeopardising future wealth. I'm not working yet, but I think it's important to have a system that allows you to calculate how much to save to allow you to pay for things like annual payments or having funds for emergency situations like sending your car to the workshop (which is unexpected) or paying for emergency medical expenditures. Even worse, having enough savings for a pandemic, like what we're facing now, the COVID-19 pandemic.

After these 6 weeks of CS50, I think I kinda have an idea how some apps work. I'll use the example of a period calendar/tracker (haha! I'm not even sure why this came first to my mind). I'm not gonna go through the entire functions of the app, like the forums and stuffs, just gonna go through the part where we have a calendar and we put in when we're having our periods, and when we have symptoms like spotting and mood swings.

So first of all, we have the calendar. I think the calendar is a hash table that stores many variables. Other than variables, it also stores the address where it can access the values we added, so that whenever we want to view the info we saved into a particular day, we just need to go to that day, and the app will show all the info stored under that day. Imagine that all the info are connected like nodes in a linked list, and there are additional functions that copy the values so that it can display all the values to us by the end of the linked list.

Imagine all the dates in the calendar as an array of buckets to be filled in with info

When we access one of the dates, we are redirected to a linked list of variables

To add data, the programme is going to allocate just enough memory to do it. Like, obviously, we won't be using all the dates available in the calendar since there are days we're totally fine. Allocating and using unnecessary memory to store nothing is just ridiculous and memory space-wasting, so I guess, the programme will also frequently malloc-ing and freeing memory when we're done using it.

Not sure about the visual representation of the apps though. Like how do they design the icons and stuffs? I kinda get the idea of printing stuffs out, but not sure about how they do it beautifully and aesthetically. Maybe manipulate some bits, combine the three basic colours to make images? I'm not sure if this is gonna be taught in the course, but I hope they do.

The second one that I'm thinking of doing is developing a webpage that helps students do econometrics or illustrate Economic theory using specific numbers (since a lot of stuffs are done using algebra at higher level). Some people may not have a strong background in Maths (I've seen people struggling in my Master's programme because of the Maths), so having a website that can show step-by-step procedures in calculating values would be nice. Especially for problems that involve matrices. If I can also make accurate diagrams based on the input that the user gives, that'd also be nice. I'm envisioning an interactive Economics learning website.

So those are the ideas I have so far. Will see if one of them is feasible to do, or I may need to come up with new ideas. 

Tuesday 15 December 2020

CS50 Week 5 (14/12/2020)

Following the completion of PSet 4, I took another two-week break from CS50 because I wanted to focus on my research proposal write up and completing my Financial Econometrics assignment. After finishing Financial Econometrics Assignment 5, I immediately opened the edX webpage and head over to CS50 Week 5 to watch the lecture.

So far so good. I was able to answer questions whenever the lecturer asked questions to the lecture attendees, though my answers won't reach the lecturer since it is pre-recorded. But when I began working on the first part of the assignment Speller, my brain felt blank. I kept staring at what I wrote down (the to-do list) but I can't seem to comprehend what I should do to achieve them.



I began thinking (again) that I am not fit for this course. The thought of quitting hits me really hard. I began Googling whether I should do it or not. Fortunately, the internet community is very supportive and they encouraged people who had the same thoughts as me to endure it, and we'll definitely gain a life-changing experience out of the course.


When I wake up the next day, I reread the lecture notes and watched one of the shorts videos on Hash Functions to gain a better understanding of what it actually is and what it actually does. Reading the lecture notes helped me write codes when I need to connect nodes for the hash function while watching the shorts helped me understand hash functions better.

In short, hash functions are actually an array of 'buckets' that store numbers. These numbers represent a string, calculated using a function (can be anything, but easier to use an established hash function that has been written by someone else). When we pass a string into the function, the function generates a number, and stores this into one of the buckets. Whenever we want to check whether the string exists or not in one of the buckets, we just have to find the bucket using the same number, and check whether the string is stored in there.


I had so many segmentation faults, but it was mainly because I typed the wrong 'stuff', so the computer was searching for something that doesn't exist, to begin with. But after correcting it, the programme ran smoothly. Yet, that was not the end of the problem.

When I checked the output of my programme, my Speller doesn't consider a word with full capital letters the same as the same word with lower cases. After searching for answers to this problem online, I realised that it was because my hash function was dependent on the ASCII values of each character of a string. The ASCII value for a capital letter is not the same as the one for the same letter but of lower case, so the words "word" and "WORD" would have different numbers generated by the hash function, and so, Speller considers these words as two different words.

Once I fixed this, I was finally done. Alhamdulillah.