Monday, 2 February 2015

CSC148 - Entry 2

Entry no. 2, Week 4: First week impressions

Topics

1. My impression of the first few weeks


Going into the course, the pacing of the lectures felt a tiny bit slow to me, but that much was to be expected with the amount of new-comers from CSC108. Even though the lectures were slow, there were a few interesting concepts that I hadn't come across yet. 

A really useful concept was List-Comprehension, where new lists can be created based on other lists. 
For example in Python it looks a little bit like this.

>>> L = [1, 2, 3, 4].
>>> S = [ x ** x for x in L]
>>> S
[1, 4, 9, 16]

In addition to basic mathematical operators, well-defined functions or methods can be called on the elements inside as well.

>>> from math import sqrt

>>> L = [1, 4, 9, 16]
>>> S = [sqrt(x) for x in L]
>>> S
[1.0, 2.0, 3.0, 4.0]

Another thing that caught my eye was that Python didn't really have a "private" feature like other languages do. A single underscore ('_') on instance variables and methods coupled with the use of property(<fget>, <fset>, <fdel>, <doc>) acts as a way to redirect the access of information from the general public.

Other things we tackled over the first three weeks were Inheritance and ADT's, both of which are less new to me than the above topics. Below is a short run-down of what they are.

Inheritance is the idea of an Initial class (Super Class) giving its properties and methods to Subsequent classes (Sub Classes) where the Sub Classes are free to change (Over-ride), add to (Extend) or simply take (Inherit) from the Super Class.

ADT's  (Abstract Data Types) are ways of storing information. So far, we looked at Stacks, which is LastInFirstOut (LIFO) type of data type. With a stack, users can push in objects, pop the top-most one out, or just peek at it without popping it out.

No comments:

Post a Comment