@legolas, PM box is clear
speakeasy said:
Can you tell me why these are better than php and mysql? I'm just learning php and mysql and haven't only briefly heard about ruby on rails and I've never heard of PostgreSQL.
Not so much a question of which is better. Both PHP and Ruby are very capable languages. It just turns out that Ruby was a better fit for my brain - it reads like plain english and has more object-oriented goodness baked in.
Consider the following code snippets which do exactly same thing:
PHP said:
class String {
var $str;
protected static $counter = 0;
public function set_value($str) {
$this->str = $str;
}
public function __construct($str) {
$this->set_value($str);
}
public function __toString() {
return $this->str;
}
public function testfunc2() {
$array = split(' ', $this);
$str = "";
foreach ($array as $word) {
if (!(empty($word) || self::$counter < 0)) {
$str .= $word;
}
self::$counter++;
}
return $array;
}
public function testfunc() {
$this->set_value($this . "abc ");
implode($this->testfunc2(), "-");
}
}
$str = new String("initial string");
$i = 5000;
do {
$str->testfunc();
} while (--$i !== 0);
:crazy:
I can hardly read that with so many brackets, dollar signs and semi-colons littered throughout the code. It's also ridiculously long.
Check out the Ruby version:
Ruby said:
class String
@@counter = 0
def testfunc2
array = self.split
str = ""
array.each do |word|
str << word unless word.empty? or @@counter < 0
@@counter += 1
end
end
def testfunc!
self << "abc "
testfunc2.join("-")
end
end
str = "initial string"
5000.times { str.testfunc! }
Note: I lifted these examples from a
great article
In the web programming world, frameworks are hot topic right now, thanks mainly to Ruby on Rails. A lot of imitations have been spawned since...CakePHP is a direct clone of Rails and others (Zend, CodeIgniter, etc) follow the same MVC (Model View Controller) philosophy. IMHO, none of them hold a candle to Rails.
The only downside for Ruby is that its not as widespread as PHP, but this is changing rapidly as more web hosts provide support for RoR and Ruby wins more converts from PHP and Java-land.
As for PostgreSQL vs MySQL, that is also preference. PostgreSQL is a little harder to get your head around since it has more features, but for the type of stuff I'm doing I really do need them (especially security features)
At the end of the day it's really just a question of personal choice. You pick whatever tool best suits your way of thinking, and the job at hand.