This is awesome. I've created a "Where's Concrete Used" wiki page on
github and added this to it - let me know if you don't want it there
and I'll remove it.
I notice you're using _ to mark private functions. What's your feeling
about this? The '_ is private' rule is fairly well known, but it sure
looks ugly.
I've been thinking about adding the ability to limit a function to
namespace-block internal usage only (which provides the most desirable
feature of private functions - having functions available to internal
code without polluting the exposed API) but I haven't been able to
come up with a nice syntax.
I'm a little concerned about the amount of scaffold that you start
getting in a Concrete app with this addition. IMO, underscores are
less ugly. ;-)
One slightly more philosophical question is relevant here: are you
trying to nail down a new syntax that people should follow - a
Concrete DSL - or are you trying to provide a toolkit for people to
mix and match as they see fit - a Concrete API?
If you're going for an API, then $.concrete.internal makes sense,
because you could potentially mix and match these $.concrete.internal
closures/lambas in other ways.
However, I suspect that you're actually going for DSL, mostly because
the internals of Concrete appear to be designed to be
indistinguishable from magic to most of the people that use it. ;-)
In that case, it would seem best to optimise the API design towards
allowing for a nice easy to read syntax that Concrete users can write
their code in.
I don't really know what that would be, but one option is this:
$.concrete('namespace', function($){
$('.selector').concrete({
'foo.private': function(){
},
bar: function(){
this.foo(); // Allowed
}
})
});
From a DSL perspective, it seems better than "$.concrete.private()".
You could even hijack the underscores and automatically attach as
private any method that starts with an underscore. It's the closest
thing to a convention that JavaScript has in this area - why not adopt
it?
> Private isn't really the right word, because it's not fully private -
> you could still access it by doing
>
> $.concrete('namespace', function($){ $(this).foo(); })
Maybe "protected", then? Since protected methods can be broken into
in a similar way. Here's a little PHP simile:
class MyClass extends ClassWithProtectedMethod {
public function publicMethod() {
return $this->protectedMethod();
}
}
> and you could still override it in subclasses. It's more like internal
> function verses exposed api function. So maybe internal is better than
> private:
>
> http://gist.github.com/217337/567de648e34f637589667b9d1652d1d43b4f0121
The advantage of "protected" rather than "internal" is that people
have heard it 100 times before.
One slightly more philosophical question is relevant here: are you trying to nail down a new syntax that people should follow - a Concrete DSL - or are you trying to provide a toolkit for people to mix and match as they see fit - a Concrete API?
If you're going for an API, then $.concrete.internal makes sense, because you could potentially mix and match these $.concrete.internal closures/lambas in other ways.
However, I suspect that you're actually going for DSL, mostly because the internals of Concrete appear to be designed to be indistinguishable from magic to most of the people that use it. ;-) In that case, it would seem best to optimise the API design towards allowing for a nice easy to read syntax that Concrete users can write their code in.
I don't really know what that would be, but one option is this:
$.concrete('namespace', function($){
$('.selector').concrete({
'foo.private': function(){
},
bar: function(){
this.foo(); // Allowed
}
})
});
From a DSL perspective, it seems better than "$.concrete.private()".
You could even hijack the underscores and automatically attach as private any method that starts with an underscore. It's the closest thing to a convention that JavaScript has in this area - why not adopt it?
The advantage of "protected" rather than "internal" is that people have heard it 100 times before.