
Originally Posted by
JIAM
I've been considering learning RoR or CodeIgniter.
Which one is easier to learn? Would CodeIgniter be worthwile?
I don't have a specific requirement for any other than trying to learn how to build more powerful websites with more flexibility and in less time.
Thanks
I would go with RoR, mostly because it has so many useful, and in my opinion necessary, tools that PHP really doesn't have, such as the tools I linked to in my first post. It is rather easy to get started in, too, and simple to deploy. To me, Ruby is much mor eintuitive than PHP.
There are several things in Ruby that just would take more work in PHP. In PHP, it feels like OO has just been hacked into the language. They try to fix that a bit in PHP5 but it doesn't negate the mess created in the previous versions.
In contrast, in Ruby, absolutely everything is an object. It makes it much more intuitive to work with the language, because objects are an integral part of the language.
Also, I love blocks/procs/closures.
Example:
[
Code:
(1..10).select { |num| num % 2 == 0 }
#=> [2, 4, 6, 8, 10]
Or:
Code:
(1..10).to_a.delete_if do |num|
num > 3
end
#=> [1, 2, 3]
Sorting is very flexible:
Code:
class Widget
attr_accessor :name, :price
def initialize name, price
self.name, self.price = name, price
end
end
def print_widgets widgets
widgets.each do |widget|
puts "#{widget.name}: #{widget.price}"
end
end
# Creating some widgets
widgets = []
widgets << Widget.new('Foo', 4.99)
widgets << Widget.new('Bar', 2.98)
widgets << Widget.new('Baz', 9.99)
print_widgets widgets
# Foo: 4.99
# Bar: 2.98
# Baz: 9.99
# Sort by price
widgets.sort! do |w1, w2|
w1.price <=> w2.price
end
print_widgets widgets
# Bar: 2.98
# Foo: 4.99
# Baz: 9.99
]
Another cool thing is that you can extend classes. I don't know the proper word for it. I don't mean inheritance, but you can actually add methods to an existing class.
Code:
class String
def foo
puts 'I am foo. I have infultrated String.'
end
end
"hello".foo
# Outputs: "I am foo. I have infultrated String."
There are also mixins, the ability for classes to include and extend modules.
Code:
module Foo
def do_something
puts "I am doing something."
end
end
module Calculator
def add a, b
a + b
end
end
class Bar
include Foo
include Calculator
end
bar=Bar.new
bar.do_something
# Outputs: "I am doing something."
bar.calc 1, 2
#=> 3
And it continues, but i've been working on this post for like an hour.
Of course, that's only Ruby, and I haven't discussed anything from Rails, which is really great in its own right. There are frameworks inspired by Rails in PHP, but Rails does everything much more elegantly.
If nothing else, I think you should learn it just for the experience of another language. I don't think there's ever harm in learning a new language and perspective on programming.
Hope that helps.
Bookmarks