Introduction
I am a student studying at University of Toronto, doing my best to learn all I can in computer science. Currently, I have one huge goal that I have my heart set on: Creating a mind-blowing video game that will surpass all others that are currently available AND the ones to come in the future. If someone wishes to know the specifics of this video game, feel free to ask. :)
This courSe LOG is all about my perspective, experiences and knowledge of the material that is taught in CSC148. Hopefully this SLOG will be helpful to those who read it!
Introductions aside, let's move on to the interesting stuff taught during the first two weeks of 148.
Overview
Having taken CSC108 last semester, I was surprised from how much new content that was already taught in the first 2 weeks of class.
Stuff we learned:
- Abstract Datatypes (ADT's)
- Stacks and Stack ADT's
- Object Oriented Programming (OOP)
- Ternary
- Comprehensions
- Recursion
- New Built-in Functions
Abstract Datatypes (ADT's)
This was super confusing for me at first but I think I've got it down. It's called abstract since it allows the programmer (the provider) to create methods or programs without having to worry about how others (the clients) will use it. It's something that will save time for the programmer if the client intends on using it without worrying about the code, while also maintaining the code's consistency without having to go into the specifics of each and every method. I can see how this would be useful in certain work related projects where there are time constraints and also in certain methods where it isn't necessary to explain how it works.
Stacks and Stack ADT's
Stack was somewhat touched on in 108. In 108, tracing our Python programs was the method used for learning about call stacks. However, in 148, we learned that stacks can also be in the form of lists and sets. These stacks in particular follow a structure known as LIFO, (Last In, First Out). LIFO can be recalled in real life situations! Picture this: Imagine taking a newspaper from a newspaper stand. They are usually stacked face down by placing one on top of another. Then when you take a newspaper, you take the one that was last placed (the one on top!) and with or without knowing it, you just had a LIFO moment! Easy Peasy!
However, we can also change the algorithm of LIFO and for example, take the item at the bottom of the stack out rather than the top. There are many ways to program this to get different desired results and the programmer can choose to make the algorithm abstract (without worrying about how clients will use the code). If this is the case, we have a Stack Abstract Data Type.
Object Oriented Programming
This is simply a paradigm where focus is emphasized on creating objects by means of classes as opposed to another paradigm called Procedural Programming which is the creation of methods and how they manipulate data. The latter (Procedural Programming) was mostly what was taught in 108, which I think is the appropriate order to learn programming in for people who are new to computer science.
Ternary
In this case, ternary isn't about the ternary numbering system, but rather an expression that has three arguments. Here is a simple example:
if The time is 9:00 A.M. <-- 1st argument
I need coffee <-- 2nd argument
else
I don't need coffee <-- 3rd argument
Comprehensions
From what I know, comprehensions are simply reducing a code from being multiple lines long, into a shorter version of code that is no less concise than the prior. Taking my example from above, let's see how the comprehension form of it looks!
(I need coffee) if (The time is 9:00 A.M.) else (I don't need coffee.)
BAM! Simple as that and something I hope to get used to since my code from l08 was horrendously long.
Recursion
Alright, so this is very new to me and probably everyone else but I will try my best to explain this! In order to deal with a complicated problem, rather than writing incredibly long code, perhaps this problem can be tackled down in smaller sizes and every time you tackle a small problem, the solution becomes easier to obtain. Recursion gets its name from implying repetition in solving a larger problem at a smaller scale.
Picture this: You're the captain of a pirate ship (YARR!!) and you encounter a Kraken (basically a gigantic octopus). It's looking for a fight! If you try to smack it in the face with your cannon, it will block it and instantly crush your treasured ship. That's a BIG issue so let's deal with the smaller problem first: The arms. Smack the arms with your cannons first, then when they're all dealt with, go for the prize!
And that's my story version of recursion.
New Built-in Functions
Many, many new things built-in functions were taught in the first two weeks. These functions were perhaps the most interesting things I've learned so far. They are of interest to me since I now have a larger arsenal of weaponry to handle the tests, assignments and exam (heheheh).
So what's new?
set : Sets are another type that are different from lists as they do not permit the same two items in one set. so if you typed in python: x = set((1, 1)), x would equal {1}. You can also do subtraction with other sets which removes objects and convert them to lists as well using the built-in function list().
isinstance : This checks if an object is a certain type. So for example: isinstace(1, int) would return True. Lots of potential here when going through loops which we'll probably encounter in many programming problems.
intersection : intersection takes two sets and compares them, returning objects that are in both sets. Although we haven't done much with sets yet, I can't wait to see the usefulness of this in particular.
re.split : Remember the split method? This is its brother, and he's stronger! Keep in mind to use method re, you have to import it first, so include import re in the code before you call method re, or there'll be an error. It basically allows you to add an operator '^' without the quotations which will negate a set such as [0-9] or [A-z]. From experimenting, I learned that the lowercase and uppercase matters.
Here's an example I used while playing around with it.
>>> import re
>>> a = 'I am Robot #52'
>>> re.split("([^A-z])", a)
['I', ' ', 'am', ' ', 'Robot', ' ', '', '#', '', '5', '', '2', '']
As you can see, there are some empty strings but the '#52' string has been totally split apart and the 'I am Robot' is split nicely. There are many desirable things one could obtain with this!
Anyways I would like to end my first SLOG here. So a few final words.
Please discuss with me if you like, I would love to.
I have an AMAZING lab partner, here's his SLOG:
http://mycsc148experience.blogspot.ca/
Also I really enjoyed reading this student's SLOG, he/she was very clear in explaining the new material and even I learned from this person's real life examples which I thought were hilarious! Check it out if you'd like:
http://ddc-csc148slog.blogspot.ca/
Hope you enjoyed,
Ciao for now - Brian.
However, we can also change the algorithm of LIFO and for example, take the item at the bottom of the stack out rather than the top. There are many ways to program this to get different desired results and the programmer can choose to make the algorithm abstract (without worrying about how clients will use the code). If this is the case, we have a Stack Abstract Data Type.
Object Oriented Programming
This is simply a paradigm where focus is emphasized on creating objects by means of classes as opposed to another paradigm called Procedural Programming which is the creation of methods and how they manipulate data. The latter (Procedural Programming) was mostly what was taught in 108, which I think is the appropriate order to learn programming in for people who are new to computer science.
Ternary
In this case, ternary isn't about the ternary numbering system, but rather an expression that has three arguments. Here is a simple example:
if The time is 9:00 A.M. <-- 1st argument
I need coffee <-- 2nd argument
else
I don't need coffee <-- 3rd argument
Comprehensions
From what I know, comprehensions are simply reducing a code from being multiple lines long, into a shorter version of code that is no less concise than the prior. Taking my example from above, let's see how the comprehension form of it looks!
(I need coffee) if (The time is 9:00 A.M.) else (I don't need coffee.)
BAM! Simple as that and something I hope to get used to since my code from l08 was horrendously long.
Recursion
Alright, so this is very new to me and probably everyone else but I will try my best to explain this! In order to deal with a complicated problem, rather than writing incredibly long code, perhaps this problem can be tackled down in smaller sizes and every time you tackle a small problem, the solution becomes easier to obtain. Recursion gets its name from implying repetition in solving a larger problem at a smaller scale.
Picture this: You're the captain of a pirate ship (YARR!!) and you encounter a Kraken (basically a gigantic octopus). It's looking for a fight! If you try to smack it in the face with your cannon, it will block it and instantly crush your treasured ship. That's a BIG issue so let's deal with the smaller problem first: The arms. Smack the arms with your cannons first, then when they're all dealt with, go for the prize!
And that's my story version of recursion.
New Built-in Functions
Many, many new things built-in functions were taught in the first two weeks. These functions were perhaps the most interesting things I've learned so far. They are of interest to me since I now have a larger arsenal of weaponry to handle the tests, assignments and exam (heheheh).
So what's new?
set : Sets are another type that are different from lists as they do not permit the same two items in one set. so if you typed in python: x = set((1, 1)), x would equal {1}. You can also do subtraction with other sets which removes objects and convert them to lists as well using the built-in function list().
isinstance : This checks if an object is a certain type. So for example: isinstace(1, int) would return True. Lots of potential here when going through loops which we'll probably encounter in many programming problems.
intersection : intersection takes two sets and compares them, returning objects that are in both sets. Although we haven't done much with sets yet, I can't wait to see the usefulness of this in particular.
re.split : Remember the split method? This is its brother, and he's stronger! Keep in mind to use method re, you have to import it first, so include import re in the code before you call method re, or there'll be an error. It basically allows you to add an operator '^' without the quotations which will negate a set such as [0-9] or [A-z]. From experimenting, I learned that the lowercase and uppercase matters.
Here's an example I used while playing around with it.
>>> import re
>>> a = 'I am Robot #52'
>>> re.split("([^A-z])", a)
['I', ' ', 'am', ' ', 'Robot', ' ', '', '#', '', '5', '', '2', '']
As you can see, there are some empty strings but the '#52' string has been totally split apart and the 'I am Robot' is split nicely. There are many desirable things one could obtain with this!
Anyways I would like to end my first SLOG here. So a few final words.
Please discuss with me if you like, I would love to.
I have an AMAZING lab partner, here's his SLOG:
http://mycsc148experience.blogspot.ca/
Also I really enjoyed reading this student's SLOG, he/she was very clear in explaining the new material and even I learned from this person's real life examples which I thought were hilarious! Check it out if you'd like:
http://ddc-csc148slog.blogspot.ca/
Hope you enjoyed,
Ciao for now - Brian.
Good post! You covered a lot!
ReplyDeleteReally nicely written, lots of detail.
ReplyDeleteComprehensions are dazzling... not sure I understood the intersection one he started to show us on Friday! Too much crossing over.
Hey! Sorry for a tad late response but hopefully this will clarify intersection for you. So let's set x = {1, 2, 3, 4, 5} and y = {3, 4, 5, 6, 7}.
DeleteTwo sets, simple so far yeah?
Now try this code!
x.intersection(y) and it will return the items that are in both sets.
So if I use z = x.intersection(y)
z will be assigned the set {3, 4. 5}.