Hodges' Model: Welcome to the QUAD: domain specific languages

Hodges' model is a conceptual framework to support reflection and critical thinking. Situated, the model can help integrate all disciplines (academic and professional). Amid news items, are posts that illustrate the scope and application of the model. A bibliography and A4 template are provided in the sidebar. Welcome to the QUAD ...

Showing posts with label domain specific languages. Show all posts
Showing posts with label domain specific languages. Show all posts

Wednesday, August 14, 2024

There is this thing - 'universal construction'

The problem of bugs in software is an ongoing problem across all IT industries. For application that are safety critical we are still reminded of the risk implications and consequences if bugs are software is not tested and bugs - errors identified and corrected.

Back in the 90s during BA(Joint Hons. Philosophy & Computing) studies, I was introduced to the formal specification language 'Z'. It was designed for definition, and modelling of computer software, working from specification to implementation, as per these images:

https://personalpages.bradley.edu/~young/CS592M120_OLD/handoutZed.pdf

https://personalpages.bradley.edu/~young/CS592M120_OLD/handoutZed.pdf

To be clear I've never worked as part of a software project and my 'tinkering' - Drupal, Pharo, online groups, hosting platform - reveals how the development stack and work processes have developed apace. The challenge is keeping up. Simultaneously, there is the sense of being on the bank of deep water; or, a vertiginous cliff:

A little learning is a dang’rous thing;
Drink deep, or taste not the Pierian spring:
There shallow draughts intoxicate the brain,
And drinking largely sobers us again.
Fir’d at first sight with what the Muse imparts,
In fearless youth we tempt the heights of arts,
While from the bounded level of our mind,
Short views we take, nor see the lengths behind,
But more advanc’d, behold with strange surprise
New, distant scenes of endless science rise! 
Pope. https://interestingliterature.com/2021/09/a-little-learning-is-a-dangerous-thing-meaning-analysis-origin/

 Acknowledging the need for an 'evidence-base' and theoretical underpinning the effort to 'push' Hodges' model forward is ongoing. Maths remains an alien territory to me, but the 'secret garden' is as tantalizing as ever. Over the years I have posted - with much overlap about:

  • maths
  • relation
  • logic
- and more recently:
  • isomorphism
  • category theory
  • and as previously posted - laws of form.
In an effort to get to grips with the above, I'm following various online videos, books and papers. Bartosz Milewski's videos, blog and publications are aimed at programmers, but are very interesting nonetheless. The first video provides an introduction to the motivation and philosophy of category theory. In another, Milewski refers to 'universal construction' on YouTube and in a blog post about 'Function Types'.

The 'universal' figures in healthcare too: universal health access, and universal health coverage appear to over-shadow 'universal health care'. The quality of 'universal' also creeps into assessment. Data gathering is not merely complete, it is comprehensive. It has to be, to contribute not just to a care plan, for one that is (supposedly) person-centred, with risks identified, strengths, weaknesses - needs, history, social network, and much more. The care plan informs and orchestrates the interventions; then evaluation follows. Are we delivering? What is the patient's (client's, carer's) level of satisfaction. Have care stages and actions been completed as per policy (in time!)? (More on this to follow later this year in light of UK mental health/illness news.)

So as I consider (wrestle with...) initial, and terminal objects, sets and categories … I can hopefully, especially with help, extend the number of posts tagged 'universal' here on W2tQ. In this vein, is Hodges' model a universal construction? There may not be a universal truth to reveal, but it will prove a marvellous learning journey.

Tuesday, July 17, 2012

ERCIM News No. 90 Special theme: "Cybercrime and Privacy Issues"

Dear ERCIM News Reader,

ERCIM News No. 90 has just been published at http://ercim-news.ercim.eu/

Special Theme: "Cybercrime and Privacy Issues"

Guest editors: Jean-Jacques Quisquater (Université catholique de Louvain), Solange Ghernaouti-Hélie (University of Lausanne), Jens Tölle and Peter Martini (Fraunhofer Institute for Communication, Information Processing and Ergonomics FKIE)
http://ercim-news.ercim.eu/en90/special



Keynote: "Current Cybersecurity Best Practices – a Clear and Present Danger to Privacy" by Roger R. Schell
http://ercim-news.ercim.eu/en90/keynote

ERCIM News 90 issue for download in pdf:
http://ercim-news.ercim.eu/EN90/EN90-web.pdf

Next issue: No. 91, October 2012 - Special theme: "What is Computation? Alan Turing's Legacy"
(see call at http://ercim-news.ercim.eu/call)

Thank you for your interest in ERCIM News.

Feel free to forward this message to others who might be interested.
Peter Kunz
ERCIM News central editor

Friday, January 20, 2012

Scope, Space, Nursing, Informatics: Fusion I

Paolo Perrotta writes:

Imagine being a little debugger making your way through a Ruby program. You jump from statement to statement until you finally hit a breakpoint. Now, catch your breath and look around. See the scenery around you? That's your scope.

You can see bindings all over the scope. Look down at your feet, and you see a bunch of local variables. Raise your head, and you see that you're standing within an object, with its own methods and instance variables; that's the current object, also known as self. Further away, you see the tree of constants so clear that you could mark your current position on a map. Squint your eyes, and you can even see a bunch of global variables off in the distance. p.75.

Paolo Perrotta, (2010). Metaprogramming Ruby, The Pragmatic Bookshelf.

Tuesday, January 03, 2012

ERCIM News No. 88 Special theme: "Evolving Software"

Dear ERCIM News Reader,

ERCIM News No. 88 has just been published at http://ercim-news.ercim.eu/

Guest editors: Tom Mens (University of Mons, Belgium) and Jacques Klein (University of Luxembourg)

http://ercim-news.ercim.eu/en88/special

Keynote "Change is the Constant" by Joost Visser, Head of Research at Software Improvement Group
http://ercim-news.ercim.eu/en88/keynote/change-is-the-constant

Next issue: No. 89, April 2012 - Special Theme: "Big Data"
(see call at http://ercim-news.ercim.eu/call)

Thank you for your interest in ERCIM News.
Feel free to forward this message to others who might be interested.
Happy New Year!
Peter Kunz
ERCIM News central editor

[Includes: An introduction to this theme; Holistic Software Evolution; Wireless Sensor Networks and the Tower that Breathes; and Innovation in Disaster Management: Report from Exercise EU POSEIDON 2011. ] PJ


ERCIM News
is published quarterly by ERCIM, the European Research Consortium for Informatics and Mathematics.
The printed edition will reach about 10,000 readers.
This email alert reaches some 6000 subscribers.

Friday, May 06, 2011

h2cm: where does 'programming' begin and end?

On first impressions Hodges' model is a table. Its structure shouts "table!"
It is a table around which we can gather. It is political: a tabular rasa.

Since 1987 I've been fascinated by the potential that this basic construct, call it the 2 x 2 starter kit for holistic care has to conceptualise (as someone at the HEA Critical Reflection SIG meeting noted), represent, and explain nursing, health, social care and umpteen other situations.

It has great potential because of what we might do with the contents of the table.

This two x two table instructs.
It makes demands: "Initialise Me" with at least four care concepts.
It has critical reflective potential.
  
Nursing care problems, relapse prevention plans, strengths and steps to recovery can suddenly take on another dynamic form. The extent to which this transforms is still in human* hands (and minds!) but I am sure this informational potential and purpose is there; especially reading Fowler (2010):
This use of tables as source code is unusual, but it's an application that could be used more often. People like specifying things in tabular form, whether it's examples for test data or more general processing rules such as a Decision Table (495). Many domain experts are very comfortable with editing tables in spreadsheets, which can then be processed into source code. p.156. Fowler (2010) Chapter 10 A Zoo of DSLs.
You can see why nursing - health and social care are so complex:

- staff are busily 'programming' in at least two or three domains and constantly pressured to theorise and practice safely and effectively in four (*five when we include the spiritual).

Fowler, M. (2010) Domain Specific Languages: Addison-Wesley Signature Series, Addison-Wesley Professional.

Saturday, April 09, 2011

Nursing ideas somewhere between Drupal & Ruby

It's been a busy week:

  • getting ready for the Scottish Ruby Conference [SRC] three fascinating days 7 - 9 April.
  • checking with the client of the Drupal site, confirming that the following CSS3 adornments are not required: coloured lettering : 3D text : and others. KISS - OK!
SRC started with the charity day a day long tutorial from Chad Fowler author of The Passionate Programmer and Keavy McMinn. They delivered too - indeed it's all great! The venue - The Royal College of Physicians is quite amazing, full of history in its architecture and the portraits of esteemed members. Whether or not I attend a session in there today I must visit the library. The charity day covered:
  • Blocks and bindings
  • The Ruby object model
  • Meta-programming
  • Hooks, callbacks, and reflection.
When it came to the exercises I let the experts do their thing and followed the solutions. I missed last year's Ruby bash so it's good to be back.

Swapping to Ruby while tinkering with Drupal is not a help and yet there is overlap. GIT is the must-do within both communities. PHPNW's meeting on Wednesday on OOP with Lorna Mitchell highlighted some common aspects. I'm probably getting a lot of this (as in 'all' plain) wrong but Lorna's mention of $this and static methods sent me on a reverie. ...

Abstract classes are apparently incomplete and $this is not available to them. Suddenly I'm thinking well that's different. In nursing our abstractions on nursing care are complete - in the idealised sense. It's the concrete / practical (dynamic) delivery that sadly falls short.

PHPNW - the conference in October, a Saturday event in prospect and being here in Edinburgh reminds me I have this itch. Dave Hoover's keynote spoke about his career and finding his technical groove from a therapeutic role as a psychologist.

One thing I do know: from the books he mentioned I ain't got 10,000 hours. That's why I am trying to leverage Drupal and in Ruby - the Rails framework. There's an IDE I have just learned of JetBrain's Ruby Mine.

(Despite that) I'm reading Martin Fowler's book on Domain Specific Languages. Not because I'm going to write one (or like rashes), but because I'm totally intrigued and wondering about a research question. What question(s) can I ask that I might also be able to answer (or not)?

method_missing, meta programming and DSLs are still here in Edinburgh. No longer the latest and greatest (Jim Weirich suggested that was c.2006), but then neither are models of nursing. ;-)

In his book, Fowler identifies 'illustrative programming'. Spreadsheets are the key example and quite remarkable in how they are used and the niche they occupy from a programming, DSL, and an everyday tool perspective.

Hodges' model is a spreadsheet; or a decision table of sorts. Basically, does the patient have a problem in each of the care domains? Fowler writes:
The key benefits of a DSL - greater productivity and communications with domain experts - really kick in when you are using an alternative computational model. Domain experts often think about their problems in a nonimperative way, such as via a decision table. An Adaptive Model allows you allows you capture their way of thinking more directly in a program and the DSL allows you to communicate that representation more clearly to them (and yourself). p.116.
I'm really taking liberties with definitions. My domain experts might actually be student nurses.

I know book titles are intended to sell, but I look at the title of Chad Fowler's book above and wonder about the Compassionate Care Programmer and what alternative computational models may be needed to achieve that?

Fowler, M. (2010) Domain Specific Languages: Addison-Wesley Signature Series, Addison-Wesley Professional.

Sunday, April 18, 2010

Musings in the nursing domain (specific language)

It is one giant leap from the humanistic world of nursing, health and social care to the m(a-e)chismo of information technology. It is no Earth-bound chasm that greets us in considering the vaguest possibility that nursing could ever be captured, distilled and represented in a domain specific language (DSL). Given the full title of Hodges' model my attraction to DSLs should be obvious, but how realistic is this fascination?

Here are some links to definitions / resources on DSLs:

I am not advocating DSLs as a real time clinical software application, there is neither time here, nor on the wards. Since the sky above is clear blue with not a contrail in sight I am indulging in a little blue sky thinking, a reverie...

Nursing already has its concept analysis, but taken at face value this says nothing about domains as per h2cm (other than the context / application is nursing). To avoid confusion with career in the job-work sense, I have emphasized the notion of domains. By this I mean a partition of specific knowledge about a discipline or subject. This disciplinary focus or subject is often the province of expert practitioners. My forte then in Hodges' model are the INTERPERSONAL and SOCIAL care domains. This is my rationale for the musings here, as all experts were learners once upon a time, and are still as lifelong learners. It is an educational application that I have in mind.

I have come across a paper by Reinhartz-Berger, who describes the movement - Towards automatization of domain modeling. The author refers to domains artifacts and domain analysis:
(I have removed the reference numbers and inserted from prev para*)

A domain in this context [Domain engineering, also known as software product line engineering]* can be defined as a set of applications that use common concepts to describe requirements, problems, capabilities, and solutions. Domain artifacts are built and reused through domain analysis, which identifies the domains and captures their ontology to assist and guide system developers with particular applications in those domains. Despite the rapid growth of technologies and technical solutions, domain analysis models usually remain valid longer than domain designs and implementations, potentially justifying the cost and effort required for their development. Domain analysis artifacts may also serve as the basis for defining Domain-Specific Languages (DSL). Reinhartz-Berger (2010), p.491.
As the previous post - Reading the signs... Idealised Care - amongst several revealed, the domains within the health career model are broad to say the least. So broad that from the INDIVIDUAL-GROUP axis the left-hand margin of the INTRAPERSONAL-SOCIOLOGY# care domains are but distant horizons (with no curvature in-sight). It's no surprise that I keep wondering about how to get a grasp on that 'space', for reasons of a website, a potential community of explorers, educational objectives and sheer enthusiasm for trying to mix IT up. Reinhartz-Berger continues:
Several domain analysis methods have been proposed over the years. However, they all can be criticized as making the domain engineer alone responsible for developing correct, complete, and consistent domain analysis artifacts. Since domains may cover broad areas and are usually understood only during the development process, creating domain models can be a very demanding task. It requires expertise in the domain, reaching a very high level of abstraction, and providing flexible, yet formal, artifacts. Reinhartz-Berger (2010), p.491.
Also in the literature Chavarriaga and Macías (2009) highlight two approaches that are the focus more generally to help get a grip and the big wide world of knowledge: The Semantic Web and Web 2.0.:
... However, in spite of its semantic power, one of the main underlying problems with this [semantic] paradigm is the explicit representation and visualization of information, mainly focused on ontologies and the complex relationships that these code. This has made the Semantic Web inaccessible and unmanageable by most designers that are not expert on ontological representations and languages, but on domain specific applications and creative design.
On the contrary, the Web 2.0 paradigm provides a rather pragmatic vision. It is based on the use of wikis, folksonomies and protocols like SOAP, mainly intended to the automatic management of services and the collaborative maintenance of (mainly) syntactic knowledge-based information. Moreover, Web 2.0 can be considered an end-user paradigm. ... Chavarriaga and Macías (2009), p.1329.
The Semantic Web, Web 2.0 will (at some point) figure in the new site. A folksonomy can be quite broad by definition, as there is no strict control on the definition of terms. As to DSLs in Hodges' model, there we have four VERY broad domains. Exactly how domain analysis proceeds and what domain artifacts might emerge from this model would no doubt depend on reducing each of the domains, sub-dividing, being more specific.

If nothing else at present the health career model is a hybrid cognitive domain specific language.

References: (my source: Science Direct)

Iris Reinhartz-Berger (2010) Towards automatization of domain modeling, Data & Knowledge Engineering, Volume 69, Issue 5, May 2010, Pages 491-515. doi:10.1016/j.datak.2010.01.002

Enrique Chavarriaga, José A. Macías (2009) A model-driven approach to building modern Semantic Web-Based User Interfaces, Advances in Engineering Software, Volume 40, Issue 12, December 2009, Pages 1329-1334. doi:10.1016/j.advengsoft.2009.01.016

Monday, June 02, 2008

a Book? and DSLs on Weds night

On Wednesday night I plan to attend -

ThoughtWorks GeekNight Manchester - The 5 Ws of DSLs:

Domain Specific Languages (DSLs) have been around for a very long time; however, the past 2 years have brought a resurgence of interest to the topic. DSLs are a great idea, but they are the most beneficial when used appropriately. This talk will discuss who DSLs are designed to help, what is a DSL, when you should create a DSL, where you should apply DSLs, why DSLs are important, and how to get started with DSLs. We will begin at the introduction level, almost no previous knowledge of DSLs is necessary.
The other week I received an e-mail with a proposal: a future book and a role acting as an editor. The theme would extend the book chapter on Hodges' model, Michel Serres and (for me) would include conceptual frameworks for global health. I approached a few publishers about this global health aspect about 18 months ago. What other actual and potential tools are out there? What cognitive and practical tools could Africa, South American, Australasia and Asia ... bring to the table?

This is a ways off yet, which is why I need to know more, but needless to say I am definitely interested. It's a big responsibility (and here is me without any formal PRINCE-X training). I do enjoy reviewing and critically appraising documents and this could be a truly marvellous collaborative project.

Monday, April 14, 2008

Hooks - Blogs and Mental Health Care

It seems I'm surrounded by hooks. VanDyk's Pro Drupal book is chock-full of them, so too Ruby (and Rails?).

Sitting and listening to a couple of clients in particular I'm busy trying to locate the hooks:

  • those I need to avoid (get one of these stuck in your lip and you'll end up talking gibberish);
  • those I need to find as ways to move 'things' forward.
So, health care and programming are worlds apart?: don't you believe it!

The book I've to review has arrived Mercer's Drupal 6. I've Drupal 6.2 installed and having been exploring Netbeans and JRuby it's time to revisit the future site c/o Drupal.

Without direct comparison so far the text seems to follow the format of Mercer's previous Drupal 4.7 text. The explanation about Drupal menus - primary and secondary links is really helpful, I'll check this out this week. I've come to the conclusion that Hodges' model needs a forum, encouraged by Mercer's discussion of user roles, permissions and the need to provide a hub for a h2cm community. I've started to map the forum out having also settled on an existing theme. I'd like to avoid the usual 'nursing' forum categories, but this may be difficult. The existing subdivisions are not accidental, so would forums on holistic care and domain specific care be feasible? A key aim is to demonstrate how Hodges' model can also be applied in social care, informatics, education and other fields.

My exposure to NetBeans this past week has highlighted a need to (finally) read about MySQL which is essential for Drupal too. Reading the jQuery book makes a specific glossary page seem redundant, we'll see.

The idea of a community made me think about a conceptual currency - something concrete to help drive development and interchange. About 7-8 years ago when XML was emerging I'd wondered about creating an XML format for Hodges' model. I may still have the e-mails from a couple of people who were interested in this. There was even a web page that included mention of HCML - health career markup language.

In light of this I suppose my latching on to the development of domain specific languages is no surprise. XML has its limitations, but it would be brilliant to have a 'standard' template, a file format for Hodges' model upon which to place key care concepts. I suppose a Word document will suffice for now, but I do believe that much more is possible: hooked indeed. ...

Saturday, April 05, 2008

"Great Scot!" Ruby & Rails - Scotland On Rails

Just back from Edinburgh this evening. Took it steady about 60mph, so used just half a tank of fuel - not bad for 400 miles (return). Had to take it easy as it was just above freezing in places and I ended up playing Star Trek. It was snowing for a time North of Penrith. When I was able I put the head lights on full-beam: warp drive!

Scotland On Rails was great - the organisation, speakers, content and company. The sessions I attended included testing, testing testing, migrating to Ruby 1.9, DSLs .... and the last session on JRuby with the announcement of version 1.1 that provoked a round of applause:

JRuby on Rails: Up And Running!

Charles Oliver Nutter and Thomas Enebo

JRuby 1.1 has been released, and is becoming the Rails platform of choice for many Rails shops. In this session, we’ll show how to start from scratch or migrate your existing Rails app to JRuby. We’ll demonstrate the various deployment options on JRuby. We’ll show how to integrate Java libraries into your app. We’ll walk through NetBeans’ Ruby and Rails support and talk about how JRuby has enabled better tools and better solutions for Ruby developers. And we’ll have a conversation with the audience about where JRuby on Rails should go from here. Be prepared to talk shop and see lots of code and demos.
I'd been really looking forward to Joe's presentation on DSLs and was not disappointed. My enthusiasm here is not because Hodges' domains makes a DSL a dead-cert, far from it; it's just that I miss playing with Plasticine:
Domain Specific Languages : Moulding Ruby

Joe O'Brien

Ever wondered what all the fuss is about when it comes to DSL’s and Ruby? It seems to be all we hear about. This talk will peel away the onion and look at what it is about Ruby that makes it the perfect candidate for creating your own languages. I will show you, through examples, how you can create your own languages without the need for compilers and parsers. We will also cover some real world examples in areas of Banking and Medicine where DSL’s have been applied.
Amid the clamour that is Rails, Joe also stressed that people should focus and explore Ruby itself. Something I need to get on with. Paul Dix's talk this afternoon was fascinating in terms of scale, processing, math libraries and mention of clustering:
Collective Intelligence: Leveraging User Data to Create Intelligent Rails Applications
Paul Dix

Take advantage of user data to create intelligent Rails applications! This talk will focus on data mining to create complex application behavior and gain insight into the patterns and habits of your users. Examples of these techniques can be seen with recommendation systems like those created by Amazon, Netflix, last.fm, and others. Additional examples include spam filtering systems for email or comment filtering provided by Akismet.
I will focus on techniques for gathering data, specific gems and plugins for performing various data mining and machine learning tasks, and performance issues like how to distribute the work to separate servers. Theory in this talk will be light and the specific algorithms will only get a mention by name. We’ll be looking at real world Ruby and Rails code examples for building recommendation, ranking, and classification systems.
I wasn't the only Ruby newbie and met a few of my peers, we noticed on the first day the number of sessions on the theme of testing. Last week I'd watched Matz' February talk on Ruby 1.9 and the future which helped me out through the past two days. Last night in The Crags one of the speakers Ritchie (whose session I missed) kindly explained about his conjoint talk and the significance of JRuby, NetBeans IDE and IntelliJ. Given Richie's knowledge, experience and that closing session, I'll definitely investigate these.

There's only one conclusion - totally overwhelming: but totally worth the brain ache.
So great job and many thanks to Alan and the team, plus the luminous speakers and sponsors.

Sunday, March 16, 2008

BASIC, Ruby, DATA and Scotland On Rails

This weekend reading more of Hal Fulton's The Ruby Way, there was a blast from the past in the form of '10.1.25 Reading Data Embedded in a Program' and a reminder of all those DATA statements typed in from magazines.

Ruby not only supports the industry database and SQL standards, but other approaches such as embedded data and KirbyBase. Fulton's book is designed for 'random access' and yet I'm reading it through. There are jewels in the texts on Ruby. Sentences that while fairly obvious still serve to catch my breathe '... They differ in the amount of context they copy. ...'

10.4.7 Object-Relational Mappers discusses ActiveRecord and Og (object graph). Apparently Og can generate a database schema from Ruby class definitions (rather than vice-versa). This is a useful and powerful ORM 'especially if you design your database after your objects.' p. 384.OK ....

With all this reading on databases whatever happened to the Associative Data Model? Still alive and very well I believe, yet more Sentences to figure out.

In order to try and make some headway, next month I'm heading for Edinburgh and the Scotland On Rails conference.

I can't attend the full event, but plan to make sure the trip is well worthwhile. While I hope all the speakers stay in fine fettle, there is a speaker for Saturday whom I pray stays in finest lustre - a presentation on DSLs! Just one highlight of what should be a great talk. [Stay well Joe!]

Monday, March 03, 2008

DSL examples - thrills and spills: "Data lend me your ear!"

The final chapters of Olsen's book Design Patterns in Ruby made my lips dry. I hadn't checked ahead, but Olsen mentions mid-text what's to follow. In getting there and reading about the Interpreter pattern and DSLs, I do hope this does not prove a one-off date. Olsen's book IS brilliant (and besides Ruby looks so dynamic across the dance floor), but the examples used were tinged with anti-climax and prompted a reality check.

Olsen's examples DO illustrate the principles, like most things worthwhile they need deliberate reading, but they DO deliver. So what's up? Well, the examples presented are taken from the world of IT (file backup). Yes, I know... well what do you expect! I had hoped for a DSL from a less technical domain; something left-of-centre, something that traverses the HUMANISTIC - MECHANISTIC divide. This is where the definitions of domain, DSL and the craft of caring and programming can (possibly) provide some useful insights.

For decades the literature and projects have focussed upon nursing languages. Communication relies on language of course. Even the absence of messages - verbal, non-verbal or other - tells us something. In health and other professions great emphasis is placed upon communication skills. We have to listen actively. How we listen - the constraints, what we deem as significant, and what is subsequently recorded and retained defines our care domains.

Star Trek Galactic QuadrantsThe domains that are the subject of DSL are specific, which explains how they can be implemented in some 50-70 lines of code (this also says something about Ruby). In contrast, within Hodges' model those four domains may as well be galactic quadrants they are so broad. Regardless of this (non-trivial) issue, standing at the nexus of h2cm the question needs to be asked (and is constantly being asked by health & informatics communities):

How good a listener can the MECHANISTIC ear be?

Saturday, February 23, 2008

Domain Specific Languages [II] + a Ruby mixin

Last year in one of those pick-it-up:put-it-down cycles, I surfed into this article on DSLs and Ruby c/o:

Artima logo

Ruby Code & Style Creating DSLs with Ruby
by Jim Freeze, March 16, 2006

Although as mentioned the other week, I'd read - and keep reading! - Chris Pine's intro Ruby book and the Thomas's Pickaxe, much of the code is hard to follow for a beginner - here's a snippet (from page 3 of 4):

[n.b. Some lines below are incomplete due to Blogger's interpretation of the characters]
Again, we update the require statement in dsl-loader.rb to load the mydsl4.rb file and run the loader:
% ruby dsl-loader.rb params.dsl
#
["@parameter", "@name"]
This is all well and good, but what if we don’t know the parameter names in advance? Depending on the use cases for the DSL, parameter names may be generated by the user. Never fear. With Ruby, we have the power of method_missing. A two-line method added to MyDSL will define a DSL attribute with dsl_accessor on demand. That is, if a value is to be assigned to a (thus far) non-existent parameter, method_missing will define the getters and setters and assign the value to the parameter.

% cat mydsl5.rb
require 'dslhelper'

class MyDSL
def method_missing(sym, *args)
self.class.dsl_accessor sym
send(sym, *args)
end

def self.load(filename)
# ... Same as before
end
end

% head -1 dsl-loader.rb
require 'mydsl5'

% ruby dsl-loader.rb params.dsl
#
["@parameter", "@name"]
Once again Olsen's - Design Patterns in Ruby has helped me (to begin to) understand  method-missing (p.184). I swear I heard some clanks as the pieces re-arranged themselves and one or two fell (almost) in place. Having copied Freeze's code into Ruby, it would not run. At least now the code is not as complex looking at it was and reading it through now it makes a lot more sense. I'm really looking forward to trying this again in Eclipse. On that first exposure I had a vague notion of the principle of method-missing, but reading Olsen's book I've a better grasp and may be able to keep hold of this and other Ruby concepts. Believe me that helps in my pick-it-up:put-it-down world.

more to follow ....

Friday, February 22, 2008

Domain Specific Languages [I]

Even after a brief acquaintance with the h2cm web site and W2tQ, you'll appreciate the word domain is both hard and soft-wired into my consciousness. On first discovering Hodges' model, the four quadrants were clearly recognisable as knowledge domains.

As the website evolved and after consulting with Brian Hodges, 'Care Domains' was added to the model's title (which has also paid some dividends in search engine terms).

In the early days of hobbyist programming a major project would be to write a compiler. I'm sure I can recall several magazine articles on this (Practical Computing?); step-by-step of course.

Searching on 'domains' as I frequently do, it was inevitable I would come across DSLs or Domain Specific Languages, which instantly caught my attention. Here are some intros -

http://martinfowler.com/bliki/DomainSpecificLanguage.html

http://www.infoq.com/presentations/domain-specific-languages


Monday, February 18, 2008

A dog, glorious weather and misc link

18th February was a great day to be in Sedbergh, the weather was glorious. So quiet, bright and promising.

I found a path from the village up onto the surrounding fells and after a walk up-then-down: a bench for a break.

While I was sat in the sun a lady walked past with her dog -

"Come on Ruby!", she shouted. (Honest!)

"Excuse me, did you say Ruby?"

"Yes, that's right." ...

So I showed her the book I was reading:

Olsen's Design Patterns in Ruby.

This must be a sign! So - give that dog a bone!
In between other reading (Drupal!), I keep referring to Chris Pine's Learn to Program and Dave Thomas's Programming Ruby. These two books are excellent, but although I'm only up to the second design pattern Olsen's book has clarified so much already. DPiR's quick intro chapter on Ruby is itself a jewel.

So far the two initial patterns (template and strategy) have also seen Olsen describe other key aspects of Ruby. I'll try and elaborate on this is the near future - Gang of Four - indeed. You see it isn't just scintillating Ruby that has caught my eye, but domain specific languages.