DEV Community

Tong Liu
Tong Liu

Posted on

Reflect for Lab 4

What did I do and how did I do

In Lab 4, I added JSON config file support to Piotr's GitHub repo. Since Python language is arguably an easy-to-use language, most of the commonly used functions are natively supported. Of course, JSON is natively supported so parsing JSON is quite simple; I just used the file reader to read the config file that is passed with the argument '-c' or '--config', and pass this file object to the JSON parser function named load() in the JSON package and a JSON object will be returned. However, it wasn't actually going that smoothly, I had two issues in coding this lab.

Problem 1

The first one was with the JSON parsing function. There was a JSON object returned by JSON.load() that I mentioned earlier, although it truly returned a JSON map object after a successful parsing, the return type of JSON map object is a generic object which means the IDE can't infer what functions can be called onto the object and which function I can make a call on to check if an element exists in this JSON map object. I tried to google it, but nothing seemed to be useful. When I started to feel desperate, I realized maybe I can add a breakpoint to that JSON map object to see what it looks like in runtime. Luckily this solution worked. I noticed there was a function named __contains__(weird name..), I tried to make a call on it and it finally checked if the passed key exists in the JSON map.

Problem 2

Another issue was the way how Piotr coded the argument parsing code was hard-cording, which means it only accepts the argument in the designed sequence, for example, if I make the argument passing sequence -i ./input -c ./config.json work, then if I pass -c ./config.json -i ./input, only -i ./input will be taken. Apparently, this doesn't meet the requirement. To fix it, I refactored the code of this part and it worked well in the end.

My careless self..

Also, this shouldn't be counted as an issue, but I forgot to update my forked project before starting working on it, I tried to create a PR on my forked project to merge back the new update after I came to the realization that I had not done so. This time I wasn't that lucky, I had to deal with 3 conflicts since the part I had rewritten overlapped with Piotr's update. Resolving conflict wasn't very pleasant, but still, I did it.

Something makes my life easier

From this lab, the useful thing I've learned is the Draft Pull Request because it's very useful since it can be used as a way to create a pre-created Pull Request without actually posting it for review.

Don't be sorry be better

The biggest lesson I've learned is don't even think about coding before you've made sure that the your base branch's code is up-to-date, otherwise, have fun resolving conflicts.

Top comments (0)