Slashdot Mirror


TurboGears: Python on Rails?

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.'"

61 of 279 comments (clear)

  1. 20 mins vs 15 mins!! by VC · · Score: 3, Funny

    How do the python crowd expect to get taken seriously when implementing a wiki takes an whopping 125% as long in python as in ruby!!!!!!????

    (oh wait, they did ajax as well.. ;-)

    1. Re:20 mins vs 15 mins!! by jurt1235 · · Score: 2, Funny

      How does anybody get taken seriously anymore when creating just another wiki?

      --

      My wife's sketchblog Blob[p]: Gastrono-me
  2. no sql? by ambilio · · Score: 3, Insightful
    ...not a single SQL query in sight...

    Why is this an advantage?

    1. Re:no sql? by quigonn · · Score: 5, Informative

      It shows a high level of abstraction when you access the DB by simply loading/persisting objects instead of having to handle queries, result sets, records and all the other low-level stuff. And abstraction (in this case) is good, as it helps the developer concentrate on the relevant parts of the program.

      --
      A monkey is doing the real work for me.
    2. Re:no sql? by wootest · · 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.

    3. Re:no sql? by VGPowerlord · · Score: 2, Insightful
      Why is this an advantage?

      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, customers who have never placed an order would not be listed.

      I keep seeing people mentioned SQLObject, so I'll pull up a selected reference to the SQLObject FAQ: "How can I do a LEFT JOIN?."

      The Simple method on that page is what I believe is referred to as the "1+N" problem. 1 Query becomes 1+N queries, where N is the number of results in the first query's result set. Needless to say, this doesn't scale well.

      The Efficient method is actually much more complicated than the SQL to do the query, and it still takes 2 queries to boot.

      This is why you'll never see a large business relying on an SQL builder to build queries. In the hands of someone who knows what they're doing, hand written queries are optimized much better than generated ones.

      --
      GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
    4. Re:no sql? by mixmasterjake · · Score: 4, Informative

      Persistance layers are cool for a lot of reasons. Though, it definitely takes some getting used to for those of us who have developed a lot of SQL driven applications.

      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.

      --
      TODO: come up with a clever sig
    5. Re:no sql? by ammoQ · · Score: 2, Funny

      Because SQL with its subqueries, joins, unions, aggregate function etc. is way to powerfull. It doesn't match the OO paradigm, therefore it must be bad.
      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 on top of a database.

    6. Re:no sql? by jrcamp · · Score: 2, Informative
      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?

      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?

    7. Re:no sql? by holle2 · · Score: 3, Insightful
      It shows a high level of abstraction when you access the DB by simply loading/persisting objects [...]

      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/Plone, so we tried out the Archetypes, which come with a hand attributes (or better PropertySheet) to SQL mapper. But the code was that ugly, it created a single SQL insert/update statement for each property (attribute) even if it did not change.
      This resulted in an extremely long running "save" operation that you could simply throw the code out of the project ... . The data is now stored in the Zopes own ZODB and gets archived after a while in a SQL DB.
      For archiving purposes a hand-crafted SQL statement is used that runs lightning fast :-) .

      On the other hand, I have seen Java code querying an SQL DB using the Oracles TopLink product to abstract the underlying database. The code was so gross, you simply felt the urge to go and wash yourself after looking at it.

      The result of this experience is:
      • If you want to concentrate on your object oriented approach, stick to databases that can handle objects, like the ZODB (usable w/o Zope if you like).
      • If you have to access mass-data from legacy systems (like e.g. master product data), you have to program SQL, since nothing is faster than that. Make sure the results can be converted into something like a list of dictionaries so handling of the results is more natural in an object oriented manner.
      • Every good programmer should be able to switch between programming languages and be able to access data stored in legacy systems as well. Sometimes the data comes only via an ODBC connector from an old AS/400, but if that is the source of the master data, you have to live with it.
      • SQL databases are not the primary choice to store objects and/or tree like structures. They were designed it the "good ole' times" when everybody though that relational databases were cool. Sometimes it can be much more useful to store a tree in an object persistent storage and put the node data into an SQL DB (for performance).
      • For debugging: If you use SQL code in your project you can actually print out the statements before they get send over to the database so you can simply copy them from your logfile (you have a logfile, do you ?) and run them manually to see if they produce the outcome you want. This is often more useful than enabling query logging on the server since digging through thousands of lines of log-messages can be rather time consuming.
      • For designing: You can build your queries step by step in a "Query Analyzer" using some example data and then embed the results into your code (including the exchange of fixed teststring with variable names).
      • For performance: You might know that you have to run a query 3000 times in a row with different variables (e.g. insert into ...) but you object mapper does not know that fact. Thus you can use one prepared SQL statement and fill in the variables upon execution. This saves a hell lot of time (depending on your database system, some systems are slow either way).


      Ok, I got my flame shield up, let 'em come ...
    8. Re:no sql? by Ian+Bicking · · Score: 2, Informative

      Well, no points for the docs on this one (hey, it's open source) but there is some help for outer joins noted here.

  3. My Experience by HogynCymraeg · · Score: 3, Informative

    I've used Python/SQLObject/CherryPy on a project before. It's very quick to code something useful. SQLObject will change the way you think about how you integrate DBs to web applications. All in all, it's well worth checking out.

  4. What is natural about that? by barcodez · · Score: 2, Interesting

    as natural as writing a function.

    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).

    --

    ----
  5. Video software by The+OPTiCIAN · · Score: 3, Insightful

    What software do people use for making these neat videos? (I realise this is bordering on off-topic :) )

    --


    Believe with me, my saplings.
    1. Re:Video software by jrockway · · Score: 3, Informative

      Since it was made on a mac, my guess is Snapz Pro X.

      http://www.ambrosiasw.com/utilities/snapzprox/

      --
      My other car is first.
    2. Re:Video software by mykdavies · · Score: 4, Informative

      What software do people use for making these neat videos?

      vnc2swf

      And to bring us (nearly) back on topic, the latest version is written in python!

      --
      The world has changed and we all have become metal men.
  6. SQLObject rocks! by SimHacker · · 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

    --
    Take a look and feel free: http://www.PieMenu.com
    1. Re:SQLObject rocks! by ambilio · · Score: 2, Interesting

      Sounds like an Object-Relational Mapper. You can find these for just about any platform out there: Ruby - ActiveRecord, Java - Hibernate (and *many* more), PHP - Propel. Explicit SQL is also optional with these.

    2. Re:SQLObject rocks! by Osty · · Score: 3, Informative

      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.

      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 layer like SQLObject may be better in that regard because it's main focus is interfacing with SQL and thus should be more focused on catching these kinds of bugs, if it's mixing in dynamic SQL queries there's a good chance it also has SQL injection holes.

      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 (assuming, of course, that your stored procedures aren't just dumb "take a string and 'exec' it as SQL code" queries). You may not agree with the people that tell you to use stored procedures to keep your business logic near the data, or that using stored procedures allows you to easily expose only the permissions required (GRANT EXECUTE on the stored proc, rather than having to figure out what tables need INSERT permissions, which ones need SELECT permissions, etc for each app that uses this database), but I don't see how you could argue their protection against injection. Yes, parameterized queries allow you to write dynamic SQL code with some level of injection protection, but that still leaves you with the downside of having SQL mixed into your code.

      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.

      I call BS. First off, SQL is a set-based language. Very rarely do you need to loop over a result set (if you find yourself looping in SQL code, you're not thinking hard enough). Whatever "loop and operate" action you'd take with Python can be done quicker and more efficiently with SQL code than with app code. Second, for Python code to loop over a result set means it has to get that result set. If your database is not local to your web server (bad idea!), that means network I/O costs. You can and should avoid that cost by processing the data first at the SQL Server (hey, stored procedures again! Why return 100,000 rows that you're going to process down to 1,000 when you could just return the 1,000 processed rows in the first place? Why return anything at all when you're going to insert/update data based on what's in a different table?). Finally, while it may be "easier" for a developer proficient in Python and not the SQL dialect used by your chosen DBMS, that's a cop-out. As so many people are so fond of saying, you should use the right tool for the job. In this case, you're trying to use the hammer of Python to pound a screw, when you'd be better off with the screwdriver of SQL. Sure, you may be able to pound that screw into the wood, but it'd be quicker and easier to do it in SQL. Maybe you don't want to learn SQL, in which case you probably shouldn't be working with a database. You have a responsibility to learn how to use the tools you're going to apply to a problem.

      I've intentionally ignored the problem of database portability, because a) you should be using stored procedures, which means you'll want to port them yourself anyway for maximum benefit, b) you should be using a proper DBI layer such that you just have to tell it, "I'm using Oracle now instead of Postgres, do the right thing", and c) because you're using stored procedures, you won't be switching to a DBMS that doesn't support the (*cough*MySQL*cough*) (and yes, I know MySQL "will" support them, but that's still some way off in non-beta form).

    3. Re:SQLObject rocks! by moro_666 · · Score: 2, 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.

      dont get me wrong here, i like the sql to object and vica versa mappings, the idea is cool ... but it always comes with a performance penalty, and if your project planning isnt provisional enough, you might end up using the cute toy in the very wrong space and after all the hussle you just rewrite the code to some sort of optimized stuff. and using the sql-object layer with an additional hack to get the same speed is actually much worse in terms of portability than either one of the pure implementations (either pure object-sql bridge or pure sql code without any bridge at all), and the most likely one to break too.

      choose the right thing for the right job.

      and no, i dont think we need another wiki ... maybe it's time to evolve to a next level and invent something totally new ?
      --

      I'd tell you the chances of this story being a dupe, but you wouldn't like it.
    4. Re:SQLObject rocks! by Trejkaz · · Score: 4, 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.

      --
      Karma: It's all a bunch of tree-huggin' hippy crap!
    5. Re:SQLObject rocks! by njyoder · · Score: 3, Insightful

      if it's mixing in dynamic SQL queries there's a good chance it also has SQL injection holes.

      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 forbid someone make things easier.

      I call BS. First off, SQL is a set-based language. Very rarely do you need to loop over a result set (if you find yourself looping in SQL code, you're not thinking hard enough). Whatever "loop and operate" action you'd take with Python can be done quicker and more efficiently with SQL code than with app code.

      And I call BS on your BS, because you didn't actually read what you were responding to. I'm beginning to notice a pattern here, first you start frothing at the mouth based on speculation from not having RTFV (video), then you do it for not reading the comment you're responding to. They specifically used the descriptive words "powerful" and "easier" not "faster." The issue isn't effeciency, no one is claiming that TurboGears produces the most effecient code. The whole purpose of TurboGears is to make things easier on the programmer, which is what this does. Designing the logic within python, which actually does allow you to do quite a bit more in terms of 'business logic', makes things easier.

      Finally, while it may be "easier" for a developer proficient in Python and not the SQL dialect used by your chosen DBMS, that's a cop-out. As so many people are so fond of saying, you should use the right tool for the job

      No, even for someone very proficient in SQL it's still easier in Python due to these bindings. Of course, not having actually read anything about TurboGears (e.g. the documentation) and engaging and rampant speculation and all, you wouldn't know that.

      And they ARE using the right tool for the right job, you should follow your own damn advice. TurboGears is designed for jobs where EASE is a priority over effeciency. GUESS WHAT, effeciency isn't always the #1 priority, genius.

      You speak boldly, but you can't read worth shit, excercise critical thinking skills nor even follow your own advice.

      I've intentionally ignored the problem of database portability, because a) you should be using stored procedures, which means you'll want to port them yourself anyway for maximum benefit, b) you should be using a proper DBI layer such that you just have to tell it, "I'm using Oracle now instead of Postgres, do the right thing", and c) because you're using stored procedures, you won't be switching to a DBMS that doesn't support the

      A isn't even a "reason", it's just a circular statement. "You'll want to do it because you'll want to."
      B isn't valid either, which leads me to believe that you're not actually a database programmer, since DBI layers don't just magically translate from one proprietarism to another. If you DO use an sql stored procedure, you're forced to stick to strict standards, otherwise the DBI layer becomes useless.
      C is just a lame excuse to bash MySQL, it's not even a real reason. Keep on frothing there, buddy.

    6. Re:SQLObject rocks! by fireboy1919 · · Score: 2, Informative

      In this case, stored procedures shelter you from SQL injection attacks

      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 something you don't want them to do.

        So you run
      "select * getnumber(arg1,arg2);"

      Is this vulnerable to injection attacks? Yes.

      If arg2="32); create user..."

      You see the problem? Stored procedures didn't help. Actually, I'd like to know what stored procedures will do for you that does help.

      On the other hand, having a single place that validates the input does help - pretty much every time, and you're invulnerable. Its not nearly as hard as making sure that there's no buffer overflows.

      This is all that is necessary and sufficient to protect against SQL injection:
      1) Any quote symbols in the user input are escaped so that they won't be considered quotes.
      2) Each user-supplied value is quoted before being put into an SQL statment.
      3) Users are allowed to enter values only. If users are allowed to enter column names, then the data must be validated against all allowed column names. But generally this is stupid. Best to let users enter data only, never metadata.
      4) Users may not enter any SQL.

      Pretty much all of these database converters have one or two points of entry that do 1-2 before doing any kind of optimization/fetching/whatever, and they don't really allow you to do 3-4. Of course, maybe I'm wrong and the GP knows about some mystical forms of SQL injection attacks that I don't. If so, I would certainly like to hear about any injection attempts that can fool this sort of thing. I would also like to hear about some big ORM (object-relational mapping) tools that prove that what the GP says isn't FUD.

      Keep in mind that escaped values are escaped both when they're entered, and when they come out of a database. You pretty much always have to manually unescape them if you want to show them the original way.

      --
      Mod me down and I will become more powerful than you can possibly imagine!
  7. Re:Does it scale? by Anonymous Coward · · Score: 2, Interesting

    Bullshit. J2EE is all about hype, the latest buzzword that clueless managers will use whenever a new project is discussed. People talking about the "power of Java" don't really know what they're talking about, or have never actually used it.

  8. Re:Does it scale? by Anonymous Coward · · Score: 2, Insightful

    Amazon don't use J2EE most of it is written in C/C++.

    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.

  9. Scaling up, and scaling down by DavidNWelton · · Score: 5, Insightful

    Ok, so some of these tools are not suitable for running Amazon. But guess what - most people are not running Amazon! A lot of people don't have the development resources that amazon has, either, so what they are really looking for is a sweet spot that lets them get going quickly, and will grow within reason.

    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

    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.

  10. torrent (just in case) by Anonymous Coward · · Score: 2, Informative
  11. OpenDoc Cookbook by Graymalkin · · Score: 3, Insightful

    I'm definitely not an expert in Python, in fact I've only ever given it a cursory look. However that tutorial was damn impressive. Obviously he had some prior knowlege of Python and using TurboGears but it is really not all that difficult to build something like a Wiki using that framework. As far as web work I've slowly become disenchanted with PHP. It's a good language to be sure but it's simplicity is short-lived. As you want to do more complex things you end up having to work around PHP more than you get to benefit from it. A large web project in PHP ends up structured like a project of similar size in Perl or Python. Between TurboGears on Python and Ruby on Rails it looks like I have some reading to do.

    --
    I'm a loner Dottie, a Rebel.
    1. Re:OpenDoc Cookbook by Bogtha · · Score: 2, Interesting

      As far as web work I've slowly become disenchanted with PHP. It's a good language to be sure but it's simplicity is short-lived. As you want to do more complex things you end up having to work around PHP more than you get to benefit from it.

      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 much better.

      I'd actually gotten most of the way through implementing a PHP compiler for mod_python* before I discovered Kid, the templating system used in Turbogears. It really hits the sweet spot where it's not too rigid like other XML-based templates, but not too loose, unstructured (and just plain bizarre) as other Python-in-HTML systems.

      I'd highly recommend trying out Python + Kid for any decent PHP coders, even if it's not specifically TurboGears (which I haven't tried out yet). After the first couple of days, your productivity will shoot up and you'll wonder how you ever managed to cope with PHP.

      * Compiling to Python bytecode is simple, it's the irregularities of PHP that's the bitch. PHP is a fairly nice templating language, which is what it was originally - it's just the actual programming where it sucks.

      --
      Bogtha Bogtha Bogtha
  12. Re:There are too many ways to answer that by cpghost · · Score: 2

    As opposed to...?

    As opposed to using transparent persisting of objects, e.g. with ZODB (which doesn't use SQL at all) or other persistance frameworks (which translate everything to SQL behind the scenes).

    --
    cpghost at Cordula's Web.
  13. Re:Does it scale? by ashot · · Score: 2, Interesting

    Python is one language they actually use quite a bit

    --
    -ashot
  14. Re:Does it scale? by Scarblac · · Score: 4, 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.

    --
    I believe posters are recognized by their sig. So I made one.
  15. Tried it, too bitty by Boffy · · Score: 3, Informative

    Tried TurboGears, but the fact that it's a glue was way too appparent. I then moved on to trying Django and fell in love. All the stuff TurboGears can do Django can too, but natively.

    1. Re:Tried it, too bitty by aleph · · Score: 3, Informative

      Still downloading the movie from TurboGears (tried streaming, but well.. That wasn't happening too well :)), but I have been playing with Django a bit the past few days.

      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've mostly been dealing with Zope/Plone for the past couple of years, and while that platform isn't without it's problems, it does have a lot of nice features you begin to take for granted.

      I also came across areas where Django would silently fail to do things in the admin interface with no sign of an error anywhere (it wasn't even attempting to insert the new object in the db, nor raising an exception anywhere). That kind of behaviour makes me a bit nervous :p

  16. Small Wikis by xihr · · Score: 3, Interesting

    If you're up for small Wikis, there's always HeyHeyWickie, a Python Wiki in under 4K lines of code (using EmPy and docutils).

  17. Re:Rails everywhere. by hexene · · Score: 2, Insightful

    Although only recently open-sourced, Django has powered real-world sites for several years now. So whilst the project will borrow ideas from other frameworks where it makes sense, it's more of a case of parallel evolution than trying to ape Rails.

  18. Re:Does it scale? by Qbertino · · Score: 2, Insightful

    Wrong.
    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 realistic. MySQL sucks for certain purposes. But if a certain OSS CMS I like only runs with it, but the project is big enough to imperatively require Postgres or Firebird, then the projects budget should allow to patch in support for that DB.

    --
    We suffer more in our imagination than in reality. - Seneca
  19. Twisted by jcr · · Score: 4, Informative

    Also worth checking out: Twisted. I haven't had occasion to use it myself, but people I know swear by it.

    -jcr

    --
    The only title of honor that a tyrant can grant is "Enemy of the State."
  20. Ruby functional? Not. by archeopterix · · Score: 3, Insightful
    Because, like it or not, functional programming has been trying to hit the mainstream for decades without result because functional programming is not as easy and straightforward as imperative programming.
    Ruby is no more functional than Python, even by the most twisted definition of 'functional'. Yup, it uses closures (aka blocks) and that is how far it goes towards functional. For a language to be functional it is essential to restrict side effects (haskell with monads, ocaml with 'mutable'), or at least have some good support for no-side-effects programming: currying, higher-order functions, the "let x = expr1 in expr2" (aka non-destructive assignment) construct and so on. Both Python and Ruby make routine use of destructive assignment, which is the epithome of side effects.
    1. Re:Ruby functional? Not. by csirac · · Score: 2, Insightful

      Ruby is far from perfect and declaring that we should drop all development in other languages and immediately switch to it is just plain fucking stupid and lacking in any pragmatism whatsoever.

      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 years, all I've ever known is C, 8/16-bit ASM, Perl, a few FPGA HDLs... even if I don't do websites or databases, RoR has inspired me to climb out of my comfort zone and take on something new. Guess what? I've discovered a language which looks to be a new favourite of mine. I'm going to use it now instead of where I would have used Perl.

      You can't even distinguish it from Haskell and functional programming, but yet you seem to think you're qualified to say how "perfect" it isn't... no wonder you're posting AC.

  21. Re:Rails everywhere. by arevos · · Score: 4, Informative
    To me it seems like a silly exercise to replicate rails in python or what have you. Ruby is easy to pick up and a nice language to boot. Why bother really? Just learn ruby and get on board.

    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.

  22. Proof is Slashdot itself by arevos · · Score: 2, Insightful

    Slashdot itself uses Apache/mod_perl/MySQL, and there's little between mod_perl and mod_python in terms of performance. Slashdot handles 3 million pages per day without any trouble. Does Slashdot not count as a 'large site'?

    The idea that J2EE is the only system that can handle high traffic sites is a myth.

  23. Re:Does it scale? by m50d · · Score: 2, Insightful

    Google uses python all the time.

    --
    I am trolling
  24. Yeah, why use SQL halfway? by TheLink · · Score: 3, Insightful

    Yeah, that's the part that gets me wondering. People keep talking about hiding away the SQL. But if they don't want SQL, then why are they using an SQL RDBMS in the first place?

    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 ;) ), rather than it being neatly stored with 1000 other nonrelated SQL statements (as functions or otherwise).

    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.

    --
  25. Using a bulldozer to kill weeds by porkThreeWays · · Score: 2, Insightful

    J2EE based web services are 900 pound gorillas. Sure, amazon etc use it, but I don't spend my day making amazon.com's. I spend it getting requests from various departments for single purpose programs that are web based (so we don't have to maintain yet another fat client on the desktop). These simplier frameworks make it possible to make quality web applications quickly. Most of these programs are just a varation on a theme. 2 or 3 tables with maybe a foreign key and 3 or 4 web pages. These frameworks make it possible for me to give them a finished application in a couple of hours so I can spend my time doing more important stuff.

    --
    If an officer ever threatens to taze you, say you have a pacemaker.
  26. Re:Perl on rails? by holy+zarquon's+singi · · Score: 4, Informative
    --
    "...we should just trust our president in every decision that he makes and we should just support that." B.Spears 2003
  27. Visual Programming by youval · · Score: 2, Interesting

    My project, Tersus, uses an alternative approache to web application development. Take a look at http://www.tersus.org/

  28. Well, they didn't get Slashdotted by shis-ka-bob · · Score: 2, Interesting

    I was pleasantly surprised that the TurboGears site not only came up, it came up fast. Quite unusual for a new developer framework appearing for the frist time on Slashdot. Especically since 'Python', 'Ruby on Rails' and 'AJAX' were mentioned, I'll bet they got hammered pretty hard in the last few minutes. So at least we can see that the server scales pretty well with the number of users. This could mean nothing more than the site uses a cached home page and we are seeing the value of (something like) Squid. No matter what the cause, it is encouraging to see thay they didn't get swamped by all of us checking out the new tool.

    --
    Think global, act loco
  29. Amateurs Versus The Industry by Greyfox · · Score: 2
    I've tinkered with rails a bit and I think it's a step in the right direction. What I want to know is, why doesn't anyone in the industry make it this easy? All the commercial solutions seem to be going in the opposite direction, constantly adding more XML files and more layers of API to try to cope with HTTP's deficiencies as an application development protocol. Meanwhile a bunch of amateurs with a semi-obscure scripting language manage to upstage all of them. And if I'm not mistaken, you have to do any xml httprequest stuff in the commercial packages by hand, while rails seems to do it all more or less automatically.

    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.

    --

    I'm trying to teach myself to set people on fire with my mind... Is it hot in here?

  30. Question by g2devi · · Score: 3, Interesting

    > 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?

    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 change, when the change was made, and by whom.

    You have to code, normalize, index, and select from these tables in a particular way otherwise you'd end up with extremely inefficient code. I just don't see how a persistance layer can handle this.

    Another thing, one thing I've learned is that for enterprise applications, data outlives the application and in many cases, it predates the application. In essense, the persistence layer will need to be retrofitted into the application. Top-down GUIs like the ones presented for Rails appear to be of no use. We already know the exact representation of the data so Rails will need to work from the bottom up by default.

    As a side note, I don't see why people are so afraid of a little SQL. Sure it takes time to learn how to master efficient SQL coding, but it's well worth it. It's the most efficient way to deal with most data, and because it's a declarative language, it's often more intuitive than the imperative language you're working in. It's also supported by most languages, so it's universal. If you're using a strict model-view-controller paradigm, database access will be restricted to the model and recast into data objects that can be used by the view and controller. If done correctly, you can rewrite the data code of several applications every day of the week without affecting the view and the controller (i.e. the bulk of your code). From what I've seen, that clarity of what exactly is happening and how complex things are mapped really helps with maintenance and optimization. From trying to maintain persistense layers, I'm left trying to figure out "what on earth is the persistense layer trying to do that is causing so much trouble".

  31. I've got one major problem with Django by jocknerd · · Score: 2, Interesting

    I was very interested in Django since I love Python. It looked simple enough and I was able to get through the tutorials and thought that Django was my holy grail. But then I tried to adapt it to an existing database system I had. And here is where the project failed for me.

    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 tables and indexes. But what if you've already got a database? Well, they provide a way to use your existing database too. But unfortunately, Django wants to add its own stuff to your database. I find this unacceptable. If Django needs a database for its internal administration stuff, fine. Create a separate database for that. But don't throw your tables inside a database that may already be in use for other projects.

    Plus, what if I want this database used for multiple projects. I don't think Django makes that possible.

  32. A necessary evil by Kaseijin · · Score: 2, Insightful
    But if they don't want SQL, then why are they using an SQL RDBMS in the first place?
    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.
    How would you achieve this when you're so abstracted away from the SQL database?
    Use a mapper with the required feature or drop down a level. Abstraction isn't all-or-nothing.
    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....
    If someone already has, why should I do it again?
  33. Re:Object/relational mapping by mikkom · · Score: 2, Interesting
    In other words, I want a single layer of cleverness: My domain model. Object-orientation is all about encapsulating clever. Letting it sieve half ways through to the database is a terrible violation of those fine intentions. And I want no part of it.
    This works fine if you only have one program accessing the database but is terrible if you have multiple clients for example. Even worse if you have real "enterprise" environment with legacy apps and such.
  34. Re:Rails everywhere. by Ian+Bicking · · Score: 5, Informative
    To me it seems like a silly exercise to replicate rails in python or what have you.
    1. TurboGears is not a Rails clone.
    2. Most parts of TurboGears existed before Rails: CherryPy, SQLObject, FormEncode (and Python of course).
    3. Kid is most closely related to Zope Page Templates (from the Python world), not anything from Rails.
    4. MochiKit has a certain relationship to Prototype (the Javascript library from Rails), and is compatible with it. However, it's not that the author particularly likes Prototype.

    Rails has taught us some important lessons, but they aren't really technical lessons:

    1. We shouldn't sit around and say "oh, those poor people using PHP/Java/etc, too bad they don't know about what you can do using X". Instead we should talk more loudly and insistently about the advantages of our platforms. If you do it right people will pay attention.
    2. We haven't concentrated enough on full-stack integration. We've been overvaluing decoupled pick-and-choose components. Full-stack integration doesn't have to mean coupling -- it can just be a matter of presentation, and making sure tools are complimentary. Not all of the Python frameworks are coming at it from this direction, but TurboGears very much is.
    3. Things like screencasts are nice.

    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 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.

  35. Re:if you refuse to use Ruby, I guess this is okay by lcracker · · Score: 2, Interesting

    You're comparing apples to tacos here. The SQLObject example contains the definition of the table, so that it can be automatically created if it does not already exist, where the ActiveRecord example depends on the existence of the table in the database.

    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 content of the page as a reStructuredText document, and get the result as an HTML fragment.
    4. Encode the HTML fragment as UTF-8
    5. Return a dictionary containing the page name and the HTML fragment for usage by the template (or a direct JSON request)

  36. I'm ready... but I can't get it working by MrBlic · · Score: 2, Interesting

    I've been following python web development for a while, and currently have a few sites running with Zope + Zope Page Templates + ZSQL Objects + MySQL and they work great. The only problem is that I want a more lightweight faster server.

    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 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

    --
    Celebrate Excellence!
  37. Re:Does it scale? by swillden · · Score: 3, 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.

    --
    Note to ACs: I usually delete AC replies without reading them. If you want to talk to me, log in.
  38. Re:There are too many ways to answer that by pthisis · · Score: 2, Informative

    Python has ONE (ok, one and a half if you count Jython) implementation

    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 Python compiler that achieved speedups of up to a factor of 100 for numeric code).

    IronPython looks to be abandoned.

    --
    rage, rage against the dying of the light
  39. You're making the wrong comparison by Estanislao+Mart�nez · · Score: 2, Informative

    You're saying that a statement that does *less* than the other one is easier to understand.  Way to go, Sherlock.

    Now let's try a comparison between statements that do the *same* thing.  First, the one using the block to manage resource allocation and deallocation:

        Net::HTTP.start( 'www.ruby-lang.org', 80 ) do |http|
          print( http.get( '/en/LICENSE.txt' ).body )
        end

    ...and second, the *real* equivalent without blocks:

        begin
          http = Net::HTTP.start( 'www.ruby-lang.org', 80 )
          print( http.get( '/en/LICENSE.txt' ).body )
        ensure
          http.close
        end

    Needless to say, the block version is shorter.

    Anyway, this pattern you see here is one of the most common Ruby idioms, which you should get the hang of if you're learning the language: using blocks to decouple code that manages a resource *through its whole lifecycle* from code that use the resource.  It's always like this:

        Resource.acquire {|resource|
          # do stuff that requires resource
        }
        # resource has been released, without you having to say so,
        # even if the there was an exception

    The same pattern applies to files, network connections, database result sets, thread locks, anything.  Sure, it's unfamiliar to *you*, but you only need to learn the pattern *once*, and you reuse it all the time for different kinds of resources.

    And to top it off, you can write your own methods like acquire() above in Ruby itself, just by using yield.  This is not some special syntax sugar for resource management--this is just blocks.  Here's the pattern for writing a method like acquire():

        def acquire
          begin
            resource = low_level_acquire()
            yield resource
          ensure
            resource.low_level_release()
          end
        end

  40. Re:Rails everywhere. by Ian+Bicking · · Score: 2, Interesting
    I added this feature (using the database as the source of the model) to SQLObject a couple years ago, before I'd ever heard of Rails. But, after adding it, it never seemed like that neat of a feature, and it only gets moderate use. I don't claim SQLObject was the first... rather that it's not that great a feature compared to using the class itself as an authoritative representation (which no one uses in Rails because they don't have a choice, since ActiveRecord doesn't implement that).

    No one familiar with Python development should have ever been wowed by anything Rails does from a technical point of view. All the surprise about these features is coming from Java and PHP people, who have lived in darkness and to whom all light is blinding and full of amazement. I don't have a problem with that -- you'll get no arguments from me that Rails is better than what PHP or Java offers. But it doesn't mean Rails is novel.

  41. Re:You're not getting "functional programming" rig by arevos · · Score: 2, Insightful
    Here I'd respond that Ruby provides much more natural support for higher-order functions (because of blocks), its libraries are designed around them. It's actualy hard to avoid using them any time you program in Ruby.

    I think you'll find there's not too much difference between Python and Ruby in this respect. In Ruby, code such as this:

    method(method_args) { |yield_args| code }

    is just about equivalent to this in Python:

    for yield_args in method(method_args): code

    Ruby and Python take different approaches to the same problem, but I'd hesitate in saying one was clearly superior to another.

    This is not so with Python, whose design is in fact evolving to discourage a functional programming style (Guido has repeatedly rejected adding anonymous closures to the language, and is planning to get rid of built-in functional combinators like map and reduce).

    That's because list comprehensions, generators, and inner functions do the same thing in a more Pythonic way. No functionality will be lost with the disappearance of lambda, map, filter, etc.