Tuesday, September 30, 2014

Changes 9/30/14

Java:

  • Looked at Safari textbook, but only a little
  • Learned more about looking at big O notation for measuring the efficiency of algorithms
  • In my LList program, added support for adding elements to a specific index.  It was actually really simple to implement.  I'll set up Github for Windows tomorrow and upload the source.

Monday, September 29, 2014

Changes 9/29/14

Ruby:

Java:

  • Learned more about big O notation and mapping out the amount of time it takes functions to run.
  • I'm having trouble understanding some of the things they are doing, so I'll have to talk to you tomorrow about it, since I'm out of time today
  • Forgot to look at the safari book, I'll do that tomorrow as well

Friday, September 26, 2014

Changes 9/26/14

Ruby:

  • Looked into ruby's Queue object
  • Saw that the method Queue#pop, which returns the first element and removes it from the queue, is blocking, meaning that it will block its thread if the queue is empty while waiting for a value to return.
  • This is great for me, because I was looking for a way to have a thread that could pause itself while waiting for files to download and resume itself once those files are downloaded
  • I rewrote my threading test to use the queue object, and it ended up being much more straight-forward and probably more thread safe as well

  • In the code marked 1. in the code section I have an excerpt I came up with to utilize Queue#pop.  This code is intended to be run in a method in a separate thread, and will either parse items if there are any in the queue or do nothing while waiting for more to be added
  • END_PARSE_SYM is a constant value that is added to the queue when another method, Parser#finish, is called.  As you can see by the code, this signals that there are no more files for the queue to wait for, and therefore the infinite while loop is exited.

  • One choice I made while writing my Parser class was to keep the thread behavior up to the code calling the Parser#parse method, meaning that Parser doesn't actually have any multithreading code.
  • Instead, you must call something like what is listed in code excerpt 2.  The statement within the { } runs in a separate thread, which is good, because in its current form, this method blocks its thread due to the Queue#pop statement being called on an empty queue within Parser#parse
  • A side effect of this is that if you call parser.parse in the main thread, it throws a deadlock exception, because the @queue.pop statement is now blocking the main thread, so nothing will ever happen.  I think this is acceptable behavior though, because Parser#parse really should never be called in the main thread anyway.
  • I will look into other ways to throw an exception if Parser#parse is being called in the main thread

Code:

1.
def parse
  ...
  while true do
    puts "Waiting for queue" if @queue.empty?
    file = @queue.pop
    break if file == END_PARSE_SYM
    <... parse code here >
  end
end
2.
thread = Thread.new { parser.parse }

Thursday, September 25, 2014

Changes 9/25/14

Java:

  • Worked more on improving the LList class
  • Added a size() variable, so you can get the size of the LList
  • Each time an element is added to the array, the size is increased
  • Currently there is no way to remove elements, so the size can never decrease
  • With this size() variable, the class can also do bounds checking.  For example, with the code LList<String> llist = new LList<String>("sudo", "rm", "-rf");, calling llist.get(5); would result in Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 5 out of bounds for <LList elements=[sudo, rm, -rfl]>
  • As you can see from this example, the LList.toString() method prints out the elements it contains.  This uses a StringBuilder object to avoid the inefficiencies of adding strings together with the + operator (such as "abc" + "def").  Instead, you use the append() method of StringBuilder, then convert the StringBuilder to a string when you want to use it as one.
  • I think that the LList structure is really interesting.  The fact that you can have infinitely sized lists with no penalty for adding or removing elements is really cool, but I can see the drawbacks as well.  For example, if something happens and one Node gets unlinked, all the other Nodes after it will get unlinked as well.
  • Tomorrow I will work on implementing a remove() method for elements, and finish implementing a LList.toArray() method, which will return an array of the data stored in the LList

Tuesday, September 23, 2014

Changes 9/23/14

Java:

  • Continued reading the Data Structures and Abstractions book
  • Renamed my ChainLink class to Nodes like they have in the book, and hid them within a class called LList, so the end user doesn't have to deal with creating and traversing Nodes himself.  Instead, the LList class takes care of it
  • Right now it doesn't actually work, but I'll fix it tomorrow

Monday, September 22, 2014

Changes 9/22/14

Java:

  • Finished up looking at quicksorts
  • Started learning about preconditions, postconditions, and loop invariants, which are assertions you can make within a loop
  • Started learning about timing functions

Friday, September 19, 2014

Changes 9/19/14

Java:

  • Finished up the eimacs hash table section
  • I feel like it wrapped up too quick, it just showed the basics without really talking about advanced hash collision strategies and stuff like that
  • Started looking at sorting algorithms
  • It's walking me through how an in-place quicksort works, which is when an array is sorted just by swapping the placement of elements
  • It's very complicated, but they do a good job of walking you through it slowly
  • They have an interactive example where it highlights the step the program is on, and explains what is being done

Thursday, September 18, 2014

Changes 9/18/14

Java:

  • Got eIMacs account
  • Started the advanced topics curriculum
  • Started learning about hashes and hash tables
  • Every object in Java has a hashCode() method, which is implemented in different ways.  For example, Integer's hashCode is simply the number it represents.  The hashCode of Strings has to do with the values of the characters in the string.
  • There can be multiple objects with the same hash, however, and the data structure must make some attempt to resolve this

Wednesday, September 17, 2014

Changes 9/17/14

Java:

  • Chapter 6 starts talking about linked data, and uses the analogy of desks in a classroom, where each desk has the number of the next desk in the sequence on it.
  • This allows the instructor to access any desk in the series, simply by memorizing the number of the first desk, then asking each desk in succession what the number of the next desk is.
  • I decided to test this out in Java, so I wrote a ChainLink class.
  • Each ChainLink has two fields, a data field and a next field.  The data field contains a string, and the next field is initially set to null.
  • The method I wrote to set up the chain is called like this:
  • createChain(new ChainLink("value1"), new ChainLink("value2"), new ChainLink("value3"), new ChainLink("value4"));
  • This takes each ChainLink, and sets the next value of each to the next ChainLink in the sequence.  The ChainLink with datavalue "value4" has its next field set to null, though.
  • Then you can get a ChainLink at whatever index you want, with the getLink() method!
  • Unfortunately I didn't have time to finish the chapter, though.

Tuesday, September 16, 2014

Changes 9/16/14

Java:

  • Read more in the Java book, started looking at the ADT List structure
  • So far the book has been walking through an implementation of a List class that uses an array to store items and has methods to add, remove, etc.
  • Some of it is review from AP Comp Sci, like how variables deal with actual objects in memory
  • One approach to having a list with no maximum length is to double the size of the array each time it becomes full.  This is better than just adding 1 slot when one is needed, because you end up having to do less operations as more and more items are added.

Monday, September 15, 2014

Changes 9/15/14

Ruby:

  • Read Kevin's email, which talked about problems with a variable being modified in separate threads
  • This can cause problems, because one thread may find its information about the variable out of date.
  • For example, if one thread stored a list's length in a variable, and another thread removed all elements from the list, then the original thread's length variable would become out of date.
  • This example's failure is easy to fix though, and I'm not sure what the best way to discover the faults in what I've written

Java:

  • Learned about Javadoc, assertions, and inheritance
  • Javadocs allow you to show other developers what the different variables in your methods do. When someone enters a method with a Javadoc into their IDE, it will pop up with your explanation of what the variables do and what it returns
  • Assertions are a way to test your code, but you need to set a compiler flag to have them do anything, and I don't know how to set that
  • For example, assert x > 0; will throw an exception if the flag is set and x is less than or equal to 0

Friday, September 12, 2014

Changes 9/12/14

Java:

  • Fleshed out the T type test to support 2 separate data types for the two values, so it is defined with new T_Test<String, Integer>(); for example
  • Read about inheritance, and wrote a class testing how methods override each other.
  • Basically, the methods of a base class will be overridden by methods further down in the inheritance.  For example, if Person inherits from Thing, and both have a method called exist(), Person's exist method will override Thing's if the created object is a Person.

Thursday, September 11, 2014

Changes 9/11/14

Java:

  • Read a bit more of the book
  • Figured out how to set font size for IntelliJ (since I'm on a high DPI screen, everything was tiny)

Ruby:

  • Read Kevin's feedback on the parser mockup
  • Investigated race conditions (when the program freezes up or crashes due to two threads trying to modify the same thing at once)
  • Tomorrow I will try to replace the array I am using as a stack with something thread safe.
  • Interestingly, the built in ruby objects might be thread safe, as discussed here.

Wednesday, September 10, 2014

Changes 9/10/14

Java:

  • Set up my JDK and IntelliJ Idea, which is the IDE I will be using
  • Wrote a simple class to test out how Java handles a class like public class ExampleClass<T> {}
  • Essentially I can then replace T with whatever I want when defining a new instance of ExampleClass, like new ExampleClass<String> or new ExampleClass<Integer> (you can't use primitive data types like int or float, though)
  • Then, any time you put a T in the class definition, it will be replaced with whatever the data type is, so with the statement public T exampleVariable;, exampleVariable would be of type String in the first case and of type Integer in the second.  This is pretty cool, and was not something I really understood before.

Changes 9/9/14

Java:

  • Read book, and started installing IntelliJ, which is a java IDE.
  • I'm on windows, and I couldn't figure out how to set my java home directory

Monday, September 8, 2014

Changes 9/8/14

NSF:

  • Sent Kevin my parser/downloader mockup for his thoughts

Data Structures

  • Started reading Data Structures and Abstractions with Java

Friday, September 5, 2014

Changes 9/5/14

NSFPatents2:

  • Worked on a threading mockup for the NSFPatents2 application
  • Eventually we want the program to be able to download files and parse local copies at the same time.
  • I'm working on creating that functionality in a separate program to see what the basic structure should be.
  • Basically it has two things happening concurrently
    • Downloading of patent files
    • Parsing of patent files which have already been downloading
  • It is set up currently to "download" a file and notify the parser that there is a new file to be parsed.
  • If there is already a parse in progress, it should add the new file to the queue.
  • If there is no parse in progress, the notify method will create a thread so that the file can be parsed.
  • This way, the program properly handles adding new files to the parse whether there is a currently parsing file or not.

Thursday, September 4, 2014

Changes 9/4/14

  • Started researching AB computer science concepts