Thursday, December 5, 2013

week 15


The semester comes to an end today. The final test is a nightmare for me. I didn’t complete the whole section of problems. It seems time is too limited. It is really a pity that I cannot get an A for the course even if I did well in everything except the final test. Anyway, I really gained a lot in this class.
First, the second half of the class taught us many knowledge about object oriented concepts and design principles. Abstraction, encapsulation, polymorphism, dynamic binding, they are really complicated and cool!
I would like to thank Professor Downing’s lecture, which is unique and great. It is so different to what I received before. But after I got accustomed to it, I really appreciate it. The code sample is very meaningful and helpful to help us master the concepts. I also like the way we discussed it, which is ask and answer. It forced everyone focus on the material from beginning to the end.
We have done five projects finally, and the last three are more complex and useful, which require us to apply object-oriented concepts.  It will always be better to write code than only read design principles. My C++ skills improved after the practices of those projects. That is cool.
I have some feedback to the following items:
the use of GTest: to be honest I didn’t benefit too much from it. It looks a burden to me that I have to fill out enough test cases for each function. However, I always finish that at the end of the project, which means I really passed the acceptance tests, making it meaningless to do unit test using GTest.
The three projects, Allocator, Darwin,and Life. I really like Allocator and Life, from which I learnt inner knowledge of c++. It seems that Darwin is not necessary considering we implement life project, which is a higher challenge.
Company talks are cool. They show a broader world to us and make the lecture not so stressed.
Estimated Stat:
weekly time spent studying: 2 hours
weekly time spent coding, testing, debugging: 10 hours

total lines of code produced for the team: 5000 lines

Saturday, November 23, 2013

week 13

This is the week before last week and we had many “last” done, such as last project and last quiz. 

Thanks to Downing for giving us 5 in the last quiz and an one day extension of the 5th project life. It is reasonable that last project will always be most difficult, especially if we have many topics uncovered yet. To well figure out how the life system works and how to design different classes, we have to first understand the code slides on the class homepage. However, just as Downing said, the slide may help us more than we expect because of the strong relevance between them. After the instruction, I read the slide again and finally had the design phase done. I found that doing such a project really helped me to have a bettering understanding of object oriented programming, especially inheritance, abstract class, and dynamic casting. It is better than reading textbooks and code. Another thing worth mentioning is how I debugged the code. On Tuesday I found my output of cell is a little different from other students in the public repo. After simulating step by step myself, I thought my result was what I expected. Did it mean I have some misunderstanding of the requirement of the project? In fact, it is true. I incorrectly dealt with the case about age resume. After realizing that, I quickly got the correct answer

After the project, I think it is time to begin reviewing everything we learnt in the class during this semester because the final test is approaching. A should be my goal surely. I should be confident about it because of my current rank. However, just pay enough efforts in the incoming week. I can make it.


There was another company talk from square. The introduction was amazing to me! I really like it for many aspects. The first thing is their product, of course. What’s more, their working environment looks cool from video. For some sense, it is a still startup and the feeling is absolutely different from Google or Microsoft. It will push you to learn many new technologies. I really look forward to a chance of doing a summer intern there next year.

Saturday, November 16, 2013

week 12


This is a tough week for me. I had an interview for seeking a summer intern to Microsoft. During the interview there are some behavior questions such as describe my most challenging project. The main part of the interview is coding. I was asked to reverse a single linked list. It was an easy and trivial question. However, I was too nervous during that time and only had so clear idea about the best solution. Initially I gave a straightforward solution that copy each node in extra space and construct a new single linked list. It did waste a lot of space, which is big O of N complexity. Then the recruiter asked me not to use extra space to solve this problem. In fact I did know that I should not use extra spaces but I thought extra space would make it easier. So when it comes to find a solution of not use extra space, I began to think about the arrangement of pointers in the list node. Although a little complicated and I was a little messy, I finally made it. However, the follow up question made me crazy. How to make it done in O(1) time rather than O(n)? I just though it was impossible but the recruiter said I could make some changes. I could not figure it out about what the change could be. He gave me some hints but even with these hints I don’t know how to do it, until he gave me the whole solution.
Well, this is my first interview after coming to UT Austin. Although my performance is not so satisfied, I took it and consider it as an important and useful experience. Wish I could do better next time.
It happens to have a company talk from Bloomberg this week on Friday. Their work is really interesting, especially the research and development of machine learning. Bloomberg really have many data resources in this big data era and it would be really cool if I could have an opportunity to have an intern there. So just applied online yesterday!

Saturday, November 9, 2013

week 11


This week I mainly did two things for cs371p.
This first thing is that I created my portfolios with the help of seelio.com. I have to say seelio is really a great service that you just need to fill in your information and get an impressive and nontrivial homepage, which from my point of view is much better than Google site. It also saves your time comparing to build your own site from scratch. Portfolio is meaningful to me that it reminds to collect my projects to web so that I will never lose them and could show others a good demo. It is a similar story that I should push all my project code to github. That’s cool.
Another thing is Nick and I completed the fourth project Darwin. It is an interesting project. We are simulating a world that different creatures compete with each other. It is great to see after a number of steps simulation there will be only one or two species left, which is the most intelligent one. In this project, we learned how to write a decent program following the object-oriented guidelines. Avoid to use setters and getters is definitely a lesson we learned. The high light of the project is that we created a new species that beat all creatures of other species after enough steps of simulation. In fact, we didn’t design a totally new species. It is just a simple modification of rover, but it really works well that our creatures are dominant in the final grid. It far out numbered others, which made my partner and I feel great.
In this week’s lecture we discussed initializer list, which looks very complicated that I failed in the last quiz. Even though I could understand what the code is written for, it is totally different to write it by myself. As a result, in the quiz, I had no idea about how to implement the initialization list. We need to consider the inheritance, const, reference, and object’s copy constructor, default constructor. Next time, I should have a quick review after the lecture and may write some code if there is new syntax discussed in the lecture. Practice is very very important in coding.

Friday, November 1, 2013

week 10


We are entering November, the last month that will have cs371p classes. In this week, the company’s talk was really impressive. The representative of Mutual Mobile, mainly talked about changes. Comparing to previous talks, I am much more interested in this topic because I am a huge fan of mobile. I won’t miss any news of iOS/Android and their mobile devices. It is cool to hear some opinions about the changes and how should we handle the changes in mobile era, especially after I developed my own Android app this semester. Although it may be a little too far away for me to consider the architecture of my android development, learning some knowledge about it is still useful during I am learning the fundamentals.
It is a good question to think how to deal with the disappearance of service like Google Reader, if it is used in your application. The story just teaches us to make the services in a relative separate places so that we can easily get rid of it and choose some other services to replace it if necessary.
Another interesting point is the shift of major platform like iOS 7. I like the opinion that such a dramatic shift is not only a task to developers, but also a chance to do something. It is well known that currently some big application developing company dominants the app store and it is very hard for individual developer to achieve success. When a change happens, it is the individual developer’s chance to quickly adopt it and make the application more appealing to users. That could be the best way to attract new users.
In this week, we also talked about the project 4, Darwin. It is totally different from previous projects and we are supposed to have more object oriented design. Although we read many articles teaching us what is object oriented and the basic principle of object oriented, completing a project with object oriented guideline will be much more helpful. We need to think over the design before writing code. Pay attention to the use of getter and setter, which should be discouraged.
Fight.

Tuesday, October 29, 2013

Paper Review


One common problem that many programmers may be confused of is how variables we declare and use are managed inside the memory. It is also a hot topic that is discussed in CS371P class for countless times. For example, Downing likes to ask us, whether the new variable is stored in stack, or heap? Sometimes we have to guess because there are too many scenarios in both Java and C++.

Before discussing what is presented in the paper, we need to figure out, what is the literal definition of Memory Management? It is the process of recognizing when allocated objects are no longer needed, deallocating the memory used by such objects, and making it available for subsequent allocations.

There are mainly two approaches to memory management and we are lucky to see that C++ and Java happen to cover the two approaches. Java corresponds to automatic memory management, while C++ corresponds to explicit memory management.

The author of the paper began with the Java garbage collector. As we know, Java only stores primitives on the stack and they exist within the scope of the function they are created in. Objects on the other hand are created on heap using keyword new. It is also common sense that garbage collector is responsible for deallocating the memory that were no longer used. What we are interested is how does gc finish this job. According to the paper, in JVM there is a full state diagram of totally eight possible object states. Among them, the garbage collector is interested in the reachability state (are there still references in the program to this object) and the finalization state. The garbage maintains a circular state diagram for objects. Once the object becomes finalizer-reachable, it will be garbage collected eventually.

C++, on the other hand, is quite different. The author first introduced basic concepts of the locations where objects can be placed, which include static memory, stack and heap. Similarly, objects located on the stack are fully managed by the compiler and there is no need to manually allocated memory or delete them when they are no longer used. The limitation is that the size of objects must be known at compile time. Objects on the head are dynamically allocated at runtime and this is what we will focus on, since we have to manage the memory using new/delete manually. It is the cost of flexibility without garbage collector.

As mentioned in our lecture, the author also pointed out a potential problem during memory deallocation. That is exception. Different techniques of both Java and C++ were presented in the paper to address this problem.
For Java, the trick is finally blocks. Although C++ also support try/catch blocks to handle exceptions, only the Java programming language knows the so-called finally blocks. It is always executed as last part of the try block, so in the presence of catch blocks, the catch blocks are executed first in case of exceptions.
Code is better example than words.
Void JavaFinally(){
       resource = new resource();
       try{
              // something which could throw exception
       }finally{
              resource.cleanup();
       }
}
Regardless how the try block is left, the finally block will be used to call the cleanup method.
For C++, techniques include 1) avoid the requirement for manually managed dynamic memory 2) using smart pointer types and 3) possibility to use custom garbage collector.
Method 1 is trivial that we just use STL that provides many generic class implementation to meet our common requirements. Vector is the example we discussed in class.
The second method is interesting. The basic idea is to implement a class who is compatible to a normal pointer and has a destructor that performs the cleanup. As we talked in the class, auto_ptr<> from STL is such a class.
void HeapAlloc(){
       int* x = new int(0);
       int* z;
       {
              *x = 3;
              int& y = new int(*x);
              y++;
              z = &y;
       }
       (*x)++;
       delete x;
       ++(*z);
       delete z;
}

#include <memory>
void CPPauto_ptr(){
       std::auto_ptr<int> x(new int(0));
       std::auto_ptr<int> z;
       {
              *x = 3;
              std::auto_ptr<int> hlp)new int(*x));
              int& y = *hlp;
              y++;
              z = hlp;
       }
       (*x)++;
       ++(*z);
}
Comparing the two sections of code, we could get rid of the delete after using auto_ptr. Another point worth mentioning is that, if an exception happens in std::auto_ptr<int> hlp)new int(*x));, the resources occupied by the previously allocated object will be cleaned up properly. This is also the reason why each allocated object is directly passed to an auto_ptr<> (line 8). Using this technique guarantees to not leak if an exception happens.

The author didn’t provide many details about the third method and only said that there were systems that implement a garbage collection for the C++ programming language similar to Java. But the limitation is also obvious for most of them that they don’t destroy the objects properly and just re-use memory occupied by this object.

In conclusion, although many topics in the paper were discussed in class, it is still meaningful to review them together, which makes all knowledge connected to each. Comparison of memory management between Java and C++ showed us both similarities and differences and strengthen our programming abilities in both languages.


Friday, October 25, 2013

week 9


Have a nice week with full credits of three quizzes. Project 3 Allocator was also due this Thursday.
Allocator is different from previous projects that there is no online judge for us to see if our code work or not. We only implement header file and the correctness of code will heavily rely on our own unit tests. Maybe in previous projects we can pass the online judge and then complete the unit test, during which we will be very confident. This time, we have no idea about how our code performs. We need to design every possible corner and edge test cases ourselves. Only doing in this way could help us to make sure that we are in a safe environment. In fact, we did find many potential bugs with our test cases. The bug is not so obvious to fail every test. It occurred in some cases. Finding such bugs made me feel great and more confident about our work.
I also want to say some about the test review session. I failed to attend Monday’s session. Since I lost 20 points in multiple choices and 9 points in short answer, and I knew one short answer problem that I made a mistake, I just thought the review session had little meaning to me. However, after seeing my exam on Friday, I found more mistakes than I expected. Some of the problem is just so tricky such as comparing the size of array a and &a[0]. I took it for granted that they are different, just like what we discussed in the class. However, this time size of array a from the second element is 8 bytes, which is the same with the size of an pointer. It reminds me to be more careful during doing these problems.
I also liked the lectures that systematically introduced 6 kinds of variables about their numbers, allocation, initialization, score, and lifetime. Comparison between them will make the knowledge much more clear than ever before. Adding static to local variable changes everything except scope, while adding it to global variable changes nothing but scope. It is such a great sentence to help us memorize the concepts about static, local and global.
Keep fighting in next week!