Tutorial Name: Pinax Solutions at Pycon 2011 (March 9th)
This year I am yet again part of a two man team providing instruction on Pinax at Pycon. Last year's Long Pinax Tutorial went well, with myself and James Tauber receiving a lot of positive feedback plus some really good constructive criticism.
Based off that criticism and our own experiences since last year's tutorial we decided to make some changes, specifically we wanted our class to be very solutions focused. Think of it as an organized brain dump of how best to start a project, leverage in the Pinax framework plus the rest of the Django ecosphere to do all that tedious make work we so dislike. Using these tools will let you focus on your project's unique attributes, meaning you get to focus on all the fun stuff!
Another big change to the class is that Brian Rosner will be taking over in James' place as co-presenter (last year he was instrumental in reviewing the content of the class). Brian is a Django core committer, a Pinax core developer, the tech lead of Eldarion, and the steward of Gondor. If you like how the current Django admin works, you can thank him for his hard work. Even if he didn't have those credentials, Brian is a great speaker and really patient with questions. He started me on git back back at Pycon 2009 and has been kind to me the times I've screwed things up in git ever since.
The course itself will go over the 0.9 series of Pinax. You'll need a laptop with Python 2.6+ installed (Python 3.x won't work in Django). You should be familiar with Django and Python.
See you there!
Monday, January 10, 2011
Thursday, January 6, 2011
I don't work in a vacuum
Not too long ago I wrote a blog rant called 'Stupid Template Languages'. I suspected I was setting off a firestorm, but I have to admit I didn't quite expect to have the singular honor of having both Armin Ronacher and Mike Bayer respond to me in their own blogs. As one might say, "Danny, you really stepped into it."
My initial response to their entries was to start writing another post that would refute what they said point-by-point. However, while the tone in my original post was somewhat confrontational, the problem is that I didn't want to turn the debate into a sordid affair with drawn sides. You see, I've long respected both Mike and Armin as developers and people. Even if I didn't care about them, all it would do is stir up angry retaliations and steer people away from good tools. So I linked to their responses, let it go, and I hope we can drink over the issue this year at Pycon.
However, if we step away from the tools, the real problem I was addressing in my post was this:
I don't work in a vacuum
Any tool has the potential for misuse. As Alex Gaynor pointed out in Django Dose, he is familiar with the poorly crafted system which was part of the reason why I wrote 'Stupid Template Languages'. Heck, anyone reading this blog has probably run into one of those nightmarish system created by others that we have to maintain, and many of us will sheepishly admit to having been the author of such systems.
When you create a system like that you are making things harder for others to contribute and enhance. Trivial tasks become monumental and the desire to post your sad story to The Daily WTF becomes very strong.
Don't work in a vacuum
There are the well-documented methods called 'best practices' that us programmers ought to follow in order to make our work more maintainable. In the general programming world, patterns like Model-View-Controller (MVC) is a common way to break up pieces of a project into predictable components. In the Python world, we generally follow a set of standards called 'pep-8' for writing our code. Various groups and organizations often have additional standards for naming, tests, and documentation styles.
Standards can be created without wisdom or consideration for real-world issues. Too many tests and documentation can eat up time on a project and cause interminable delays; there are horror stories about developers writing pages of non-technical material in order to produce a single line of working code.
Following these methods and doing so with wisdom is like striving for a platonic ideal. It is both gratifying and time consuming to reach for perfection - and this perfection is fleeting because of the shifting requirements of clients, operating systems, and tool changes. To attempt to reach for this helps a person be considered a good developer, but doesn't guarantee that they are actually good.
Breaking the rules
Sometimes you have to abandon best practices. Sometimes the tool at hand makes it hard to perform a task without breaking the rules. In the python world a good example is monkey-patching, which we do with trepidation. In the relational database world, people with a deep understanding of normalization will sometimes indulge in de-normalization in order to boost performance.
Unlike best practices, there is no platonic ideal that clearly states when breaking the rules is a good thing. Ever seen a database created by a developer without any knowledge of normalization who smugly says their database is better because it started off de-normalized? How many of us have seen views where control and persistence is integrally embedded? Or where views are embedded in control code?
In regards to the debate that triggered this post, I've read the following phrase a few times as an argument against my rant: "We're all consenting adults here".
Does that mean we can do what we want? That we can write spaghetti code?
Certainly most people reading this post will know that statement generally refers to variable handling in Python, not the right to sunder the rules of good coding practices. Yet I've seen people use that as a mantra to ignore any sense of good coding practices for python related projects. Which meant that the level of effort to maintain and expand those projects increased at the same rapid rate that the bus factor decreased.
Conclusion
I'll just throw out some well known platitudes:
My initial response to their entries was to start writing another post that would refute what they said point-by-point. However, while the tone in my original post was somewhat confrontational, the problem is that I didn't want to turn the debate into a sordid affair with drawn sides. You see, I've long respected both Mike and Armin as developers and people. Even if I didn't care about them, all it would do is stir up angry retaliations and steer people away from good tools. So I linked to their responses, let it go, and I hope we can drink over the issue this year at Pycon.
However, if we step away from the tools, the real problem I was addressing in my post was this:
I don't work in a vacuum
Any tool has the potential for misuse. As Alex Gaynor pointed out in Django Dose, he is familiar with the poorly crafted system which was part of the reason why I wrote 'Stupid Template Languages'. Heck, anyone reading this blog has probably run into one of those nightmarish system created by others that we have to maintain, and many of us will sheepishly admit to having been the author of such systems.
When you create a system like that you are making things harder for others to contribute and enhance. Trivial tasks become monumental and the desire to post your sad story to The Daily WTF becomes very strong.
Don't work in a vacuum
There are the well-documented methods called 'best practices' that us programmers ought to follow in order to make our work more maintainable. In the general programming world, patterns like Model-View-Controller (MVC) is a common way to break up pieces of a project into predictable components. In the Python world, we generally follow a set of standards called 'pep-8' for writing our code. Various groups and organizations often have additional standards for naming, tests, and documentation styles.
Standards can be created without wisdom or consideration for real-world issues. Too many tests and documentation can eat up time on a project and cause interminable delays; there are horror stories about developers writing pages of non-technical material in order to produce a single line of working code.
Following these methods and doing so with wisdom is like striving for a platonic ideal. It is both gratifying and time consuming to reach for perfection - and this perfection is fleeting because of the shifting requirements of clients, operating systems, and tool changes. To attempt to reach for this helps a person be considered a good developer, but doesn't guarantee that they are actually good.
Breaking the rules
Sometimes you have to abandon best practices. Sometimes the tool at hand makes it hard to perform a task without breaking the rules. In the python world a good example is monkey-patching, which we do with trepidation. In the relational database world, people with a deep understanding of normalization will sometimes indulge in de-normalization in order to boost performance.
Unlike best practices, there is no platonic ideal that clearly states when breaking the rules is a good thing. Ever seen a database created by a developer without any knowledge of normalization who smugly says their database is better because it started off de-normalized? How many of us have seen views where control and persistence is integrally embedded? Or where views are embedded in control code?
In regards to the debate that triggered this post, I've read the following phrase a few times as an argument against my rant: "We're all consenting adults here".
Does that mean we can do what we want? That we can write spaghetti code?
Certainly most people reading this post will know that statement generally refers to variable handling in Python, not the right to sunder the rules of good coding practices. Yet I've seen people use that as a mantra to ignore any sense of good coding practices for python related projects. Which meant that the level of effort to maintain and expand those projects increased at the same rapid rate that the bus factor decreased.
Conclusion
I'll just throw out some well known platitudes:
- Code like you aren't in a vacuum.
- Break the rules only when you have a concrete reason.
- Learn to take criticism well.
Thursday, December 30, 2010
Resolutions for 2011
- Travel to Europe again.
- Travel to Asia or Africa.
- Visit a Disney park.
See a place in the USA I've never been.- Drop the waist size 2 inches and not break any bones.
Go to Pycon and present or teach.Go to DjangoCon and present or teach.Present at LA DjangoContinue my Muay Thai and Capoeira studies, get back into Eskrima, learn some more BJJ, andpractice the forms I know.- Work out at least three times a week.
- Go back east and teach martial arts for a day.
Finish some outstanding legal proceedings.Launch a site that does cool stuff and somehow brings in money.- Get to the point with LISP where I can do cool stuff in it without needing a textbook.
- Blog once a week. That is at least 52 blog entries!
Explain why I wrote Diversity Rocks.
Recap of 2010
This has been an unforgettable year. I can't believe all this stuff happened. I've moved many times, met wonderful people, and seen my life change in ways I could have never predicted.
The good:
The good:
- Met a whole new bunch of wonderful people - relationships to last a lifetime. Arthur, Audrey, Celso, Cody, Daniel, Jacob, Jeff, Lahn, Moriah, Skyler, Todd and others I'm certainly forgetting to my undying shame. Thanks for your awesomeness!
- Presented and taught at Pycon 2010.
- Had a blast in the blizzard of 2010.
- Prepped my house of 9 years for sale and sold it.
- Paid off my debts. I sleep so much better now.
- Left NASA after 5 years and 3 months for freelancing pastures. Thanks Eldarion LLC, Revsys LLC, Holdenweb LLC, and Bryan Klein. Being exposed to some of the incredible code and developers on these projects has made me a better developer. Show me more!
- Flew enough in the spring to put me ahead of notorious traveller James Tauber for about 2 months in sheer mileage accumulated.
- Got to reconnect with a cousin and met his lovely wife and handsome son. Also hung out with my Uncle Al and Aunt Sandra.
- Got a tour of Ames Research Center thanks to Michael Sims. He'll probably be presenting at Pycon!
- Attended another NASA wedding by Mark and Ariel.
- Took a cruise to Mexico on a ship that caught fire just months later.
- Said goodbye to Virginia and moved to Lawrence, Kansas to run with the unicorns and 5 months later to Los Angeles, California.
- Road tripped across the Western half of the country! Twice! Spent 3 days in Las Vegas over Halloween!
- Learned fundamentals of Capoeira from Celso Wills. Wish I could learn more from him. :(
- Learned how to drive and bought my first car.
- Worked on another course for Holdenweb LLC.
- Launched Django Packages.
- Presented at DjangoCon 2010.
- Started Muay Thai classes in Los Angeles. I've done quite a bit of it, but these were the first regular classes I've had in about 16 years.
- Brought my son to Los Angeles so I could spend a week with him for the first time in 15 months.
- Almost up to 7 years without a broken bone!
- Worked another year in Python related technologies.
- Started learning LISP and played a lot more with JavaScript (especially JQuery and JQuery UI).
- Left my students in Virginia. The young ones were especially hard to let go.
- Had to say goodbye to friends in the DC area. Some people I'll miss are Alex, Beth, Brandon, Chris, Dave, Daye, Eric, Jim, Joe, Katie, Muhammed, Pilar, Rich, Renee, Ron, Sarah, Sebastion, Shawn, Steve, and Whitney. I know I'm missing some names!
- I'm far from all my immediate family: Carla, Ciana, Dad, Doug, Michele, Midori, Mom, Seth, and Timiri.
- Watched NOVA Django falter after I left the DC area.
- Had to wait 15 months between spending more than a day or so with my son.
- Didn't really practice much Eskrima all year.
- Didn't blog enough. Last year I blogged almost twice as much!
- Frustratingly, haven't been able to finish something that prevents me from writing about certain things. Yes, this is quite vague, and my hope is to clarify it in a few weeks.
2010 Resolution Summary
Items that are crossed out are completed.
Sell the house, pay off the remainders of my debts, and get my own place to stay. And get a car too.
Travel to another country.
- Take my son to another country.
- Drop the waist size 2 inches
and not break any bones.
Go to an amusement park, visit the beach, and also see a part of the USA I've never been.
Do more educational work for Python related technologies, and that includes getting the Django Education Foundation really rolling forwards.
- T
hrow away at least half my current stuff. I don't have much stuff now, and I want even less. Also, If I don't use or interact with any one of my non-book remaining possessions by 2011, I'm throwing it away.
- Move my blog to my own system and blog at least once a week.
- Get a mountain bike and have reasons to use it.
- Get back into Eskrima, focus more on BJJ,
get into Capoeira.
- Hire a maid. I'm not messy, but I want someone to do the fine tuning of my place.
- Go to
Pycon,DjangoCon, and a new conference.
- Have a beer with
Thomas,Andy, Andy, Tony, Garrick, Bernd, and the rest of Ye Aulde Gange.
Monday, December 6, 2010
Reactions to "Stupid Template Languages"
My blog post on Stupid Template Languages has had some excellently crafted responses by Armin Ronacher, Mike Bayer, and Steve Holden. I respect and admire each of these developers, and their combined projects have made a real impact on my career. I'm happy that our community is large enough to have a difference of opinion, delighted that our base language of Python allows us the power to play with different options so easily, and hope that we can debate our differences of opinion this year at PyCon. The first round of drinks are on me!
- Response of Armin Ronacher, creator of Jinja2 and other projects
- Response of Mike Bayer, creator of Mako and SQL Alchemy
- Response of Steve Holden, Chairman of the Python Software Foundation and creator of PyCon
Friday, December 3, 2010
Stupid Template Languages
For years I've been absolutely certain that I really prefer stupid template languages any time I'm generating HTML. The less the template language can do the better. Since I spend most of my time coding in Python you might assume this applies just to Python, but I think it also applies to anything where you have the power to readily mix HTML generation and code.
The biggest annoyance I have with smart template languages (Mako, Genshi, Jinja2, PHP, Perl, ColdFusion, etc) is that you have the capability to mix core business logic with your end views, hence violating the rules of Model-View-Controller architecture. While the web can be hard to match to MVC, in general you aren't supposed to do that sort of thing. I've made the mistake of putting core logic in the wrong places in the past, but I'm proud to say I've gotten good at avoiding that particular mistake.
I don't work in a vacuum.
I often work on projects crafted by others, some who decided for arcane/brilliant/idiotic reasons to mix the kernel of their applications in template function/macros. This is only possible in Smart Template Languages! If they were using a Stupid Template Language they would have been forced put their kernel code in a Python file where it applies, not in a template that was supposed to just render HTML or XML or plain text.
What it comes down to is that Smart Template Languages designers assume that developers are smart enough to avoid making this mistake. Stupid Template Languages designers assume that developers generally lack the discipline to avoid creating horrific atrocities that because of unnecessary complexity have a bus factor of 1.
So what is a Smart Template Language?
Next comes Genius Template Languages, which take things a step further. These template languages allow you to not only define functions/macros, but also let you embed unrestricted Python (or Java or Ruby or whatever) in the template. This 'feature' lets you code your entire application in the templates! In the Python world what comes to mind is Mako and Genshi, but I'm sure there are many other tools with this 'capability'.
I like Stupid Template Languages!
Stupid Template Languages don't let you define functions/macros. They don't let you embed Python code. They barely let you define variables and often have simplistic control architectures.
For Django efforts, which is about 70% of my work, I like the Django Template Language (DTL). Since it is used by a huge community, there are a ton of useful apps which have it as a dependency. Switching away from it would mean cutting myself off from a large ecosphere of tools I can use to not reinvent the wheel.
Back in my Zope/Plone days I really, really enjoyed the Template Attribute Language (TAL) because it was stupid too. If I needed an XML generation template language and could import it easily I might consider using it again, or perhaps Chameleon, which is a new, improved version . The downside is that they come paired with another tool paired with it, METAL, which gave it macros. My own experience with METAL is that it was all too easy to do what we developers do with Smart Template Languages.
But DTL and TAL are slow!
So what?
If you want to boost your performance, first try caching. There are a ton of tools you can use, with Varnish being one I keep seeing in action. Read the docs on your favorite web framework's caching engine and apply what you learn. And Djangonauts should read up on Mike Malone as much as possible.
If after all that the site still delivers slow content and it appears to be a template language issue, then identify the bottleneck content and consider alternatives for that one portion. My favorite response is a bit of AJAX. Use your framework to render the content as JSON and have JavaScript parse it into legible content, a task which JQuery makes trivial.
The biggest annoyance I have with smart template languages (Mako, Genshi, Jinja2, PHP, Perl, ColdFusion, etc) is that you have the capability to mix core business logic with your end views, hence violating the rules of Model-View-Controller architecture. While the web can be hard to match to MVC, in general you aren't supposed to do that sort of thing. I've made the mistake of putting core logic in the wrong places in the past, but I'm proud to say I've gotten good at avoiding that particular mistake.
I don't work in a vacuum.
I often work on projects crafted by others, some who decided for arcane/brilliant/idiotic reasons to mix the kernel of their applications in template function/macros. This is only possible in Smart Template Languages! If they were using a Stupid Template Language they would have been forced put their kernel code in a Python file where it applies, not in a template that was supposed to just render HTML or XML or plain text.
What it comes down to is that Smart Template Languages designers assume that developers are smart enough to avoid making this mistake. Stupid Template Languages designers assume that developers generally lack the discipline to avoid creating horrific atrocities that because of unnecessary complexity have a bus factor of 1.
So what is a Smart Template Language?
In my own vernacular, template languages that let you write functions/macros are what I call a Smart Template Language. Some of them are brilliantly executed, the example of Jinja2 comes to mind, but invariably I suffer through abuse of its Macro control structure as implemented by others.
Misery Cubed a.k.a. Genius Template Languages
Next comes Genius Template Languages, which take things a step further. These template languages allow you to not only define functions/macros, but also let you embed unrestricted Python (or Java or Ruby or whatever) in the template. This 'feature' lets you code your entire application in the templates! In the Python world what comes to mind is Mako and Genshi, but I'm sure there are many other tools with this 'capability'.
I like Stupid Template Languages!
Stupid Template Languages don't let you define functions/macros. They don't let you embed Python code. They barely let you define variables and often have simplistic control architectures.
For Django efforts, which is about 70% of my work, I like the Django Template Language (DTL). Since it is used by a huge community, there are a ton of useful apps which have it as a dependency. Switching away from it would mean cutting myself off from a large ecosphere of tools I can use to not reinvent the wheel.
Back in my Zope/Plone days I really, really enjoyed the Template Attribute Language (TAL) because it was stupid too. If I needed an XML generation template language and could import it easily I might consider using it again, or perhaps Chameleon, which is a new, improved version . The downside is that they come paired with another tool paired with it, METAL, which gave it macros. My own experience with METAL is that it was all too easy to do what we developers do with Smart Template Languages.
But DTL and TAL are slow!
So what?
If you want to boost your performance, first try caching. There are a ton of tools you can use, with Varnish being one I keep seeing in action. Read the docs on your favorite web framework's caching engine and apply what you learn. And Djangonauts should read up on Mike Malone as much as possible.
If after all that the site still delivers slow content and it appears to be a template language issue, then identify the bottleneck content and consider alternatives for that one portion. My favorite response is a bit of AJAX. Use your framework to render the content as JSON and have JavaScript parse it into legible content, a task which JQuery makes trivial.
Subscribe to:
Comments (Atom)