Hello Blog-Viewers,
Welcome to my fourth week of working with ScrapZero. Last week I set a goal of completing the program by this past Tuesday. Unfortunately, time has past and I have yet to complete it.
I discovered something new about programming this week—threading. Apparently, in most computers, programs run operations simultaneously and do not always follow the order specified by the programmer. Logically, this would seem to speed up computer processes and it does.. But it definitely slowed down my process (of completing the program.)
So here is an example of multi-threading:
If I have two functions, “f1” and “f2”, I might choose to run “f1” before “f2”. Logically, in a generic programming language, one would write:
“run f1”
“run f2”
The problem is that “f2” might have already completed a task before “f1” finished. In my case, “f2” was highly dependent on the results of “f1” which basically made the program fail every time.
So what did I do about this? I learned how to use multi-threading in programs to my advantage. In the Swift programming language, there is a method of prioritizing events with a block of code that looks like this:
dispatch_async(qos, { () -> Void in
//code to be run goes here
}
//qos is another variable that defines how important the process is.
//qos is another variable that defines how important the process is.
I probably should not go into too much detail as these processes are still a brain teaser for me.
So I finally fixed my code and the app is running properly. Although the app is not complete, I am going to start building an interface for ScrapZero so that it can easily modify the JSON file that I mentioned in the last blog post. This way, I won’t have to be the one to update the information that is uploaded to the app.
Thank you for checking out my blog. I hope to have some serious results in soon.
Lorentz
Awesome work! What exactly does multi-threading do to prevent code dependent on other parts of code from finishing too fast? Does it slow down that code, or does it re-order the order of execution altogether, or something else?
ReplyDeleteHi Pranav,
DeleteI'm glad that you are interested in the computer science aspect of my project. Threading, as I understand it, simply reorganizes the ordering of "threads" of code. In more complicated process, a programmer can also specify the priority of a certain process so optimize the program and make it more efficient.
For example, in my program I put the priority of getting map data from the web to "high" because it is very important that the user gets that information quickly. This will use more battery and data in the initialization of the app, but it necessary.
Threading just adds another layer of complexity to programming for the real world.
It sounds like your app is coming along nicely (even if the timing is a tad delayed). When it is finished, what do you plan to do for the rest of your srp?
ReplyDeleteThis is a great question. I plan to work on general media such as Facebook and website development. I might also just work on brainstorming other general ideas for the company. But I still have a bit of coding to do before I am finished with what I am working on.
DeleteDo you mean you planned to have the app completed by Tuesday or just part of it? If so, would we be able to test it out when you're done?
ReplyDeleteYou will be able to test and run the program when it is done.. However, I meant that my intentions were to have the app running sooner than it seems is currently possible. I am working hard though.
Delete