TurboGears: Python on Rails? 279
gcantallopsr writes "If you liked Ruby on Rails and its 15m intro video (.mov) you will probably like TurboGears and its 20 minute wiki tutorial. (.mov) It shows you the development of a simple wiki in just 20 minutes, and there is a text version of the tutorial. TurboGears uses Python, SQLObject, CherryPy, Kid, MochiKit and some extra pythonic glue to help you to (in their own words) 'Create a database-driven, ready-to-extend application in minutes. All with designer friendly templates, easy AJAX on the browser side and on the server side, not a single SQL query in sight with code that is as natural as writing a function.'"
20 mins vs 15 mins!! (Score:3, Funny)
(oh wait, they did ajax as well..
Re:20 mins vs 15 mins!! (Score:3, Funny)
Re:20 mins vs 15 mins!! (Score:2)
Wiki sites are _extremely_ useful for all sorts of things far transcending OSS and Wikipedia both.
Re:20 mins vs 15 mins!! (Score:2)
FYI (Score:2)
no sql? (Score:3, Insightful)
Why is this an advantage?
Re:no sql? (Score:5, Informative)
Object/relational mapping (Score:2)
It shows a high level of abstraction when you access the DB by simply loading/persisting objects
An idea that is at least 15 years old, and has never worked very well either. The problem is most relational database schemas (structure, types) do not map cleanly C++ or Java to objects. From what I've seen in corporate applications the design of database and software are typically done by separate teams with different modelling skills and design priorities. As a software developer I want speed and simplicit
Re:Object/relational mapping (Score:2)
Re:Object/relational mapping (Score:3, Interesting)
Re:no sql? (Score:3, Insightful)
Last time we used an object-to-sql mapper was quite some time ago, so my info might be outdated:
We attempted to create objects (in Python) to store a lot of attributes ( > 30 ). The design explicitly asked for a "flat" database.
All this happened inside Zope [zope.org]/Plone [plone.org], so we tried out the Archetypes [plone.org], which come with a hand attributes (or better PropertySheet) to SQL mapper. But the code was that ugly, it crea
SQLObject rocks! (Score:5, Informative)
One of the nicest features of SQLObject is that it insulates you from the peculiararities of the database's SQL syntax, so you don't need to put any SQL code directly into the Python code (but you can if you need to for efficiency or if you're willing to write non-portable code).
The SQL database abstraction layer is an important feature of SQLObject, that Ruby on Rails doesn't currently support -- you have to write database dependent SQL code mixed in with your Ruby code.
SQLObject lets you write generic SQL queries with normal Pythonic expressions and operators, which are automatically translated into the database dependent SQL syntax by the database driver. So you don't have to change any of your Python code to port it to a different database, and you don't have to mix together two different notations, or quote a bunch of SQL strings in your Python code. It's a much more "pythonic" way of database programming than raw SQL.
The great thing is that it's so convenient and the syntax is so simple, that you can use the interactive Python shell to browse and test out and edit your database. It's trivial enough to type in some Python code on the keyboard that loops over the results of a query, performs some complex logic, and validates and edits a bunch of rows in the database. Much more powerful and easier to use than anything you can do with raw SQL.
-Don
Re:SQLObject rocks! (Score:2)
Re:SQLObject rocks! (Score:2)
ActiveRecord basically autogenerates methods to link classes together based somewhat on the data found in the SQL database.
What people are talking about here is the exact opposite... generating the SQL from the code.
Of course, Ruby also has at least one method to do this already... it just isn't part of Rails. Yet.
Re:SQLObject rocks! (Score:2)
Ruby already has Og/Nitro [rubyforge.org], which drives the SQL from the code. Developers can focus on thinking in terms of their object model and object relationships, and let Og, the ORM part, handle the database work.
Many developers find this way of working far more natural than spreading their object definitions over multiple locations (SQL definitions and Ruby code).
Good to hear, though, that Rails continues to pick
Re:SQLObject rocks! (Score:2)
I'ts what I use. So I never have to manually create any database fields or tables.
Re:SQLObject rocks! (Score:2, Interesting)
Re:SQLObject rocks! (Score:3, Informative)
There's your problem -- you're mixing SQL code in with your app code. Bad developer! Bad! You're introducing SQL injection holes (I don't care how well you think you're filtering your input, chances are you missed something, especially if you're trying to do so in a DBMS-agnostic way). While an abstraction
Re:SQLObject rocks! (Score:5, Informative)
There's a reason why stored procedures are important, and it doesn't have anything to do with perceived performance increases from not having to re-parse the same SQL code every call (that's definitely a benefit, but it's minor). In this case, stored procedures shelter you from SQL injection attacks
Whereas this is true, it's also true that using "?" parameters for any user-entered values can solve the SQL injection problem just as well.
Re:SQLObject rocks! (Score:3, Informative)
I'm not sure that they do. In fact, I'd go so far as to say that this doesn't make much sense at all. Not that its hard to protect against injection attacks, though.
Let's say you have a stored procedure called "getnumber" that takes two args.
Your goal is that this procedure is going to protect you from injection attacks; that you can put two untrusted args into it and you won't have to worry about someone using the procedure to do some
Re:SQLObject rocks! (Score:2)
And you seem to forget another basic thing. Even if you too the unrestricted type string as the parameter type, simply using stored procedures pretects you from all SQL injection. Stored procedures are compiled. All the statements in the procedures need no parsing anympore, they are already executable binary. No matter what you write i
Re:SQLObject rocks! (Score:2)
Like that number I used in the injection was typed? It was clearly a number, and the stored procedure would have recognized it as such. Didn't matter, did it?
No matter what you write in those arguments, at runtime there is no parsing anymore and no ambiguities by cleverly chosen strings matter to the parse anymore...since it is simply not used.
That only works if you ca
Database portability (Score:2)
Of course, for the plain SQL procedures that many or most of your stored procedures will be that's no problem at all. Porting your procedural stored procs isn't going to be too bad so long as they're all well docum
Re:SQLObject rocks! (Score:3, Insightful)
I'll take that "if" to mean you haven't read the documentation and didn't actually watch the video. Stop frothing at the mouth about SQL injection holes. If you had bothered to watch the fucking video (which you didn't), you'd notice it has specific mechanisms to deal with them.
Also, its main purpose isn't to "catch bugs", it's to make things easier on the programmer. Abstraction toolkits like this are good. God
Re:SQLObject rocks! (Score:2)
About optimization. If you need to do lots of specific lookups, you can do your own indexes. Have an extra dict that points to a list with the ids for that record. {'kw1':[id1,id2],'kw2':[id3,id1],}. Or better, use ZODB + ZCatalog.
Re:SQLObject rocks! (Score:2)
This [rubyonrails.org] doesn't look at all like database dependent SQL code... SQL queries are an option in Ruby on Rails, but active record tries to make you avoid them as much as possible.
Re:SQLObject rocks! (Score:2)
Hmm, SQLObject sounds interesting, but I'm confused.
All the Ruby demos I've watched made a point of showing that you didn't have to write SQL statements. You wire Activerecord up to a database you've made (the "wiring" can be as simple as specifying the server/db/table - and it infers the rest so you can build what
Re:SQLObject rocks! (Score:2)
In pretty much every Ruby tutorial I've seen (including Agile Web Development with Rails [pragmaticprogrammer.com] ), the sequence goes: write the SQL, write the class, let Rails infer what isn't worth specifying.
More specifically: Rails makes a vast number of assumptions about the manner in which you store your
Re:SQLObject rocks! (Score:2)
I'm going to assume you haven't actually
Re:SQLObject rocks! (Score:3, Insightful)
stored procedures and triggers *are* code - its a hack to follow the "do it all in the database" mentality.
no kidding, they are indeed code, but this code mostly is on the other side of the database pipe/socket/stream/ which is very important. for example if you update 500 000 records then a database side trigger is affordable ... but any hack in sqlobject or is just awfully slow and inefficient.
... but it al
dont get me wrong here, i like the sql to object and vica versa mappings, the idea is cool
Re:SQLObject rocks! (Score:2)
for example, by using functions it means i can write to one table, then write a pre culminated figure into ano
Re:no sql? (Score:5, Informative)
Other people have answered in-depth, but the short answer is:
a) You do not need to worry about which vendor's dialect of SQL syntax you're using - provided you know how to create and populate the tables in any database system, you can switch at the drop of a hat if you need or want to.
b) Provided the layers are stable, it protects you from SQL query injections. The abstraction layer does the escaping for you.
c) Abstracted queries makes queries 'just another function/method call', and you get ordinary data structures back. This in combination with a) and b) and a competent framework (Rails, Django, TurboGears, Cake, Trax, WebObjects) makes coding much quicker as you don't have to keep the semantics of SQL and your database in mind - just the model itself.
There are *many* nuances to this, but the above three are some of the most pertinent ones. Peruse the other comments if you want to get in-depth.
Re:no sql? (Score:3, Insightful)
It makes it easier for the programmer.
However, I really wrote this to say what it is not an advantage. I have two words for you: Outer Joins.
First of all, an Outer Join (of which LEFT JOIN is the most common) is used to get information from two tables, whether or not the information in one table has matching information in the other table. A real world example would be a list of customers and the number of orders they've placed with your business. With a normal (inner) join
Re:no sql? (Score:3, Informative)
Re:no sql? (Score:5, Informative)
Don't let anyone fool you into thinking that a persistance layer will be less development work for you - I have found this to be untrue. I can use automated tools to get myself 80% of the way there. For anything substantial, though, it always seem to wind up being more work as I figure out how to configure & trick the persistance layer into giving me my data in the most efficient way. This can be frustrating when you know how to accomplish the same thing in 5 seconds using plain SQL. Maybe it's just me?
But, if you do manage to get over the hump, the benefit is that your business logic layer is very clean with no DB code whatsoever. If you use it properly, you can get 100% separation between these layers.
If you're using a strongly typed language, you get the added bonus of compile-time checks for certain illegal assigment errors. You don't have to fumble around with things like converting dates into SQL. You don't have to check for SQL injection. Lots of other little things.
Re:no sql? (Score:2)
Ruby on Rails, proper noun: The VisualBasic of the
Web, making the first ninety percent of what you need to do easy by
making the last ten percent impossible.
Re:no sql? (Score:3, Informative)
If there is something you need to specifically query by hand in SQL you just use find_by_sql in Rails. I'm not sure how this is configuring and tricking it?
Question (Score:3, Interesting)
> being more work as I figure out how to configure & trick the
> persistance layer into giving me my data in the most efficient
> way. This can be frustrating when you know how to accomplish
> the same thing in 5 seconds using plain SQL. Maybe it's just me?
That raises a question about these persistence layers. Most of the tables we create use an "always insert, never update or delete" model so we can keep track of who made the chan
Re:no sql? (Score:2, Funny)
It's obviously much more efficient to retrieve a million records, create a million objects and count those objects with a certain property than runnig a simple "select count(*) from x where y=z" against the database.
If this assumption does not hold, you should build caching, optimizations etc. into the persistence framework, until you have a database sitting
Re:no sql? (Score:2)
- is an absolute PITA to assemble dynamically, involving lots of icky string mangling;
- is often rather ugly; and
- is not trivial to do safely - it's way too easy to expose SQL injection holes.
Re:no sql? (Score:2)
I've used languages with built-in database integration. In particular I did a bit with Progress 4GL. Progress isn't magic by any stretch (and it's tied to a database that makes MySQL 3 look advanced), but in my experience it did significantly reduce the frequency with which I had to start
Re:There are too many ways to answer that (Score:2)
Re:There are too many ways to answer that (Score:3)
As opposed to...?
As opposed to using transparent persisting of objects, e.g. with ZODB [dion.ne.jp] (which doesn't use SQL at all) or other persistance frameworks (which translate everything to SQL behind the scenes).
Re:There are too many ways to answer that (Score:2)
As opposed to SQLObject, [sqlobject.org] which was mentioned in the summary. It allows you to make the objects in your program persistent by transparently storing them in a traditional SQL database. All you have to do is inherit from a base class and set/get the object's attributes normally.
Re:There are too many ways to answer that (Score:2)
Re:There are too many ways to answer that (Score:3, Informative)
I'm not disputing your basic point, but there are many Python implementations. Off the top of my head:
CPython (aka "standard" Python)
Jython
Stackless Python
IronPython
PyPy
CPython, Stackless, and Jython are real production implementations.
PyPy is rapidly headed that way (and already self-hosting and passes more than 95% of the Python compliance tests). One of the primary developers is Armin Rigo, who did psyco (the specializing dynamic Pyth
My Experience (Score:3, Informative)
What is natural about that? (Score:3, Interesting)
So what is so natural about writing a function? I would have though if it is based on Python it would be OO with behavioral methods rather than procedural function calls.
Why is everyone clambering to find the 'next' language for programming in the small when quite clearly a good language for programming in the large is what is required - at least for enterprise applications (I'm going to include wikis in that for now).
Video software (Score:4, Insightful)
Re:Video software (Score:4, Informative)
http://www.ambrosiasw.com/utilities/snapzprox/ [ambrosiasw.com]
Re:Video software (Score:5, Informative)
What software do people use for making these neat videos?
vnc2swf [unixuser.org]
And to bring us (nearly) back on topic, the latest version is written in python!
Re:Video software (Score:2)
Personally, I'd say "Interesting". The guy you're replying to appears to be trolling there though, don't worry about it.
torrent (just in case) (Score:2, Informative)
OpenDoc Cookbook (Score:4, Insightful)
Re:OpenDoc Cookbook (Score:3, Interesting)
That's exactly what I found. I was already familiar with Python in non-web application domains, so I started looking around for decent web application platforms for Python. I settled on mod_python, but the templating was awful, and none of the alternatives seemed
Perl on rails? (Score:2)
Re: (Score:2, Funny)
Re:Perl on rails? (Score:4, Informative)
Tried it, too bitty (Score:3, Informative)
Re:Tried it, too bitty (Score:3, Informative)
It does look kind of cool, the admin interface is good for _simple_ objects, but seems to start to fall down when you want to construct interesting relationships between the objects, and I haven't started to look into doing custom (or using generic) create/update templates yet.
That being said I'm still suffering a bit of paradigm lag since i
Small Wikis (Score:4, Interesting)
Some friendly competition (Score:2, Offtopic)
I have a competing project: http://entropy.homelinux.org/axis_not_evil [homelinux.org]
It's a collection of Perl modules:
- Gtk2::Ex::DBI ( forms )
- Gtk2::Ex::Datasheet ( datasheets )
- PDF::ReportWriter ( reports )
It's all open-source, cross-platform goodness. It of course uses Gtk2 as the widget toolkit ( which is now a push-over to install on Windows thanks to a number of people providing single-cli
Re:Some friendly competition (Score:2)
Comment removed (Score:5, Informative)
Re:Twisted (Score:2)
Re: (Score:2)
Regular expressions (Score:2)
Visual Programming (Score:2, Interesting)
Amateurs Versus The Industry (Score:3)
Rails is another example of innovation in the open source community, and will be conveninetly forgotten by the people who say there's no innovation in the open source community.
Re:Amateurs Versus The Industry (Score:2)
Anyways, the answer is probably something along the lines of "more complexity = more enterprisey = more money". Corporate execs are big fans of "enterprise" software, cuz enterprise software is adventureous and complex and hard and stuff.
mod_python support? (Score:2)
I'm ready... but I can't get it working (Score:3, Interesting)
I am all ready to try TurboGears, but I have not been able to get mod_python + apache2 running on my mac mini. Does anyone know of a howto that will make my TurboGears web app start when the mac starts and mix TurboGears with static content? I really want to follow this example http://www.jamwt.com/mpcp.py [jamwt.com] but don't quite know how to get past some compilation errors with mod_python on my mac (OSX 10.3) and convert this to be TurboGears-aware instead of just cherrypy aware.
The Kid templates are a great alternative / improvement over the Zope Page templates. The pages are cleaner and I don't have to look up how to do tal:defines as often. I would probably not use SQLObject, but instead start with Durus.
I'm just waiting a few months for it to become even more of a no-brainer for me.
-Jim
Re:Does it scale? (Score:2, Interesting)
Re:Does it scale? (Score:2, Insightful)
I'm sure there's a Google engineer chuckling at the thought of using J2EE for their entire system. If anything Google are quite varied in what languages they use I expect, like any sensible company. If your too tied to a single language, your screwed in the long term.
Java != Panacea.
Peon.
Re:Does it scale? (Score:3, Interesting)
Scaling up, and scaling down (Score:5, Insightful)
I'm still mulling it over and working on it, but I talk some about "scaling down" in this article:
http://dedasys.com/articles/scalable_systems.html [dedasys.com]
You're right of course that you don't want stuff that falls over the first time traffic spikes a bit, but you absolutely must have something that you can use to produce a functional product. You can have the fanciest, most scalable system out there, but if you spend two months twiddling with XML config files, things just aren't going to work out.
Re:Does it scale? (Score:5, Insightful)
if you want to do something for your professional career, don't waste your time with those kind of frameworks.
If you want to do something for your professional career, get familiar with as varied a collection of tools as you can. Know the pros and cons of each. Actually test their performance, make toy projects, steal ideas and patterns. Be opinionated, but prepared to honestly choose the best tool for the job you're given, and to explain why it is the best, to suits and to techies. A few hours getting to know something new is never wasted.
Re:Does it scale? (Score:4, Funny)
A few hours getting to know something new is never wasted.
I once spent a couple of hours looking at VBScript.
I think I came away knowing less about good programming than before, *and* I was out two hours.
Re:Does it scale? (Score:3, Insightful)
If you're building Amazon or a simular service (million visits/day) everything scales. I don't know the exact budget the Amazon portals had, but buying Guido von Rossum or Larry Wall and ten of their favorite programmers for life would've probalby been less than a month of amazons electricity bill.
If I were to rebuild Amazon I'd actually consider Python. If the VM doesn't cut it, I'd hire 20 programmers to optimize it. Which, btw, I don't think would be neccesary.
Another scenario is even more realisti
Proof is Slashdot itself (Score:3, Insightful)
The idea that J2EE is the only system that can handle high traffic sites is a myth.
Re:Does it scale? (Score:3, Insightful)
Using a bulldozer to kill weeds (Score:2, Insightful)
Re:Does it scale? (Score:2)
http://www.loudthinking.com/arc/000479.html [loudthinking.com]
Well, they didn't get Slashdotted (Score:3, Interesting)
Re:Rails everywhere. (Score:3, Insightful)
I've got one major problem with Django (Score:3, Interesting)
The problem I have with Django is that it wants to hijack your database. Sure, they make it real nice to start from scratch. You write classes, run some scripts, and next thing you know, its created a database and all the necessary
Re:Rails everywhere. (Score:5, Informative)
Whilst Rails is an excellent framework for web applications, I've found that it gets exponentially more difficult to work with when your database structures grow more complex than interconnected lists. I recently designed a double-booked accounts program in Rails, and whilst most of the code was simple to design, I quickly got bogged down in handling the accounts-tree and the double-booking of financial records. Here the documentation ran out, and I was forced to go through the Rails source to discover a solution to my problem, which turned out to be less than optimum.
Secondly, whilst I have done a fair bit of work in Ruby, I can't help but prefer Python. If there's little difference between Rails and, say, Turbogears, Django or Subway, then surely it comes down to personal preference. Python web frameworks appear to take a more piecemeal approach than Rail, which can provide a more flexible solution in certain situations.
Can't say I much like SQLObject's syntax, though; but CherryPy seems rather elegant.
Yeah, why use SQL halfway? (Score:4, Insightful)
Shouldn't they be using something else then? Otherwise they'll get the drawbacks of using an SQL database but fewer of the advantages. What happens if performance in a particular area is not good enough?
Say you want to store a session in a database and you want it to expire after X seconds of inactivity.
A simplistic method would be to update the session row each time there's activity. But this would cause lots of writes which would be slower in most proper databases (those that actually write to disk for writes). An alternative would be the databases equivalent of "update sessiontable set lastactive=now() where sessionid='$sessionid' and lastactive+'1 second' <= now()".
With this, you could have thousands of hits per second but only 1 forced write to disk per second due to that query.
How would you achieve this when you're so abstracted away from the SQL database? And it might look strange to others when you try to do the same thing N layers above the database. I'm sure there are better examples.
Those sort of queries are likely to look different on different RDBMSes. You could make a function that looks the same, but someone still is going to have to write the SQL for portability (and sometimes bad luck, it's not possible - DB doesn't support functions or that sort of function). Also, if only the program's session module does that stuff, then what's so bad about leaving the SQL in there? At least then there'll be some context to understand the SQL (and whether it's wrong or right
Sure it's ugly. But if people want it all so elegant and clean maybe they should write _everything_ in some version of Lisp, and not interface with the rest of the ugly real world.
A necessary evil (Score:3, Insightful)
It's a robust data store that isn't tied to any one application language or object model. Often, SQL per se isn't the problem, but differing dialects are.
Use a mapper with the required feature or drop down a level. Abstraction isn't all-or-nothing.
Re:Rails everywhere. (Score:5, Informative)
Rails has taught us some important lessons, but they aren't really technical lessons:
After looking at various pieces of Rails, these lessons have stood out to me, but the particular technology in Rails has not. Sure, there are some good ideas, but nothing radical, and there's good ideas everywhere waiting to be mined. We're not beneath mining other people's ideas, but it does not follow that the result is merely a "replication" in part or in whole.
As for Ruby: I think the two languages are largely equivalent [ianbicking.org] in terms of what you can do. I would not say the same about PHP or Java. As for Rails specifically, I think it is only ahead of Python options in the second derivative. With conscious players the second derivative doesn't mean a whole lot.
Re:Rails everywhere. (Score:3, Interesting)
No one familiar w
Ruby functional? Not. (Score:4, Insightful)
Re:Ruby functional? Not. (Score:3, Insightful)
Perhaps he's not saying Ruby should become a new standard, but that people like you should open your mind just a little, tiny bit, open the door and walk outside - and try a new language for a few hours sometime.
People like you like to get stuck in a rut and cling to what you know, forsaking everything else. For year
Re:Ruby functional? Not. (Score:2)
I think I'll write this one off to the "not being a morning person" thing... I read it as: "Why bother to learn the imitation, have a go at the original". Or something along those lines.
Re:You're not getting "functional programming" rig (Score:3, Insightful)
I think you'll find there's not too much difference between Python and Ruby in this respect. In Ruby, code such as this:
is just about equivalent to this in Python:
Ruby and Python take different approa
Re:Yawn. Perl Catalyst had this same example (Score:2)
Re:Yawn. Perl Catalyst had this same example (Score:2)
Re:Yawn. Perl Catalyst had this same example (Score:2)
Re:Why Mirrors? (Score:2)
http://www.turbogears.org.nyud.net:8090/ [nyud.net]
http://www.rubyonrails.org.nyud.net:8090/ [nyud.net]
Re:if you refuse to use Ruby, I guess this is okay (Score:3, Interesting)
As for the page example, clearly you have no idea what you're talking about. It says:
1. Expose an "index" URL as this method with the "wiki20/templates/page.html" template
2. Look up the content of the page in the database
3. Use docutils to parse the conten