Wednesday, December 21, 2011

New Year's Python Meme

Here is my #2012pythonmeme, enjoy!


1. What’s the coolest Python application, framework or library you have discovered in 2011 ?
I think it's probably a tie between xhtml2pdf and django-jenkins.

2. What new programming technique did you learn in 2011 ?
Automation of machine setup. I did a lot of work this year around automating server setup and deployment. Though I was setting up machines for deployment of Python web applications, I actually used Ruby to automate these processes. Capistrano and Chef  are excellent tools that use Ruby to easily automate tasks such as these.

3. What’s the name of the open source project you contributed the most in 2011 ? What did you do ?
Probably django-wizard or one of the many other open source projects for imtapps. I didn't really do much that is note worthy, just some minor enhancements and bug fixes. 


4. What was the Python blog or website you read the most in 2011 ?  http://docs.python.org/


5. What are the three top things you want to learn in 2012 ?
First, I would like to get better about writing acceptance tests up front using lettuce and improve my lettuce familiarity in general.
Second, I would like to learn more about CoffeeScript and integrating that with django and django's staticfiles app. 
Lastly, I would like to learn more about PostgreSQL, enough to be able to decide if I should abandon MySQL in favor of it.

6. What are the top software, app or lib you wish someone would write in 2012 ?
I would like someone to write a django database backend that uses mock so that I can test without a database and be able to make assertions about how the ORM is being used.

Tuesday, November 22, 2011

Python Mixins

I am very fond of the concept of mixins as well as the Python language. The Python language does not really have the concept of mixins, however it does provide multiple inheritance. Although mixins and multiple inheritance are similar, or can be used similarly, in a lot of ways there are some very important differences.

Here is a simple illustration of mixin behavior in Python.


In this example, Jsonable is the mixin which provides generic reusable functionality that can be "mixed into" an existing object. This example is nothing special, this is a very typical use of inheritance in Python.

Let's take a look at a similar example in Ruby, which provides native mixin support.

After looking at the assertions at the ends of both the Python and Ruby examples, it is easy to see the differences between the inheritance approach and the mixin approach. The inheritance approach in the Python example actually changes the classification of our class, by making it a subclass, as well as the classification of our class's instances by making them instances of both Person and Jsonable. In the mixin approach Person is not a subclass and Person instances are not instances of Jsonable so there is no re-classification.

Before going any further, I want to say a few things about object oriented programming. OOP allows developers to categorize pieces of data and functionality into reusable components that mimic the behavior of the real world business concepts they are attempting to represent with code. In a perfect world, that statement would be true, but we all know that objects do not always represent something in the real world.

Let's analyse some OOP terminology. We have classes, which are CLASSifications of some functionality. We have superclasses, which are high level broad classifications (or SUPERsets of functionality) and subclasses which are more specific classifications (or SUBsets of functionality). Given that classes are for CLASSifying functionality, where do we, as developers, draw the line between how we classify our objects and what our objects are capable of doing? Good question.

Random pic to keep your interest

Is an object classified by what it can do, or by what it is? I am a Person. I am a Developer. I am a Male. I can do a somersault and stand on my head, but I'm not a Gymnast, and I would never classify myself as one. I can do those things, like many other People, many other Developers, and many other Males but so can Females and Gymnasts and probably even some kinds of Monkeys and maybe some kinds of Fish. Really, the only thing shared between all of these groups is that they have the ability to do the same action.

So, we have a bunch of different classifications of objects that share only a single ability. We could categorize them all as Somersaulters, but is that really a valid classification? I can do a somersault, but I wouldn't call myself a somersaulter, because as far as my abilities go that is quite insignificant. There are much more important and significant things that should classify me. When I meet someone on the street are they more likely to say, "Are you a somersaulter?" or "Can you do a somersault?" ? Honestly, probably neither. I would think the latter is more likely, however.

The point that I am alluding to is that using multiple inheritance to "mix in" some type of functionality to an object causes us to do some things that I consider breaking the rules, and we all know that "...Special cases aren't special enough to break the rules...". Referring back to the Python code example, we are reclassifying Person by making it a subclass of Jsonable. Is the fact that the Person can "save_json" significant enough that it should define it? Think about the relationship between Jsonable and Person. Person is a subclass of Jsonable, which means that Person should further define Jsonable to be more specific, right? Does it? No, I don't think so. A Person doesn't further define anything about Jsonable, other than the fact that it prints Person related json data, but Jsonable already does that without any further definition.

tl;dr - I know, so I'll cut it off here. There will be a follow up post about mixins because there was a lot I didn't cover. First class functions as mixin alternatives, why some think that mixins are harmful, and classification of bacteria and lichen. Hope you check back soon, thanks for reading!


Wednesday, November 9, 2011

My Crusade for Agility: Part 12

Welcome to the 12th installment of My Crusade for Agility. My crusade began nearly two years ago when I changed employers. In that time I have seen more change than I would think many developers have seen in their entire career. Fortunately, I've got a great team to work with who are all on board with implementing changes that allow our team to be more adaptive.

We're doing a lot of good things that include but are not limited to:
  • test driven development
  • pair programming
  • a weekly code kata
  • continuous integration
  • automated deployments
  • automated database migrations
  • contributing to open source
  • development sprints

Fairly recently we added some monitors in our common development area that displays all of our bilds on one monitor and scrolls through each build individually (to show more details for each build) on the other (see above). We also recently got some new (awesome) laptops for our development machines and added a third pairing station in our development area (see left and below). 





We also did a bit of redecorating. We raised some desks to standing height (like the rest of our desks) for both our build display monitors and a dedicated IE testing machine (see below). We also added some shelves four our growing library of technical books. 





Our team has grown quite a bit recently also. When I first started there was myself and 2 other developers working on our project, now we have 3 Full time web developers, 1 part time web developer, 1 half web developer / half manager, 3 developers who have been primarily supporting the legacy system who are recently getting more involved with web development.


Another challenge
Along side all of the agile adoption changes that have been going on there has been another very important thing happening. We are transitioning from our legacy desktop application technology (written in PC Cobol) to the web (written in Python). We are trying to approach this as iteratively as possible, swapping out components and sub-systems and integrating with the legacy system where necessary. This is a fairly significant amount of work to do, but the challenge is training ourselves.

The fact that the replacement system is written in a completely different technology for a completely different platform makes the transition very difficult for the developers and maintainers of the legacy system. Also, the fact that the legacy system is so vast with a large number of undocumented features complicates the process of providing the same business value in a new platform. We need to simultaneously iteratively develop a replacement product and train the existing developers in the new technology and the new developers on the legacy system. The technical training is more than just learning a new language or platform, it's learning OOP, Python, JavaScript, CSS, HTML, HTTP, SQL (and relational databases), etc, plus all of the various open source libraries that we use.

To help with the technical training we started doing a weekly code kata. We started with Uncle Bob's bowling kata to practice pair programming and TDD. We have had quite a few katas now, each has added some type of functionality to our original bowling game, and have largely focused on pairing/mentoring and TDD. I have found that the katas that seem to go the most smoothly are those that we start with some failing acceptance tests.

That concludes part 12 of My Crusade for Agility. Thanks for reading and I hope you check in again for future installments.

Tuesday, October 25, 2011

My Crusade for Agility: Part 11

Welcome to the 11th installment of My Crusade for Agility. In my ten previous posts I've discussed just about everything I can think of relating to championing agile adoption at my place of employment. This is a very exciting installment because we just finished our first development sprint. We definitely have room for improvement. This week was a very unfortunate week to be ending a sprint, and maybe last week was an equally bad week to start one for lots of reasons.


The reason that this was an unfortunate timing for a first sprint is because:
  1. We just got new hardware, so there was downtime setting that up.
  2. I am taking vacation for the second half of the sprint, so we will be short-handed.
  3. We are getting a new team member this week, so there will be some training and whatnot involved with bringing them onboard.
One of the first issues that I noticed with this sprint was that we "finished" all of our stories on the 7th day of a 10 day sprint. So our planning was off and we ended up without enough work to do... or did we? The reason that I say, "or did we?" is because of the second issue. The second issue is that besides the story and task cards we didn't have any acceptance criteria or acceptance tests so as we "completed" most of the stories they seemed to drag on and we continued to code even though the card's criteria was fulfilled. That seems like it could get dangerous because we, the developers, start to make assumptions about how things should work. Another issue is that now that all of the code is written, unit tested and deployed to staging it has not been QA tested.

QA testing is a very important thing that needs to happen. Since we finished the development work with 2 days left we, the developers, could take off our developer hats and put on QA tester hats, however developers don't make good QAs. I say that because if I write some code, then QA test that same code there is a good chance that I am going to be aware of the brittle bits and intentionally avoid them. The whole "switching hats" idea that I mentioned before starts to seem pretty waterfall-ish. We do not currently have a dedicated QA testing team member, hopefully we will one day.

I think our biggest issue that needs to be resolved, at this point, is our broken feedback loop between completing development and QA testing. The reason that loop is broken is pretty obviously a gap in staffing. There just isn't anyone at our disposal who can dedicate their time to quality assurance. Unfortunately, adding to staff is completely out of my control (not a responsibility that I want, btw).

Finally, because I'm going on vacation our retrospective is probably going to be delayed. I think it would be ideal to deliver all of the QA tested and signed-off-on changes sometime on the 9th day of the sprint, have the retro meeting that afternoon or on the morning of the final day then demo everything on the final day. That, unfortunately, is not going to work out this time (for me at least - maybe this is something that the rest of the team will do while I'm gone).

At the end of the day, and the end of this post, I think sprints are going to be a huge win for my team. Adding a full time QA team member would help improve our process significantly, but in the meantime there are plenty of things that we can improve. I plan to write more about our first sprint after we have discussed it as a team, so tune in next time for the 12th edition of My Crusade for Agility.

Monday, October 24, 2011

My Crusade for Agility: Part 10

This is the 10th installment of My Crusade for Agility. I began writing this blog at the beginning of September 2010 about 9 months after starting to work for my current employer. The reason I started this whole thing in the first place is that I saw three things in my new employer: passion, trust and willingness to change. Passion for software development that my teammates and I share, the trust of our employer that we will deliver the products that our partners need to succeed and willingness to change our processes and technology to better help us succeed.

Having said that, willingness to change took time, as did trust. From my employer's perspective, and my new co-workers, I was this new guy coming in suggesting a bunch of changes. I had plenty of software development experience, but not much real experience with the things that I was suggesting, which made it hard to sell. Test driven development, acceptance test driven development, pair programming, iterative development, user stories, continuous integration, and so on. These were all things that I knew about but I had not really done much of any of them in practice, but I knew people who had. Those people are the ones who really helped me get things going at my place of work.

I'm proud to say that with the passion of my team members, the trust of our employer, and everyone's willingness to change we have successfully become an "agile shop", whatever that means. But then again, who isn't? It seems like everyone claims to be "agile", but what does that really mean? I don't know, it depends who you ask. Some people will say that you're "agile" if you do TDD, others will say that you're "agile" if you work in iterations. Maybe it is both, maybe neither. What it means to me is exactly the definition of "agile" which is "ability to move quickly and easily". Adaptive is another word that I think describes "agile" development very well.

To me, the key concept of agile development is being able to continually meet changing business needs as quickly as possible or as they occur. Feedback is important, for software developers and for businesses. Software developers need to know that they are delivering what the business needs and the business needs to know that the developers are developing what they need. We all need the same thing, communication. As early and as often as possible.

As I discussed in my previous post, our communication was not really giving us feedback as early or as often as we would have liked. We have done a solid job of using TDD, ATDD, pairing, and CI, but we haven't really been implementing anything iteratively and getting feedback. This past Monday marked the start of our first 2 week development sprint. This is hopefully a technique that will allow us to deliver an amount of work to our partners so we can receive feedback.

At the end of the first week we have completed the development of 31 of the total 39 points included in our sprint. I'm very happy with that and actually extremely surprised. Not because I didn't think we could do it, but because I was out of the office one day, I left early another day, we got new computers (so we waisted at least a day setting up the new hardware), we did a bit of house cleaning because we have a new team member joining us next week and overall I feel like we have not done a very good job of sticking to the tasks on the story cards.

Not to say that we've been working on completely random or unrelated things, but we have definitely gone outside the scope of what we initially set out to accomplish. While it appears like we are going to get away with it this time, this is a habit that we will need to break for future sprints. One thing that I added to our white board is a TODO box. I just started posting things in there that I come across that are relevant and should be done, but are not necessary to complete the tasks at hand. My hope is that these tasks will be included in future sprints.

All in all, the first week has gone very well. With only 8 points left, I think we will end up making our sprint, which I did not expect for our very first time. I am on vacation next week, so I will not be around for the tail end, but I'm sure my team mates will wrap it up nicely.

I will write another follow up once the sprint is complete to fill every one in with how we ended up.  I also have a few other fun and interesting things to share, so tune in next time. Hope you've enjoyed my first 10 installments of My Crusade for Agility.






Wednesday, October 19, 2011

Language Exploration: Part 1

I went to college at Indian Hills Community College in Ottumwa Iowa, which I do not regret in the slightest. The Software Development program was outstanding and I'm actually fairly impressed by how the curriculum changes over the years. During my time there, one class in particular really stood out as the one class that taught me the most. This class was called "Language Exploration". The syllabus was simple, take a program that you wrote for one of your other classes and re-write the exact same program in 3 different languages. The reason why I thought this class was the one that I learned more from than any other was because this was one of my first experiences with learning new languages on my own. In this class I basically taught myself how to teach myself new languages.

At IHCC we were taught quite a few different languages which included C, C++, C#, VisualBasic .NET, COBOL, CICS, JCL, Java, PHP, and SQL. For a 2 year program that is quite a wide variety. After graduation I was hired as a COBOL developer and 2 short years later I transitioned to web development using Java and I also supported some VisualBasic 6 applications. During my stint with COBOL I was doing web development using the standard web stack (HTML, CSS, JavaScript) with PHP and Perl. Then I moved to a new employer and started using primarily Python and began a few side gigs using Ruby and PHP.

I've always enjoyed learning new languages. When I've moved from project to project there are certain things that get lost. After using Python for a while and not looking at any Perl code, going back and looking at Perl's data structures takes a few minutes to wrap your brain around (with all of the referencing/dereferencing). Moving between Java and Ruby is difficult because of semi-colons and return types. There are a million different reasons why switching back and fourth between different languages can cause trip-ups.

These little trip-ups are the reasons why I wanted to create a repository dedicated to language comparison. I wanted to recreate my experiences in the language exploration class on a larger scale. Instead of the class's 3 languages I decided to go with 16. My first task was to choose languages. I started with languages that I know, and languages that I've dabbled in then I added a few others that I've heard about but never really used. I decided to cap it at 16 languages for no real reason other than that is how many languages that I came up and seventeen just seemed like too many and fifteen just didn't seem like enough.

The languages are as follows:
With a list of languages to work with, my next task was to write a "Hello World" in each of them. I opted to limit that to "Hi". So I wrote 16 programs that printed "Hi" to stdout, one in each of the above languages. That was pretty simple, so I decided to take on a slightly more challenging task. Here are the guidelines that I started with.

  • Must print the nth number of the fibonacci sequence
  • Must be a command line executable program that takes a single integer argument
  • Must print the number from the fibonacci sequence that corresponds to the command line argument to stdout (including 0 so that given 5 the result should be 3, 6 should be 5 and so on)
  • Must use recursion

That took a bit more time. Truthfully, the fibonacci sequence is fairly easy to implement using recursion in any of these languages. The hardest part was figuring out how to parse command line arguments and convert it into an integer. Erlang seemed to give me the most trouble here, in the end the solution was not all that difficult, I just had to figure out what it was which ended up taking a lot of time. XSLT was sort of a special exception rather than accepting the number from the command line it was parsed from an input xml file.


My long term goal is to continue to add new simple examples that show how a problem can be solved in each of the 16 languages, and hopefully I will be able to demonstrate some advantages that some languages provide over others.

If you care to browse the examples, please do https://github.com/mattjmorrison/polyglot. Also, I am absolutely not an expert in all of these languages, so if you are and you have some tips for me please submit a patch.

Monday, October 17, 2011

My Crusade for Agility: Part 9

Welcome to the 9th installment of My Crusade for Agility.  Just before starting to write this post I went back and re-read the previous 8, not to toot my own horn, but I think it was pretty good. I'm extremely glad that I had the foresight to write these posts as it was happening. Looking back, I would never remember all of the details and the order of events if I had tried to sit down and write everything all at once after the fact. Score 1 for iteration. So I'm going to go ahead and give myself a pat on the back, not only for the whole agile crusade but also the documentation of said crusade.

In past installments I have discussed a lot of different things. Most of which have centered around the introduction of agile software development to my current employer. It has been going extremely well. Our main code base just recently passed the 90% test coverage mark, which is exciting. We have started writing some acceptance tests using lettuce and we have over 20 automated builds which include not only testing and static analysis but also deployments. 

In Part 7 I mentioned that our workflow process needed work and that so far everything that I've tried so hard to introduce really has only benefited developers. This has pretty much held true until recently. I'll get to our workflow problem in just a minute, first I want to discuss adding value to the rest of the team (non-developers).  The whole team is made of up 6-7 developers and 5-6 non-developers (the non-developers are a combination of management, marketing and customer service). We do not currently have any formal business analysts or quality assurance team members, which is not ideal but we get by OK without them for now (we could definitely benefit a lot by getting both a dedicated QA and BA team member).

During a typical week every team member (for the most part) stays in their silo, either developer or non-developer. The non-developers do use the software created by the developers to troubleshoot and configure things for our customers, but the developers do not communicate much if anything about recent changes or things that are in progress. In a hopeful attempt to open up some communication between the devs and the non-devs I suggested that we start doing a weekly retrospective meeting with the whole team. 

In our very first retrospective the non-devs brought up the fact that we had some data entry screens that were extremely tedious and very time consuming. The following week we were able to demo an import/export feature that ended up saving days of manual data entry. We knew, as developers, that we had created a user interface that was very tedious to work with, but we had never really gotten any feedback complaining about it. These meetings have been very successful. They've given the developers a chance to hear what the customers are saying to our customer service team members and the customer service folks a chance to see what is in the works and what exciting new features have been added to make their lives easier. 

So, going back to our workflow problem that I mentioned earlier. In Part 6 and Part 7 I mentioned that we were using story cards and a white board to manage our (developer) work load. We were, but it didn't last. Our story cards basically corresponded to tickets that we keep in trac and the prioritization of the stories on the white board was pretty much non-existent. We probably spent more time working on things that never made it into trac or onto the white board than we did on anything else. 

Our problem was in the way that we were prioritizing tasks, we weren't, not in advance anyway. We would pretty much work on whatever the boss said to work on whenever he said to work on it. The major problem with this is that the developers are always having to ask "What's next?" and the boss is always having to figure out what is next whenever one of the developers asks, so there is more work for everyone to try to figure all of that out on the fly. Somebody always get caught like a deer in headlights. The boss would say, "What are you working on?". The developer answers, "Uh, um, I don't know, what do you want me to work on?" and the boss replies, "Uh, um, I don't know, I'll get back to you." and in the meantime nothing is getting done.

We've known for a long time that this was something that needed to be fixed, we have also known that the way that we were going to try to fix it was by doing development sprints. Our biggest problem here was that we didn't know what to do. We knew that we needed to dedicate some work to a timeframe and that is about the extent of it. Luckily for us, Trent from CDS Global, agreed to come to our office on a Friday afternoon and do some sprint training. He provided us with all of the missing info that we needed in order to get started. 

After meeting with Trent, we were able to do some backlog grooming to prioritize all of the work that needed to be done, followed by a sprint planning meeting where we created stories and scored them, and broke stories out into tasks. We decided that, as Trent suggested, we would create a theoretical story that we would score with a 1. Our dummy story ended up being something along the lines of, "Add a field to a web page and save it in the database". Using that as a reference point, we went through the backlog and wrote and scored 13 stories for a total of 39 points and decided that was going to be our first sprint.


Today was the first day of our first sprint. We've been going through the stories in priority order and we actually got 8 of the 13 done today. That might sound impressive, but those 8 stories only account for 9 points, so we've got a ways go to, which is a good thing considering that we've got 9 days left. I can already tell that this is going to be an excellent way to keep on track. My hope is that once we finish this sprint we will have a sprint retrospective (which will most likely be a separate get-together from our current weekly retrospective - we should probably work on calling them something different) so we can figure out how to improve our sprinting process, and also have a demo at the end so we can show (hopefully some customers) what our sprint accomplished.

I'm pretty excited about our first sprint. I think it is going to work out really well. I will make sure to post a follow up after our sprint because I'm sure you're just dying to know how it turns out. Tune in next time to hear more about My Crusade for Agility.

Sunday, October 2, 2011

October 2011 Pyowa Meeting

The IMT Group will be hosting the October Pyowa meeting on Thursday October 6th at 6pm. As always, IMT will provide free food and soda.

Wes St.Clair of The IMT Group will be talking about Appy.pod which is a Python module that allows you to turn an OpenOffice document into a template.

Does anyone else want to volunteer to present a topic, demo something neat, or get some group help with something that has been causing you grief?

Are there any topics that you would like to hear someone else present? If so, please let me know and I'll see if I can line something up.

Even if you're not able to attend this meeting, I would still be interested to hear about what types of applications people are working on and how everyone is using Python.



I am still working on finding a good (free) solution for live streaming the meetings. Suggestions are welcome.

Look forward to seeing you on the 6th!

Thursday, September 15, 2011

Avoiding Monolithic Code

Monolithic code is one of the many enemies of clean code. When I say, "monolithic code", I'm referring to a few different things.
  • A system that does absolutely everything with very few or no external dependencies 
  • A system that lives on a single machine and/or uses a single database or data store
  • A system that resides entirely in a single source control tree (or no source control at all - gasp!)
  • A system written entirely in a single language (excluding typical web languages like HTML/CSS/Javascript/XML/JSON/...)
Ideally, an application will meet all of these criteria. A system however ideally would not. When I refer to an application I'm talking about some piece of software with a single purpose that can stand on it's own whereas when I refer to a system I'm talking about software that has many features and a higher level purpose. For example maybe I have a system for social networking, one application in that system might be instant messaging. The terms "system" and "application" can be used a lot of different ways, so I hope that helps to clarify how I am going to be using them.

Monolithic code is a smell that I've been emitting a large majority of my career. In the past few months I've been trying to break this habit. Here are some of the reasons that I've found monolithic code to be a smell and what I've done or what I would like to do to help remedy it.


I think a very common situation is that a company or an architecture team will choose a technology stack and stick to it come hell or high water. I'm going to pick on COBOL and Z/OS, first of all because it's easy, secondly because this is a widely used technology stack in business today, although most likely not a very appropriate platform for most modern systems.

In the situation where we are running COBOL on a Z/OS mainframe, we are completely tied down to a specific vendor, some specific hardware, a specific OS and a specific language. This is a very monolithic architecture. I think it is fair to say that this technology stack is still so prevalent because it is so monolithic there is no easy way to gradually move away from it. I think there are a lot of businesses that are being held back by their commitment to this technology. They are so invested in it that there is not much they can do, it is not feasible to ask them to just scrap their entire system and start over. Even if they did, they would most likely end up committed to a more current but equally monolithic technology. Because it is familiar to them, it is what they know and they're used to. "Learn one thing, learn it well, and use it for everything", would be their battle cry as they march on to slaughter. (joking...sort of)

When you find yourself in this predicament, something has gone wrong. You are less able to easily adapt. You can still continue to deliver value to your customer, but at what cost? How easy is it to deliver highly available web applications when you're tied down to a single physical mainframe? You're going to have to build layers on top of the mainframe in order to make that work, which further couples you to the mainframe and gets you deeper into the problem. With all of the buzz about "the cloud" these days and all of the benefits, it sounds insane to balance your entire system on a single point no matter how fast or stable it may be. If you do, then you need to have some kind of process in place to handle power outages, freak accidents (like somebody accidentally cutting through a T1 line), natural disasters, etc.

Say you have all of those process in place, where are you spending your money? Are you spending money adding value to your business or are you spending it on trying to protect your huge monolithic basket full of eggs (or jars or gems). It seems to me like that money would have been better spent trying to advance and improve rather building a bunker around your monolithic system and even further committing to it.

Wouldn't approaching a new feature request as if you could open up your tool box and choose the best tool for the job, make the world a better place to code? Let's take our mainframe scenario again. We've got a massive mainframe based system and tons of data stored in DB2. We have a new feature request to have a customer contact management application so that internal employees can keep track of customer phone numbers, addresses and whatnot. We already have almost everything we need in some DB2 tables, but we will need to add a few columns, and update a few COBOL programs and add some new fields to some CICS screens.


Yuck, I already don't want to do it. I can't very easily pawn this off on some newbie right out of college either. What are the odds that they know how to add a field to a CICS screen? What is the point in training them to do this? People don't want to use these screens anymore, developers (especially newer developers) do not want to continue coding them, so why should we continue to create and maintain them? If I used Ruby on Rails I could meet the business's needs and give them a nice new, web based, and mobile friendly application to work with.

Using Rails' scaffolding, I could generate a large majority of the application without having to really write much code at all. So, what if instead of enhancing the COBOL program, the DB2 tables and the CICS screens, what if we just used Rails and built a web based application that meets the immediate needs of the current feature request? Then, instead of further coupling ourselves to the mainframe we could move to a more appropriate platform that is easier to maintain and more user, and developer, friendly. That sounds nice.

But now we have a problem, we have existing COBOL programs that need that data and we're taking it away from the mainframe. Yes, yes we are. It's got to happen at some point. The monolithic mainframe is not an agile place to be. If we need to be able to adapt to changes in our business and changes in technology we need to have some flexibility. We need to have independent applications that can talk to each-other, not one system that just knows everything. A system that knows everything is dangerous because it is brittle. If it does everything then changing something could break anything (not to mention the whole skynet thing). If the mainframe needs the data from our Rails app, it is going to have to come and get it.

That problem can be solved in a lot of different ways. While none are probably ideal, I know that the user will appreciate the ability to pull up a website on their phone and get an immediate response vs. having to dial into the mainframe and pulling up a CICS screen in order to get a customer's phone number or work with some slow and unstable layered web framework built on top of the mainframe.

What if we would instead just build a Rails application that access the data already on the mainframe. That could also work. We now have some CICS screens that we can throw away, but we still need to update some COBOL programs and now we will have to update Ruby code as well. So our new single purposed web application whose sole reason for existing is to maintain contact information isn't the authoritative source for that information. We've just created a very un-DRY situation. Sure, we're moving away from the mainframe... on the surface, but underneath we are just as coupled to it as ever, maybe even more so. Now we've got COBOL code and Ruby code that is 100% dependent on the mainframe. Just bite the bullet and cut the tie, it will be better for everyone.

Let's turn that around now, let's say that we've got some existing massive Ruby on Rails system and our customer comes to us with the same feature request as before. After thinking about it for a few minutes, lets say that we decide that Ruby on Rails is the technology choice that we should continue to use. We could very easily generate a new application in our existing Rails project and get this thing done and working, but wait... how is this any different than our monolithic mainframe? We've got a single code base, a single platform, we're deploying to a single server and using a single database. We are still stuck in a place that is not very easy to adapt to technology changes. What happens when we look at Rails 6 and decide that it is just massively overcomplicated and full of stuff that we do not want or need and it no longer aligns with our technology radar?

To avoid getting stuck in this situation, I would say that rather than just adding a new application to an existing project, just create a new project. A new server, new database, and a nice clean API for our existing system. Now we're completely decoupled from our monolithic system and can be more adaptive if/when it comes to that. We can easily swap out the new Rails project for something written in Clojure as long as we keep the API the same, it doesn't matter.

Of course, not all applications should have every single individual component live on a separate server with a web service API, that would be ridiculous. However, I do think that each individual component should not share the same source control tree. The API to that component can be whatever is appropriate, it doesn't matter. Maybe we wrote this contact management application in Ruby. Why don't we just bundle it into a gem and use that gem in our Rails application. If and when the time comes (and we're using jRuby) we could potentially re-write that component in Scala or some other JVM friendly language. We are still coupled to our monolithic system, but less so, because now our code lives by itself, it can be maintained independently and re-used elsewhere.

To sum it all up, here is what I recommend:
  • keep each self-standing component in it's own source tree. 
  • Don't deploy everything to the same hardware
  • Don't use the same database for everything
  • Don't use the same technology stack (including language) for everything

Having recommended that, I can't honestly say that I recommend it because I've done it and it works. But in theory, this is where I want to be. In practice I have definitely seen success in keeping separate components in separate source control repositories.

Keeping components in their own separate source control repository does a few different things that I really like. It makes you really think about your code in terms of a stand alone library instead of just being a buried piece of a system. That alone has made my APIs much cleaner and more independent from the rest of my code. One other benefit that I've seen is that my main code base, which already has many external dependencies, is smaller overall and just has a few more dependencies. The reason that this is a benefit is because it makes it feel more natural to download the source of a dependency make a change and re-submit it.  Re-submit can either mean checking out source from one of your other repos or forking an open source project and submitting a patch.

Honestly, before I started keeping my own code in separate repositories I didn't really submit many patches to open source projects, and now it seems like I do that almost weekly. Another thing to keep in mind is that I do not necessarily begin coding something with the intention of making it a reusable library, but I end up seeing re-usable pieces in working code that can be extracted into a library, and hopefully contribute it back to the open source community.

In a recent project my pair and I wrote a proof-of-concept application, then started over test driving the entire thing into a nice little stand-alone application. When we were done we extracted one part into a separate project and open sourced it. Shortly after that, we had a new feature request and we extracted yet another project from our original and the same thing happened another time, a new feature comes along and we extract another project so we can re-use it. All in all we ended up with five different open source libraries that are completely decoupled and reusable. Almost all of which we are using in at least two different applications in our system.

Just to drive home the benefit of extracting re-usable components into separate projects, the first additional feature request, from a user story perspective, was a significantly larger undertaking than the original. However, we realized that we had already built all of the infrastructure needed by the second feature when we implemented the first feature. All of that infrastructure was buried in the first feature though, so we had a choice. Either we completely combine the first and second feature into a monolith or extract what is common and have each feature use that as a dependency. We extracted the common code into it's own library, and created a library for the first feature and a library for the second feature. Now we are positioned very well for the future. If another similar feature comes along, we should be able to implement it extremely quickly with very little risk of breaking one of the other features.

If you're still with me, thanks for sticking with it. I hope to post a follow up to this after I am able to implement some more of my own advice.

Friday, September 2, 2011

September 2011 Iowa Python Users Group Follow Up

Last night's Pyowa meeting was great. We had a pretty decent attendance, with 2 new faces which is always exciting. We had some soda and pizza, which is always good, then spent about 10-15 minutes showing everyone our development area in the IMT office. After that I presented mattspackage, which is a simple application to demonstrate how to register and upload python modules to Pypi.

I also set up a uStream.tv channel and, using CamTwist, did a live screen cast and recorded it. I think this is a really great thing that I hope to continue for future Pyowa meetings.  Here is the recorded screen cast. CamTwist/uStream seems to have done a pretty adequate job as far as audio is concerned, but unfortunately the combo resulted in very poor video quality.

Also, a very important thing that I totally screwed up is that I completely ignored the fact that I was live streaming and recording myself. So if you happened to log on during the presentation and had a question, comment or concern, I'm sorry that you were ignored. You will probably also notice there are a number of comments and/or questions made in the background of the video that are inaudible. Next time, I will make sure that we have an "in person" volunteer who can be the voice of any remote attendees. I will also be sure to repeat questions for the microphone. If you are reading this, it is your responsibility to hold me to those promises.

In future meetings, I think I will give TinyChat a try, and depending on how that goes maybe also try LiveStream. If anybody has any suggestions for some light weight live screen cast software, I'd be more than happy to try anything. Also, if you happen to be a company who has some excellent live screen casting software and would like some beta testers or someone to endorse your product I would be willing to use your product for free :).

Here is the unfortunately low quality live screen cast from our meeting. You can browse the code here.


Video streaming by Ustream

Saturday, August 20, 2011

September 2011 Iowa Python Users Group

For all who are interested:


The IMT Group will be hosting the Iowa Python Users Group in our office in West Des
Moines on Thursday, September 1st at 6pm.


We're going to be talking about distributing python modules using the Python
Package Index (pypi) and maybe some throw in topics if there is time. We
will also have free pizza and soda for everyone who attends and we will be
showing everyone around our recently renovated development area.


Please RSVP to me (mattjmorrison at mattjmorrison dot com) if you plan on attending
so I know how much pizza to get.


Hope to see you there.


View Larger Map

Saturday, July 23, 2011

Learning Rails: Part 1

I was recently approached at my place of employment by a co-worker with an idea for a startup. The idea was great, so I was on board, but I needed to decide what technology to choose. By day, I write Python and use Django. I'm very comfortable with that stack, so initially my brain went right to Django. I love Django, but I've got an opportunity to expand my horizons so why not?

I also considered using at Scala and Lift, Python or Java on Google App Engine,  or some new hotness that I don't even know about. In the end I landed on Ruby on Rails for a few reasons. The main reason is that since I've been attending the Iowa Ruby Brigade it seems like the Ruby and the Rails communities are very dedicated to testing. Cucumber and RSpec are two examples of things that I have just barely began to use but I already almost can't imagine not being able to use them.

So, I chose Ruby on Rails (Rails 3) to start this new project with and my intention with this blog series is to document my learning experiences. I've really just gotten started, I've got 11 Cucumberscenarios and 10 RSpec unit tests, I've got one model with about 40 lines of code and one controller with about 30 lines (lines include white space). This is really the first real Rails code I've ever written (thanks JR for helping me get started). I've messed around with Rails in the past, but that usually consisted of me scaffolding some model, playing with the UI, not knowing what to do next and leaving it at that.

Once I got into writing something real I was overwhelmed by the magic that is Rails. The first thing that confused me was the routes. It seems like there are an overabundance of ways to define routes. I think i settled on just using 'match' for everything because I can have it create the magical _path variables that I can use in my controllers. The first thing that really freaked me out was that it seems like everything is just always in scope. There are all of these helper functions and objects that I can just use. I don't know where they come from or how they get there, but they are there and they are pretty great. It is pretty overwhelming to not have to 'require' anything but have who-knows-how-many helper functions available to use. It actually reminds me of PHP'sbuilt-in function's namespacelessness, it's chaos! 

Looking at it from a comparison to Django perspective: if I want to get the url to an action I would import Django's reverse function and call that providing the "namespace:view_name" and any additional arguments that may need to be included in the url. In Django land, that is "The Way" to do it. So far, and again I'm just starting out, I've seen at least 3 different ways to get a url in Rails, #1 "controller#action", #2 render :action => 'action', #3 action_name_path, and I'm sure there are more. I have no idea when to use which one, or if I even ever need to use different combinations of these or just choose one and stick with it. At this point I'm trying to stick with using the action_name_path method because it seems to be the simplest (and also most magical).

RSpec and Cucumber have been pretty easy to pick up and simultaneously fracking awesome! The ease of writing behavioral tests with Cucumber is an absolute delight. The way that RSpec allows you to describe a class and describe it's methods is equally pleasurable. Getting used to setting up expectations in RSpec is going to take a while because it is so much different (albeit easier and a hundred times more sane) than what I'm used to with Java and Python.

Overall, I'm really enjoying my time with Ruby and Rails, I'm learning a lot and the more I learn the more I like it. And, to any Rails haters out there, if you're reading this, it is not just hype. I'm just barely getting into it and I can already tell there is some really good stuff going on. Thanks for reading and tune in next time for more about my experiences with learning Ruby on Rails.