The Artima Developer Community
Sponsored Link

Weblogs Forum
Ruby vs Python for Code Generation and Flippin' Templates

16 replies on 2 pages. Most recent reply: Feb 19, 2008 9:51 AM by mike bayer

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 16 replies on 2 pages [ « | 1 2 ]
James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Ruby vs Python for Code Generation and Flippin' Templates Posted: Feb 16, 2008 6:30 PM
Reply to this message Reply
Advertisement
> When it comes to storing structured data, the reason I
> recommend XML (or any other format with named closing
> structures) is that complex data often lacks the
> redundancy in content that clues us to indentation levels
> being incorrect and thus nesting being wrong. If you have
> nested levels of items with arbitrary property lists, how
> do you tell if a given key-value pair belongs to a parent
> structure other than solely by the indent level?

In the case of my own custom structure, I restrict the indents to 4 spaces only. My understanding was that the issue is the mixed whitespace as you mention in your post.

Based on what you are suggesting and my own thought about this I am wondering if I should add an attribute ending character and one for the start of an element.

The reason I wished to avoid this in the first place is that now I have no need for escaping. Obviously, if I want to support attributes with newlines, I'd need to change that anyway. Escaping isn't a big deal really, I've added it to parsers before.

mike bayer

Posts: 22
Nickname: zzzeek
Registered: Jan, 2005

Re: Ruby vs Python for Code Generation and Flippin' Templates Posted: Feb 19, 2008 9:51 AM
Reply to this message Reply
> Thanks for the pointer to Genshi and I particularly
> appreciated its plain text mode:

> Dear $name,
>
> These are some of my favorite fruits:
> #for fruit in fruits
> * $fruit
> #end
>


if you appreciated Genshi's plain text mode (as opposed to its XML mode which is its bread and butter) then you should consider Mako:


Dear ${name},

These are some of my favorite fruits:
% for fruit in fruits:
* ${fruit}
% endfor


note that we are doing real python for the "for" statement, including the colon.

if the {} are killing you, I would note the purpose of them is so that you can say:

thisisa${somestring}with${dynamic}sections${embedded}

i.e. {} is a better delimiter than non-alphanumeric character detection (explicit as opposed to implicit).

Flat View: This topic has 16 replies on 2 pages [ « | 1  2 ]
Topic: Ruby vs Python for Code Generation and Flippin' Templates Previous Topic   Next Topic Topic: Ode to the Python Quick Reference (Ruby Needs One!)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use