Patheos

BuddhistCatholicContemplativeEvangelicalGeneral ChristianHinduJewishLatter-day SaintMuslimNew VisionsProgressive Christian

Beliefs

Topics

Columnists

Resource Library

Research Tools

Video

Podcasts

Thought Readers

Faith In Media Tracker

Newsletters

Ad-Free & Subscriber Log-In Subscription Support

Patheos

Ad-Free & Subscriber Log-In Subscription Support

Follow Patheos Patheos on Facebook Patheos on YouTube

Cry 'Woof'

Coding Beyond The Screen, Part I

Last updated on: November 15, 2014 at 10:34 am   by willduquette

Coding Beyond The Screen, Part I 2014-11-15T10:34:01-05:00 willduquette

LOGO Patheos Explore the world's faith through different perspectives on religion and spirituality! Patheos has the views of the prevalent religions and spiritualities of the world.

Quill I’m sitting in Portland International waiting for my flight after the end of the Tcl/Tk conference, so it seems an appropriate time to continue my series on software aesthetics. Previously I talked about writing individual procedures, small and large. But what about entire modules—files—of code?

Some modules are simply one utility procedure after another with a header comment at the top. Those are straightforward. More often, though, I prefer to implement a module as an ensemble command: a Tcl command with subcommands. This gives the whole module a single entry point (the module name) and all of the subcommands are clearly and visibly related together.

The standard Tcl dict command is an example of an ensemble command. A dictionary is similar to an array in other languages, but an array that can be indexed on any value. Dictionaries are often used to store records of data:

set rec [dict create]

dict set rec firstname Joe
dict set rec lastname  Blow
dict set rec age       42

if {[dict get $rec age] > 18} {
    puts "Person is old enough to vote."
}

Here, we use three of the dict command’s subcommands: dict create, dict set, and dict get. (You’re right; I didn’t add color to the code today. My bad.)

There are many ways to implement ensemble commands; my preferred method is to use the Snit package’s snit::type mechanism. Usually, snit::type defines an object type with instances, rather like a class in other languages; but it can also define a singleton object. And since the standard way of representing an object in Tcl is as a command with subcommands, the singleton object is an ensemble.

Here’s an excerpt from Quill’s project module, which is responsible for retrieving the project’s metadata from disk and making it available to other modules:

snit::type project {
    pragma -hasinstances no -hastypedestroy no

    # meta - Project metadata array for the project 
    # being managed.
    #
    # project       - The project name
    # version       - The project version number
    # description   - The project description

    typevariable meta -array {
        project     ""
        version     ""
        description ""
    }


    typemethod name            {} { return $meta(project)     }
    typemethod version         {} { return $meta(version)     }
    typemethod description     {} { return $meta(description) }
}

I’ve remove most of the comments and most of the code from this listing, because I’m trying to illustrate the concept. This code is contained in project.tcl, and defines a snit::type called project. The type includes a “type variable”, meta, which contains metadata about the project (far more than is shown here). It also defines “type methods”, which are essentially Tcl procedures that define subcommands of the type command. Here we define three type methods, to return the project’s name, version number, and description.

Another module in Quill might use these commands like this:

puts "Building project:"
puts "Name:     [project name]"
puts "Version:  [project version]"
... code to build the project ...

Next time, I’ll talk about the structure of a singleton module.

____
photo credit: campra via photopin cc

Quill

Software Development

quill

software aesthetics

tcl/tk

Previous Post



November 14, 2014

Portland, O Portland

Next Post



November 17, 2014 Catching up....


Browse Our Archives

Select a Category Admin App o' the Morning Ask the Dogmat Believing Thomas Bits of Fiction Blasts from the Past Bootstrapping the Interior Life Catholic Mom Christian Living Deep Thoughts from the Doghouse Dominicana Evangelii Gaudium Interviews It Was A Dark and Stormy Night Links to This and That Lumen Fidei Meme Watch On Writing Operation Gratitude Pedant Errant Photography Quill Random Barkings S'Mary's World Shakers of Salt Software Development The Dog Whistler The Dogmat Sez Third Orders Thomas Aquinas Uncategorized Vikings at Dinos Woof Guide to Cinema Woof Guide to History Woof Guide to Literature Woof Guide to Obscure Catholic Music Woof Guide to Philosophy Woof Guide to Popular Music Woof Guide to Technology Woof Guide to Theology Words I Wish I'd Written Works For Me

Select a Month September 2016 August 2016 June 2016 May 2016 April 2016 March 2016 February 2016 January 2016 December 2015 November 2015 October 2015 September 2015 August 2015 July 2015 June 2015 May 2015 April 2015 March 2015 February 2015 January 2015 December 2014 November 2014 October 2014 September 2014 August 2014 July 2014 June 2014 May 2014 April 2014 March 2014 February 2014 January 2014 December 2013 November 2013 October 2013


Follow Us!

Follow Us on Facebook Follow Us on Twitter



TAKE THE

Religious Wisdom Quiz

What does "Shema" mean in Hebrew?

Select your answer to see how you score.

Wait Obey Pray Hear

Related posts from Cry 'Woof'

Catholic

Quill v0.4.0

Cry 'Woof'

Catholic

Portland, O Portland

Cry 'Woof'

Catholic

Quill v0.3.0

Cry 'Woof'

Catholic

Beautiful Code One Screen at a Time, Part...

Cry 'Woof'

TRENDING AT PATHEOS Catholic

Rejecting Doom: Christian Hope And Human Action

Christianity is a religion of hope. We are to have hope and...

It’s What Comes From Within Which Matters

One of the most difficult things for us to understand is why...

Why I Choose the Eucharist Over the Sermon

Choose the Eucharist, Not the Sermon What are we supposed to get...

5 Design Elements Found in Spiritually Rooted Homes

Putting Spirituality Into Home Decor Our homes are more than our living...

Credo: A Story of God Told with the...

About 10 years ago, I began to imagine a personal "Credo" that...

The Anatomy of Divine Revelation in Catholic Thought

The claim that God has made Himself known to human beings is...

view all Catholic blogs

Patheos on Facebook Patheos on YouTube

Ad-Free & Subscriber Log-In Subscription Support

Copyright 2008-2026, Patheos. All rights reserved.

Subscription Support Ad-Free & Subscriber Log-In

Follow Patheos Patheos on Facebook Patheos on YouTube