92 points · by iamelgringo · 16y ago · 73 comments
I was intending on eventually writing my own HAML-type language in Python, but it looks like with SHPAML, I won't have to. Because SHPAML supports raw HTML and doesn't do anything with the {} characters, I can use SHPAML in conjunction with my existing Jinja2 templates. This will enable me to convert my templates organically. The intermediate HTML/Jinja representation doesn't need to appear on disk, so this really looks like an easy way to add "cute" HTML syntax to and existing Python text templating language.
FWIW, there's a C implementation of Markdown called "discount" (http://www.pell.portland.or.us/~orc/Code/discount/) which is crazy fast, easy to embed, and has a couple nice extensions.
(Also, "SHPAML"? Gross.)
SHPAML is not a pseudo-programming syntax. It is purely a markup language, so there are no programming constructs.
SHPAML very deliberately tries to be a lightweight abstraction on top of HTML, unlike wikis and Markdown, which operate at a higher level abstraction. I am a huge fan of wikis, so I value the higher level abstraction at times, but I also see the need for an in-between solution.
I have not used Markdown much, but I see its merits as well.
While generating stub code for class declarations, getters, setters, etc., can help with writing boilerplate-y OO code quickly, anyone trying to read it to decipher its intent will still have to deal with all the clutter. That's more likely to cause problems in the long run.
1) by posting link to it on discussion site you are assumed to be soliciting opinions.
2) it was called "beautiful". A claim so false as to require immediate and forceful contradiction.
2) Beauty is a matter of taste. It might not be the Bar Rafaeli of languages, but I wouldn't think it's so ugly as to require "forceful contradiction".
Coke vs. Pepsi - taste
Python vs. PHP - not-taste
For a better explanation, see: http://www.paulgraham.com/taste.html
The best way I've found of representing XML/XHTML or even HTML for that matter, is with X-Expressions--a subset of S-Expressions. But, they are most useful in a language that fully supports S-Expressions, like Lisp, since you can then use standard functions to generate your markup for you.
These things might be ok for small, tight teams, but I don't see them as buying that much in the long term, as opposed to tools that let you be more productive with HTML.
But the verbosity is also one of its weaknesses for large projects; it adds a great deal of overhead in terms of keeping track of the tags, especially if the HTML needs to be re-arranged. And with no language-supplied rules for how much whitespace to use or where (beyond "all adjacent whitespace is compressed"), there is too much flexibility for a large team to work smoothly. My usage case doesn't mesh with your example, because I'm working in an environment with version control and multiple developers. The guy using Notepad will be told to get a tab-aware text editor, because his changes will mangle the whitespace in the file and lead to unnecessary noise when he commits.
When structure in your whitespace is already desired (to avoid making your version control noisy), you can leverage the fact that you are structuring the whitespace to make it a semantic element. This greatly decreases typing, makes the code easier to eye-scan, and allows details such as proper closing bracing to be left to the compilation tool and not to the developer. I agree with commenters who have noted that HAML has been proven useful for some developers.
I would categorize both SHPAML and HAML as tools that let you be more productive with HTML.
Some of these inventions are a bit nicer than the original thing, but not so much that I'd give up being able to share the code with pretty much anyone and everyone.
I can do HTML pretty quickly with Emacs' psgml mode, and I'm sure there are other people who specialize in it who can do it even faster with other tools. I think that's the place to look for improvements, rather than generating it like machine code.
I agree that there are plenty of other useful ways to represent XML/HTML.
SHPAML does require or even support tabs. The "|" is not for line continuation; it is to separate markup from content.
On the other hand, I don't like new DSLs for writing what is already a simple markup language.
This probably appeals more to people who have made the Python jump and like that whitespace means something, as that's what really makes it terse.
Glad you like it! I have also been hand writing HTML for well over a decade too (as well as other means of producing HTML), so my goal in SHPAML was simply to relieve pain points for an everyday task. It has worked for me.
Finding the potentially missing closing </div> tag has been a common problem I have seen some people face.
but once you've done that, this could be very neat. no processors - just constructing html in python.
(i don't know if this sounds crazy or not, but you can see the same kind of approach in lepl, which i wrote. the main problem is operator precedence.)
apart from stopping people from doing things, are there any what you might call "positive" reasons - advantages - to doing it your way?
I don't buy this. The problem with HTML is not that it isn't expressive enough or that it's too hard to use; it's that arbitrary user code can easily compromise the integrity of your website.
I find HTML expressive and generally easy to use. I wrote SHPAML in a way that I hope preserves the useful expressiveness of HTML, while eliminating some of the 1990s-style syntax.
I do not know what your criteria are for judging a "first-class" DSL in Python, so I cannot comment on the feasibility. My goal was to create a simple markup language that maps well to HTML and plays nice with templates. SHPAML does that.
Browsers don't halt when fed less-than-good HTML the same way an interpreter/compiler dies when fed bad syntax.
In addition, using something like SHPAML requires knowledge of the final output syntax, so the person using it must already know how to code.
Edit: In reading my response, it seems too curt. I definitely see your point, but more so in contexts other than this.
SHPAML users are expected to be literate in both HTML semantics and syntax. The semantics of HTML are not abstracted away at all. The syntax is only abstracted away where it is redundant.
As a couple folks have pointed out, HTML is a pretty simple language. The problem with HTML is not its lack of simplicity; it is its verbosity.
So, if you use SHPAML, you undeniably get the terseness of SHPAML and the powerful semantics of HTML. So the question then comes down to simplicity. Does SHPAML eliminate too much of the simplicity of HTML syntax in trying to achieve terseness?
As far as I am concerned this is a useful abstraction on a trivial problem.
http://shpaml.webfactional.com/tutorial/7
SHPAML is mostly targeted at Python users for now. If you are not using Python, but you like the idea of having a syntax layer on top of HTML, then you should consider other solutions like the markup generator or haml.