
Porting Flask to Go – Jinja2 to Pongo2 - eatonphil
http://blog.thinkful.me/porting-flask-to-go-jinja2-to-pongo2
======
Goranek
Last 2 years I've been using Go (instead of Python), even for webpages & apis.
I'm actually considering going back to Python(for webpages and apis) because
dealing with database in Go is really ugly. Currently available orms are
nowhere near as useful as sqlAlchemy or django orm :(

~~~
alberth
ORMs?

Am I alone when I say that I still hand code SQL into my applications?

Regardless of what web framework I'm using (e.g. Pylons/Rails/Django/etc), I
still hand code SQL statement in my applications.

I've had far to many times ORMs unexpectedly nuke performance and have other
issues than what's it's worth gaining by using an ORM.

~~~
reinhardt
By "hand code SQL" I hope you really mean using prepared statements of
whatever language/framework you're using, not concatenating strings with input
values. If not, say hello to SQLi.

------
davexunit
String-based templating is a bad pattern fraught with security issues that
shouldn't be translated from old languages to new ones.

~~~
jamespo
I'm interested to hear an alternative, particularly one that will work with
separate front end dev teams etc.

~~~
xaritas
Enlive and related libraries for Clojure, Lift for Scala, and heist for
Haskell use node transformation. I know that there are a few others I'm
forgetting. Basically given a fragment of an HTML 5 or XML document, your view
functions transform it into a different fragment. E.g. in Lift, given

    
    
        <div class="greeting-container" data-lift="SayHello"><span class="greeting">lorem ipsum</span></div>
    

And a transformation:

    
    
        ".greeting *" #> "Hello World"
    

The output will be:

    
    
         <div class="greeting-container"><span class="greeting">Hello World</span></div>
    

See [http://exploring.liftweb.net/master/index-5.html#entry-
CSS-T...](http://exploring.liftweb.net/master/index-5.html#entry-CSS-
Transforms-0) et alia

With this technique, your designers can create pure HTML and assets, with no
logic in the templates. Basically they create static mock-ups and then the
developers "enliven" them.

I prefer this but I don't imagine it will ever become mainstream.

React's JSX is also (as far as I can tell) node based, but with a lot less
power (you can really only do insert operations, and the operations don't
really compose well).

~~~
tootie
I recently did a project using this type of template system and it was ok, but
not really better than string-based templating. You're really still doing
String-based templating except you're embedding all your directives in data
attributes and it gets super messy and unreadable.

------
fidget
Oh thank god. Go is bearable in most areas, but the template system makes me
weep. Is there any particular reason the string concatenation doesn't work?
Seems special enough to be specialcased ;)

~~~
tapirl
You can use {{print .foo.bar "string"}} and {{printf "%sstring" .foo.bar}} to
concat strings in golang template, or even simpler way:
{{.foo.bar}}{{"string"}}.

