Tag Archive: coding

codingI’ve been fairly quiet on the blog the past two weeks. This has been because I have been head down in code catching up from the holidays and being sick. I know all to well how abstract and vague I’ve been on what The Project is. I’m still shooting for a grand unveiling upon the ides of March. (March 15 for those who read not the Shakespeare)

I however do not want to be without any information. So I decided to play the magnifier game. This is the game where you show someone a picture of a common object through a magnifying glass and let them guess what it is they are looking at. Granted, that’s not my intent. I know what I’m showing is intentionally obfuscated to hide The Project’s intent.

However, I want to show a checkin from one of the classes that I did today to talk about what’s going on.

I’ve make no secret that this project uses a database to manage the content and Java and Tomcat to serve as a buffer to clients. Today, I am working on the database upload abstract class. In revamping my Java Servlets this past week, I have managed to completely abstract the query command class to the point that I can create any pre-packaged SQL query on the database into a 4 line subclass. This subclass can handle variant queries, compares, subqueries, and most importantly documentation on the return. This work made me very happy.

In pushing data up to the database there is more work needed. I have to verify that the call is including the correct information. I have to make sure that the subclasses have defined the necessary info to check. (So subclasses will be closer to 10 lines instead of 4)

Effectively, a push command should identify the table in the database, the usable column names, the required column names. And of course error check and return the response in a consumable way.

Below is my checkin comments from today’s abstract Class work. (Note there are redactions)

(Ah, the fun of Java)

imports java.util.List
adds ivars
	MUST BE OVERRIDDEN List requiredHeaders
	MUST BE OVERRIDDEN List usableHeaders
	String sqlQueryHeaders (for building sql update)
	String sqlQueryValues (for building sql update)
doSQLQuery() now doSQL()
	setRC not setRS with executeUpdate instead of executeQuery
	Sends a formatted json error response (put, not get)
validateSubClass() (new)
	Checks to see that there is at least 1 usableHeaders
	Checks to see that there are no more required headers than usable headers
	Checks that all required Headers are in usable Headers
	Checks that there is a table conversion equiv in getDbaseTable() {below}
	Throws Exception (Programming error) if any of these cases fail.
validateRequest() (new)
	Verifies that required headers are in the request http Header
	Returns first missing required header if failure
processHeaderPair() (new)
	examines each HTTP header pair
	searches for headers that are: Package.Command.usableHeader
	converts them into caseCorrected usableHeader and Value
	Appends them into Strings for use in SQL Update request
getDbaseTable() (new)
	converts servlet full DNS name into table in Database
	returns null if not set.
doPost() now doPut()
	Adds failNote as a return from validateRequest()
	Calls validateSubclass()
	Calls and evaluates validateRequest()
	Runs ProcessHeader() while iteration headers
	Builds SQLQuery (Should be update)
	Calls doSQL() and evaluates
	re-Enables SqlResult display in output
	ErrorIn -> ErrorLoc
	Shows failNote

On top of this, since you can’t test a PUT command in a browser; I’ve had to write a mini Putter app on my Mac. Let me assure you, hopping back and forth between Cocoa for OS X in Xcode and Java for Servlets in Eclipse can be a bit of a mind scramble.

This has been a personally hard week for The Project. Iin moving the data structures to MySQL as a database I had to also start developing Java servlet code. The reason for this is that it creates both the ability to have a Web-API for any number of clients: iOS, Android, Win, Mac, etc… while at the same time affording more ease for Web functions.

mgbUnfortunately my Java and Servlet knowledge were (and likely are) still lacking. The problem is that when you start a new programming environment you basically create sample code to test what you are trying to write and then adjust that code as you see success. Then you build on top of that. This sounds like a good idea at first and then you realise, that you are in fact building an upside down pyramid.

You learn one thing and you carefully build on top of it. This lets you learn a few more things so you balance them on top of the one thing you started with.  At some point you have to realise that you can’t build any higher because it’s all balancing act. This is where architecture comes in. Architecture takes the tools and designs a strong foundation. It designs a good skeleton and lets you put things where they best fit in.

All this CS theory sounds great in general; but at the same time you are trying to get a product done. This past Tuesday I hit a roadblock. The way I had put my Java class together, there was no easy way to add the next function. For those with understanding; I was dumping EVERYTHING into one class. I’ve been doing Object Oriented Code for a VERY long time. I knew how wrong my code was (in design) but it worked and got what I needed done.

So I was left with the very hard process of:

“Do I keep shoe horning in, to get a working version OR do I use what I have to build into something designed from scratch and put me back about a week?” This is the ‘Ooh, Shiny’ that as an engineer it’s very easy to get blown away by.

  • The project started with a client and hand build data. (Working on the client)
  • Then the data moved to a database. (Drop client work on MySQL)
  • Need to add data remotely to database (Lock in database, make data client)
  • Now a connector was needed between the clients and the database. (Web service, go to Tomcat, Java, Eclipse, learn new tech)

Of course the actual product client hasn’t moved in two weeks as far as code. The data entry client ramped up last week, but the connectors aren’t there.  So, the fear is not putting so much into one that we don’t move forward with the actual Gem of the lot.  This week I had to decide… how do I proceed and will the decision be right or wrong.

On the one hand it was ‘keep pushing forward and working around the problems being created.’ On the other it was ‘Stop, learn, regroup, rewrite, take the hit.’ And this decision was going to leave me unhappy due to the cons on both sides.

After two days of being in really crappy head-space over this, I realise that this is my product and unlike many of the companies I have coded for: I want it RIGHT. I do NOT want it RIGHT NOW. The dates I set for release are still somewhat arbitrary. Better I be happy with what is under the hood.

Digression. When I was 21 years old my father bought me a 1970’s red MGB convertible (Similar picture above). This thing was beautiful. It was missing some mirrors and had no seat belts (some did.) My father managed to snag this beauty for $800. My dad also never actually looked at the condition of the car. When we opened the hood we saw the electrical had been ripped out and replaced with speaker wire. Half the gauges didn’t work on the dashboard (including Oil, temp, and Fuel) The car also didn’t have a starter button.  I could ramble on telling stories about this car that I eventually named Truddi due to the car’s penchant for having multiple personalities. The point is that the car looked beautiful, but it had horrible guts. There is the right way to wire a car and a wrong way.

While you may think, “Well, aren’t you just ripping out the wiring and redoing it?” The metaphor here is that I am making sure that what I put in there from the start is correct, and not just a pretty outside with horrid innards that don’t belong. And you can believe me that I’ve been asking myself these questions and fighting both sides of the battle.

(long sigh) Well, enough procrastination. Time to design and write some Java from scratch. (But profit from a distributable JAR)

progressThis is going to be short and sweet. But after a few days of being utterly distracted with other things on the blog and endless phone calls today; I got the live data from the server to show up in the app. It formats correctly and even sorts on the fly.

Now we’re cooking!

confused cat huhWell, it was bound to happen working on all the backend stuff today. Once I knew that I was reading the data in; today it was all about putting the data in a commonly accessible area; formatting the data for different calls; and then letting those calls bask in the glory of real data.

At least that was the plan. (Hang on kids, it gets technical now)

Originally, the data was pulled in at app startup using the call:


Then I moved that out of the startup system and into its own data management class. All was going along well, but I couldn’t get the shared data where I wanted it. So I decided to pull out the big guns. We call that “Gang of 4.” This is the bible of software design patterns. I reached into the tome (well, not actually; as I don’t really need the book as much anymore) and called on one of my favourite (albeit most overly used and accursed) patterns: The Singleton.

The singleton, is muchly like building a cookie cutter for a one of a kind cookie. You take great care in making a cookie cutter, which could make lots of cookies; but this one is specially crafted so that people will simply have to share the one (and only one) cookie it will ever cut out.

That’s when life got weird. Suddenly the call above stopped working. It didn’t cause an error; it didn’t complain; it didn’t throw a wild exception and crash the device… It just blithely skipped over it.

I tried wiping the object files and compiling fresh. That didn’t work. I tried changing and maintaining the queue. That didn’t work. I changed how the singleton was instantiated… Nope. Just weirdness all around. Sadly; I got to this point about 30 minutes before I had to leave to pick up my boy from school. (My spouse got the flu). I figured, Okay… I guess I’ll spend 3-4 hours fixing it more tonight.

This also would not come to pass because I also am deeply invested in the show “The Sing Off” and have been writing reviews and analysis…es…(plural?!?!). Granted, if you read this blog… which you are at the moment (take my word on it) , then you probably have noticed a few of those posts.

So tomorrow: I have to write my Sing Off review from tonight, spend about 5 hours figuring out why the API took a hike, and then gearing up for the penultimate episode of the Sing Off. Oh what a hard life I lead at the moment. Honestly, I’m hoping that it’s 1 hour of fix and 4 hours continuing to get the real data in the app.

Oh, and to those who said they’d be interested in testing once I get to the iPad; Please remember that iPhone apps run just fine on the iPad and you can test them early. (Yes, S… I’m looking at you first and foremost 😉

We’ll figure out what went kerschlump tomorrow. I’m going to actually try to get some sleep tonight.

Fear not friends, there will be a SingOff post or two today.

Today I’ve been working on the back end of my software. UI is one thing, but you can only get so far with ‘lorem ipsum‘ data. Well, okay… in my case some fake data that sort of fits the project. So today, I started the process of moving from fake data to real data. This is always an iterative process that programmers and project designers know far too well.

First we sketch out what we think is the data we want. I usually jump from a text editor to a spread sheet. I realise this would probably be better right off the bat with a database; but that’s just crazy talk. I start out by trying to map out my main object (not really normalised at this point) and then make one or two side objects where I think they will need to stand off by themselves. With this model we build up some quick code to insert data by hand to have it generate out into a couple of different formats: (CSV, XML, JSON, etc) This allows me to easily re-use this data once output.

Now I go looking for actual data. I know what data I’m working with, so finding sample data on the interwebz is fairly easy. HOWEVER, and that’s a big however; once you start looking at real data and trying to shoehorn it into your model; you begin to realise exactly how limited your model is and where you need to make fixes. (This is why lorem ipsum only gets you so far).

Unfortunately, I need about 10 entries to work with the data correctly and each entry is about 60 lines/2000 characters of hand transposed data. (The whole database side of things happens once I am happy with what I have.) Oh, did I mention… if there is ANYONE reading who knows how to go from MySQL through REST calls into a JSON output (preferably using Tomcat) I may have some work/hobby time for you? Not kidding here. Also, if anyone knows a service that does this (with load balancing, metrics, yadda yadda yadda) comments welcome… knowledge dump will be appreciated/rewarded (eventually)

So, currently I’m up to 3 records. I’ll be working this afternoon on the other 7. Now that the first part is done, each record takes about 5-10 minutes to research and build up. Then I turn the whole monster around and have the Project import and use the data. That’s when things start to get ‘exciting.’

Those who I talked to informally about “The Project” should feel free to message me if they want details or are interested in some questions.

Until later… having fun and making great progress!