Sunday, October 19, 2014

HTTP GET vs HTTP POST Requests

The primary difference between HTTP GET and HTTP POST requests is that HTTP GET request asks for data from the specific resource while the HTTP POST request submits data to be processed. For example, in the Guess Number lab the get() method in my code responded to the HTTP GET request from the browser by writing a response that output "Good luck!" with a form asking for the initial guess a submit button. The form then uses an HTTP POST request to provide the guess to be processed by the post() method in my web application.

There are also other differences between HTTP GET and HTTP POST requests. HTTP GET requests include the parameters in the URL, are used for fetching content, have a maximum length dictated by the maximum URL length, are okay to cache, and should not change the server. HTTP POST requests include the parameters in the body of the request, is used for updating data, has no maximum length, is not okay to cache, and can change the server.

Tuesday, October 14, 2014

Vectors and Arrays Advanced Computer Science

After working with both arrays and vectors in c++, the primary difference I see between the two is that while arrays are of fixed length, vectors can constantly be added to by inserting new elements. This naturally inclines both of these different data structures to be effective for different tasks. While arrays are very good for programs in which I know exactly how long of an array I need, vectors are good for performing operations in which the length of the vector either changes or depends on the value of an alternate variable. For this reason, I find vectors to be much more useful. They also are useful in that they store with them their size and their capacity (how many elements could potentially be stored in the currently allocated memory block). Vectors also change the amount of memory they are allocated as their size changes and the memory they took up is freed when they are destroyed. The trade off of all of the benefits of vectors is that for small, short-lived arrays vectors are not as efficient. One example of when vectors came in handy was when doing the lab that the group presenting vectors designed. In the lab I had to iterate through thousands of triangle numbers to find the one that had over 500 multiples. This would have been impossible to do with arrays because I didn't know how many triangle numbers it would take to come to an answer (it ended up being a lot). However, with vectors, I was able to continue to add triangle numbers to the first position of the vector and expand the size of the vector until I reached the triangle number I wanted. Overall, I like using vectors more than arrays, but both data structures have their own advantages and disadvantages and which one to use depends largely on the situation at hand.