Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Their solution to the template whitespace thing underlines a fundamental difference between what the Go core developers consider to be good language/library design and what I do.

To me adding the - to the template tag {{foo -}} to get rid of whitespace on that side of the tag is totally unintuitive and a really kludgy solution. Sure, it's terse and being terse can be nice, but terseness to me probably doesn't even make it into my top 10 concerns when designing a language or library.

In my mind a lot more thought and consideration should be put into solutions for problems that are going into core libraries. Stuffing cute hacks into the core libraries willy nilly leads you to PHP. The consequences of which I deal with daily.



This change simply draws from Jinja, which has had this feature for nearly 10 years[0]. It's a simple and efficient solution to the problem of trimming whitespace on either side of a template tag, I fail to see what is kludgy about it (and intuitiveness is in the eye of the beholder). In my experience it's clear, simple and doesn't make the template less readable.

> Sure, it's terse and being terse can be nice, but terseness to me probably doesn't even make it into my top 10 concerns when designing a language or library.

The whole point of this feature is to be terse, otherwise you could already use template comment to trim formatting whitespace.

[0] http://jinja.pocoo.org/docs/dev/templates/#whitespace-contro...


Perl's Template Toolkit has had this feature since at least 2001 (and I remember it being available before that but my googlefu is failing me right now.)

cf http://www.perl.com/pub/2001/01/tt2.html

> If these tags are replaced with [%- -%] then the preceding or following linefeed is suppressed.


Nice, thanks for the history lesson. Now I wonder whether Armin Ronacher got it from there or independently reinvented it.


> The whole point of this feature is to be terse...

I get that. I don't think you understood my objection, which was that being terse is not as important to me as being elegant and easily understood. {{foo -}} is not clear looking at it what that - is gonna do. You have to already know, or look it up. There is basically no way to know from context what the desired behavior is. That's bad design IMHO.


How much programming language syntax is really intuitive, as compared to what you've grown familiar with over time?

Once you use the Go(/Jinja/Perl) syntax once or twice, then putting a minus sign to remove whitespace will be easily understood.

I am interested in an alternative that you find more elegant.


> I am interested in an alternative that you find more elegant.

Why not make it a filter/pipeline (I haven't used template/text in ages, does it support this?), like in Django {{ thing|trimleft }}.


{{ foo -}} does not strip white space from the output of foo. It eats up the following white space.

So "{{ foo -}} bar" renders the same as "{{ foo }}bar".


It's worth observing that while text/template may ship with the core code, it's a very, well, library-y library. Get 10 programmers together and ask about text templating and you'll probably get 11 answers. It's very easy to replace it with whatever floats your boat; it's not deeply integrated into anything else, and just ties in to very standard io.Writer interfaces and such.

Bikeshedding about text/template really is just bikeshedding about text/template moreso than Go qua Go.


That's a fair point, but official libraries should be held to a higher standard, I think.


I fail to see what's so "kludgy" about it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: