KBD

Keith Devens .com

Monday, September 8, 2008 Flag waving
Beer is living proof that God loves us and wants us to be happy. – Benjamin Franklin

Archive: June 22, 2004

← June 21, 2004June 23, 2004 →

Daily link icon Tuesday, June 22, 2004

Protest Warrior

This is a great account of a student fighting for non-left free speech rights as his school. I laughed out loud at some of the interactions he recounts:

On the sign saying "End the Arab Occupation of Jewish Land" she said "what if instead of Arab it said nigger!" I told her that wouldn't make sense because black people aren't occupying Jewish land, and that Arab was not a racial slur.

What's fascinating, reading the thing, is how anti-intellectual, and (dare I say it?) closed-minded the students are. It's amazing to see their inability to think. That the kid remained calm and composed the entire time is very impressive. Kudos to him.

Via The Smallest Minority

http://www.electoral-vote.com/

Check out the Electoral Vote Predictor 2004 at http://www.electoral-vote.com/

Push vs. Pull templating

I've heard good things about SmartTemplate and I'm thinking of using it for my site. Syntax issues aside, one of the biggest distinctions between different templating systems is that of "push" vs. "pull" templating.

I don't know that anyone has used these terms before, so I'll define them:

  • A "push" templating system is one in which you "assign" variables to the template processor and then are able to reference those variables in your template.
  • A "pull" templating system is one in which you reference variables in your template and the templating system then figures out how to populate those variables before injecting the data into your template.

SmartTemplate is a classic "push" templating system, as you can see from their "hello world" example. So are all other templating systems I know of, including Smarty (see their crash course). I actually don't know of any templating systems that implement the "pull" style, though I was seriously planning to modify Cheetah to enable this. Unfortunately, I'm no longer planning to switch my web site to Python so that's not going to happen anytime soon.

I was going to write more here and provide examples, but suffice it to say that it seems like using a "pull" templating system can reduce the coupling between your template and your controller because the controller doesn't have to know what variables your template needs. All your system has to provide is a way for the template processor to know what functions you make available to fill data, and maybe what variable names are associated with what data (in other words, what functions can provide that data). This way, instead of populating the template with data "manually" for each template you have, you can, just once, create a table that maps functions to variable names, and then you can use the variables in that table for as many templates as you have. So, it's sort of like an O(1) algorithm vs. an O(n) algorithm.

This can be implemented in two ways:

  1. On each variable access, a lookup is done to see if that data has been retrieved yet. If it has, use it in the template. If not, cache it and then use it in the template.
  2. Do some static analysis on the templates and keep track of all variables that are used in each template. Then, on execution, the template processor pre-caches all variables that are used in the templates you're filling.

Option 2 saves a lookup on each variable access, but it's impossible to account for all conditionals and you may wind up caching more data than you actually use for the request. This also limits you on how much flexibility you can allow within the template to control exactly what data you get back since the template processor caches all data prior to template execution (though, arguably you shouldn't be able to have that much control within the template anyway).

So, assuming pull templating can be implemented efficiently, wouldn't this be a better way to do templating? Rather than maintaining the templates along with the code that populates the data for each template, with a pull templating system all you have to maintain is the one lookup table. You basically populate it with functions for all the different data your web site can provide, and then you can use those data at will within your templates.

The Spirit of C

There's a great article by Greg Colvin over at Artima on the Spirit of C. I'm a little indignant about some of his comments about Java on the third page (it pains me to count Java in C's lineage), but the article as a whole is very enjoyable.

The article is also very well written. Colvin weaves a discussion of typing throughout, and recounts the transition from B's typeless nature, to adding types in C and more in C++, to adding templates (generics) in C++, and continues on to discuss future possibilities for type inference that could bring C++, or another language such as D, back to the feel of typelessness that the C family of languages lost in their transition from B. His discussion of Java didn't have anything much to add to this thread in the article, which was another reason I disliked that part of it. However, the type inference mentioned is currenly a staple of languages in the ML family, and his account of the evolution of these languages makes it feel as if ML-style type inference will inexorably work its way into more mainstream languages over time.

There's also this neat tidbit about C++'s templates:

Although object-orientation was the initial motivation for extending C to C++, the most powerful extension has turned out to be the generic programming facility provided by templates. Templates were introduced to allow for type-safe containers, so that one could define a class like list<T> just once and then use it for any kind of list element. But in 1994 Erwin Unruh brought an innocent-looking little program to Santa Cruz that failed to compile, but caused the compiler to generate a sequence of prime numbers in its diagnostic output. I recall being mystified, then amused, then horrified. By introducing templates we had inadvertently added a Turing- complete meta-language to C++. At that point we could have restricted the template facility to prevent such meta-programming, but instead we took a gamble and embraced it, which cost us no end of pain as the impact of templates rumbled through the language and library.

Bush is not a conservative

Bush is officially not conservative. I've known this, of course, but this is one of the most clear illustrations I've seen (besides his signing of the enormous new medicare 'entitlement') of his non-conservatism[1]. This is why I find it so incredulous when people refer to Bush's administration as some kind of "extreme right wing" something or other.

Footnotes:
[1]: dare I say... liberalism

HTML fragment highlighter

Oh goody, Paul links to this HTML fragment highlighter in Javascript. Now if I decide to implement this I might not have to write my own.

Though, Charles has something to say about the practice of using something like this to highlight search engine results. Charles may have changed my mind on this...

The spam you're receiving is not from me

In case you're coming here to see what that spam from keithdevens.com is about, it's not from me. I've been joe jobbed.

← June 21, 2004June 23, 2004 →
September 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
282930 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 8 posts

Recent comments XML

new⇒Girls, please don't get breast implants

I got implants this year and it was​the biggest mistake I ever made.  I​am ...

75.156.208.88: Sep 7, 8:03pm

Trogdor tattoo!!

Oh, so cute, wowoowow....

Kathy Mead: Sep 7, 6:07am

I hate Norton Antivirus

Long long live AVG I love you!...

kevin sands: Sep 6, 7:31pm

I hate ASP.NET

CF, why pick that piece of trash?​Cold Confusion. Is it finally​really a OO...

ColdConfusion: Sep 5, 8:36pm

Maps of Iraq

This is for Linda, I will be​visiting that site some time in the​near futur...

Bob: Sep 5, 1:20pm

Spider solitaire

I don't think the question was​necessarily if there are unbeatable​games.  ...

Jared: Sep 4, 12:44pm

Convert Pantone Colors to RGB and Hex - Color Conversion Chart

The colors on those website don't​seem to relate to the pantone data​we hav...

blah: Sep 3, 10:12am

Generated in about 0.069s.

(Used 7 db queries)

mobile phone