Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// this is an example of what the first pass at native (fab) templates will look like:
with ( require( "fab" ) ) fab
( listen, 0xFAB )
( /\// )
( /1/ )
( "This is a template with no variables: a unary app" )
( /2/ )
( "This is a template with {{1}} variable: a binary app." )
( "one" )
( /3/ )
( "This is a template with {{1}} variables: a {{2}} app." )
( "two" )
( "ternary" )
( /4/ )
( "You can even {{1}} them!" )
( "{{1}} and {{2}}" )
( "mix" )
( "match" )
( "Any feedback appreciated:{{1}}" )
( "jedschmidt" )
( 404 );
isaacs commented Apr 28, 2010

why the with?

jed commented Apr 29, 2010

the (fab) function acts as a namespace for all built-in apps, and the with just makes them more accessible. only useful for fab.listen in this case, tho.

isaacs commented Apr 29, 2010

Yeah... it seems like asking for trouble. It'd be better to do something like this:

With is like a disgruntled employee that makes everyone else worse at their jobs.

jed commented Apr 29, 2010

yeah, since in this case it's only exposed at define-time and not run-time, i'm okay with it. once you start inlining functions tho, all bets are off.

isaacs commented Apr 29, 2010

The issue is that if you have functions with variables in that block, you'll find that they significantly slow down. with(){} even makes it slower to read local variables. It's not as deadly as eval, but twice as rowdy.

jed commented Apr 29, 2010

that's my point. if you have any functions in there, i would stop using with entirely.

but i think it's fine here, and actually think that with is a good thing; if it encourages you to keep your functions separately, and therefore more reusable, all the better.

(i'm anti-with otherwise, for sure.)

jed commented Apr 29, 2010

maybe i should make a t-shirt:

i'm with (isaacs)

isaacs commented Apr 29, 2010

I don't think that making functions slow will be enough to convince people not to use it. They'll just decide that (fab) is slow, and whine about it.

That shirt idea is AWESOME.

jed commented Apr 29, 2010

it's possible, but the good news is that like most overly-indented code, writing inline functions in (fab) gets awkward really fast. hopefully that'll be enough of a deterrent.

with ( isaacs ); is probably better tho.

isaacs commented Apr 29, 2010


Wouldn't that shirt just say that I'm with myself?

Which I guess is true...

This looks like BS to me. BuildSugar that is. My crazy template experiment.
I'm still not exactly sure if this code style is horrifying or fabulous.


What if you want a template with more than 2 variables?

jed commented May 4, 2010

the template app actually creates an n-ary app, where n = the highest variable number + 1.

felixge commented May 7, 2010

I'm with (isaacs) too: No with please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment