Tuesday, August 9, 2011

Tools for a new generation

We've been hard at work on the Stealthy Startup. A few days of 12+ hour coding sessions and things are really starting to come together. We have a lot more work to do to implement the application logic, but at least we have settled on what we feel is a great basis for building a next generation web application.

One of the goals of this application is to do as little framework code as possible. While we are more than technically capable, we also don't want to have to hire an IT / operations department or run servers ourselves. There just isn't a need to do that any longer and this will allow us to focus on coding features and running the business. It is simply amazing that the services and frameworks that have been created in the last 6-7 years exist and are as high quality as they are.

While everyone seems to be zigging towards Rubyland, I still feel that staying the course with Java is the right choice. You just can't beat a strongly typed language when it comes to building an application. Especially from scratch. The need to be able to re-factor code on a whim prevents bad decisions and mistakes from propagating long term. On top of that, the JVM is simply a faster product. Scala is another approach, but I'm afraid I'm just not fond of the language syntax. I'm super efficient at writing bug free Java, so why would I want to slow my development time down? Anyway, this isn't intended as a language war posting...

People have been asking me what tools we are using for our startup, so here is the list so far:
Google App Engine and the Datastore enables us to not have to run servers or manage databases. It also means that as our traffic increases, we can scale automatically, without even having to think about it or code up solutions on EC2. This is because we are running on Google's own architecture and we can trust them to deal with these issues in a timely fashion. We also know that we won't have to wear a pager if the system goes down and we won't have to hire a team in India to help us when things go south at 2am.

Cambridge Template Engine is one of the more unique and somewhat 'beta' projects that we are using, so it is a bit of a risk, but not that bad as it seems to work pretty well as it stands right now. That said, the language it uses enables us to write extremely flexible html code. Take a look at this blog posting for a comparison between various engines.

Lombok is one of the coolest extensions to Java ever invented. It prevents you from having to write all of that silly boilerplate code that the Rubytards make fun of the Javatards for. It also allows you to annotate your classes with a simple @Slf4j annotation to enable a 'log' object to be used. Unfortunately, it only works with Eclipse, so if you are in a mixed IDE environment, you are out of luck. That said, Eclipse is the best free IDE out there, so there isn't much reason to not use it.

These days, using Rest on the server side is pretty much the best way to deal with things. You aren't returning HTML, you are returning data and you use JavaScript to process that data. Both Resteasy and Htmleasy make this simple to implement.

For dependency injection, Guice is the way to go. While I like some parts of Spring, it doesn't suffer from the jarfest/xmlfest that Spring comes with and is just as fast and powerful.

RequireJS is great because it allows us to separate our CoffeeScript/JS into small components that we can include on pages that need it. Effectively giving us an 'import' statement.

You don't really want to use JavaScript anymore either. Once you check out CoffeeScript, you won't go back. People who are against using CS are out of their minds. Take this example for using JQuery to do an Ajax call to flip some toggles(), bring effects to the page and post some data to a server:

$ ->gt;	$('#nameSave').click ->
		$('#nameEdit img').show()
		$('#nameSave').attr("disabled", "disabled")
		$.ajax
			type: "POST"
			url: "/account/name"
			data:
				firstName: $("input[name='firstName']").text()
				lastName: $("input[name='lastName']").text()
			success: ->
				$('.confirmation').show()
				$('.error').hide()
				$('#nameEdit img').fadeOut(1500)
				$('#nameSave').attr("disabled", "")
			error: ->
				$('.confirmation').hide()
				$('.error').fadeIn().delay(2000).fadeOut()
				$('#nameEdit img').fadeOut(1500)
				$('#nameSave').delay(2000).attr("disabled", "")

That generates this JavaScript:

(function() {
  $(function() {
    return $('#nameSave').click(function() {
      $('#nameEdit img').show();
      $('#nameSave').attr("disabled", "disabled");
      return $.ajax({
        type: "POST",
        url: "/account/name",
        data: {
          firstName: $("input[name='firstName']").text(),
          lastName: $("input[name='lastName']").text()
        },
        success: function() {
          $('.confirmation').show();
          $('.error').hide();
          $('#nameEdit img').fadeOut(1500);
          return $('#nameSave').attr("disabled", "");
        },
        error: function() {
          $('.confirmation').hide();
          $('.error').fadeIn().delay(2000).fadeOut();
          $('#nameEdit img').fadeOut(1500);
          return $('#nameSave').delay(2000).attr("disabled", "");
        }
      });
    });
  });
}).call(this);

I know they are both kind of difficult to read (that is the nature of these languages), but which one do you think is easier to write? I've integrated it with Eclipse with a Builder so that as soon as you save a .coffee file, it gets 'compiled' into js. That JS is then watched with another Builder which runs is through the RequireJS optimizer which runs UglyJS or Closure Compiler on the output.

Sass scss is wonderful because it gives us greater control over our CSS. Another Eclipse Builder is used to automatically generate the CSS files as well.

We are using GitHub for all of our source code and wiki documents. At $7/month it is the perfect environment for doing development. Their new Mac GitHub native app is pretty useful as well. I just wish you could do a sync without having to also push.

JRebel allows us to write Java code, click save and then reload in the browser to see the changes immediately. No need to restart Jetty/Tomcat/JBoss any longer.

Friday, August 5, 2011

A busy week... A new company...

You'd think that being recently jobsingle would have allowed me to slow down for a few weeks and catch my breath. Well, turns out that is not the case. I just can't sit still. My mind has been buzzing for new possibilities. As a result of this focus, a really great business idea that satisfies all of my requirements for success has presented itself to me. After talking it through with a few people who also like the idea, I know it is a GO.

Thus, my buddy Jeff and I are in the process of creating a stealthy startup that is going to provide a useful service to a whole lot of people, in a market that is sorely lacking in technology and sophistication. Even better is that it starts with an area I know quite well and absolutely love... bicycles. We have an exciting name, a great domain, a solid plan, a clear set of requirements and are busy setting up the infrastructure to execute upon.

I love the idea of working for myself again. Why didn't I think of this sooner? ;-)