Chariot Training Classes

Training Courses

I run Chariot's training and mentoring services. We provide training in AngularJS, HTML5, Spring, Hibernate, Maven, Scala, and more.

Chariot Education Services

Technology

Chariot Emerging Tech

Learn about upcoming technologies and trends from my colleagues at Chariot Solutions.

Resources

Chariot Conferences

Podcasts

Entries in chariot-news (45)

Sunday
Feb192012

Quizzo in Roo, Introduction

We at Chariot have this awesome internal conference we call Chariot Day. We get to dish on the latest things that turn us all on, technically.

I am working on two presentations - one on Roo add-ons that will be a pre-cursor to the ETE presentation, and another on my favorite dynamic language platform, Grails, describing what is new in the 2.x version of the framework (hint: a lot, but mostly it's to make your life super easy and productive).

I also heard that we were resurrecting a quizzo game from the last Chariot Day. Rather than use the same quiz program again, I figured I'd take a stab at writing one (heck, if I fail, we can just use the old one).

This is a series of blog posts about trying to use Roo rapid-style to build up a quiz system in less than three (ok two) weeks. I'll be outlining some of the lessons learned and tips and tricks along the way. These promise to be short blog entries, all tagged with quizzo-in-roo so you can find them in one bunch.

Update: there are two links to help you through this at the moment:

Ken

 

Tuesday
Oct182011

Roo (in the) Corner - new features in trunk...

I've been spending my time readying Roo in Action for publication. Turns out, the Roo team had other ideas - including lots of new things you may want to be aware of if you are looking to support Roo 1.2 once it is released.

Keep in mind these changes are in-flight. If you don't need to work on trunk, DO NOT WORK ON TRUNK. This is something other platform afficianados do - for example, the Rails development community commonly calls this working on the "edge". So, let's get edgy.

There are some really, really cool things in here. I've seen them move toward opening up for all modes of development - some want JSF, so there is a JSF add-on. They use PrimeFaces, and a dialog motif for adding new elements. I'm sure they will tweak this as it goes along, but it looks more like the GWT or Flex mode of editing I saw before.

Breaking Changes (so far) - you may need to edit your code - I know I have to for now, but this is a temporary pain for some consistency gain within Roo.


  • @RooEntity -> @RooJpaActiveRecord

  • @RooWebScaffold - now a .scaffold. package after .controller.

  • @RooConversionService - now a .converter. package after .controller.


Additions


  • New @RooEquals - and a shell command for equals - this has been here for a little while, but is something that can be of use when defining models or other objects that need to be compared. You can exclude fields from the factoring of the comparison.

  • new entity flags (recent anyway) to set entity name, table, and other attributes on entities - this is great, and includes the ability to define transaction manager names for cases where you are working with multiple JDBC datasources - nice! Also, it lets you specify the entity manager - so if you have two persistence units to separate transaction managers (reporting database -vs- transactions) you have that option. Again, not a huge deal, but lets you stay within Roo to get things done, without digging into code for a configuration option. You can even set the table name, entity name, etc...

  • New settings for the json command - --deepSerialize and --rootName - I am not sure if these have been here long, but they are good to know about.

  • New —packaging element in project - includes POM or JAR right now. Also includes --parent. This could be great, as I think they are going to implement multi-pom support in Roo 1.2. We'll stay tuned on that, and perhaps write a quick blog entry on what we've found.

  • New support for database dot com - a new database provider - I don't know much about it.

  • New date field support for both dateTimeFormatPattern AND dateFormat - I am unsure that the scaffold would deal with dateTimeFormatPattern.

  • JSF scaffolding in place - uses PrimeFaces for the widgets - this is interesting, and has a different look and feel, native to PrimeFaces. But, it does exactly the same work as the scaffold in MVC. So, if you're looking at complexities and benefits of each, go for it. The CI build server is here, and you just need to follow these rules to get it to use trunk.


It was so easy to switch between JSF and MVC for my testing, I used these two scripts:

Roo with MVC

 

project --topLevelPackage foo.bar.mvc --packaging JAR --projectName mvcrules
jpa setup --database HYPERSONIC_PERSISTENT --provider OPENJPA
entity jpa --class ~.model.Course --testAutomatically
field string --fieldName name
field date --fieldName runDate --type java.util.Date --dateFormat SHORT
web mvc setup
web mvc all --package ~.mvc quit
Roo with JSF
project --topLevelPackage foo.bar.jsf.sortarules --packaging JAR --projectName jsfsortarules
jpa setup --database HYPERSONIC_PERSISTENT --provider OPENJPA
entity jpa --class ~.model.Course --testAutomatically
field string --fieldName namefield date --fieldName runDate --type java.util.Date --dateFormat SHORT
web jsf setup
web jsf all --package ~.jsf quit

I will attempt to update this article as I find new things... No promises, as the primary artifact is the book. But hopefully this is a warning shot across the bow that change is indeed a-coming.

Sunday
Aug212011

Now you can choose ActiveRecord or Service/Repo for Roo 1.2

Check it out!  Now you can install services and repositories, and when you scaffold the project automatically generates calls to the service layer rather than to the Active Record pattern.

I think personally it's a huge win for Roo to be able to support both approaches, since having to switch tools based on a difference in one pattern approach to me feels wrongheaded.  Here's a screenshot from IntelliJ:


The new service model in action with IntelliJHere is a snippet of the code written in the CourseController_Roo_Controller.aj file proving the nice integration:

privileged aspect CourseController_Roo_Controller {
  
  @Autowired
  CourseService CourseController.courseService;
  
  @RequestMapping(method = RequestMethod.POST)
  public String CourseController.create(@Valid Course course, 
       BindingResult bindingResult, Model uiModel, 
       HttpServletRequest httpServletRequest) {
    if (bindingResult.hasErrors()) {
        uiModel.addAttribute("course", course);
        return "courses/create";
    }
    uiModel.asMap().clear();
    courseService.saveCourse(course);
    return "redirect:/courses/" + 
         encodeUrlPathSegment(
            course.getId().toString(), httpServletRequest);
  }
  
  @RequestMapping(params = "form", method = RequestMethod.GET)
  public String CourseController.createForm(Model uiModel) {
      uiModel.addAttribute("course", new Course());
      return "courses/create";
  }
  
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  public String CourseController.show(
      @PathVariable("id") Long id, Model uiModel) {
    uiModel.addAttribute("course", courseService.findCourse(id));
    uiModel.addAttribute("itemId", id);
    return "courses/show";
  } 
...
}

To try it out, head over to the nightly builds page and download the latest nightly.  (Do NOT unzip this over a working 1.1 or earlier 1.2 or you'll be crying a sweater of tears).  Then, make your /usr/bin/roo or /usr/bin/roo12 symbolic link (my angle as during the writing of the book I've been testing things against roo 1.1, 1.2, etc).  Create your project and you'll see the options.

You can build this if you put the snapshot repository into your list of repositories in your pom.xml file:

<repository>
    <id>spring-roo-internal-repo</id>
    <name>Spring Roo Internal Snapshot Repo</name>
    <url>http://spring-roo-repository.springsource.org/snapshot</url>
</repository>

Best of luck, and enjoy playing with the upcoming Roo features. I'm also going to check out some newer add-ons, such as JSF and the newly updated Flex (by Roo forum contributor working with the team on a patch) and GWT addons in future blog entries. For now, though, it's back to my add-ons chapter, which is coming soon.

Sunday
Jul242011

Maven Search Site Online

I was a bit surprised to find out about this, but in teaching a couple of Maven courses two weeks ago, I did my usual "and you can go to the Maven Central repository at repo1.maven.org/maven2" - but things changed on me...

For years (since the inception of Maven), when you browsed that repository URL, you'd get a file listing of the entire repository, which you could drill down into manually.  Wanna see what's in commons-lang/commons-lang/2.6?  Just click away.  However, there was no search.  In fact, there were two search URLs that I knew of (and more I'm sure) - such as mvnrepository.com and repository.sonatype.org (I think, that URL is offline now).

It looks like Nexus is powering the Maven central repo now, and also they've put a message up at that central URL:

Browsing for this directory has been disabled.

View this directory's contents on http://search.maven.org instead.

Huh.  Ok, so I'll bite...  If you go to the http://search.maven.org site, you'll see a nice search engine.  I typed in commons-lang, and lo and behold, there is a 3.0 version too.  Click on the image below to see the whole screen capture, if you're curious.

 

Maven Central Search Engine
Uploaded with Skitch!

I'm glad they did this. The Nexus repository gives useful reports on dependencies, and provides the mounting code for a number of dependency managers, including Maven, Ivy, Buildr, and more. A nice touch. By the way, the new URL to remember is http://search.maven.org!

Thursday
May192011

RailsConf 2011 - My Personal Recap

RailsConf2011 is my first Rails conference.  Held in Baltimore, MD, in the Baltimore Convention Center, there were five tracks, including one unconference (bohconf) that ran concurrent to the main conference.  As we are preparing to offer our first Intro to Rails course with Engine Yard in the summer, I wanted to start getting involved in the Rails community a bit more and see where it is heading.

Attendance was very strong - and so were the pleas from companies that are hiring.  The job message board spanned three full corkboards, and was full of writing from various companies pleading for Ruby and Rails talent.  Just about everyone was saying "we're hiring," even to the point of wearing it on their shirts.

Clearly, the Rails community is growing and currently has lots of need for additional talent as the market increases faster than the number of experts in the field. A good problem for rails experts, I'd say.

Tutorials

I attended two half-day tutorials on Monday.  Those tutorial sessions were very instructive.

Building WebApps with HTML 5

The HTML 5 tutorial by Mike Subelsky of OtherInbox left me with a ton of resources, a good set of labs and solutions, and lots to research.  

I learned about the HTML 5 Boilerplate Project, where you can download a template of a fully HTML 5 compliant document with tons of comments.  I also learned all about drawing, text and image rendering, extra forms hints such as types of fields (phone #), default focus, and more.  The local storage API is quite easy to use, and he talked about the issue of the socket API and Firefox.  So all in all, a great talk and very valuable to me.

The second one was a Rails Best Practices talk from Gregg Pollack of Envy Labs.  Gregg stopped by and said hello, as he is a friend of ETE and Chariot and really helped us out in 2009 (there's even a Viddler video somewhere on the 2009 ETE conference that he did).

Rails Best Practices - Gregg Pollack of CodeSchool

Gregg Pollack has a good website, if you're into self-paced training, called CodeSchool.  They have a number of classes online, including one called Rails Best Practices.  This was the in-person version of that course, and he kept it entertaining.  I really like his Web IDE and the "challenges" he puts you through.  Great concepts, and an approach for us education people to think about, especially with delivering online training.  He also has this penchant for doing mashups of old 8-bit video games, complete with his voice for all sound effects.

DHH Keynote

DHH gave a keynote on the first day (Tuesday) of the conference where he announced the RC release of Rails 3.1 this week.  In 3.1 will be several significant changes, including the default scaffolding now using Sass and CoffeeScript by default instead of CSS and Javascript.  

Also, they're including a refactored application resources approach to deliver Javascript libraries as modules, and bring more organization to that area.  Rails can then aggregate those into something like a /resources URL, very similar in concept to what Spring MVC does today.  All-in-all a needed feature and something that will make it easier to start organizing the way your applications script.

He also mentioned that jQuery will be the default Javascript library going forward, rather than prototype.  

Fat Models Aren't Enough

Jeff Casimir from Jumpstart Lab gave a talk on further refactoring of Rails applications called Fat Models aren't Enough, stating on the record that he feels that some controllers do too much even today.  For example, he suggested using a Presenter (think of it as a controller helper that is responsible for representing the view data to the view object).  The refactor is to pull the unrelated objects into the presenter, intialize the presenter which then loads the view objects, and only expose the presenter to the view.  

He then told us to take that further - maybe instead of delegating things like reports to the models themselves, polluting them with code really that is a representation artifact, write the code in the presenter to handle that data processing.  You can even call helpers in the presenter, since they are also part of the view and you are just helping to represent the data to the view.  I hope I'm presenting the presenter the right way here, but anyway it was great food for thought.

He then got into a good discussion of the Single Responsibility Principal and how many objects do more than one thing - if your model handles processing of its children to do things for them, or some type of other thingness (think of printing, ordering, etc) maybe you need to extract that and make it another model.  He was big on having methods be less than 8 lines of code. Also, he really hated scopes and prefers the new Ruby class method approach (so do I).

Active Support

Bryan Liles of Smarticus gave a talk on Active Support, which went into the history of Ruby's Facets library, and how the Active Support library was created to give features from that library that were useful to rails programmers, without having to load the relatively large Facets library.

There are a lot of things in Active Support, such as module and class accessors, constantizing and pluralization, a benchmarking API, configurables, callbacks, instrumentation (sending and processing events), even gzip and various types of randoms.  His comment to all of us was READ THE SOURCE!  I agree.  Now if I can just get Chapter 9 of Roo in Action sorted out I'll have a little time to do that...

Confident Code

Another talk, this one by Avdi Grimm of ShipRise discussed how to write Confident Code.  He urged everybody to read Code Complete (yet another book on my Kindle now, I can't believe I've never read it).  Discussed that every method should have four parts - gather input, perform work, deliver results, and handle failure.  That's pretty straight-forward in concept to most of us, however he then went on to show how people do bad things in each of these areas, and how to try to write better code.

For example, a confident input handler in a method is sure of the type of object coming in.  You should treat the object, with duck typing perhaps, the way you expect it to be.  He says one of the "code smells" in this area is when you do switches to process various input types, or check for nils.  I have a ton of notes to go over for his talk.  Great stuff.

Coffee Script?

Ok, I never heard of this before now.  Yes, I've been hiding under a rock.  Think of a simple language like a Groovy for Javascript, and a pre-compilation process to turn it into Javascript.  Bingo, that's Coffee Script.  I had really wanted to see that talk, but it was super-over-full and so I just sat down and hacked with Coffee Script itself.  VERY cool idea.  I have to see how it works in practice, and how to integrate things like jQuery with it, but wow.  You should just take a few minutes and hack around with it. 

Sass - CSS meets code

I didn't get a seat for the Sass talk either.  You'll see a theme here. See, I'm not 24 so I can't run to the talks as fast as some of these other guys.  Ok, it's an excuse.  By the time I got to the sass talk, the best I could do is stand in the back for a bit and write down some URLs.  So I sat down and also took a look at that as well.  Again, nifty pre-processing DSL for CSS.  If you thought it would be a good idea to put your palette RGB numbers in variables and re-use them throughout your CSS file, this is easy in Sass.  There are a lot more cool things, like blocks for nested items such as table rows of tables within divs.  So, again, something on my short list.

Legacy Code - In Rails?

As we well know at Chariot, and Noel Rappin of Obtiva points out, at some point, you'll have to deal with a legacy Rails app.  If you've ever been on a rescue project, you know what I'm talking about.  Noel points out that your first job is to make everything better incrementally.  He brings up the Boy Scout Rule (quick, what is it?  I remembered the Cub Scout one, Always Do Your Best, but it's "Leave the campsite in better shape than you found it").  

Lots of tips here, after showing us the modern version of Goofus and Gallant (which still exists apparently) and how you can really harm your effort by rushing to push or rewrite the something without testing.  He strongly suggests using Git to make cheap branches (an idea I highly agree with) and pressed us to learn git bisect if we haven't already.  A tool that helps you figure out when things started to change in your history so you can figure out what commit changed the world on you. 

He suggests things like using Cucumber first for outside in testing - that way you can cover a lot of the application early on.  Many other suggestions including things like test driven exploration.  Lots of notes to review, lots of food for thought.

Building Rich Applications in Rails

Yehuda Katz was on this morning talking about how you may think about writing your own rack-based Restful platform to serve data for RIAs, using something like Sinatra, but that Rails gives you so much that you should take pause and really think about it. He suggests building Rich Applications in Rails.

He had tons of details on how to approach writing restful APIs, especially on returning predicatable results in JSON, so that your programs can consistently call the API in a safe way.  He discussed the Bulk_API project, which lets you do things like POST /api/bulk?posts=1,5,6,34 so that you can get them back with one hit, etc...

He mentioned some Javascript templating engines, something I have to check out (echo, handlebars /moustache, etc..)  So much detail in that talk!

Trinidad

I also saw a talk on the Engine Yard sponsored Trinidad project.  This is a server that hosts rack-based applications on JRuby using Tomcat behind the scenes.  You can configure tomcat using YAML, deploy multiple applications, and it's now on my short list of new engines to take a look at.  More on that project at the gitub site, https://github.com/trinidad/trinidad.

Wrap-up

All-in-all, I see a lot of activity in the Rails community and a lot of life.  There is an energy here and tons of people deeply committed to the platform and language.  Rails 3 seems to be "growing up" into the enterprise a bit more, and DHH seems committed to opinionated development and dependency injection (take bundler for example), and to not just improving rails, but delighting developers with very well thought out and meaningful improvements.