Archive for the ‘Programming’ Category

Leaves of Wonder

Monday, November 24th, 2008

So it would appear that those few Wolverine fans that frequent this blog from time to time were too embarrassed to even declare their allegiance. So this first installment of the FloydWing Big Game Fan Poll goes to the Buckeye Fans 2-0.  I’m bummed I didn’t even get to cast a tie breaking vote.

So I spent the weekend finally working on the last dump of leaves in the yard.  Rain, sickness, rain, and time change conspired to put me way behind.  I had been caught up before that.  I got a little over half of the back yard piled and had bagged 9 big bags of the stuff, hardly making a dent from the pile.  The rest of the backyard and front still waited to be piled up.  A neighbor stopped by and talked me into just having one of the local yard services come and pile and remove the leaves.  He had used to do it, but since decided it’s just not worth it anymore, and pretty much the rest of the neighborhood has converted to that also.  Hopefully, this late in the season, I can find a discount from someone looking for a little extra Christmas money.

I’m hoping to start some more posts in the same vein as my Part-Time Developer series over the next couple of months.  No, this doesn’t mean I’m looking for another job, it’s just that I’m starting to equip my laptop and desktop with the newest Java development tools.  I hope to start a new tinkering project and hope to be able to involve you readers with next to no time commitment.  I should go back over those old posts and see if I can properly format the code, especially since I just upgraded.

I don’t know if I should keep the same name or come up with something new.  I am a full time developer now, so perhaps the part time title could refer to my hobbyist pursuits.  If anybody has any thoughts, please post them.  Hopefully, in the next couple weeks I can make an initial post talking about the tools I’m going to use for my tinkering and take any suggestions of other good tools to play around with.

I’ve still found nothing about the “accented A” problem, so it’s looking like that will just be a crappy artifact.  I don’t think I’m keen to sit and manually edit every post.

Good news for Pit.  I have a copy of Visual Studio 2005 so I should be able to install that and work with the current codebase.  However, the bad news is I don’t know where my CDs are that I copied everything off to are.  I copied the Pit codebase, site backup, and everything to a CD or two and I don’t know where they are.  I believe I also have the important stuff on a USB key so disaster isn’t yet imminent.  As far as when season 8 will start, that’s still up in the air.  We’ll have a few things to sort out.  I’ll make a post here when it’s time to start paying attention to the forums.

I miss my MacBook Pro something fierce.  My old HP just isn’t doing it for me.  It seems so blocky, nothing like the sleekness of my Mac.  Development was such a joy, being able to drop to the command line at a moments notice.  I feel so hampered by Windows.  One of the biggest things I miss, is being able to have multiple desktop windows set up (I would have 4), and being able to put running apps in different ones.  So I could have my email and browser in one, Eclipse in another, command line access in a different one, and the fourth for whatever else.  Plus doing the cube rotation switch between them was always so elegant.  I figure it’s been a while since I gave Sixftunda something to razz me about, so this paragraph is dedicated to him.  :)

News you can’t use

Monday, November 17th, 2008

As I was working today I was database diving, checking to make sure some data was added correctly.  There happened to be a date field involved and I froze upon seeing it.  There was something very familiar about it.

2008-11-17 ??

???8-11-17 ???

1858-11-17 !!!!

Yes!  That date holds quite a familiarity to me.  I saw that many a time in an old debugger and in data for default dates.

It’s none other than the epoch value for OpenVMS, an operating system that is near and dear to my heart.

“The OpenVMS Alpha operating system counts intervals of 100 nanoseconds since the Modified Julian Day epoch, 1858-11-17, 00:00:00.00 UTC. However, it is only incremented every 10 milliseconds, 100,000 intervals (10,000,000 ns) at a time. OpenVMS VAX (formerly VAX/VMS) uses the beginning of the current year as the epoch.”

Spring Source becoming an enterprise of it’s own

Wednesday, November 12th, 2008

Wow!  Spring Source acquires Groovy/Grails.

Document Imaging Mogul

Monday, September 29th, 2008

Lately at work I’ve been working on an aspect of our program for storing images and drawings and relating them to a sales order line.  I was charged with making the ground level of it as generic as possible, so we could use it within our ERP app and for any other app that may need it, which we just happen to have.  Each individual instance that needed such storage could write an upper level to make use of the generic storage layer.

It was a nice break and gave me a little creative license to come up with something.  It was also nice to make something that didn’t depend on all the previous framework code and get to tinker with the basic building blocks of Spring and Hibernate.  That’s one thing that has always bugged me with big built up frameworks.  When you want to just take a small portion of something and start building something completely different, you end up wasting a lot of time just trying to untangle it from what it was attached to before.  Wasn’t that what dependency injection was supposed to free us from?  Maybe if it’s done right.  :)

Anyway, it’s been an enjoyable experience and after pretty much completing the base generic layer, I moved on today to use it in the ERP system for our images and drawings.  I also moved it into a separate codebase for our other application that needs it and will help integrate it there when the current developer is ready.

I basically made it to store any type of file as an attachment.  What I came to realize is that I had probably created a very simplistic document management system.  The base system is only concerned with storing, retrieving, and deleting the attachment and giving an id via a simple database table that tracks to the storage location scheme (which is Spring injectable).  Each instance that has a need for such storage can layer on it’s own specific search or naming needs.  For instance, the ERP part that I’m concerned with right now only needs to map order lines to the attachments, keeping it’s user file name so the user can relate to it.  The other current app, layers a virtual directory system on top of the attachment storage to make it stay consistent with what the end user is used to.

All in all it’s pretty neat.  Not rocket science mind you.  It’s not that much code.  The time was taken thinking about what I wanted and how it would be used and refactoring it to how I wanted it to be.  It’s been “existing framework neutered” so hopefully the core development team won’t complain to much, but it makes it easier for our development team’s other applications.  Programming religious wars are always an annoying thing.

Part Time Developer No More!

Tuesday, May 6th, 2008

You read the headline correctly, I am going to be a “full time developer” now.  Last Wednesday I accepted a Java developer position.  Thursday I turned in my resignation, and after next week I’m no longer in the education field.  I’ll be working for what I feel is a great company doing what I enjoy doing.  Add in a great employment package and a great feeling of being wanted and I’m pretty excited.

The only downside is we’ll be moving up around 75 minutes to the north.  Still close enough to see family and friends now and then, but it does require uprooting the girly-wogs to a new school.  I’ve tried to avoid putting them through that, but this last job search pretty much convinced the wif-al unit and myself that what I’m looking for ain’t around here.  Even the original opportunity that started the Part Time Developer series was a couple hours to the south.  They’re handling it better than I thought they would, but we’re probably still going to end up spoiling them as much as we can.

So now has begun the fun of completing all those house projects that we’ve put off over the years.  Putting the house on the market.  Finding a nice house to move to.  All the unplanned expenses (COBRA - yuck!).  These are the times that try men’s souls.  Indeed it will be interesting.

So goodbye to management life (and good riddance!).  Goodbye to having to worrying about what everyone else is working on.  To doing tech support for third party software packages.  To the frustration of not doing what I so desperately want and need to do.  To my MacBook Pro (nearly the most painful of all :) ).  To the friends here that I’ve made.

But also goodbye to softball (I’m probably too old anyways).  Goodbye to childhood friends (and new ones).  To country small town living.  To the house that we’ve made home.

The wif-al unit, the girlywogs, and myself all say that it doesn’t seem like this is really happening.  We’ve begun working on the house, cleaning, boxing, etc.  We know that we will be moving once we find something and our house is sold, but it hasn’t really hit us.  I think that’s going to make the last time we drive out of our driveway that much harder.

It’s going to be a while before the house is on the market.  And until we find our new home.  I’ll be commuting for a while, but hopefully not too long.  It seems like we’re a long ways off, but I’m sure time will fly.

Brain Dump

Monday, April 28th, 2008

Just on the spurs of a comment about teaching my oldest to program in my post on programming games, a couple blogs I read noted that Sun has put up a resource for young programmers.  This would probably be a good resource for any non-programmers wanting to give it go.  I know at least one of you Bud Light swilling heathens has made a comment to that effect to me before.  :)

Wings had a great weekend.  Hopefully they can avoid duplicating what happened in the Nashville series in games 3 and 4.  I’m gonna be a tired puppy this week with these late start times.  Nephew #2 has bad mouthed Chelios probably since the Wings got him.  I usually defend him, more to annoy my nephew than anything, though I did see value in his skills.  My opinion may be changing.  I’m starting to really cringe whenever Chelios is on the ice.  I’m starting to see a lot of mistakes and problems that weren’t occurring in the past.  It’s a little worrisome.

How many pictures does a 2GB SD card give my 4 mega pixel Kodak LS443?  1,650 pictures.  Want to know what’s even scarier?  I’ve  got two cards.  I can record 80 minutes of video on each card.  Someday I’d like to get smaller camera that fits in my pocket easier.  One of those digital video cameras would be cool too.  Someday…

The wif-al unit has taken a very nice upswing from her surgery.  She’s acting more like herself now.  I’m very glad.  She still needs to avoid any sickies, as that wouldn’t be good at this stage.

I went with my youngest on a zoo field trip last week.  It turned out, she was the only child in my group.  We had a blast.  Wish I could do that more with the girlywogs.

For those worried about my programming studies, fear not.  Over the last 2-3 weeks I studied myself silly.  I worked on a nice little project for someone and have very nearly burnt myself out.  I need to get back into things after a little break.  I probably should continue to work on my Hibernate/Spring project, but I’m very tempted to start learning Groovy.

I picked up some Sapporo from the IGA last week to enjoy during the Wings’ games.  This is my Japanese beer of choice when eating at a hibachi restaurant.  This batch wasn’t so good.  I’m wondering how long it’s been sitting there, because it tastes a bit skunky.

Looks like a big decision will need to be made this week.  Hopefully two.  One cool, one not so cool.  But a stressful decision nonetheless.

Programming as a game

Tuesday, April 22nd, 2008

I think there’s been a few games in my time where the game consists of actually doing some sort of programming.  Most would involve combat in some way.  The first I probably encountered was on the MoleMan’s Atari ST called Omega.  You had to provide the logic for how your tank would behave.  You could make it as simple or as complicated as you wanted.  You could make a tank that randomly drove around and randomly fired it’s cannon.  Or you could have routines that would actively use it’s scanner to seek other tanks and how it would behave if it got hit.  You would then throw that tank at game provided tanks or tanks that your friends created.  I never made a tank of my own.  It sounded neat to me, but I couldn’t see taking the time.  I figured it would be a bit frustrating.  Kind of funny considering that’s what I used to do for a living and would like to get back to doing.

This blog post by Jeff Atwood is what reminded me of these types of games.  I’ve heard of Java Robots which is meant as programmer entertainment and as a learning tool for newer programmers.  I should take a look at it and see what it would be like for a total newb and maybe use it to teach my oldest programming.

I’ve often thought of creating some sort of game where the players would select predefined logic for their sport players or provide their own.  Just another one of those plethora of ideas that roll around in my head, making me what I am.

The Part Time Developer 6: Adding Hibernate to the Spring Tutorial

Saturday, March 22nd, 2008

The code formatting in this post is crap. I’ve been fighting with the WordPress code tag all day and I’m giving up. It doesn’t seem to work if I have blank lines and would reposition itself to not include the entire code fragment that I inserted. It also would do away with my tab spacing. So I’m done putting code in here until I can find out how I’m supposed to use it or find a plugin that works better.

So to document this for myself, I thought I’d add an additional section to the Developing a Spring Framework MVC application step-by-step tutuorial. So here’s part 7 of the tutorial: Swapping in Hibernate for Database Persistence.

I didn’t keep track of all the jars I added to the WEB-INF/lib directory, but here’s what I think I added. I probably missed something.
antlr-2.7.6.jar
asm.jar
asm-attrs.jar
c3p0-0.9.1.jar
cglib-2.1.3.jar
commons-collections-2.1.1.jar
commons-dbcp.jar
doms4j-1.6.1.jar
hibernate3.jar

Add the normal HibernateUtil.java to the springapp.repository package. This makes it easier to grab a session object when it’s needed.
package springapp.repository;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
private static SessionFactory sessionFactory;
static {
//Static initializers must catch and wrap any exceptions
try {
sessionFactory = new Configuration().configure()
.buildSessionFactory();
} catch (Throwable ex) {
System.out.println(ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
// Alternatively, you could look up in JNDI here
return sessionFactory;
}
public static void shutdown() {
// Close caches and connection pools
getSessionFactory().close();
}
}

Then we’ll create a Hibernate version of our ProductDao interface, HibernateProductDao.java.

package springapp.repository;
import java.util.List;
import org.hibernate.Session;
import springapp.domain.Product;
public class HibernateProductDao implements ProductDao {
public List
getProductList() {

Session sess = HibernateUtil.getSessionFactory().openSession();
List
products = sess.createQuery(”from Product”).list();
return products;
}
public void saveProduct(Product prod) {
Session sess = HibernateUtil.getSessionFactory().openSession();
sess.beginTransaction();
sess.saveOrUpdate(prod);
sess.getTransaction().commit();
}
}
Now add the necessary hibernate mapping and configuration files:
I added my table mapping file for the product table to war/WEB-INF/classes/springapp/domain directory. I don’t know if this would be the normal place you’d put it. It’s where it should be in a running system. In my previous experience we would put it next to the definition of the product class and then copy it here, but I don’t like having to remember to copy it down when you change it. I’m still looking for an elegant way for doing this.
Product.hbm.xml
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE hibernate-mapping PUBLIC
“-//Hibernate/Hibernate Mapping DTD 3.0//EN”
“http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd”>
<hibernate-mapping>
<class name=”springapp.domain.Product” table=”products”>
<id name=”id” column=”id”>
<generator class=”native”/>
</id>
<property name=”description”/>
<property name=”price”/>
</class>
</hibernate-mapping>

Here’s the war/WEB-INF/classes/springapp/hibernate.cfg.xml configuration file
<!DOCTYPE hibernate-configuration SYSTEM
“http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”>
<hibernate-configuration>
<session-factory><property name=”hibernate.connection.driver_class”>org.hsqldb.jdbcDriver</property>
<property name=”hibernate.connection.url”>jdbc:hsqldb:hsql://localhost</property>
<property name=”hibernate.connection.username”>sa</property>
<property name=”hibernate.dialect”>org.hibernate.dialect.HSQLDialect</property><!– Use the C3P0 connection pool provider –>
<property name=”hibernate.c3p0.min_size”>5</property>
<property name=”hibernate.c3p0.max_size”>20</property>
<property name=”hibernate.c3p0.timeout”>300</property>
<property name=”hibernate.c3p0.max_statements”>50</property>
<property name=”hibernate.c3p0.idle_test_period”>3000</property>

<!– Show and print nice SQL on stdout –>
<property name=”show_sql”>true</property>
<property name=”format_sql”>true</property>
<property name=”use_sql_comments”>true</property>

<!– List of XML mapping files –>
<mapping resource=”springapp/domain/Product.hbm.xml”/>
</session-factory>
</hibernate-configuration>

Now that all the groundwork as been put into place, the final piece of the puzzle is to use the power of Spring dependency injection and switch the class we’re using for our ProductDao implementation. Modify the applicationContext.xml file and comment out the previous productDao bean and add our new Hibernate version.<bean id=”productDao” class=”springapp.repository.HibernateProductDao”/>
<!–
<bean id=”productDao” class=”springapp.repository.JdbcProductDao”>
<property name=”dataSource” ref=”dataSource”/>
</bean>
–>
And that’s it. Rebuild, redeploy, reload, and browse to the application and things still work as before. Only now we’re using Hibernate for interacting with the database rather than using JDBC and Spring. That’s the power of these tools. If for some reason you need to switch implementations, it’s easy to do. Nothing in your plain Java objects is explicitly tied to a certain technology. By coding to interfaces, it’s easy to switch implementations.

Pit Playoff Bug

Tuesday, March 18th, 2008

So I spent the last two lunchtimes trying to figure out what was wrong in Pit playoff code that worked in season’s past. This really irks me because I had Part-Time Developer plans in mind. I believe I’ve found the problem and should be able to run the first round of the vaunted Pit playoffs tonight, and get everything back on track.

The problem occurred when I was running the main Pit playoffs. It found the first series, ran the fight, then prompted me to input the fighters for the next fight of the same series. It was only supposed to run the first fight in the series then go to the next series.

I beat my head against the wall most of Sunday night trying to figure it out.  Then Monday over my lunch I pretty much nailed down the problem, and then today over lunch I put in the fix and tested it.  I think it’s got a clean bill of health now, at least hopefully through the rest of the playoffs.

The problem turned out to be a very rookie mistake on my part.  Somehow it had worked through the first 6 seasons of playoffs.  I attribute this surfacing due to switching from VS2003 to VS2005 at the beginning of this season.   When I made the switch I had to change includes such as “include fstream.h” to “include <fstream>”.  I’m guessing something with the basic C++ includes changed as to why I had to change my includes.  I hadn’t kept up with the language enough to understand why I had to change things.  So it would seem the old fstream library somehow hid my boneheaded programming bug.  How I don’t know.  It seems to defy the way it should’ve behaved.

The problem was in the way I was using my file handler class that I use for the binary flat files that hold the Pit data.  (Binary flat files?  It seemed like a good idea at the time.)  I had a file handler for my playoff series file (basically a summary file).  I was looping through the file looking for a series that matched the season and playoff round I was in as well as not being already completed.  Once I found a series that wasn’t done, I would loop through my playoff games file (basically a detail file) with another file hander.  When it found the next game it would run it.  Once done I would need to update the playoff series file, which keeps track of the current win/loss situation.  However, I used the same file handler that I was using to loop through the same file.  After the update, it threw my location earlier in the file for some reason.  (I believe that the position pointer is undefined at this point and can’t be relied upon.)  Logically I would think it would put the position to the end of the record it wrote leaving me where I want to be to loop on, but from experience I know you can’t count on this.  It was throwing it much earlier in the file, which caused it to loop and eventually find the same playoff series again.  Something really got hosed though, because even when I would cancel, supposedly continuing the loop it would jump back again, continually finding that first series.  And it just got worse from there, duplicating records and caused the file to double in size with duplicate records.  Not quite sure where that came from, but I understand the base problem.

So I now have a different file handler doing the update and we’re now happy.  I could give the excuse that I wasn’t super familiar with serial filestream io at that time of the original coding, but I had been doing DEC Fortran with flat files for a few years at that time and you always had to be aware of that sort of problem.

If my reasoning on this is way off, please let me know so I can fix my understanding of the problem.

The Part Time Developer 5: Spring

Sunday, March 16th, 2008

So now that I’m relatively back in the land of the healthy (except for some remaining congestion and constant runny nose) I figured I needed to come clean with what I’ve been working on. Before the big week of sickness I had started to reacquaint myself with the Spring Framework, which is now up to version 2.5 (I’m not sure but I think when I was using it it was like version 1.2 or something). I was working my way through a pretty nice little tutorial on Spring MVC. I continued it over lunches at work this week, and expanded on it this weekend.

Let’s get a little explanation of what this stuff is. Spring’s basic claim to fame (though not only) is dependency injection (or Inversion of Control). This allows you to “inject” things into your programming objects that they “depend” on. This is easiest to understand with an example. Most of this stuff involves programming to interfaces. As I’ve mentioned previously, interfaces are like placeholders in code that state the type of object it can be (I’m finding this leads to too many examples.) For example, an Animal interface could have an eat() method, and then I could have a Dog class that implements the eat() method. So then wherever an Animal is needed, I could use the Dog class since it implements the requirements of the Animal interface (namely the eat() method). (Sometime I’ll have to do a Programming terms for non-programmers series.)

So let’s say I’ve finally put some functionality in place in Pit where police show up and start fighting with fighters involved in a Black Pit fight. Let’s say I’m smart and I have a Fighter interface that spells out such things that Pit combatants can do, like attack(). Let’s say that my PitFighter class that is used most everywhere is the type of object that will represent my police. So both the fighters and the police are the same type of object.

Now let’s say down the line I decide I want to spice things up a bit and change the police normal fighter types to be ravenous bloodthirsty animals. I create a PitAnimalFighter class which implements the Fighter interface, maybe this prints out “GRRR!” in it’s attack() method.

Now that I have the new class, the hard way would be for me to go and change over to using that class everywhere in my code that I want to use the animal to represent the policing entity. The easiest way would be, if I had this all set up ahead of time, would be if I had a configuration file (in XML) that mapped the type of class that I wanted to use for the policing entity interface. So all I’d have to do would be to change it over to my new PitAnimalFighter. Spring would do the rest by injecting a class of that type in where it was needed.  It would also be simple to change back if I needed to.

I don’t know if this rambling would make any sense to anybody, but I understand it, which is the point of this. One thing Spring can suffer from is XML hell. You have all this wiring that you do in XML files for what injecting these class types and other dependencies that it’s not always readily apparent. It can get a little confusing. The hardest part for me is all the secret little hidden things (that I’m sure are in the documentation) that I would need to use during the tutorial. I don’t know if I’d be able to make a Spring MVC application from scratch without heavily looking back at examples.

Oh yeah, Spring MVC.  MVC stands for model/view/controller architecture.  It’s just getting big in the .NET world but has been in the Java space for a while.  It aims to separate the dependencies within your code on each other.  So for example you create a web application.  If you have the code that deals with displaying it on a web page tied too closely to how you get your data, it would be difficult for you to create a desktop version of the app.  By using MVC correctly, it should be easy to change your front end or back end, since they aren’t tied together.  Spring does all the tying together with its injection mechanism.

Today I added an extra step to the tutorial I ran through by adding Hibernate as my persistence framework in place of the Spring JDBC persistence.  This nicely illustrates how easy it is to switch this sort of mechanism when you code to interfaces and use dependency injection.  I plan to document this in my next installment.

I’m guessing once I do part 6 of this series I’m planning to work on my own application using Spring and Hibernate together.  While I’d like to move on to the next technology in my list, I need to delve more into these two main technologies since my having a good understanding of these is essential.