<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>RSS feed for InstantSpot site EdomGroup Blog</title><link>http://edomgroup.instantspot.com</link><description>ColdFusion, Java, Computer Science, and the musings of inspired developers...</description><language>en-us</language><copyright>This work is Copyright &#xA9; 2009 by EdomGroup Blog</copyright><generator>RSSVille ColdFusion FeedMaker, version 1.0</generator><pubDate>Sat, 21 Nov 2009 14:50:50 GMT</pubDate><item><title>An Unbiased Description Of Interfaces</title><link>http://edomgroup.instantspot.com/blog/2006/07/25/An-Unbiased-Description-Of-Interfaces</link><description>For a long time I&amp;#39;ve been reading everyone wanting interfaces or not  wanting interfaces in ColdFusion; make it more like Java or make it  more abstract. No one has yet described what an interface means to them  (since most think of or only know of Java interfaces). So, for anyone  reading and for people just coming to ColdFusion or programming in  general I supply this short list of what an interface is. No opinion,  just the description of an interface/protocol as used in the Object  Oriented Programming paradigm.   &lt;p&gt;  &lt;strong&gt;An interface is:&lt;/strong&gt;    &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;      &lt;em&gt;      the list of operations understood by the object      &lt;/em&gt;    &lt;/li&gt;   &lt;li&gt;      &lt;em&gt;      the arguments these operations can be supplied with      &lt;/em&gt;    &lt;/li&gt;   &lt;li&gt;      &lt;em&gt;      the types of results the operations return      &lt;/em&gt;         &lt;p&gt;   What #1 - #3 mean is that you as a developer can be       handed an      object that you have no idea &lt;em&gt;how&lt;/em&gt; it works but       because it adheres to an interface you know       &lt;em&gt;what&lt;/em&gt;   it does. This also means that you can write an interface for something   you need -say image resizing- and use that interface throughout your   program. Then give your interface to some other programmer to develop   and as long as they adhere to that interface it will work in your code.   &lt;/p&gt;   &lt;/li&gt;   &lt;li&gt;      &lt;em&gt;      the invariants preserved despite modification to the      object      &lt;/em&gt;         &lt;p&gt;   An invariant is a condition that does not change. The simplest example   I can think of is where you have an object with two fields (variables):   &lt;em&gt;VariableA&lt;/em&gt;      and &lt;em&gt;VariableB&lt;/em&gt; then in a method that receives      an argument and sets the value of &lt;em&gt;VariableA&lt;/em&gt; the      value of &lt;em&gt;VariableB&lt;/em&gt;   should not be changed after the method returns. This is important   because if you call a method you have to have a clear understanding not   only of what was modified but what wasn&amp;#39;t.    &lt;/p&gt;   &lt;/li&gt;   &lt;li&gt;      &lt;em&gt;      any exceptional situations the client using the       interface must handle      &lt;/em&gt;         &lt;p&gt;   Error handling is important especially when code is being written by   more than one person. Supplying the exceptional situations of a method   is a good way to ensure that everyone is on the same page.    &lt;/p&gt;   &lt;/li&gt;  &lt;/ol&gt;  </description><pubDate>Tue, 25 Jul 2006 13:43:22 GMT</pubDate><guid>http://edomgroup.instantspot.com/blog/2006/07/25/An-Unbiased-Description-Of-Interfaces</guid><category>Programming</category></item><item><title>Java performance analysis - a real life example</title><link>http://edomgroup.instantspot.com/blog/2006/06/01/Java-performance-analysis--a-real-life-example</link><description>For my thesis I&amp;#39;m writing a Java program that parses two text files  (representing satellite images) and performs some analysis on them. The  two files are 128 MB and each was taking ~33 seconds to parse. The  analysis takes only a fraction of that time, then the results are  written back to an output file.   &lt;p&gt;  Thinking this was very slow, since the files should be pretty much  sequential access off the disk and the read-ahead-buffer would have  cached the next block, I decided to dig a little. I rewrote the parsing  algorithm in C since it&amp;#39;s easier to manage the low-level IO. I used the  file stream functions (fopen,fread,fclose) provided by stdio. When I ran the program it took ~10 seconds.      &lt;/p&gt;  &lt;p&gt;  This was insane. Java does have more overhead due to its garbage  collection, HotSpot optimizer, and object memory management but it  should not be a magnitude of 3x slower. After a few minutes looking at  the Java implementation I realized I had forgotten to instantiate a BufferedReader. I immediately jumped to the documentation and there it was, each call to the read method of the FileReader blocks until data is available. If no BufferedReader  is supplied this means a context switch for each call. No wonder Java  was taking so long. Adding the buffering I reran the algorithm and wow,  13 seconds. Not to bad for a &amp;ldquo;boated&amp;rdquo; language.   &lt;/p&gt;  &lt;p&gt;  Figuring I had more places in my program which could be optimized I  began looking. The first place I went was to one of the main methods,  the one which did the analysis on each image. The logic was pretty  simple, find the next pattern in the given image, see if it exists in a  lookup table, if so update its statistics or create a new key and add  it as a new entry. The data structure I was using for the lookup table  was a simple HashMap  object. When writing that section of the program I was still relatively  new to the Java language and just went with what I&amp;#39;d used in other  languages, an associative array.   &lt;/p&gt;  &lt;p&gt;  I did a little analysis with some System.out.println  statements and found that on average there was a 14,000 : 15 ratio  between reads and writes on the lookup table. Knowing this ratio was  pretty stable (I wasn&amp;#39;t going to get anywhere near 50% writes) I  decided a better data structure would be something with read time of  O(n) or less, instead of O(h(k)) where h(k) was the hash function on  the key. This meant an array would be best, but I didn&amp;#39;t want the  hassle of managing the size of the array as new patterns where found.  Java had to have something for this. After a little searching I found java.util.concurrent.CopyOnWriteArrayList. This was exactly what I needed. After a little tweaking the new code ran in 1/3 the time.      &lt;/p&gt;  &lt;p&gt;  After this I wrote some small timed programs to examine the running time of the HashMap data structure and the CopyOnWriteArrayList. What I found was as the mutations  approached 25% the CopyOnWriteArrayList&amp;#39;s  performance slowed at an exponential rate. Finally, I couldn&amp;#39;t evaluate  the performance because the tests were taking too long. On the other  hand, the HashMap data structure had a fairly constant performance time irrelevant on the read/write ratio.   &lt;/p&gt;  </description><pubDate>Fri, 02 Jun 2006 03:43:25 GMT</pubDate><guid>http://edomgroup.instantspot.com/blog/2006/06/01/Java-performance-analysis--a-real-life-example</guid><category>Java</category></item></channel></rss>