Hacker News new | ask | show | jobs
by apgwoz 6388 days ago
Study up on context managers, decorators, and meta-classes, which will assist in creating DSLs. However, you don't really need to use these features to build DSLs.

The use of method chaining (think jQuery) can lead to interesting languages.

Or, take Django's chaining for making queries. User.objects.filter(first_name='Andrew').order_by('last_name')

Or, you can get more complicated and do something like described at: http://code.activestate.com/recipes/534150/

EDIT: s/be vital/assist/ on line 1.

2 comments

> Study up on context managers, decorators, and meta-classes, which will be vital to creating DSLs. However, you don't really need to use these features to build DSLs.

Make your mind up. Either they're vital or they're not. You can't have both.

No. I won't make my mind up. I'm not providing a recipe for DSLs in Python. I'm simply stating ingredients and saying "now go create."
I think he/she was more criticizing that you effectively said "X, Y and Z are vital" and then "But X, Y and Z are not vital."

If you'd said "useful" instead of "vital" it'd have been fine logically, but "vital" implies necessity.

Yeah. I ended up editing the original post when I realized it later.
apgwoz has a excellent suggestion. Python has a clean syntax, so you may not need to invent your own. Meta-classes allow you to do the DSL magic behind the scenes. It's less fun than inventing a whole new language, but you can get something working in a couple of hours. Even more useful are the mind stretching exercises inherent in understanding meta-classes and their friends. You will see programming in a whole new light.