Showing that fear of mediocrity can make the world a better place.

Posts tagged “dsl

Thought leading keywords

Try starting to write by staring at a blank page. It’s pretty difficult to start but once you do the words seem to follow each other. Its almost like the first words lead your thoughts and guide them the rest of the way. It would then make sense that some words are better at generating followup thoughts than other. For example “it was a hot summer day when…” is better than “tuesday is fun because…”. The first one leads your mind down an ambiguous staement. It lets you figure out the rest of the story without forcing anything extra. The second one starts out with a declarative statement that leaves little room for your thoughts to follow. The same thing can be said of certain words in programming.

Good words

Given, When, Then

Given, When, Then syntax for BDD specs is a pretty powerful phrase. It can sum up some pretty complex topics and helps to get business talking the an Arrange Act Assert style language. The nice thing is that each word leads into the actual text.

Given some data
When I perform an action
Then the result should be testable. 

The syntax lends itself to a nicely structured wording style. There is power in the flexibility but care still needs to be taken to make sure the words that follow are meaningful though since it is quite open ended. The rest of the Gherkin language (http://docs.behat.org/guides/1.gherkin.html) uses similarly leading words to fill out the rest of a scenario.

Get{x}By{y} / Find{x}By{y}

A method that says GetSomethingBySomeProperty helps you follow a simple data access strategy. Don’t believe me? Check out how Simple.Data uses this structure to effectively drive the framework. The framework makes sure you are consistent since the method name drives the data lookup. It’s interesting in that it removes the need for discipline in consistent naming since it will only work if your name everything correctly.

Should

Should is a powerful word. Care has to be taken that it doesn’t get watered down like those “the system shall” requirements of yesteryear and that the word expresses it’s intent. It is useful in testing and assertions. If you want to should your way through assertions you should check out shoudly. It usually shows up in my tests methods and it helps me to think through what the system should do as opposed to the more technical implementation details.

On

What even based systems would be complete without such a simple preposition. Onclick, onsubmit, and on(‘user registered’, sendConfirm) are all examples of using On to specify intent to do something for an event. This one shouldn’t need much explanation if you have done any web programming. It is a utility player that is probably the most concise way to say what you want to do when a given event occurs.

On ‘end’ ShouldWrapup

It’s no surprise DSLs (domain specific languages) are gaining popularity. Coding is becoming a game of expressiveness and clarity of concept. Is your code readable? By a developer? By a business user? Should it be? Thought leading words all have a few things in common. In these cases they are prefixes. It’s tough to lead , after all, if you are at the back. They get you to think about what should be the next piece in the thought. Interfaces like IHandle and IAuthorize prompt you to type IHandle…what do i handle? I handle user registration so I guess it’s IHandle.

No, library and framework coding isn’t just about setting up a MadLibs exercise for the consuming developer but it’s about starting the sentence and having the library consumer finish it. Not only does it promote a consistent expression of ideas but it also helps by giving someone a starting point for their thoughts. Don’t give someone a blank page, inspire them to create a masterpiece.

Advertisements