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.'"
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..
Official GOD FAQ.
Why is this an advantage?
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.
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).
----
SQL is an awful language, and don't let anyone tell you otherwise. It is highly non-portable, insofar as it is non-trivial, it is not easy to parse, it is difficult to debug, it is a lot of work to test, it's tedious, it's time-consuming, and, worst of all, it's an awful mishmash of "human-readable" code with grammars. The resulting mess is something that is cumbersome, ugly, and definitely not human readable.
What software do people use for making these neat videos? (I realise this is bordering on off-topic :) )
Believe with me, my saplings.
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
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.
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.
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.
http://www.welton.it/davidw/
torrent
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.
Python is one language they actually use quite a bit
-ashot
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.
Anybody?
Linking to a site with a 20 min Quicktime Movie on ./, and then pointing it out so everyone downloads it is just cruel! Won't anyone think of the poor servers?
nothing to see here, move along
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.
The best bits about catalyst are:
1. built in webserver. Apache/Apache2 is in flux at the moment, and you're caught in shifting sands of documentation, libraries and online-help. A built in webserver means you can prototype fastest.
2. Eclipse. With EPIC you can code and debug your perl in Eclipse.
[% slash_sig_val.text %]
Hi,
I've seen both quicktime movies now: Ruby on Rails and now this one. And this video is not nearly as impressing as the rails one is - mostly, because the python solution here is violating the DRY (don't repeat yourself) principle at many places.
This makes the demonstration look dull and complicated.
While I like the general idea of the project, there's still a large way to go till it reaches the ease and simplicity of Rails.
Philip
Quote " as natural as writng a function". In other words, completely unnatural, formal in the extreme, a highly technical task. Is this why linux geeks think that one day all the world will use Linux/Debian/BSD.
new Weblog(); new Wiki(); tadaaah!
If imitation is the sincerest form of flattery then David Heinemeier Hansson must be blushing right now. His framework has insipired every other language proponent to make a rails like framework. There is trails in java, django in python (and now turbogears), there are at least two PHP frameworks and even a .NET one. I think somehow David touched a nerve someplace and produced something really beautiful.
.NET people are resorting to code generation to try and mimic some of the functionality of rails.
Much of what makes rails great is the highly dynamic nature of Ruby itself. Do yourself a favor and read the activerecord source code. Even if you don't know ruby it's an interesting lesson on how to take advantage of dynamic scripting languages. I am sure python and PHP could also do something like this but the Java and
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.
evil is as evil does
If you're up for small Wikis, there's always HeyHeyWickie, a Python Wiki in under 4K lines of code (using EmPy and docutils).
Interesting. It's good to see a number of people taking on the project of providing RAD tools with database access.
I have a competing project: http://entropy.homelinux.org/axis_not_evil
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-click installers ).
Admittedly my project isn't quite as polished ( in terms of point-and-click setup of objects ) as TurboGears, but in my defense, there's only one of me, and I've only been programming in Perl for just over a year.
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
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."
this video, because Stephen Grady of RedMonks is not featured - he is not even quoted in the Video. I am forced to conclude that this software project is amateurish and not enterprise class.
I'm using Perl on Poles!
There's one issue with database portability, and that's that each database uses different languages for stored procedures. This is getting better in some areas, and some DBs now have a basic procedural language that's mostly compatible, but it's not really good from a DB portability point of view.
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 documented and isolated neatly.
Additionally, many DBs let you use your preferred language for stored procedures - for example, Java or Python . Sometimes this can be a very handy thing, though of course abuse of it is hideous.
I tend to agree regarding doing data operations in the app. The more SQL and good database use I learn, the simpler the code that's responsible for fetching and storing data gets as more and more of it moves into the database its self.
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.
Got Apple QT installed on an XP box and I can't play this video. I don't know that I've ever seen QuickTime tell me I didn't have a codec on a .mov file.
.mov file so what do I need to play this? Oh and they're calling it a compressor in my error message...
I'm a loss...gSpot doesn't understand the
Sound works great though.
I think that the biggist problem of all the "platforms" is incompatibility. Do you want to use Python on Rails and you don't know Python? Do you want to use "*" and you don't know "*"? Did any "platfrom" developer thought about this problem? Or is it just a marketing how to bind the developers just to your platform?
.net... generally whatever language you know... I generally don't like tons of documentation/tutorials and so on to get integrated with other platform. I'm sure that the platform developers and I always share at least one technology that I can use without reading "How to integrate with *" tutorials...
I think it is not so difficult. My working prototype of an extension for my project will allow you to write modules for my CMS in ruby, python, php,
I don't like to switch my "mother" programming language for other language just to take advantage of some great functions in some third-party platform...
Hey! Why do we have so great _standards_ and widely supperted technologies...?
Well, I've got to get back to work. When I stop rowing, the slave ship just goes in circles.
So, do you think he actually wrote a regular expression off the top of his head, or do you think he had it memorized or written down somewhere? I didn't think any human being could write regular expressions that quickly. =P
If you want similar functionality with some more capable tools, have a look at Twisted with Divmod's Nevow & Axiom. Similar functionality but with a a whole lot more to boot.
Google uses python all the time.
I am trolling
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?
;) ), rather than it being neatly stored with 1000 other nonrelated SQL statements (as functions or otherwise).
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.
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 simplicity in the RDB and to avoid deadlock at all cost. The RDB person wanted complete problem representation in data. If the requirement is really for the database just to provide for serialization of objects it is surprising that object oriented databases have not become more popular. They've also been around 15 years. Corporations are too hooked on the report and ad hoc query capability of RDBs I guess.
an ill wind that blows no good
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.
Hello to all. Interestingly enough I just installed TurboGears for the first time this weekend. To test how versatile it is, I installed it three times: on my main Mac OS X box, on a Windows laptop and on an old Linux box.
All three installs went flawlessly and I was up and running in less than half an hour. I must say that the installation of TurboGears is as smooth as I have ever seen, and the documentation is superb.
I went ahead and made a podcast recording my initial experiences, and I will continue to podcast about TurboGears as I go forward, as part of my Python411 podcast series that can be found here: http://www.awaretek.com/python/index.html or subscribed to here: http://www.awaretek.com/python/index.xml
Ron Stephens
Why does this person insist on mirrors of these sites on his own network? (http://www.rubyonrails.org.nyud.net8090/ http://www.turbogears.org.nyud.net8090/ The first was slow and the second won't pull up for me. Please, just put a link to the mirrors site or link to the main page, especially for projects like rubyonrails.org.
Thank you, and good night.
And I thought Rails was some type of new animal.
How the hell do you know that they don't scale? Have you tried it? It's called the 'share nothing' approach. Livejounal and yahoo both use it.
http://www.loudthinking.com/arc/000479.html
Yep. Take a look at Gmail - there are a LOT of .py files running around in there. Not to mention that the original web crawler/indexer (the one that started their meteoric rise) was written in Python...
HAH! I just wasted a second of your life making you read this, but I wasted a minute of mine thinking it up. DAMN.
My project, Tersus, uses an alternative approache to web application development. Take a look at http://www.tersus.org/
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
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?
> 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".
Sigh.. the only way to watch it is via MOV?? And they're 50-80Mb!!? People please be kind and give options.. I'd prefer a format like this 5 minutes to build an app that retrieves images from Flickr(presentation from web 2.0 conference in Flash8) or better yet one of these Which is a tiny file.. or even a WMV file..
I really need to watch the videos referenced in this article, but I have to install software on my system to do it and would rather not have Qucktime on my system.
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.
So it's simple, it only uses
- Python,
- SQLObject,
- CherryPy,
- Kid,
- MochiKit,
- some extra pythonic glue.
I know you don't really have to know these to trash together some wiki. Still, I would never ever in this life give the task to someone who doesn't know them just uses them (by some higher level lib or toolkit whatever).
All in all, I find it nice that there are quite some number of ways for mostly average skilled users to put together stuff like that wiki. Still, for a real task, I'd prefer someone who can make it all happen with one or max two languages and some db backend.
I am putting myself to the fullest possible use, which is all I can think that any conscious entity can ever hope to do.
catalyst gave me more of a programming woody than rubyonrails did :)
This framework looks very-vey similar to Django. Unlike TG, Django is all-in-one solution: built-in admin interface, built-in extensible template system, and so on.
5 1258
If someone is interested: http://it.slashdot.org/article.pl?sid=05/08/02/00
igor
So... do I have to run it on the "built in" webserver or will it run under mod_python? Doesn't appear to do so.
MORTAR COMBAT!
whoops...
20/15 is 133% :)
qntm.org
But, man, it ain't rails. Look at this:
class Page(SQLObject):
_connection = hub
pagename=StringCol(alternateID=True, length=30)
data=StringCol()
To me, that looks too much like your typical Python code. Quite *readable* yes, but when you read it, you have no idea *why* all that stuff is there. StringCol? data=Stringcol()? And yes, a leading underscore thrown in for good measure (every Python program must have a few underscores thrown in.. I guess python programmers long for the dollar signs and punctuation of Perl).
Now look at the Rails (ActiveRecord) equivalent:
class Page < ActiveRecord::Base
end
Hmm, no boilerplate.
Now, let's have a laugh:
@turbogears.expose(html= "wiki20.templates.page" )
def index(self, pagename="FrontPage"):
page = Page.byPagename(pagename)
content = publish_parts(page.data, writer_name= "html" )[ "html_body" ]
content = content.encode( "utf8" )
return dict (data=content, pagename=page.pagename)
What is all that *STUFF* for? He even goes on to call that "very readable" !!! Here's the ruby version (as far as I can make it out, anyway):
def index
end
Do you see the difference? In a Rails app, most of the code is at the level of your problem domain, NOT the level of pushing bits around from the DB to the HTML templates. All the knock-offs are full of *noise*.
That's what makes Rails so lovely.
But I guess if you just refuse to use Ruby, you'll have to settle for what you can get.
And their WHOLE support system.
Learn to speak Americun English, dude!
Comment removed based on user account deletion
Because your last example doesn't close the HTTP connection. And it's not exception safe.
File.open("my_file") do |f|
f.read # do stuff with it
# if exceptions are thrown, the file will be closed
end
Breakfast served all day!
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!
Comment removed based on user account deletion
From what I understand Google uses C++, Python, and Java. Java is used mostly for internal accounting projects. C++ is used for all the stuff that has to be Really Fast, and I suspect lots of code gets migrated from Python to C++ during the development cycle. They use SWIG to interface between Python and C++. I haven't heard about them using many other languages, except XSLT and other special-purpose languages.
There's too many new/emerging techs integrated into one monolithic framework as if it will work next year...Here's something new it will teach you, what works one year for a complex framework (made up of independent vendors) wont work next year when you install the latest releases. If someone is specifically maintaining the framework for $$$ you will probably be able to get it to work with a lot of tweaking the Pythonic glue... I think they meant pythonic scripts. Right. I will reiterate the parent, this is a waste of time.
Often wrong but never in doubt.
I am Jack9.
Everyone knows me.
do || .. end is basically equivalent to { || ... }, so I'm not sure where you're going with that.
Personally, I find the block approach to be more clear. The other method is what C / C++ / Perl / Python probably do, but blocks are a big reason of why I like Ruby.
Using blocks makes it really clear when the HTTP connection is open and when it is closed. Same with doing a database transaction or a File operation.
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.
I don't think any of these features, other than higher-order functions, is really essential. Though if you rework the "let x = expr1 in expr2" as "lexical scoping," I might accept that (though I'd still point out that let is "really" just lambda: "((lambda (x) expr2) expr1)"). Scheme is routinely labeled as a functional language, and it has side effects. Cons pairs in Lisp in general are mutable.
Anyway, I think asking whether a language is "functional" is not as good of an exercise as seeing functional programming as a programming style or set of techniques, and then asking how much support a language provides for using that style, and how natural it is to use it in that language.
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. [...] Both Python and Ruby make routine use of destructive assignment, which is the epithome of side effects.
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.
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).
What's non-functional about Ruby? I'd say the biggest thing is the fact that its default sequence datatype is a flexible array type, and not a singly-linked list type.
Are you adequate?
DB interfaces offer you a way to bind parameters
so you can create queries like
qry = new Query("select * from foo where bar = ?");
qry.setParameter(1, "xxx");
or execute stored procedures like
qry = new Query("exec foo(?,?)");
qry.setParameter(1, "zzz'x'");
qry.setParameter(2, "yyyy'q'");
and the interface ensures that no sql injection attacks are possible
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
Are you adequate?
It's "much easier to understand" if you're a Python or Java programmer, maybe.
...} syntax is much more natural.
The idea of explicitly binding locals for only a specified scope isn't new -- if you're a Lisp or Smalltalk programmer the other way seems much more natural.
I find that lots of programmers who grew up with low-level languages are afraid of high-level features -- for example, they'll find that passing closures to map/reduce isn't as "easy to understand" as doing a for(i=0;ilt;n;i++) {...} loop. There are good reasons for using high-level features, though: you can't really have an off-by-one error when using map and reduce, and it's much easier to identify the invariants. (Everybody remembers how to prove correctness, right?) Avoiding assignments makes things clearer.
I'm a Python programmer, and I've never written more than 50 lines of Ruby, but I think the {|x|
Point the first: nothing that you mentioned has yet been removed from python.
Point the second: map and reduce are on the suggested drop list in favor of other functional programming constructs like list comprehensions and generators that do the exact same thing with cleaner syntax. Because that's what python is about
Point the third: please explain how anonymous closures are superior to lambda constructs, list comprehensions, or generators each used in the appropriate context.
When I interviewed at Amazon last year, they told me that they still used C++ for a lot of stuff.
The cake is a pie
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 approaches to the same problem, but I'd hesitate in saying one was clearly superior to another.
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.
I'm waiting for Perl's Acme::Rails module, myself.
I'm sure it will be MUCH faster than these.
Unless someone compares it to Roadrunner, at least. No beating that thing.
Some people would say that Ruby's one feature -- anonymous closures -- is superior because it is responsible for all sorts of functionality that is implemented via several constructs in Python. That I would disagree with -- the features (things like looping) are such fundamental patterns in a language that their use will always be idiomatic, no matter how elegantly they fit into some underlying syntax or functionality.
First, by "much nicer syntax" you must mean "with a syntax that I'm already used to." (OTOH, I spend all day programming Scheme, so you probably think I'm a loony anyway when it comes to syntax.)
Anyway, yeah. The Python language is going to be revised to add yet another special-purpose feature and syntax to do yet another specific thing that any language with closures can do trivially with a higher-order function, without any revisions to the language.
And then it's going to take a while for the revisions to be available in all of the implementations of Python, and for third-party libraries to catch up with the language and implement APIs that use this feature. Sure. Sounds great.
Same story with list comprehensions, generators and generator expressions. Ruby, Scheme, and other such languages don't have any of those. Instead, they've had anonymous lexical closures since the start. For example, Python required a new language version to implement generators; in Ruby, the same functionality was implemented as a standard library, and to boot, it was implemented in Ruby itself.
Are you adequate?
Or, in other words, list comprehensions, generators and inner functions are designed to discourage a functional programming style.
Are you adequate?
Archetypes does not handle Object-Relational mapping well, and shouldn't be used to store relational data regardless- The ZODB was not designed for large numbers of objects, and most certainly doesn't handle relational data well.
:)
Try Hornet (http://www.plone.org/products/hornet). It stores everything directly in a relational database, works with ZODB transaction (So it commits and rolls back at the same time, keeping ACID complience), and uses lazy iteration to handle millions of rows without a problem. Plus, As far as any regular zope app is concerned, you can treat it as a normal folder/object in Zope/Plone whatever.
Theres no excuse to ever store relational data in the ZODB again
Come on people, there's no need to make a revolution every time a new language is released!
Ruby's been around for ten years.
- Scott
Scott Stevenson
Tree House Ideas
on http://www.turbogears.org.nyud.net:8090/docs/wiki2 0/page4.html
should not it be:
2 def save(self, pagename, data, submit, new):
3 hub.begin()
4 if new == True:
5 page = Page(pagename=pagename, data=data)
6 else:
7 page = Page.byPagename(pagename)
8 page.data = data
Comment removed based on user account deletion