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).
----
As opposed to...?
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.
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.
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?
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.
As opposed to python!
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 %]
As opposed to SQLObject, which was mentioned in the summary. It allows you to make the objects in your program persistent by transparently storing them in a traditional SQL database. All you have to do is inherit from a base class and set/get the object's attributes normally.
Bogtha Bogtha Bogtha
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."
you can do the one line sql statament in one line python, using list comprehension.
I'll do the stupid thing first and then you shy people follow...
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.
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.
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.
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?
You forgot to put the colons into those URLs:
http://www.turbogears.org.nyud.net:8090/
http://www.rubyonrails.org.nyud.net:8090/
Do not meddle in the affairs of geeks for they are subtle and quick to anger
> 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.
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
Having jumped ship to Ruby/Rails quite a while back I'd have to say I didn't find it very impressive in comparison but if I was using Python I suspect I'd see it differently.
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
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)
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!
Rails supports many-to-many relationships as well. And provides support for many other relationships (see acts_as_list, acts_as_tree, acts_as_nested_set, etc).
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.
SELECT * FROM address, transaction, lineitem where lineitem.cost > 200 and address.city = 'New New York' and lineitem.transaction_id = transaction.transaction_id and transaction.address_id = address.address_id
In SQLObject you would typically write this as:
Transaction.select((Address.q.id == Transaction.q.id) & (LineItem.q.transactionID == Transaction.q.id) & (Address.q.city == 'New New York') & (LineItem.q.cost > 200))
The code and the result are pretty much the same.
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?
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
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?
No amount of eligance saves you from the fact that Rails is as slow as a two-legged dog. It simply can't compete with anything else performance-wise.
Any man who afflicts the human race with ideas must be prepared to see them misunderstood. -- H. L. Mencken
IronPython isn't abandoned, it's just in some weird Microsoft limbo. It's by the original author of Jython, who got hired by Microsoft and has apparently been caught in some bureaucratic limbo where he spends most of his time in meetings (though another programmer internal to MS has also been allocated, from what I understand).
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.
GLaDOS for President 2016! "Well here we are again. It's always such a pleasure." -- GLaDOS, 2011
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.
Hmm - if your priority is raw speed, then Rails might not be the best framework for you. But how many applications are like this?
Let's assume (and this is my experience, and the experience of countless others) that a Rails project can be developed much faster than a Java project or a PHP project. (I come from the PHP world and can back this up; others have seen the same advantages with Java.) And development is typically a much bigger cost than hosting when it comes to most web applications.
We can immediately cross off any website that is hosted on a shared server (99%?), since these sites don't even need a dedicated server (which can be had for a fairly trivial cost of $99-$299/month). And if a single server is too slow, then scaling across 2-4 machines a fairly affordable option. So what are we looking at? Banking software? Amazon.com?
The only sites I can imagine that "need" the speed avantage of PHP or the database scaling of Java are (1) sites that are ridiculously large, or (2) sites that are very easy to program and get a huge amount of traffic. If a site can be built in a day or two in PHP and has hundreds or thousands of concurrant users, then the development advantages of Rails are less important. And if a site is going to be built by 10+ developers, and it needs to scale across a dozen servers, then maybe Rails isn't right. But I would suggest that for 99.9% of projects, application speed should be one of the least important criteria used when deciding on a language or framework.
Dood...
IronPython 0.9.2
======================================
Writers get in shape by pumping irony.
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
You can filter thigns from a list comprehension, yes. But when you have things like joins between different object lists, fugetaboutit.
Although list comprehensions are nice. Thank Haskell for that.
The dangers of excessive individualism are nothing compared to the oppressiveness of excessive collectivism
Spin it any way you like but I've never been on a project, web-based or otherwise, where they didn't care about performance. Until someone shows me something other than some annecdotal evidence that the development of Rails is SO much faster than Java or PHP that it makes up for the massively beefed up server you will need to run it on, I call bullshit. For that matter, most companies aren't willing to simply toss servers that they have that work perfectly well currently. Sometimes you just can't upgrade them enough to make the difference and since Rails apps are an ORDER OF MAGNITUDE slower than Java and PHP apps you will definitely have to make a huge upgarde to keep the equivalent performance level.
It's funny because I remember the time when people use to make all kinds of jokes about the old "throw more hardware at the problem" solution to problem solving but now that we have Rails it's simply Ok!
The other problem with Rails is that if you have an existing data model you need to code against, it suddenly becomes tons less attractive and less quick. Sorry but there's just too many limiting issues with it for me to call it ready for primetime for anything but the most low capacity, non-mission critical sites imaginable.
Any man who afflicts the human race with ideas must be prepared to see them misunderstood. -- H. L. Mencken
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
I come to Rails from PHP. I was a pretty good PHP programmer, but no expert. I wrote object-oriented code, tried to keep logic out of my presentation, etc. I switched to Rails three months ago, and I would estimate that I already program at least 3x-5x faster in Rails. I recently recreated a project that took me 3 weeks in 2 days. Granted, having built the site once, I had worked through the planning issues, but these were not that complex. My experience with PHP was that it is great for small projects (a few pages), but time and difficulty grew really fast as the project got bigger. It was like going from 5 major functional items to 6 major functional items would double the project.
A better PHP programmer could have probably avoided some of the problems I ran into. But after a few months on Rails, I am developing faster, making more money, and writing far better code. It is scary to think of where I will be in a year.
This is anecdotal, like you said, but it is true. People have come from the other direction (Java) and reported similar things.
Rails may not be for everyone. If I worked for a team 10+ programmers, I might not use it. If I were a designer who just needed to add basic functionality to pages (like a random image gallery), I might go quick-and-dirty with PHP. But for my own purposes--working with one or two other programmers on a project; building $8k-$25k web applications for small businesses--Rails is perfect.
The reason performance isn't a big deal is simple, for myself and for many others.
1. Most of my projects are low traffic/high complexity.
2. A dedicated server can handle a lot of traffic, even with Rails, and can be had for $1200-$3000/year.
3. Most of my projects don't even need a dedicated server to begin with, even using Rails.
4. Development and maintenance savings far exceed any extra hosting costs.
Like I said earlier, a low complexity/high traffic site might benefit from PHP. But in my world, these sites are rare.
Finally, in my experience the low performance of Rails is a lot of hype. Use caching, use fastcgi, optimize your queries, and it is definitely _not_ "an order of magnitude" slower than other technologies. If I am wrong, fine... Just show me some solid data.
Comment removed based on user account deletion