Sunday, September 2, 2012

JavaZone 2012

If you are looking for one of the top Java conferences, you need to take a look at JavaZone in Oslo, Norway.   Having been there a number of times over the last several years and comparing it to other Java conferences... It is top notch!   I'll be speaking there again in a couple of weeks and I'm certainly looking forward to it!

If you can sneak away... this is the one to come to!

Hope to see you there!

Monday, May 28, 2012

The Key Tenets - 7 Years after The Internet Services Disruption

October 28 2005 Ray Ozzie, having recently joined Microsoft (msft) at the time, put together an interesting manifesto with the subject title of "The Internet Services Disruption", with the purpose of "get all of us roughly on the same page".  For currently undisclosed reasons,  I had reason to review this document and found it completely fascinating.  Ray's foresight and ability to forecast the future is just amazing.   Although his writing was made public (good for us all), it was intended to inspire and position MSFT for it's next great phase.   Let's look at each of the key tenets Ray outlined and see who in our industry has the upper hand.

1.  The power of the advertising-supported model
Is MSFT winning here... definitely not.   Winners in this category are Google, making money off google.com.   Facebook making money on ads based again on high traffic visitations.  While these two companies are making good money with this concept, the company to watch is Apple.  Why?  Apple is actually empowering developers with this ad-support model through iAd.  Like ads or not... Apple is enabling developers to provide solutions free to consumers and are paid through ad hits.    There has also been a resent uptick in the number of ads off services like Hulu and youtube.   So there is no question that Ray nailed this tenet.

2. The effectiveness of a new delivery and adoption model
While Ray describes this in a try before you buy, and a readership and review model,  while being valid it is ubiquitous, so it is hard to give any one company brownie points for this.  Most of the good companies have their share of fan boys, VIP programs and evangelist (in the which MSFT does a stellar good at),   I would like to take this concept a little deeper.   New delivery... and delivery of what.  Considering operating systems and software, everyone is going disc-less.  Delivery of updates are internet provided.   But lets talk content... There is a new delivery mechanism for content... how do you watch your movies, how to you read your books, how do you get your music?   Where is MSFT in this space?  No where to be found.   Who owns this space?  Well... depending it seems divided between Amazon, NetFlix AND the big one?  Apple.   Apple hits gold stars in this category up and down their product like.  In fact one could say that the adoption of an iPod or iPad is a gateway into the full Apple stack.

3. The demand of compelling, integrated user experiences that "just work"
While I could go into detail and beat around the bush... this statement screams Apple.   While apple costs more in some cases, they are uncompromising and focus on the user experience.  They have all the advantages in this category as well.  they own the full tech stack... they don't have to make it work on a billion devices... they have theirs.

I consider myself a technologist and I don't "belong" to a specific tech group.  I see value in a number of camps.   The take away for me... is how insightful Ray was almost 7 years ago.  He nailed it.  It is too bad that MSFT doesn't seem to be paying attention to him. 

Thursday, April 5, 2012

Getting the Spock out of a Gradle War

I recent ran into a interesting situation, for which I thought it would be worth sharing. I have a new project with the following build needs: Java, Spring MVC and Spock Testing. The problem is simple... The WAR build in gradle was building a WAR file that included the Groovy libraries. This project has no need for groovy at runtime. Groovy is needed because I'm using Spock for my testing.

Gradle and providedCompile

In older versions of Gradle it was commonly necessary to manage the jars in the lib directory. In the maven world, there is a dependency scope of "provided". This scope basically means that the dependency will be provided on the server classpath, however for the purposes of compiling the code in the project it is necessary. From a WAR perspective it means use this dependency for compile, but do not include it in the lib directory of the WAR. Gradle within the last year has added the same feature as providedCompile or providedRuntime. In my project I have this very need with the servlet-api, shown below.
dependencies {
compile "org.springframework:spring-webmvc:$springVersion"
compile 'javax.servlet:jstl:1.2'
providedCompile 'javax.servlet:servlet-api:2.5'
}

Spock dependencies and Gradle

As Spock is a groovy testing tool, it is no surprise that Spock requires groovy. This requires a couple of well documented configurations in your gradle file. First, you'll have to add the groovy plugin. Second you have to set as a dependency the groovy version. But wait!!! The dependency for groovy doesn't have a scoping ability. This is area where the "model" of gradle breaks down a little bit IMO. Ideally you would be interested in expressing in the model that there are "testing" needs... and those testing needs require groovy and spock dependencies.
apply plugin: 'groovy'

def spockVersion = '0.5-groovy-1.8'
def springVersion = '3.1.0.RELEASE'

dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.8.3'
testCompile 'junit:junit:4.8.1'
testCompile "org.spockframework:spock-core:$spockVersion"
testCompile "org.spockframework:spock-spring:$spockVersion"
}
With this groovy dependency any build of WAR will result in a the groovy-all-?.?.?.jar file being added to the the WEB-INF/lib directory. The problem is I have no current interest in having groovy in production for this project. What to do? What to do?

Gradle Doc to the Rescue

I find that a large number of people (usually new to gradle) struggle with discovering how to resolve such a problem. The best starting point for getting to know gradle is the gradle user guide documentation, but the best starting point to use as a reference is the gradle dsl documentation (http://gradle.org/docs/current/dsl). Hopefully it is obvious that what we want to change is the build of the WAR. So lets look at the War task. Here we see all of it's properties... which includes the classpath property. The documentation for this property clearly states that this property affects the WEB-INF/classes and the WEB-INF/lib. Diving deeper into that property we see the default behavior which is:
project.configurations.runtime - project.configurations.providedRuntime
So our logical solution would be to include a war task configuration for the building of the classpath like this:
war {
classpath = classpath - project.configurations.groovy
}


Happy Coding! and may your builds never fail!

Sunday, March 18, 2012

Speak at the 33rd Degree


I will be speaking in Poland this month at the 33rd. It looks like a great conference line up and Krakow is wonderful.

Wednesday, March 14, 2012

Agile: getting the standup right!

The standup meeting as part of an agile discipline at first seems like an easy and obvious activity. Yet I keep coming across clients and organizations that seem to struggle with getting it right. It appears that as long as everyone is standing... and we do that everyday... that we can check "standup" off the list. Just standing up doesn't make it a stand up! (Please repeat that... as often as it takes to get it.) On top of that... many organizations seem to think that the stand up is for the scrum master or management to get status. That's not it either! Here are some warning signs:
  • Standups take 30 mins or longer
  • People regularly miss the meeting
  • You are always waiting 10 minutes for that one person
  • The PM or Scrum Master is asking clarifying questions
The standup meeting is NOT:
  • Primarily for status (I know that might seem confusing)
  • About the position you are in during the meeting
  • About the Scrum Master
Getting the standup right is crucial for a healthy agile team. It is for and about the team. Here is the purpose of the standard up:
  • Synergy - It is a point for developers to synchronize their efforts and realize when there is about to be some code thrash. It is a point to say, "hey joe, I'm about to do task x which is closely related to your task y, lets get together after the standup".
  • Transparency - Everyone knows what is being done, which provides a double check that each person is doing the highest priority tasks and is there anything holding us up.
  • Accountability - This the best place to realize that a team mate is struggling. When you see that Joe has had a 4 hour task for 2 days its time to say "Joe... lets pair on that... lets see if we can knock that out.
These purposes come out of the standard questions most agile developers are aware of: "What did I do?", "What am I going to do?" and "is there anything holding me up?". I know this sounds like status... it's not.

Advice for Scrum Masters
  • First realize you are not the reason for the standup
  • Standups are 10-15 mins.. that's it.
  • Do not ask for follow up during the stand up... if something needs to be followed up, follow the person of interests back to their desk and ask them without tying up everyone else's time.
  • If it becomes clear that the team needs to meet.. for a design discussion or a big status meeting or... doesn't matter. It is super important to delineate that as a separate meeting. "Hey I would like to discuss x with everyone after the standup. Please stick around.". Then announce "ok, that is the end of the standup, lets discuss x"
  • The best thing you (Scrum Master) can do during the standup is to facilitate. Do not allow someone to dominate 5 mins of the 10 min standup or elaborate extensively. The challenge is not to be a jerk about it... If it is a challenge, then it is something that needs to be discussed in a retro meeting, asking for the teams opinion and possible solutions.
A big part of getting agile right is to understand why we do certain things! It isn't about standing up. It is about keeping it short and to the point. It is about getting the benefits listed above out of it.

Good Luck

Tuesday, December 20, 2011

Constant Pain with Non-Constant Constants

This thought has crossed my mind before... since it is on my mind now I thought I might share. Perhaps it will help someone on their software development career path... or perhaps it is just me venting...

The Art of Coding


One of the greatest challenges of coding is being able to understand it. Skill in coding is being able to understand the problem well enough to create a solution (otherwise known as coding). Great Skill is being able to write a solution so that someone else (including the future you) can read and understand what it is they are looking at. This concept isn't new, but yet we seem to be either challenged with the concept... or distracted. Even back in 1952 (yes 1952!!), in the computer history archive a set of lecture notes which in them states: "It is quite difficult to decipher coded programs even with notes and even if you yourself made the program several months ago." It also states: "I think the answer is simple: to make it easy one must make coding comprehensible". Well said!

The Point of Constants


One area that seems to be a constant :) struggle is constants. There are at least a couple of justifications for using constants I can think of: 1) a point of reference for tools (autocomplete with intellisense in IDEs and refactoring), 2) A common holder of value for which if it changes will be realized across the system. The main point of a constant isn't DRY or reuse... a common point of confusion for some reason.

IMO the stronger argument is point 2. if you were coding in VI or emacs, point 1 may not be of value, but point 2 certainly would be. If you name the reference of a constant the same name as the value of the constant... then you lose any the value of point 2.
It must also be said that constants, although they add value, they make code less readable (see examples below). If your constants have no value, they don't achieve points 1 and 2, then they need to be whacked!


Examples of Losing with Constants


This is real production code... some variables changed to obscure identify.


// example 1 Really?? where does this end?
String EMPTY_STRING = "";

// this isn't readable... it takes minutes (instead of seconds) to understand its value
// example 2
String ADVERTISE_PROPERTY_PREFIX = OUR_PROPERTY_PREFIX + "advertise.";
String ADVERTISE_TRADER_ADDRESS_PROPERTY = ADVERTISE_PROPERTY_PREFIX + "host";
String ADVERTISE_CONTEXT_PROPERTY = ADVERTISE_PROPERTY_PREFIX + "context";
String ADVERTISE_TYPE_PROPERTY = ADVERTISE_PROPERTY_PREFIX + "type";

// example 3
// here's a common one
static final String TABLE_NAME = "email";

// Column names for all the fields in the email table
static final String ID = TABLE_NAME + ".email_id";
static final String CUSTOMER_ID = TABLE_NAME + ".customer_id";
static final String ADDRESS = TABLE_NAME + ".address";
// ...
static final String FIELDS = ID + ", " + CUSTOMER_ID + ", " + ADDRESS + ", " + CREATED_BY + ", " + LAST_MOD_BY
+ ", " + CREATE_DATE + ", " + LAST_MOD_DATE + ", " + TERM_DATE + ", " + WEB_USER_ID;

// List of fields names with formatting used for select statements
static final String SELECT_FIELDS = ID + ", " + CUSTOMER_ID + ", " + ADDRESS + ", " + CREATED_BY + ", "
+ LAST_MOD_BY + ", " + "TO_CHAR(" + CREATE_DATE + ",'" + DATE_TIME_FORMAT + "')," + "TO_CHAR("
+ LAST_MOD_DATE + ",'" + DATE_TIME_FORMAT + "')," + "TO_CHAR(" + TERM_DATE + ",'" + DATE_TIME_FORMAT
+ "')," + WEB_USER_ID;

// SQL used to create a new EMAIL record
static final String CREATE_SQL = "INSERT INTO " + TABLE_NAME + " (" + FIELDS
+ ") VALUES (?,?,?,?,?,SYSDATE,SYSDATE,NULL,?)";

// SQL used to retrieve an email record by id
static final String RETRIEVE_BY_ID_SQL = "SELECT " + SELECT_FIELDS + " FROM " + TABLE_NAME + " WHERE " + TERM_DATE
+ " IS NULL AND " + ID + "=?";


For example 1... where does it end? would you create a constant A = "A"? When can EMPTY_STRING not be an empty string or ""? In this case, we get no value and less readability.

Example 2 is the chaining of constants, commonly found when there are a large number of property values being retrieved from a file or sys env. While not as bad as example 1, it is less readable. Having a prefix constant may be of value, but rarely is the chaining of constants of value. It isn't worth trading the potential for a company name change or something similar for readability. Or put another way, it isn't worth trading something that is unlikely to happen for something else which is more likely to be needed (that being the readability of the code)

Example 3 I see all the time... argghhhhh... please... just stop!

Examples of good constants would include, urls and database connections strings or a project defined standard date format.

May your constants always be final!

Wednesday, December 14, 2011

Advanced Spock Techniques



In recent years there have been a couple of tools that stand out when it comes to helping me be productive. One of those is the groovy test framework Spock. It is worthy of an introductory blog post... but that isn't this post. One of the challenges to Spock is the documentation isn't a complete as one would hope. The Spock Basics is fantastic when getting started but it is what it claims to be basics. I've been speaking with NFJS on the subject of Spock for the last half of 2011. On 2 occasions I've had the look our red shirted friend in the picture has when asked about controlling aspects of mocks in spock... meaning I didn't have the answer. In this case, google didn't discover it either... a quick email to the Peter Niederwieser reveals the previously undocumented solution. (at least that's my understanding)... and thanks Peter!



Here we will discuss 2 advanced aspects of mocking with spock. If you need more details on mocking in general hit the Spock site... or wait patiently for a future post:)

Problem Setup:

When mocking with Groovy we get 2 benefits from the verification of the mock. 1) order of execution, 2) failure if another method on the mock was executed but was not setup in the demand configuration.



void testDeposit() {

Account account = new Account(TEST_ACCOUNT_NO, 100)

def mock = new MockFor(AccountDao)
mock.demand.findAccount(TEST_ACCOUNT_NO) { account }
mock.demand.updateAccount(account) { assertEquals 150, account.balance }

def dao = mock.proxyDelegateInstance()
def service = new AccountServiceImpl(dao)

service.deposit TEST_ACCOUNT_NO, 50
mock.verify dao
}


Spock Cleanup


A similar solution in Spock might look like this:

def "deposit into account test refactor"() {

def mock = Mock(AccountDao)
def service = new AccountServiceImpl(mock)

when:
service.deposit nmr, amt

then:
mock.findAccount(_) >> account
1 * mock.updateAccount(_)
0 * mock.createAccount(_)

and:
account.balance == total

where:
nmr | account | amt | total
"101" | new Account("101", 100) | 50 | 150
"101" | new Account("101", 0) | 50 | 50
}


However this solution doesn't guarantee order nor do we want to use the 0 * mock. on all possible methods.

Spock Mock Solution


It turns out that we can repeatedly use the then: dsl to determine the order of events. So we can modify the Spock code above with the following changes.


then:
1 * mock.findAccount("1234") >> account

then:
_ * mock.updateAccount(_)

In this case we are saying that the findAccount() method will be called exactly once and return the account object and "then" the updateAccount will be call any number of times with any type of argument. The test will fail if the updateAccount is ever called prior to the findAccount being invoked first.

We can use this same technique to solve the strictness concern we have as well by adding one more then: block of code as outlined below:

then:
1 * mock.findAccount("1234") >> account

then:
_ * mock.updateAccount(_)

then:
0 * mock._

In this case the last 0 * mock._ says to expect nothing else. Ahhh.. the beauties of a dynamic language:)

Happy Coding... may your builds never fail and your tests always green bar!