Nov
08
2007
0
comments

Enterprise-scale Reuse

This has to be one of the best analogies to explain software reuse.

Written by jfcouture in: Jokes, Software Engineering |
Oct
24
2007
0
comments

The Presenter Pattern For Rails

The problem:

Having logic in your view is bad. Putting some in the helpers can help. Some methods can be put on the model. Sometimes, your view involves a couple of models, the helpers get bigger, you’re not sure on which model to put a method as it needs data on a few of the associations. The view is getting ugly, you have to go through pages of helper methods to find things. You’re feeling dirty.

The solution:

Move all the methods related to one of the view to a class (the presenter). Create it in the controller by passing it all the objects it needs to manipulate. Change your view to only call methods on your @presenter.

Implementation:

You will probably want to have access to the ActionView::Helpers::* in your presenter so it can useful to declare a base presenter class you will inherit from like this:

class Presenter
  include ActionView::Helpers::TagHelper
  include ActionView::Helpers::FormHelper
  include ActionView::Helpers::FormTagHelper
  include ActionView::Helpers::FormOptionsHelper
  include ActionView::Helpers::DateHelper
  include ActionView::Helpers::JavascriptHelper
  include ActionView::Helpers::AssetTagHelper

  def intialize(controller)
    @controller = controller
  end
end

Some helpers need the @controller to do their magic.

Success stories:

I’ve used this approach two times now. Last time, I had a view that showed deeply nested data (parent => children => children => children). There were a bunch a checkboxes that needed to be all checked/unchecked at the same time depending on which element was clicked. Putting all the methods required to generate the checkboxes with ids and class and restoring that from the params in case of an error was ugly. However, that ugliness was nicely sealed in a class that prevented infection of the rest of the code.

Further links:

Warning:

The approach I described here may not fit the original presenter pattern as described in those other links. What’s important here is, if your view is getting ugly, hard to test, you have too many helpers, or the code is starting to smell, you can move stuff to a new class. This may seem evident, but I sometimes feel people using rails forget that you can do stuff “outside” of the way rails normally structure a project. Also note that the presenter pattern is definitely not something you need for every project.

Written by jfcouture in: Rails, Software Engineering |
Sep
25
2007
1
comments

The M in Rails’ MVC: Domain Driven Design

One of the best books I’ve read about design is Domain Driven Design: Tackling Complexity in the Heart of Software, by Eric Evans. InfoQ has a small ebook called Domain Driven Design Quickly that provides a nice summary of the book. It was a good refresher for me as I read DDD about three years ago.

So What is Domain Driven Design? Read the link to have a good overview. Here are the two most important points:

  • Focus on modeling the domain and domain logic of your application.
  • Build a “Ubiquitous Language” that is used by all the team (from domain experts to analysts to developpers).

The most interesting part of the book for me was the patterns presented as the basic building blocks of a model-driven design: Layered Architecture, Entities, Value Objects, Services, Modules, Aggregates, Factories, Repositories. These are all very simple but fundamental patterns in software development. These are types of objects that are present in all designs. Understanding the difference between a value object and an entity is crucial and can help simplify a design.

The book also discusses the importance of iterative design, the importance of incorporating back what you learned about the domain in the model as you iterate and how to preserve the integrity of the model. There is a good discussion of ways of separating the model as the team gets bigger.

The value of this book for a Rails developer

Ever heard about skinny controller, fat model? This is THE book about building a rich model.

However, it really depends on the type of application you’re building. Most Rails application are mostly concerned about CRUD operations without too much logic behind. You won’t get out much from this book.

But if you’re working on a business app with a lot of business logic, then this is a must-read.

The ebook also has a small interview with the author. He highlights the expressiveness of ruby and mentions that DSLs are probably the next big step in Domain Driven Design.

Written by jfcouture in: Agile, Book, Rails, Ruby, Software Engineering |
Sep
19
2007
3
comments

Web Architecture, REST, Rails, the Universe and Everything

The last part is easy. Now what is architecture as related to software development, that’s a much harder problem (42 is still a good answer of course). I think I just read the best explanation of what it is.

Roy Fielding(inventor of REST) gave a talk at RailsConf Europe entitled “The Rest of REST“. The last slide really sums it best:

use principled design:

  • identify desired architectural properties
  • constrain behavior to induce properties
  • compensate for the inevitable design trade-offs

I think this is the best way to really understand why constraints are liberating. When designing, you choose the properties important to your application (whether it be efficiency, scalability, maintainability or any other -ilities). The architecture will codify a set of constraints that should lead to your application having these properties. These constraints free you from having to constantly think about any of the properties, as long as you respect the architectural guidelines.

An example from the slides: Constrain interactions to be stateless. This simplifies the server, improves scalability and reliability. However, it degrades efficency. Checkout the slides as Roy gives very detailed info on the advantages and tradeoffs of using a REST architecture. Seriously, these slides are gold. I will read them again and again over the next few weeks.

Written by jfcouture in: REST, Rails, Software Engineering |
Sep
09
2007
1
comments

Metaprogramming + DSL Considered Harmful

The Rails Edge: Quotes and Notes is a very interesting collection of quotes from the rails edge conference. Two in particular caught my attention:

“Metaprogramming + DSLs is the Ruby equivalent of Design Patterns in the Java world”
— Chad Fowler. Fowler’s point here was more about the buzz and hype, just like there was a time in the early 2000s when every Java programmer wanted Design Patterns whether or not they were needed, Fowler sees a similar rush to add DSLs to Ruby programs.

“If programmers, on average, were able to write parsers and compilers, Ruby on Rails would not have taken off”
— Stuart Halloway

This is something I’ve noticed a lot recently: every plugin that gets released is a DSL! or it uses a cool metaprogramming trick! That’s nice, but was it really needed? And can we really talk about a ‘language’ when your plugin adds two simple commands to a controller?

I guess it’s a rite passage when learning ruby to write something using metaprogramming. The problem is when you start using it for everything, just like when you add patterns after patterns to your code, just because.

Again, this is a case of using the right tool for the right job. Metaprogramming is a power tool that is useful some time.

Here are other quotes that I like, as they echo the discussion I had with Fred Brunel at the last book club about process:

“The right process is always ‘not quite enough process’”
— Stuart Halloway

“Do the dumbest, simplest thing that almost works”
— Stuart Halloway, on process

“The traditional view, with sixteen pounds of documentation, introduces a single point of failure in the process, understanding the problem domain”
— Dave Thomas

“Getting a specification involves bullying the customer”
— Dave Thomas

Written by jfcouture in: Agile, Rails, Ruby, Software Engineering |
Jul
06
2007
0
comments

Rethinking Design Patterns

Jeff Atwood has a good post entitled Rethinking Design Patterns.

It’s certainly worthwhile for every programmer to read Design Patterns at least once, if only to learn the shared vocabulary of common patterns.

No matter what you think of design patterns, you have to read the book at least one time. I remember a talk with a fellow programmer, explaining a part of his design: “so you this object inheriting from that one, and implementing that one interface, and blabla blabla object object blabla more objects etc…”. After a couple of minutes, I said “so basically, you have a composite”. “Yes”. As a design gets bigger and bigger, it’s important to have a bigger vocabulary than just class this, object this.

But there are problems with patterns as Jeff continues:

If you find yourself frequently writing a bunch of boilerplate design pattern code to deal with a “recurring design problem”, that’s not good engineering– it’s a sign that your language is fundamentally broken.

In his presentation “Design Patterns” Aren’t, Mark Dominus says the “Design Patterns” solution is to turn the programmer into a fancy macro processor.

Don’t Repeat Yourself. If the same pattern happens again and again, maybe you should find a way to automate it? A good language can help here. I hear a lot more about patterns in the java world than in the ruby world. Why? You have no choice but to code the pattern and it’s boilerplate every time in java. In ruby, you do it one time with a bit of metaprogramming. The ruby standard library provides a library for the singleton. “Include singleton” in your class and you’re done. Other design patterns are there to cover a flaw in the language. For example, you don’t need visitors if you use lisp because of multiple dispatch.

How can you distribute responsibility for design through all levels of a large hierarchy, while still maintaining consistency and harmony of overall design? This is the architectural design problem Alexander is trying to solve, but it’s also a fundamental problem of computer systems development.

I will have to read the Alexander book. That’s a much more interesting problem than something you can abstract in a good language.

Written by jfcouture in: Software Engineering |
Jun
18
2007
0
comments

Abject-Oriented Programming

The number of lines of code in the application is a common measure of the importance of the application, and the number of lines a programmer can produce in a day, week, or month is a useful metric for project planning and resource allocation. Abject-oriented programming is one of the best ways to get the most lines of code in the shortest time.

Inheritance is a way to retain features of old code in newer code. The programmer derives from an existing function or block of code by making a copy of the code, then making changes to the copy.

A modular program is one that is divided into separate files that share a common header comment block.

Introduction to Abject-Oriented Programming

Tonight is the night for funny links!

Written by jfcouture in: Jokes, Software Engineering |
Jun
18
2007
0
comments

Top 20 Stupid Client Quotes

Can you guarantee to us that we’ll get as many lines of code from you as we would if we hired a professional company to build this?

Top 20 Stupid Client Quotes at Clientcopia.

Written by jfcouture in: Jokes, Software Engineering |
Feb
17
2007
0
comments

SE Process 101: Habitability

I always wanted my blog to be about my thoughts on software engineering. I feel they have matured long enough now for me to try and write them down. Hopefully, this is the beginning of a series where I give my opinion about what’s important when developing software.

Some would argue that process is at the center of software engineering. However, that word often often brings nightmarish visions to people, visions of activities with multiple signed handoffs of deliverables, usually including a ton of documentation. These are what you would call heavyweight processes. There are of course lightweight processes and agile processes. When I talk of process, I don’t want you to think of any these. I want you to think of what you and your team do every day, of the way you are organized, the way you work to get software done. That’s your process. It may have a name, it might be documented, it might only exist in your head. No matter what, you always have a “process” when you work. It might simply be whatever works (by the way, that’s an awesome process). This article is not about whether process are good or bad. That’s irrelevant, because by the simple act of working, you have a process.

There is an attribute that I think is very important for a process: habitability. This is an idea I came across in the book Crystal Clear, A Human-Powered Methodology for Small Teams, by Alistair Cockburn (p.232-233):

Habitability became a top priority when I started noticing in my project interviews that most programmers have the power to ignore whatever methodology is mandated by their organization. All they have to do is say that it slows them down and they’ll miss their deadline if they do all that extra work. That is usually sufficient basis for ignoring it. [...] If the programmers are told they have to do it anyway, they usually find ways to circumvent it. It doesn’t matter what the methodology is if it doesn’t get used. In other words, habitability is a critical success factor of methodology adoption.

Part of habitability is tolerance for human variation. Some like to make lists, others don’t; some work best visually, others with text; some like to work alone, others in groups. Some stare at the design for hours, days, or weeks making sure it is right, while others like to “feel” the code taking shape. It is for that reason that Crystal has so much tolerance around techniques - not only do they change all the time, but different people are drawn to different techniques. The habitability priority means that the rules need to be such that the people on the team can live with them.

Emphasis mine.

The process you use should fit the team. That’s what habitability means. The process should not go against the way team members like to work. That’s what is meant by the Agile Manifesto, “individuals and interactions over processes and tools”. People have a first-order effect on software development (an article by Alistair on the subject). The process is there to help the team deliver, not the other way around.

That’s all there is to know about software process. Good people will find a way to deliver, whatever the process. That does not mean to use any process, but to use one that will make the team happy. And happy people are more productive.

Written by jfcouture in: Software Engineering |
Jan
24
2007
1
comments

CUSEC 2007 Summary

CUSEC 2007 was last week, from thursday to saturday, and it was good. Once again the organization was great (except for every day starting 30 mins behind schedule). However, I can only say that CUSEC was good, not great. It’s a conference targeting student, so it may be possible that after working a year, and after attending the 5 previous CUSEC, well there wasn’t much for me this time around.

The keynotes were all good, but there wasn’t anything new for me, nothing that changed my perception of the field like previous years, and nothing mentioned that really piqued my interest. One thing they all mentioned is the importance of making mistakes and learning from them. That’s good advice.

There were two very good presentations. The first one was from Austin Hill, one of the cofounder of Zero Knowledge (now owned by RadialPoint). He talked about what he learned there, and about startups today. The second one was from Greg Brill, CEO of Infusion Development, and it was about the soft skills you need.

I will post more details about each day of the conference later.

Written by jfcouture in: CUSEC, Software Engineering |

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes