The core domain should have the following characteristics:
Stateless- Methods are idempotent, deterministic and without side effects other than their result. For example, a “today” function that would return today’s date would be impossible due to the fact that its output is determined by when you called it rather than what arguments are passed to it. Moreover, the core domain may not reach out to any state outside function arguments, such as platform details, clocks, environment variables, persistence engines, etc.
Primitive- No native objects exist in the core domain. All information is comprised entirely of primitive, readily serializable and portable data. Dates, for example, should not be expressed as java.util.Date objects; this would limit portability of both data and implementation across platforms.
Immutable- Data employed in the core domain may not change and are taken as whole values.
Universal- Business rules at this level are universal across applications. They express the commonality which would be leveraged by use cases at a higher level.
Portable- The only concerns that should dictate if the core domain exist at the client, server or both are from the essential business needs. Specifically, technical constraints of the software implementation must not influence this decision. No code changes should have to occur to facilitate targeting the client or server. It should be impossible to determine from the results of core domain functions where the calculations were made.
Platonic- The core domain has no knowledge of the outside world- issues such as persistence, views, who calls it, what order things might be called, or even details of the platform it is currently residing on are forbidden. All data is focused entirely on the business need and carries no technical implementation details. It shouldn’t “smell” like an HTTP request or response, for example.
Saturday, August 18, 2012
Wednesday, September 14, 2011
On the pain of maintaining crufty JSPs...
Explain to me why we thought it was better to write:
<display:column title="RDL State Share"
sortable="true"
headerClass="listItemsTitleLeft"
class="listItemsLeft">
<fmt:formatNumber value="${matchingEntry.excelProject.stateShare}" type="currency"/>
</display:column>
Instead of arduously dipping into Java and writing, say...
<%= currency.format(xls.getStateShare()) %>
Friday, June 18, 2010
Clojure's Economy of Clarity
I'm digging Clojure. The syntax is both brief and incredibly flexible. The functional approach isolates state and prevents a lot of the headaches so common with imperative programming.
Of the many virtues of Clojure, the one most striking to me is its economy of clarity. Lisp languages quickly spiral poorly written code into atrocious syntax. It's not subtle; and it starts to draw blood before a single function is finished. It may work, but it leaps off of the screen as a headache in waiting. No IDE spewing library and method name tips will help you.
So, I can see where mcCoders run from Lisps like the plague. Algol-spawned languages are much more forgiving of poorly written code. You can get months into a project before you find yourself wading in a sea of cryptic, hard-to-fix, impossible-to-improve code. Clarity becomes precious; but it didn't start out that way under the siren song of 'Rapid Application Development.' By the time you discover pain, you're deep into the abyss.
The limitation on Clojure's clarity may only be due to the fact that I'm not experienced in functional coding. I don't think so, however. It's exactly the same as messy equations in pencil-and-paper algebra or physics. Finding ways to factor your problems into simple, easy-to-explain pieces prevents mistakes. It makes solving problems easier. It documents your intent and approach. It gets you A's.
These are exactly the same concerns I have programming. Simply getting the right answer wasn't good enough for my arithmetic teachers. It shouldn't be good enough for us as developers or for our employers and customers.
Sunday, March 14, 2010
Lives in Revision Control
A source code revision control system should have the following basic properties:
Many source code systems operate under the antiquated "lock" model. Under this scheme, you need to request an exclusive write lock on a file to make changes and commit them back to the repository. Avoid this like the plague.
The file-lock scheme works under the fallacy that if only one person can change a file at one time, there won't be programming conflicts. Obviously, there can remain very deep conflicts between files as they are independently changed. Worse, code clean-up becomes almost impossible since changing method calls and (ick!) global variables can touch many files at once. It also fosters bad politics- like code "ownership" of a file or section of code.
A lot of this old thinking came about with the idea that we could somehow put software in a "safe" where nothing bad could happen to it. Unfortunately, this thinking is as flawed as thinking a salad will keep indefinitely in the refrigerator.
I recommend using a source code system that is free. The leading open source revision control systems have had a lot of teams and a lot of source code run through them. It is one area, along with compilers, where open source is proving to be better in many cases than the purchased stuff.
Ones worth considering:
Do not consider RCS, CVS, or "the nightly ZIP file" a revision control strategy for your team.
Whatever revision control system your team settles on, be sure to use it. Every developer should be committing several times a day- at least locally to their own local repository. Only a revision control system prevents the common situation where code "just worked five minutes ago." Without knowing what changed, even automated testing is worthless. Trying to code without revision control in place is simply unprofessional.
- Answers the question "What changed?" Changes happen in time for one developer and across developers. Be sure your tool handles both perspectives.
- Lets developers browse or compile previous revisions without losing their current work.
- Lets developers read, extend, modify, move and delete source code with as little red tape as possible.
- Reduces the pain of conflicts between developers as much as possible without trying to artificially prevent conflicts.
Many source code systems operate under the antiquated "lock" model. Under this scheme, you need to request an exclusive write lock on a file to make changes and commit them back to the repository. Avoid this like the plague.
The file-lock scheme works under the fallacy that if only one person can change a file at one time, there won't be programming conflicts. Obviously, there can remain very deep conflicts between files as they are independently changed. Worse, code clean-up becomes almost impossible since changing method calls and (ick!) global variables can touch many files at once. It also fosters bad politics- like code "ownership" of a file or section of code.
A lot of this old thinking came about with the idea that we could somehow put software in a "safe" where nothing bad could happen to it. Unfortunately, this thinking is as flawed as thinking a salad will keep indefinitely in the refrigerator.
I recommend using a source code system that is free. The leading open source revision control systems have had a lot of teams and a lot of source code run through them. It is one area, along with compilers, where open source is proving to be better in many cases than the purchased stuff.
Ones worth considering:
- Subversion - It's been around a while, and has excellent support in IDEs and Windows. Unfortunately, it wants to put a hidden folder in every folder under revision control. This is a real hinderance to simply moving code from one package to another.
- Mercurial- It's fast and has some large projects under it- such as Java itself. Unlike Subversion, it stores the complete history on every developer's machine. It also allows developers to share code between them without having to report to a central master server. It also provides a good web-page view of history right on the developer's machine. Unfortunately, IDE support is emerging and not as solid as Subversion.
- Git- I've complained about Git before, but let me eat some crow. It's excellent. It does have a learning curve, but it pays you back by allowing much more complex merge situations. It has become a huge success in open source projects, boasting thousands of projects- from the Linux kernel to tiny single-person Ruby projects. Git works as a Subversion client as well, allowing other members of the team to use a more traditional and tool-supported platform. Like Mercurial, every copy contains the complete history of the project.
Do not consider RCS, CVS, or "the nightly ZIP file" a revision control strategy for your team.
Whatever revision control system your team settles on, be sure to use it. Every developer should be committing several times a day- at least locally to their own local repository. Only a revision control system prevents the common situation where code "just worked five minutes ago." Without knowing what changed, even automated testing is worthless. Trying to code without revision control in place is simply unprofessional.
Thursday, March 11, 2010
A Software Project Health Exam
If you're going to review an existing software project, how do you judge it?
Here is my list of five things- I'll go into each of them in subsequent posts.
The last four are Kent Beck's, paraphrased.
They are ordered in importance. So, for example, the very first thing I want to see is revision control.
Here is my list of five things- I'll go into each of them in subsequent posts.
- Lives in revision control
- Has automated tests
- Is DRY
- Is maintainable by mere mortals
- Has an economy of infrastructure
The last four are Kent Beck's, paraphrased.
They are ordered in importance. So, for example, the very first thing I want to see is revision control.
Thursday, June 18, 2009
Ruby on Rails -- Destroy Stopped Working (Fix Described)
This is the single most maddening error I’ve had to fix recently. I have a simple RESTful scaffold of a Person with the “destroy” link. I’d spent considerable commits fluffing the presentation and making it aesthetically pleasing.
The destroy functional test continued to work on the controller with every commit. I keep good code coverage. All should be well.
Except, it wasn’t. Manual browser QA discovered a nasty bug where clicking on the destroy link provides a beautiful error:
Huh? I clicked destroy, buddy. And it worked, too. The record is no longer there. But why is it trying to navigate to #show? The boilerplate scaffolding still has a redirect_to(people_url)
Spent an afternoon banging my head against the wall on this one.
Thanks to a good night of sleep, git bisect, and a cooler disposition, I find the answer.
Javascript.
I had put a convenience link on the whole row of the index listing of people:
That simple javascript was being followed even after the destroy link killed the record, invalidating the person.id for the row.
So, it wasn’t a REST bug, a scaffolding screw-up, a route wreck or a controller corruption. No matter what it might look like, it was just javascript.
The easy thing to do was to yank the destroy link off the listing, which was pretty ominous sitting adjacent to “show”, anyway. It ended up living on the #show page itself.
The destroy functional test continued to work on the controller with every commit. I keep good code coverage. All should be well.
Except, it wasn’t. Manual browser QA discovered a nasty bug where clicking on the destroy link provides a beautiful error:
ActiveRecord::RecordNotFound in PeopleController#show
Couldn’t find Person with ID=10
Huh? I clicked destroy, buddy. And it worked, too. The record is no longer there. But why is it trying to navigate to #show? The boilerplate scaffolding still has a redirect_to(people_url)
Spent an afternoon banging my head against the wall on this one.
Thanks to a good night of sleep, git bisect, and a cooler disposition, I find the answer.
Javascript.
I had put a convenience link on the whole row of the index listing of people:
<tr ... onclick=”window.location =’<%= url_for(:controller => ‘people’, :action => ‘show’, :id => person.id)%>’”>
That simple javascript was being followed even after the destroy link killed the record, invalidating the person.id for the row.
So, it wasn’t a REST bug, a scaffolding screw-up, a route wreck or a controller corruption. No matter what it might look like, it was just javascript.
The easy thing to do was to yank the destroy link off the listing, which was pretty ominous sitting adjacent to “show”, anyway. It ended up living on the #show page itself.
Monday, June 1, 2009
Rampant Fallacy
Consider the humble McDonald’s Big Mac hamburger. No matter where you go in the world -I’ve eaten them on at least two continents- they look and taste pretty much the same. This isn’t an accident. MCD strives for consistent products and service all over the world. That’s not to say it’s the best hamburger, only that it is a product of exacting, predictable quality. Certainly nobody advertises that the meat in a Big Mac is the best possible beef. It is 100% pure beef- i.e. everything on a cow they can run through a meat grinder under the nose of the USDA.
I’m not downing the sandwich- only making the point that MCD craves a more consistent product over the best possible burger. Heaven knows as a result they’ve sold billions of the things. It’s a working business formula. It’s used all over the place.
NASA wants consistently successful manned space flights. Burger joints want consistent burgers. Intel wants consistent chips. Repeatability is how things are done; and it’s met a lot of success. Virtually everywhere. Except software development.
Something different happens when you carry this mindset into software development. It has translated into generally dismal failure rates- variously 30% to 70%. Why might that be?
First of all, program code is unlike rocket launches or hamburger flipping. A line of code, once written, never bears repeating. It never wears out. It will work identically no matter how many computers it is run against. It will work identically a thousand times on a single computer by simply putting it in a loop. In fact, repeatability has negative value in software development. Repeated code is a red flag sign of bad code.
So, what about Quality? What value is a banking program that credits your deposits almost all the time? Would you reckon it to be mid-grade software? Mid-grade peanuts make peanut butter. Mid-grade meat makes burgers. Software either works, or it doesn’t.
Developers are not interchangeable parts. Testing works best when it’s done before the production code is even written. Line count doesn’t measure productivity. Despite the math and science involved, programming is still a craft. None of these thoughts fit into an assembly line/sweatshop mentality.
I think that’s why software development is still in the dark ages in so many shops. How do you change the perspective of management when their view has worked so well since the dawn of the Industrial Revolution?
I’m not downing the sandwich- only making the point that MCD craves a more consistent product over the best possible burger. Heaven knows as a result they’ve sold billions of the things. It’s a working business formula. It’s used all over the place.
NASA wants consistently successful manned space flights. Burger joints want consistent burgers. Intel wants consistent chips. Repeatability is how things are done; and it’s met a lot of success. Virtually everywhere. Except software development.
Something different happens when you carry this mindset into software development. It has translated into generally dismal failure rates- variously 30% to 70%. Why might that be?
First of all, program code is unlike rocket launches or hamburger flipping. A line of code, once written, never bears repeating. It never wears out. It will work identically no matter how many computers it is run against. It will work identically a thousand times on a single computer by simply putting it in a loop. In fact, repeatability has negative value in software development. Repeated code is a red flag sign of bad code.
So, what about Quality? What value is a banking program that credits your deposits almost all the time? Would you reckon it to be mid-grade software? Mid-grade peanuts make peanut butter. Mid-grade meat makes burgers. Software either works, or it doesn’t.
Developers are not interchangeable parts. Testing works best when it’s done before the production code is even written. Line count doesn’t measure productivity. Despite the math and science involved, programming is still a craft. None of these thoughts fit into an assembly line/sweatshop mentality.
I think that’s why software development is still in the dark ages in so many shops. How do you change the perspective of management when their view has worked so well since the dawn of the Industrial Revolution?
Subscribe to:
Posts (Atom)