Beta
×

Welcome to the Slashdot Beta site -- learn more here. Use the link in the footer or click here to return to the Classic version of Slashdot.

Thank you!

Before you choose to head back to the Classic look of the site, we'd appreciate it if you share your thoughts on the Beta; your feedback is what drives our ongoing development.

Beta is different and we value you taking the time to try it out. Please take a look at the changes we've made in Beta and  learn more about it. Thanks for reading, and for making the site better!

Rails Cookbook

samzenpus posted more than 6 years ago | from the get-cooking dept.

Book Reviews 59

honestpuck writes "When reading the foreword of Rails Cookbook I felt a strong kinship with Zed Shaw, I too have fond memories of the first edition of Perl Cookbook and the way I relied on it once I'd taken the training wheels off. Since that one I have relied on several of the O'Reilly Cookbook series. It is only when I discard the early tutorial and dive in the deep end with a "cookbook" on my desk that I really start to learn proficiency." Read the rest of honestpuck's review.

I felt timorous and unsure when I finished Agile Web Development with Rails, a marvelous tutorial that introduced me to my first real web development framework (I must have enjoyed it, I just bought the second edition). Since I have volunteered to develop a fairly large and complex web application in Rails I awaited the arrival of my copy of Rails Cookbook with hopeful anticipation and bated breath.

Rob Orsini, his fellow contributors (15 in all) and the team at O'Reilly have once again delivered. Compared to the previous titles in the series I've owned Rails Cookbook seems to have fewer recipes but as it is tackling an entire application framework and some serious issues, some of the solutions and discussions run a lot longer. The book is targeted at programmers who know something about web development but are early in their use of Rails, though it should be helpful to all Rails developers.

The book starts with tackling issues of installation and getting development tools installed in the first two chapters. Despite already deploying a couple of simple Rails apps I found that there was the odd useful tip in these chapters. The book then covers each of the three main sections of Rails; Active Record, Action View and Action Controller. The rest of the book goes on with large chapters on testing, Javascript, debugging, performance and hosting and deployment. Along the way it also covers REST, Action Mailer, security, plug-ins and graphics.

The extremely large section on Active Record was to me the most useful. I seem to spend an inordinate percentage of my Rails coding time with Active Record and it contains a large part of Rails power so I appreciated the size of this chapter. By contrast the chapter on graphics is almost entirely unread.

It seems obvious that this book should be compared to Pragmatic's Rails Recipes. The first point of difference is that Rails Cookbook covers installation and setup. The second point is that is 'Recipes' covers Rails 1.1 while 'Cookbook' targets the brand new Rails 1.2. As a project fairly new on the scene Rails is a fast moving target so the six months between the two books makes a difference. Both books have excellent coverage of the various aspects of Rails, with a great deal of overlap. 'Recipes' has more, shorter pieces while 'Cookbook' tends towards longer pieces with more discussion. 'Cookbook' is also more general, with more recipes more likely to be useful in every Rails project you write.

The style is different between the two. Here Cookbook comes off second best, it feels as though tightly edited by a number of hands and ends up lacking personality; functional but cold compared to Recipes. The writing, however, is good. It's easily read, at times it feels like a good textbook. The layout is clean, it is easy to find the information you need from each recipe when you want.

With almost all "cookbook" style books I seem to be left feeling that a number of the recipes are just a little too obvious and covered well in beginner tutorials. There is some of this in Rails Cookbook, most notably the first two chapters, but overall the book will be useful to any beginner to intermediate Rails programmer. Personally I had a couple of moments where I read a tip and wanted to scream as it demonstrated and explained in a few short sentences and half a page of code what had taken me hours to discover for myself.

The "Cookbook" series all seem to be books worth the price and shelf space. This one is no exception. I'd give it three out of five with an extra half for its timely information on Rails 1.2 and would recommend it for all Rails programmers from the absolute beginner through to all but the most experienced. If you already have a copy of 'Recipes' and are happy with it then you might want to stick with that till either volume is updated for the next major revision of Rails, otherwise you will almost certainly appreciate a copy of Rails Cookbook.


You can purchase Rails Cookbook from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

Sorry! There are no comments related to the filter you selected.

Yes, but it's rails... ;) (-1, Flamebait)

Ron Harwood (136613) | more than 6 years ago | (#18157580)

I'm afraid I've been poisoned towards it by all the fans who have to insult other languages in order to promote it. I've never liked negative campaigning.

Re:Yes, but it's rails... ;) (1)

norkakn (102380) | more than 6 years ago | (#18157780)

Then you'll _never_ touch Python!

I have a co-worker who loves it and whenever I say something like, "I'm going to write a small program around a few syscalls and some low level bit twiddling in C" his response is always "Oh, you know Python can do that, right? And it'll be faster!"

It actually looks like a decent language, but he's turned me off to it (and it seems to grab a lot of the things I don't like from perl [disclaimer: I like perl] and very few of the ones that I do). I'll learn it sometime, but I definitely agree that fanboys make learning languages seem unappealing. That being said, I've played around with rails, using it to do the interface for a desktop reclamation maya renderfarm, and it is rather cool in some respects. It's a good tool to have, but it shouldn't be used for everything.

Re:Yes, but it's rails... ;) (1)

Ron Harwood (136613) | more than 6 years ago | (#18157844)

Ah, he only says that you can do it in Python... he doesn't start off by saying the C is the bane of existence, killer of babies and that it probably was the one that keyed your car.

Re:Yes, but it's rails... ;) (5, Funny)

MrTranscendence (982312) | more than 6 years ago | (#18158064)

Hey, man, leave C++ out of this.

Re:Yes, but it's rails... ;) (2, Interesting)

PopeRatzo (965947) | more than 6 years ago | (#18159172)

I'm a geek who uses technology in the service of the arts, but I've never been a programmer. Can anyone recommend a language in which I can learn the basics of programming, but is still powerful enough for me to do useful things? I'm comfortable with a soldering iron and piano, but the mysteries of writing code have always been outside my ken.

I don't want to become a professional, I'd just like to do know what to do when I have to write a script and make simple web apps. The only real programmers I know are hardcore types who snicker whenever I ask them this question and like to pretend that what they do is some sort of priesthood, whose secrets are not easily given up. Something tells me that they just don't want me to know how easy it is.

So I'm asking you people: I don't have the time to go back to school for a CS degree, and I'm not looking to program databases for a living, but I've got the feeling that I can manipulate documents, sound files, midi a lot easier if I knew some programming. Help a brother out here. What language would be the easiest for a novice to learn and still be able to do something worthwhile?

Re:Yes, but it's rails... ;) (1)

Phukko (841877) | more than 6 years ago | (#18159398)

......... no, seriously, help this guy out. I'm not about to recommend PERL or Java or SQL, even though that's really all I'm semi-literate in. And out of those, only java might come close to the requirements. I'd like to know what you guys recommend as well

Re:Yes, but it's rails... ;) (1)

tha_mink (518151) | more than 7 years ago | (#18166472)

I'm not about to recommend PERL or Java or SQL
C'mon, I was just about to recommend Java. It's a good language to start off with since there's a ton of information out there, it's a flexable language that you can use for tons of different use cases, and it's a good introduction to OO programming, which if you're starting from scratch, is the way I'd go. I would stay away from stuff like PERL and PHP since the former is just an explosion at the punctuation factory, and the latter could help instill bad practices from the get-go since it's so easy to hack out crap that will work. Just me though.

Re:Yes, but it's rails... ;) (1)

norkakn (102380) | more than 7 years ago | (#18172792)

I'd like to append that perl is a good language to work for people who are heavy command line users. It was origionally designed as bash+, and it still fills that niche quite well. It's OO is truly horrid though, and for the one who was asking, I'd agree, perl is bad for him.

Re:Yes, but it's rails... ;) (4, Insightful)

nuzak (959558) | more than 6 years ago | (#18159462)

Python's definitely a good fit. It's not my favorite language in the world, but it's got sensible syntax that isn't too alien (the indent thing really won't bite you unless you have a really crappy editor or you copy and paste code). And it also has loads of libraries, good support for all major platforms (OSX support is so-so, but pyobjc is nice), and a lot of people who can help you out (#python on irc.freenode.net for example).

Here's the bad part: there's virtually no decent introductory programming texts for python or most other languages. Most of them tacitly assume you know some other language and gloss over basic things like structuring a program with control flow, functional (de)composition, and proper use of objects, or they make a hash out of trying to introduce them. To that end, I'd really recommend Structure and Interpretation of Computer Programs (aka SICP) as a learning text, but dear lord is it tedious and didactic. It's also going to teach you an abstract way of thinking that doesn't really map to python's practical structures (i.e. you're never going to use tail recursion generally, let alone an amb operator).

I really love smalltalk for playing around with programming, not so much for the language itself (it's just okay) but for the way that you don't think about "compiling" or "modules" so much as you just have objects that you fiddle around with, and your changes just happen. Unfortunately, Squeak is such a poorly-documented disastrous hodgepodge that I can't recommend it to new programmers.

So it's kind of a desert out there for decent introductory texts, but a language with good community support and mostly helpful people will be a big boost, and python does stand out.

Re:Yes, but it's rails... ;) (1)

PopeRatzo (965947) | more than 6 years ago | (#18159876)

I don't want you to think I asked the question and don't appreciate your taking the time to respond. I'm looking for some python books now. I guess I need some kind of compiler or libraries or something, so I'm going to search those out right now. Say, do I need to work in Linux to write python? I don't mind, I've got a machine around here I can use for Linux. I was waiting for the UbuntuStudio anyway, so I will have such a system soon.

Re:Yes, but it's rails... ;) (1)

PopeRatzo (965947) | more than 6 years ago | (#18159904)

python.org seems really good. They seem to be pretty helpful to beginners. So far so good. Thanks, friends.

Re:Yes, but it's rails... ;) (1)

nuzak (959558) | more than 6 years ago | (#18160220)

Python works great on windows as well as any unix. I recommend unix systems in general for development, but it's mostly a matter of using what you're comfortable with. Most tutorials are going to assume you're on Linux. And I see you've already discovered where you can get the interpreter from python.org. Ubuntu comes with python, but not necessarily a full install -- you'll probably want to install python2.5 from apt anyway.

Re:Yes, but it's rails... ;) (1)

PopeRatzo (965947) | more than 6 years ago | (#18160778)

Here's a dopey question: I've got to use my Windows system for music and video production. I will set up an Ubuntu box next weekend, but I'm between projects and would like to spend some time playing with Python.

If I install Python and the Win32all library and an IDE (maybe Boaconstrictor or one of those), there won't anything that runs using resources when I'm not actually working with Python, right? I mean, there won't be any libraries or little thingies running in the background that will take resources away from my DAW or Premiere, right? I have to be pretty careful of any unneeded services or stuff running when I'm mixing audio or I'll get crackles and artifacts.

Thanks again.

Re:Yes, but it's rails... ;) (1)

nuzak (959558) | more than 7 years ago | (#18160964)

Python won't install any extra daemons or services out of the box, and no python package you install is going to do that either. The only additional resource it'll suck up is disk space.

Boa Constructor is actually pretty awful. PyDev for Eclipse is decent -- yeah, it's a Java IDE, but it's a good plugin. Now THAT will eat resources when you run it. For a lighter alternative, you can always use emacs if you can get used to its weirdness, and it has a great python mode (never thought I'd call emacs slim).

There's also SPE, though I've found it crashier than a glider in a hurricane. Still more stable than Boa. Komodo's not too bad if you want to pay for it.

Re:Yes, but it's Idle (1)

brainhum (869270) | more than 7 years ago | (#18164164)

Idle comes bundled with the Windows installer. I use that all the time. It is pretty simple, a colourized text editor mostly, but it doesn't have the pokey feel of Eclipse. About my only complaint about Idle is that it doesn't have any line numbering down the left side of the window. Instead the line numbers are in the lower right corner in a box which makes me look away from my code. It might be just me though.

An good intro to Idle follows:
http://hkn.eecs.berkeley.edu/~dyoo/python/idle_int ro/index.html [berkeley.edu]

Re:Yes, but it's rails... ;) (1)

adolfojp (730818) | more than 7 years ago | (#18160880)

C# is a nice language to begin with. Its very similar to Java, it is widely used and supported, it is easy to get started with and you even get free developer tools.

http://msdn.microsoft.com/vstudio/express/ [microsoft.com]
http://www.monodevelop.com/ [monodevelop.com]

Visual C# 2005 Express Edition for Windows development, Visual Web Developer 2005 Express Edition for the web and MonoDevelop for Linux desktop apps.

Good luck, have fun and think in layers.

Re:Yes, but it's rails... ;) (1)

farker haiku (883529) | more than 7 years ago | (#18162524)

The answer is of course Ruby. You can start with Chris Pine's Learn to Program [pine.fm] which walks you through the basics of Ruby programming, or for a more psychedelic way of learning programming there is always Why's poignant guide to ruby [poignantguide.net] . Then when you get advanced enough (you've read the pickaxe and possibly the ruby way) you can start working on the bi-weekly Ruby Quiz [rubyquiz.com] . /ruby fanboy

Re:Yes, but it's rails... ;) (1)

Serious Callers Only (1022605) | more than 7 years ago | (#18163880)

Ruby or Python are probably the best places to start; they're not going to be suitable for every type of programming you do, but they might teach you some good habits before you learn other languages with horrific syntax and dangerous pointers, and you can get going very quickly.

For Ruby, there's Chris Pine's Learn to Program [pine.fm] or Why the Lucky Stiff's Poignant Guide to Ruby [poignantguide.net] which is whimsical, but does pretty much the same thing, or just go to Try Ruby [hobix.com] and type help.

For Python there's Instant Hacking [hetland.org] , or Useless Python [uselesspython.com] and I'm sure many others. These two sites, like the Rails site, are written in PHP, but I wouldn't touch PHP with a barge-pole if you're learning just now, it's only useful for web apps and will teach you bad habits.

Re:Yes, but it's rails... ;) (1)

CryBaby (679336) | more than 7 years ago | (#18164466)

Go straight to Objective C on OS X. Apple's development tools (e.g. XCode with Interface Builder, free) make it pretty easy to get started and the language is well established so you can find books, etc. More importantly, you'll be programming in an environment with first-rate multimedia support.

Re:Yes, but it's rails... ;) (1)

Felius (56017) | more than 7 years ago | (#18163680)

I held off learning python for almost two years for this very reason (meeting someone who was slightly too enthusiastic in their advocacy). Turns out though that it actually *is* quite a nifty language ;)

People don't make a big enough fuss about the interactive interpreter, partly because it's hard to describe why it's so useful. Try it out though, starting with diveintopython.org.

Re:Yes, but it's rails... ;) (2, Insightful)

Anonymous Coward | more than 6 years ago | (#18158090)

Make Rails Thread safe so the only option isn't to run multiple applications sucking up even more memory and I might be inclined to think it is a useful framework. WTF?! No I don't want to run a "pack of mongrels" or more than one FCGI process. Give me a break.

Rails is awesome for developers (cause it's easy) but from a system and resource POV it's atrocious. And I thought I'd never find something that I disliked as much as PHP (due to security concerns, again, don't get me wrong, it has it's place).

--Irate Systems Engineer.

Re:Yes, but it's rails... ;) (4, Funny)

Greenisus (262784) | more than 6 years ago | (#18158710)

Ruby on Rails is like the Macintosh of programming languages / web frameworks. So, the insulting comes quite naturally.

Re:Yes, but it's rails... ;) (0)

Anonymous Coward | more than 7 years ago | (#18168020)

Very good analogy, as long as you mean post OSX Macintosh. Very easy to use on the surface and produces quick results, but still has plenty of power under the hood for those who care.

Yeah (1)

Tarlus (1000874) | more than 6 years ago | (#18157598)

I think this has been reviewed once or twice before on Slashdot... but I digress.

I agree that this is a fantastic book, as it shows you some incredibly slick stuff you can do using Rails. But unless you already have somewhat of an understanding of Ruby then I'd strongly recommend getting a separate reference book just for Ruby by itself. O'Reilly makes one of those, too. :)

Re:Yeah (4, Funny)

nmb3000 (741169) | more than 6 years ago | (#18157748)

I think this has been reviewed once or twice before on Slashdot

No, no. That was Rails Recipes [slashdot.org] . Completely different. That's just a bunch of recipes. This is a cookbook! A COOKBOOK!

Re:Yeah (0)

Anonymous Coward | more than 7 years ago | (#18168594)

The joke would be funnier if the title was "To Serve Rails" ;)

Re:Yeah (2, Informative)

tcopeland (32225) | more than 6 years ago | (#18157756)

> then I'd strongly recommend getting a separate
> reference book just for Ruby by itself.

The Ruby Way [amazon.com] is an excellent book for that, plus, the author, Hal Fulton, is a nice guy. And his RubyForge user account name [rubyforge.org] is "hal9000", for which he gets additional points.

I went off the rails (-1, Offtopic)

Anonymous Coward | more than 6 years ago | (#18157646)

There are many things about RoR that really get on my chimes. I'm sure other users will be shortly listing things about rails that get on their chimes.

Ruby on SHIT (-1, Troll)

Anonymous Coward | more than 6 years ago | (#18157648)

Rails is a pile of crap made by/for amateurs. ASP is for real work.

What stupid names too.

Troll... (0)

Anonymous Coward | more than 6 years ago | (#18157712)

I bet you have never programmed a web app in your life... ASP? *laugh*

You can get it for more at B&N (5, Funny)

stoolpigeon (454276) | more than 6 years ago | (#18157722)

You can get it for $4 more at B&N [barnesandnoble.com]

diLck (-1, Troll)

Anonymous Coward | more than 6 years ago | (#18157738)

Havn't I seen this before? (1)

scwizard (941758) | more than 6 years ago | (#18158080)

I've seen so many slashdot book reviews with "rails" and "cookbook" in the title, that I could swear this book has been reviewed here already.

Re:Havn't I seen this before? (1)

rucs_hack (784150) | more than 6 years ago | (#18158778)

Then may I interest you in my 'Cookbook on Rails' publication?

Only 999,999 doller, love you long time...

Or there's the Extreme Programming edition of the above for an extra ten bucks.

(wtf is extreme programming anyhow, hell I've been a coder for 7 years and I haven't met a single extreme programmer face to face)

Re:Havn't I seen this before? (1)

elmaxxgt (980095) | more than 6 years ago | (#18159706)

eXtreme Programming or XP, was allegedly championed by Kent Beck. XP is an approach to projects that encourages flexible, design-oriented, higly focused planning and execution.

A good book on this movement would be "the pragmatic programmer" by Anrew Hunt and David Thomas.

Hope this helps. :)

Re:Havn't I seen this before? (1)

Raenex (947668) | more than 7 years ago | (#18184200)

Allegedly?

Lifted from the Better Book... (4, Informative)

jaredbpd (144090) | more than 6 years ago | (#18158310)

I had this book for about 26 hours before I returned it, I was deeply displeased by the repetition from the existing work, Rails Recipes. All the cookbook entries about model relationships, polymorphic associations, etc, were lifted straight from Rails Recipes, right down to using Magazines, Readers and Subscriptions as the example objects.

And, while the book has a shiny "Rails 1.2" badge on the cover, very little of it had anything to do with Rails 1.2 whatsoever, there were only a handful of recipes in the very back which dealt with the new features.

Plus, was it really necessary to burn 3 pages talking about how to join a discussion group of fellow Rails developers? If you're a web developer and you can't find an online community to discuss the language/framework, you need more help than Rob's book is able to offer...

Re:Lifted from the Better Book... (0)

Anonymous Coward | more than 7 years ago | (#18161746)

I second this opinion, though I kept the book because I'm such a Rails fanboy that I'll read *any* Rails book on the toilet. If you've built even one site with Rails you might find 5 recipes worthwhile. No mention of Ferret, no has many :through. I did discover Rails built in support for optimistic locking, and I'm hoping their's another surprise or two I've missed.

Re:Lifted from the Better Book... (1)

dscataglini (1069192) | more than 7 years ago | (#18167302)

Jaredbpd,
I am sorry to disappoint you but nothing was lifted from Rails Recipes. I would like to find you a recipe that mixes join models and polymorphism in Rails Recipe. I wrote the last 2 recipes in that chapter and that code is taken straight out (in simplified form) from one of my applications. I actually wrote the join model and polymorphism one and then I was asked to write one just about polymorphism as introduction to the concepts. The editor thought that my recipe was a little too advanced.

Your point about using common objects names that people can relate to (Magazine, Readers, Subscriptions, Cart, PhoneNumber, Company, People, Blog, Post) is plain silly.

You are pretty much saying that since Chad used those models in his book nobody else can write examples about activerecord using those same names.

I am sorry to disappoint you again, but many of those same examples that you found on Chad's book were available on the net in form of blog post, comments or documentation.

It's like saying nobody can talk about the "stack" example without "lifting" from somebody else.

BTW. Originally that recipe had User Subscribing to other Users and their Bookmarks and Subscriptions. I thought that as an example in a book those objects weren't easy to relate to in that context. So I changed them to Reader, Newspaper and Magazine.

Rails is Doomed (0, Flamebait)

Tablizer (95088) | more than 6 years ago | (#18158434)

A critique of R&R. It basically says that it will not "catch on" for the same reason that Lisp and Smalltalk never did: heavy dependence on esoteric ideas and meta programming:

http://www.beust.com/weblog/archives/000382.html [beust.com]
     

Re:Rails is Doomed (4, Informative)

swimmar132 (302744) | more than 6 years ago | (#18158638)

I think Rails has already "caught on".

Also, that blog post has a ton of errors. Here's one: If you want to write a Web application in Ruby, there is only one solution. Only one. Ruby on Rails. Hm, about about Camping [hobix.com] or Nitro [nitroproject.org] ?

Rails scales perfectly well, just the same as any other share-nothing approach.

Ugh, so much FUD.

Re:Rails is Doomed (1)

Tablizer (95088) | more than 6 years ago | (#18158748)

Ugh, so much FUD.

The author appears to *like* R&R. He/she is just being realistic about it going mainstream. I see no evidence he/she is out to bash R&R.

Whether he/she knew about the Rails alternatives or not does not diminish from the main point.
     

Re:Rails is Doomed (1)

CowboyBob500 (580695) | more than 7 years ago | (#18164128)

Ugh, so much FUD.

But no core UTF-8 support makes it useless to large numbers of people. The hacked support doesn't cut it. It needs to be supported right down in the core to make it fully stable and workable.

Bob

Are you getting enough oxygen citizen? (0)

Anonymous Coward | more than 7 years ago | (#18178304)

If by "caught on" you mean "marketing douches for go nowhere wannabe web 2.0 startups put it in their want ads" then you are right. But most people think "caught on" means a significant number of people use it for a significant number of projects. And this is simply not the case. Of myself and the 5 people I know who tried rails, I am the only still using it. And I don't really want to, I am just stuck with it for now since I got stuck with reponsability for a site which someone else made that used rails for a large app which now is having all kinds of scalability problems. Given that less than half a million people downloaded it in the first place, if my 20% use vs try rate is accurate (probably WAY high) then less than 100,000 people are using rails. That's not even approaching 1% of "caught on" languages like PHP, java and C#.

And rails scales like shit, because its poorly architected and poorly written. Making ignorant claims about it scaling "just as well" as other shared nothing frameworks/appservers is retarded. Rails has several very large scalability bottlenecks that limit its ability to scale, most unfortunate being activerecord, which needs thrown in the trash. Christ, it makes us run a few thousand ruby processes, each with its own copy of every fucking class, each using ~120MB of RAM, and each holding a database connection open all the time even though 90%+ of the time the database connection is idle and the process is running application code. We have to use an external database connection pooling app just to fix this simple, basic fuckup because rails was not designed with *any* thought put into scaling at all. Nevermind how much this sucks balls for caching data, since you are now FORCED to use external caching like memcached, you can't have a useful level 1 cache in process.

Re:Rails is Doomed (5, Funny)

Temujin_12 (832986) | more than 6 years ago | (#18159018)

No...THIS is why Lisp never caught on:
(defun fibonacci (nn)
  "Return 2 consecutive Fibonacci numbers."
  (declare (type (integer 0) nn))
  (case nn
    (0 (values 0 0)) (1 (values 1 0)) (2 (values 1 1)) (3 (values 2 1))
    (t (multiple-value-bind (mm rr) (floor nn 2)
         (declare (integer mm) (type (integer 0 1) rr))
         (multiple-value-bind (f0 f1) (fibonacci mm)
           (declare (type (integer 0) f0 f1))
           (if (zerop rr)
               (values (* f0 (+ (* f1 2) f0))
                       (+ (* f0 f0) (* f1 f1)))
               (values (+ (* f0 f0) (sqr (+ f0 f1)))
                       (* f0 (+ (* f1 2) f0)))))))))

Re:Rails is Doomed (1)

chromatic (9471) | more than 6 years ago | (#18160014)

Everyone knows Haskell is the best language for writing a Fibonnaci generator.

Re:Rails is Doomed (2, Funny)

ari_j (90255) | more than 6 years ago | (#18160194)

Everyone knows Haskell is the best language for writing a Fibonnaci generator.

You really do just have to choose the best language based on the problem you are solving. After all, every language is good at one thing, and Fibanacci generators are Haskell's. :P

Re:Rails is Doomed (2, Informative)

drix (4602) | more than 6 years ago | (#18160710)

Yes, it's easy to obfuscate almost any language. I think someone who wasn't being quite so tendentious might write:

(defun fib (n)
    "nth element of the Fibonacci sequence"
    (check-type n (integer 0 *))
    (if (< n 2) n
            (+ (fib (1- n)) (fib (- n 2)))))

Lisp is a pretty good language. Its reasons for not catching on have more to do with its grassroots beginnings (no M$ Visual Lisp) and the fact that GC/automatic memory management was about 40 years ahead of its time in terms of the hardware needed to run it well. And besides, who was it that said that behind every C or C++ program lurks a buggy, slow implementation of Common Lisp? All the cool ideas in languages these days (first class functions, dynamic typing, OOP, metacircular evaluation) were originally implemented in Lisp.

Re:Rails is Doomed (1)

fireboy1919 (257783) | more than 7 years ago | (#18163412)

You don't think the fact that people naturally think imperatively and not functionally has no bearing on the situation?

When it's the difference between lisp, which was marginally easier to develop with once you understood it, or cobol, which was easier to understand, but harder to develop with once you knew it, which do you think people would choose?

Cobol more than nine times out of ten...and with the increase in coders, there was an increase in available code. Pathways to solve common problems were made and LISP's natural ease-of-devel benefit was taken away.

If I can make a prediction about current techs, I would say that this is why things like ActiveRecord are going to beat out complex ORMs like Hibernate. There are a lot of other things with that same possibility.

SOAP versus XML-RPC, Oracle versus every other database system on the planet, and Java versus high level scripting languages that can also run on VMs.

Of course, with mitigating factors like throwing money at the problems, I could end up wrong about these. But I think that's the way that things are currently progressing: when the margin of difference is small enough, the initial learning curve makes all the difference in the world.

Re:Rails is Doomed (1)

drix (4602) | more than 7 years ago | (#18166268)

I don't know how people "naturally" think; for me grokking functional programming was one of those eureka! moments and it really felt natural. I still write a lot of functional stuff even in procedural/OO languages; Ruby lends itself well to that. But I agree with your larger point. One of the things that really blew me away about RoR was seeing someone implement a really good declarative security mechanism [writertopia.com] in about 300 lines. The Java version (JAAS) is an entire library that I never was able to fully figure out; I was left scratching my head wondering Why? Why did they make something so simple so ludicrously complex.

Re:Rails is Doomed (2, Insightful)

kubalaa (47998) | more than 6 years ago | (#18160768)

That's a highly optimized algorithm. If you think that looks bad, check out the equivalent C code.

typedef struct {
    int first;
    int second;
} intpair;
 
unsigned int sqr(unsigned int x) { return x*x; }
intpair fibonacci(unsigned int nn) {
    intpair out;
    switch (nn) {
        case 0: out.first = 0; out.second = 0; return out;
        case 1: out.first = 1; out.second = 0; return out;
        case 2: out.first = 1; out.second = 1; return out;
        case 3: out.first = 2; out.second = 1; return out;
    }
    unsigned int mm = nn >> 1;
    unsigned short int rr = nn & 1;
    intpair f = fibonacci(mm);
    unsigned int f0 = f.first;
    unsigned int f1 = f.second;
    if (rr == 0) {
        out.first = f0*(f1*2 + f0);
        out.second = f0*f0 + f1*f1;
    } else {
        out.first = f0*f0 + sqr(f0 + f1);
        out.second = f0*(f1*2 + f0);
        return out;
    }
}
Obviously if you already know C you'll find the C version easier to understand, but if you don't I think it's hard to argue that this is any more obvious than the Lisp version, and it's a lot longer. Oh yeah, and it doesn't even get the right answers:

fibonacci(1231243) => {524936933, -1076064072}

Re:Rails is Doomed (1)

Furry Ice (136126) | more than 7 years ago | (#18163206)

Yes, the algorithm is confusing. However, the C version is longer, but not *that* much longer. It also doesn't have any comically-long symbol names like multiple-value-bind. Granted, that's not an intrinsic problem with Lisp, only with ANSI Common Lisp, but prefix math is also difficult for humans to deal with. I don't know if it would be any easier if we learned math that way from the start, but I suspect it's just not how the human brain works.

I like Lisp and Paul Graham's essays almost had me won over, but I read a very long thread somewhere a few weeks ago where some Lisp hackers were trying to come up with cases that supposedly only Lisp could do, but a clever Ruby hacker kept posting little programs that did the same thing, and in my opinion, more clearly and elegantly. It's true that Ruby does not have the full power of macros, and that anything that does will be just another dialect of Lisp (or have a clunky new syntax for manipulating the parse tree, such as AOP tools for Java like AspectJ). However, with Ruby you can easily define before, after, and around advice. You can easily generate new methods on an instance or a class, or even all classes by defining methods in class Module. You can't take a data representation of code and add some statements right into the middle of it as you could with Lisp, but this is something I have never wanted to do. I'm sure there are valid reasons for wanting to do this every now and again, but is it really worth having a syntaxless language for something you so rarely need? For some applications, I'm sure the answer is yes. But for most, it's not worth it.

Re:Rails is Doomed (0)

Anonymous Coward | more than 7 years ago | (#18161202)

No...THIS is why Lisp never caught on:


Don't you mean:

(no (why (is (caught-on Lisp never) this )))

*yawn* (1)

Estanislao Martnez (203477) | more than 7 years ago | (#18163588)

;;;
;;; Return (fib n) and (fib (+ n 1))
;;;
(define (two-fibs n)
  (two-fibs-aux 0 1 n))

(define (two-fibs-aux m n i)
  (if (zero? i)
      (values m n)
      (two-fibs-aux n (+ m n) (- i 1))))

Re:Rails is Doomed (1)

Anamanaman (97418) | more than 6 years ago | (#18160730)

I read that almost a year ago and its a great post. I agree with most of it yet still use Rails everyday. Notice in it he's giving an opinion about the future of Rails. However right now, its an amazingly productive framework to develop in if you're targeting startup web applications.

To me the development tools for Rails is like a holy grail. Coming from .NET and Windows, switching all mac for Rails has given me a sort of coding nirvana that I didnt think possible. Developing code, writing tests, reusing gems and plugins, and deploying builds (cap deploy) is a near flawless experience. When something better comes along, I wont hesitate to jump on. But for now, Rails is my optimal experience for web development.

Re:Rails is Doomed (1)

corecaptain (135407) | more than 7 years ago | (#18162172)

First let me disclose I that I have worked with Java web apps
using Kiva, JRun, ATG Dynamo, Tomcat, Websphere, Spring Framework, JSEE. I have
also worked Perl+CGI, a smattering of cold fusion, plain old php,
drupal, cakephp (rails like php framework).
I am currently working on deploying a rails app.

So what is my take on Ruby/Rails?

Briefly here are the pros/cons as I see it:

pros:
    1) Ruby feels good to program in. Like Perl,PHP, or LISP you can
    layout data using the language itself. So unlike Java you don't
    find yourself needing XML to configure everything.

    2) Ruby is dynamic. Nothing new here. But this allows you to
    "build up" the language to support your problem domain. Sure,
    Java supports this to some degree, but it is much more
    complex and verbose - where in Java you might need dynamic
    byte code insertion in Ruby you just open up a class and "do it"

    3) Rails was "extracted" from a real life web application - not designed
    by a committee. The bottom line is that you find lots of support for
    "things" you are likely going to want to do in your application. You find
    that many of those "easy", "i can do it in a few hours/days" sort of things
    have already been taken care of for you.

    4) Rails is opinionated. It lays out your directory structure for you, It
    likes you to obey certain naming conventions. What is good about this is that
    a) you don't have to think about these things b) less experienced people get a
    decent skeleton MVC architecture to work with.

  Cons:

  1) The Ruby libraries have no where near the depth or maturity of what you find
  in Java. This is improving, but in a high stakes enterprise environment where
  from one day to the next you never know what you might be asked to integrate with
  this is definately a consideration.

  2) Rails works best with new applications where you have control over the database.
  If you can't control the database schema or it is already in place you can possibly
  bend Rails to work for you...but trust me, there is no 15 minute screencast that is
  going to hold your hand.

  3) Rails is (by all indications) not a framework that caters
  to enterprise users. You can take that however you like - this makes some people giddy -
  For others it gives pause. See http://www.martinfowler.com/bliki/EnterpriseRails. html [martinfowler.com] for
  a perspective on this.

  4) Ruby's runtime environment is evolving. Most people seem to agree that Ruby needs a VM (
  these are under development). Also Sun has a few guys working JRuby - Ruby compiled down to
  java bytecode. But these aren't production ready.

  5) Rails uses the ActiveRecord pattern for ORM. In a nutshell, the further your domain objects
  diverge from their representation in the database the more likely Rails is not going to work for you.

In the end, it comes down to selecting the right tools for the job. Where you have a new app, time to market
is critical, and budget is small then Ruby/Rails can be a great tool. Where you have a complex domain, existing
database, and the need to integrate with all sorts of exotic systems or middleware you might want to look elsewhere.

Oooh (1)

unablepostAC (1044474) | more than 7 years ago | (#18161718)

Oh I tought it was about a cooking on the rails, like those things trains run on
but it is just about some programming thing
me sad

I was disappointed with this title (1)

Naum (166466) | more than 7 years ago | (#18171956)

I own both titles ("Rails Recipes" by Chad Fowler) and IMO neither does a great job -- there's nothing in this book not already covered by the definitive DT/DHH Agile Rails Development book. About the only redeeming value was the information on Mongrel and the detailed instructions to get Rails installed and running on all the different platforms.

Speaking of which, though, the devoting of a good chunk of paper real estate to installation, seems to be space better left for meatier topics. Especially on a topic that changes significantly on a monthly basis -- it would seem that for a book, it would be more prudent to focus on matter not so ephemeral, knowledge that would arm and equip someone learning Rails to handle any task or illustrate more advanced techniques a web developer wishes to accomplish.
Check for New Comments
Slashdot Login

Need an Account?

Forgot your password?