Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
floWenoL
Oct 23, 2002

RonaldMcDonald posted:

In my opinion you can see a lot about languages from how they solve simple problems. So, for :science: how would the following PHP code look in RoR?

php:
<?
$result = mysql_query("select * from people order by lastname asc");
if (!$result)
    throw new Exception(mysql_error());

echo '<table>';
while ($row = mysql_fetch_array($result))
{
    echo '<tr>';
    echo '<td>', $row['lastname'], '</td>';
    echo '<td>', $row['firstname'], '</td>';
    echo '<td>', $row['age'], '</td>';
    echo '</tr>';
}
echo '</table>';
?>

You'd have an HTML template file with all the HTML interspersed with <? ?> (I forget the exact delimiters) to print out variables (much like PHP, except logic isn't mixed with presentation). You wouldn't write any SQL at all; the table structure is determined automatically. Your controller class would basically have something like:

code:
people = Person.find_all(:order_by => :lastname)
(My syntax might be off, as I'm a little rusty as Rails)

and people would be visible from the template file. Someone with access to a rails install can probably type this up in more detail.

Edit:
Like this guy below.

floWenoL fucked around with this message at 00:07 on Aug 9, 2007

Adbot
ADBOT LOVES YOU

floWenoL
Oct 23, 2002

epswing posted:

Edit: I know almost nothing about ruby or rails, but something that keeps me from diving in head first is...well, the concept of automated db access in general. Am I really going to let something write my sql for me? I really enjoy hammering out a nice query that does exactly what I need it to do, complete with inner/outer joins, unions, subselects, likes, ins, and whatever else is necessary with the appropriate indexes. For simple "select * from table where col=value" queries fine, do it for me, I won't mind. But for anything complex, can I take over? I know Hibernate allows me to take over when necessary. I don't yet trust the efficiency of a cruise controlled database.

You can definitely write your own sql if you want to, and RoR doesn't stand in your way. You'd probably end up doing this for performance or non-portable stuff.

floWenoL
Oct 23, 2002

legalcondom posted:

On that note, RoR is neat but it's not the solution everyone claims it is. I just don't understand the whole buzz around RoR and why it's so great.

Because Ruby is just a better language than PHP, and Rails meshes really well with the language. Notice how your PHP framework still requires you to write SQL, assign the result, and name the template manually.

floWenoL
Oct 23, 2002

legalcondom posted:

Actually I do have a query builder in my framework... that was just a basic example. I'd rather be in control of the queries though, I can imagine inexperienced Ruby developers are writing applications that will easily crumble under heavy load.

I can't see inexperienced PHP developers doing much better, frankly. In fact, you'd have the added bonus of all the security holes.

quote:

I didn't mean to make it a PHP vs. RoR argument, you say "Ruby is just a better language" without stating why. I just wanted to understand why so many people are on this bandwagon because I just can't seem to figure out why I should use this language. I've tried it out but anything that ruby does, perl does better, and the whole rails thing... PHP is more stable and not really a moving target like RoR.

First of all, you're confusing the framework (RoR) with the language itself. I've programmed Perl for years professionally and although it's not as bad as PHP, it has a lot of warts and gotchas. I'd like you to give me an example of something Ruby does that is done in Perl better. The only think I can think of is performance and just my own personal aesthetic sense. (I like how Perl looks better)

And, um, saying that PHP is "stable" is a polite way of saying it's stagnant, I guess. I don't think that's true, as I believe PHP is still being actively developed, but there's a large legacy PHP4 codebase, which definitely holds back the community. Not to mention debacles like this.

quote:

edit: I can understand an argument about following proper code ethics, MVC and all of that...

Ruby/RoR makes it easy. PHP does not. Simple as that.

floWenoL fucked around with this message at 06:21 on Aug 9, 2007

floWenoL
Oct 23, 2002

ryanmfw posted:

You keep comparing apples and oranges. Ruby is not an MVC framework, just like PHP. RoR, and PHP along with the several well developed frameworks like CakePHP, Symfony, and CodeIgniter make MVC development easy. Ruby itself does not make it easier, just like PHP itself does not.

I knew I should have clarified that. Ruby makes "following proper code ethics" easy. Rails makes "MVC" easy. Why PHP sucks as a language has already been covered namy times. The multitude of competing MVC frameworks, in my opinion, does not make MVC easy in PHP as the PHP programmer has to evaluate multiple frameworks to figure out what he needs, and PHP makes jumping in and just coding very easy, which is not necessarily a good thing.

I don't think I compared apples and oranges in the rest of my post.

floWenoL
Oct 23, 2002

Mr. Wynand posted:

still better then php

true dat

Adbot
ADBOT LOVES YOU

floWenoL
Oct 23, 2002

Argue posted:

Ultimately, though, I'm worried about collisions, so I'm trying to find a more elegant solution.

For md5/sha1 assuming no malicious input? :psyduck:

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply