[Grok-dev] On the Grok API

Sebastian Ware sebastian at urbantalk.se
Thu Jun 7 17:07:03 EDT 2007


This was confusing to me too. I realise that this will be crystal  
clear once one starts coding, but when looking at sample apps it was  
hard to understand what was happening.

Since I use an IDE with autocompletion I wouldn't mind longer, self- 
explanatory, names.

Mvh Sebastian

7 jun 2007 kl. 22.28 skrev Luciano Ramalho:

> When I first started reading the source of apps made with Grok, I
> found code like this a little strange:
>
> #################
>
> class WorkflowIndexes(grok.Indexes):
>    grok.site(Blog)
>    grok.context(IWorkflowState)
>    grok.name('entry_catalog')
>
>    workflow_state = index.Field(attribute='getState')
>    workflow_id = index.Field(attribute='getId')
>
> #################
>
> What bothered me were those calls to grok functions right after the
> class declaration. Those calls have a declarative intent, and perhaps
> would be class annotations if Python's syntax allowed.
>
> Then I remembered that in Ruby on Rails, they have similar  
> declarative calls:
>
> #################
> class User < ActiveRecord::Base
>    validates_presence_of :name
>    validates_uniqueness_of :name
>    attr_accessor :password_confirmation
>
>    def self.authenticate(name, password)
>        user = self.find_by_name(name)
>        if user
>            expected_password = encrypted_password(password, user.salt)
>            if user.hashed_password != expected_password
>                user = nil
>            end
>        end
>        user
>    end
>    # (... more code would follow ...)
> #################
>
> As you can see, in Rails they use the wider syntatic variability of
> Ruby to make the declarative statements look different from regular
> function calls by omitting the parenthesis around the args in the
> declarative calls, but using parenthesis in the usual function calls.
>
> In order to make this distinction explicit in Grok, we could use a
> different namespace for those declarative functions. For example, we
> could have:
>
> #################
> from grok import declare
>
> class WorkflowIndexes(grok.Indexes):
>    declare.site(Blog)
>    declare.context(IWorkflowState)
>    declare.name('entry_catalog')
>
>    workflow_state = index.Field(attribute='getState')
>    workflow_id = index.Field(attribute='getId')
> #################
>
> Of course, instead of declare we could have another word. Some shorter
> alternatives would be let or bind.
>
> This whole idea is in keeping with a usability principle stated by
> Donald Norman, that similar things should look similar, and different
> things should look different.
>
> I maybe too new to Grok to be making these kinds of suggestions, but
> the whole issue just occurred to me because I am new, and I figure one
> of my missions during this summer is to give you this perspective.
>
> Cheers,
>
> Luciano
> _______________________________________________
> Grok-dev mailing list
> Grok-dev at zope.org
> http://mail.zope.org/mailman/listinfo/grok-dev



More information about the Grok-dev mailing list