Saturday, February 27, 2016

Entry 5: The Actual Week 6: A1->A2

Okay I lied. Reading week apparently didn't count as a numbered week.
Also, no excuses for me. Although I did remember that I should update my blog during my Friday lectures, I had completely forgotten about it until this lunch when I was munching on some ___ did I realize that... maybe I should have completed my entry by Friday. Maybe I'll set an alarm for it some time later.

We finally started recursion this week, and by the looks of it, this topic will go on for quite a bit longer. I've seen enough people crack jokes about recursion (ie, pretending to recurse their sLOGs, so I won't do it here). Although many people haven't done recursion and doesn't realize it, I believe teaching us LinkedList(Nodes) was a good prequel. One can argue that the form of it drawn out like a long chain has nothing to do with recursion, which I admit is true, but actually the definition of linkedListNodes do look like recursion -- calling an object within an object, just like calling a function within a function. However, I guess I shouldn't write too much about recursion here because Week 7 sLOGS should be more focused on recursion.

Therefore, labs and assignment 1. Although Assignment 1 is now up and running (my version on events.txt and events_small.txt anyways), I must reflect on this time. I don't believe that I had done enough testing for all the different possible cases because I finished coding on Wednesday. Our group had only simulation.py and monitor.py to finish after reading week, so we thought we had some spare time and let down our guard during the last week. This should not happen in order to finish earlier for testing purposes. We should not have relaxed just before the finish line -- like a race, we should dash past the finish line before relaxing. Testing should be done anyways. The program is in fact more complicated (with more modules) than the ones before, but is still tiny as compared to major software programs. Testing should be done along the way to ensure there are no future problems. I think unittests were only written up until event.py. Doctests were rarely done. There is definitely for improvements there.

Also, finding a good group becomes essential in working in larger projects -- just as mentioned in class, there were many divorces and late constructions of groups. It is reasonable that since students don't know each other well and conflicts can happen, but at the last minute, changes like these don't seem appropriate? I guess, at least try working with someone before you decide whether you work well with them?

Usable Code:

  • zip(a, b) 
    • //maps every ele of a to b
    • zip([1,2], ["a","b"])
    • [(1,"a"), (2, "b")]
    • *zip() //unzips a zip
  • filter(bool f'n/expr, iterable/list/etc) 
    • //goes through iterable and filter by checking each element with boolean statement
    • filter(1, len(x) for x in ["a", "bc", "d"])
  • expr1 if bool else expr2
    • if bool: expr1
    • else: expr2
  • there must be something else here, but i can't quite remember...
    • maybe i'll add on later.

Friday, February 19, 2016

Entry 4: Week 6: Reading Week Freaking Week

And so I resort to blogging on Fridays.

Next week is Week 7, we will be starting recursions, and so I have to update by Thursday to print the entry out. Okay. Got it. Mental noted.

As opposed to actually having reading week to catch up on reading, I found myself doing more work. Huh. But all's well, because computer science is being worked on -- especially A1.

To be honest in some aspects A1 is easier than I thought, but in others, harder. The complexity of the code actually needed to be written wasn't as bad, but the "figuring out" what to write part was worse. Actually reading the whole document, mapping the thoughts out, and clearing up which module belongs where takes up quite some time. The tips here is to DRAW LOTS OF PICTURE!!! Okay maybe not pictures of little cars and little people, but definitely flowcharts and diagrams of classes, objects, and their connections. Especially when two classes can share a common attribute or subject, but in actuality said thing can only belong to one of them.

We are quite lucky that many of the APIs are given to direct us in the correct direction, but finishing them up are sometimes also a handful. MAKE SURE TO COMPLETE THEM!!! It gives readers and everyone else (even the coder as they come back to this program) a lot of readability.

There isn't much to say while coding, other than KEEP YOUR CODE AS SIMPLIFIED AS POSSIBLE. This is for running and reading code. Why complicate it when it could save so much space/run time/read time? Although, for a relatively smaller program like this, it is arguable to have code executable in one line written out in several lines for clarity, but I feel that it is best to simplify everything as much as possible. For this assignment, there shouldn't be a lot of hard coding in my opinion, especially for the first few classes.

TEST AS YOU GO! After writing code for a section, it is essential to test them. As much as I had complained about unittest in my previous post, I cannot deny how useful they are -- especially as programs grow larger and larger and it's almost impossible to test but simple doctests and feeding code in through the program by hand like a little baby. I found that I actually wanted to do unittests after I finish bigger classes like Events and even Dispatcher. However, unittests are extremely time consuming, so I would suggest NOT doing that unless you are sure you have enough time, or shorten them and test only the most essential cases.

Last but not least, a progress update. My group and I did originally WANT to finish the programming by this week, but it turned out to be more than we thought, given there were so many other subjects to do. However, here's a # TODO list:
- test Events; - do Simulation.py + test; - do Monitor.py + test
I'd say we are "almost" done, but those two being the two harder classes, I'd say we are ~1/3 way to go.

Friday, February 12, 2016

Entry 3: Week 5: Of Assignments and Tests

I must make a correction to my statement last class. In fact, I do indeed find a difficult aspect for me appearing in this course -- Unit Tests. While it is untrue to say that unit tests are hard in nature (since they have a defined structure so there is little variance in constructing them with code), they are trouble some in their flexibility and range covered.

To test a program fully, all significant cases of a method must be tested. However, what is exactly "significant"? Although we do follow the rule that we should at least test the null (ie 0-sized list) cases, the smallest interesting case, regular cases, borderline cases, and cases where specific variables have values that make a difference in the result, that still leaves a big variation in each one of the cases. Having to consider for all of these is a very good practice, as it prevents unexpected errors in execution, but covering all of them takes a lot of effort. Constructing each unit test also consumes as much time, or even more, than writing the code. Fixing the code for unit test is also difficult, having to consider for all cases and make it still functional. There then exists a problem of how much error prevention is needed in each method -- the open ended question of the type of improper input the end user can enter expands into a completely different universe of possibilities for the program.

As helpful as unit test is, as dreadful as I am to it.

Other than that, this week had passed in the discussion for Assignment 1 and writing Test 1. Test 1 was on Wednesday, and the only regret I had was that I didn't have enough time to check my test over. Since there was a test before our section, we were let in a bit late and I had a class immediately after. With only around 45 minutes, writing all docstring, APIs, and code, proved to be doable, but a bit rushed. I wish I had a bit more time to read what I wrote over and not make any little mistakes. And for Assignment 1, my team and I found it a bit confusing due to the interaction between classes. Currently, we have done the basic classes, and are arguing over the implementation of events. (Although I must state my confusion here... In Java and C++ for code I have done, Events are a part of the standard library in the languages. However, is it simply because we didn't import packages with specific Events so we could define Event as our own class?)

Here's what I learned this week:

List and Linked List Based Queues:
  • List based Qs are too slow
    • asymmetric
    • add @ front + remove @ back: shift right for add, too slow
    • add @ back + removed @ front: shift left for remove, too slow
  • Stacks are faster: access @ one end = ~same ease of access/speed
  • LinkedList Based Qs:
    • more symmetric @ both ends
    • doubly linked (previous + next) = more symmetric
    • if singly linked: add @ back + remove @ front:
      • del front = change first
      • add back = append
      • other way: remove cannot do "previous" of back
    • if doubly linked: both direction works
      • though slower @ middle
Linked Stacks:
  • Instead of append (like Q), prepend (to invert order)
  • add front, remove front
  • not necessarily slower than stack

Friday, February 5, 2016

Entry 2: Week 4: Stacks, Qs, and Linked Lists

I think the most difficult thing for me during this course is to actually settle down and read the notes. Up until now, I have been doing relatively well (hopefully...) understanding the concepts in class and practicing during lab. However, I always find a million things I need to do and never really review my notes and concepts... Which this blog serves at least a part of the purpose for coming back and looking at what we learned.

I haven't yet found any aspects to be extremely challenging because I have had some minimal experience in coding in other languages. I do need to be careful though, because after all, some things like linked lists are still new concepts to me. The most challenging concept will probably be efficiency and Big-O in the later half of the course -- I was never good at it.

And for this week (as a summary of this week's lecture and Friday's class. I have not decided on a set schedule to post yet, though I probably should. I was hoping for bi-weekly):

Stacks:
  • NOT built into Python
  • Last In First Out (LIFO?)
  • Good for balancing parenthesis/delimiters
    • left in (, [, { //opening: add to stack
    • right out ), ], } //closing: match with most recent, remove from stack
    • balanced if out = last in
    • concatenation of balanced = balanced
Queue:
  • First In First Out (FIFO)
  • Coffee Line/Ticket Line
Linked Lists:
  • Separate bits of data
  • Easier to grab in storage
  • Value + "Pointer" // 2 parts
  • Concept can be viewed in two ways
    1.  Quite literally like the format of its declaration:
       LinkedListNode( value1, LinkedListNode( value2, LinkedList( value3, ...)))
      A box inside a box inside a box inside a box insi-...
    2. A flowchart
      Node(v1, pointer-)-> Node(v2, pointer2-)->Node(v3)
      One points to another points to another until arrive @ no pointer
  • Node vs Wrapper
    • node: self, next
    • wrapper: front, size, back
  • Append/Prepend/Delete
    • change related variables
    • Prepend: 1st, 1st's next, size
    • Append: (if not first) oldLast's next, last, size
    • Delete: oneInFront's next, size
Usable Code/Miscellaneous:
  • A subclass of std lib class cannot simple overwrite methods of SUPER
  • super.method() //parent class's method
  • random
    • import random (package)
    • random.randint (smallest, largest)
    • inclusive
  • list.insert(i,x) insert @i before original x
  • Abstract Classes: Simple API for all the child classes to be file under
    • basically a container
    • convenient
    • no var/fn of its own
  • var_ //distinguish names from std py names
  • isinstance(var, type) vs type(var).__name__
  • walk-a-list:
    • current = first
      • while!=last:
      • current=next
  • assertion
    • bool fn, a checking statement
    • crash if false
  • __contains__ maps to "in"
  • __repr__ maps to return print value
    • def __repr__(self):
      • return "Ahaha %s nope %s" %(self.x, self.y)
    • >>> var
    • Ahaha selfXval nope selfYval
  • __getitem__ enables printing parts
    • print(LinkedList[0:3])