Ruby vs PHP for the web

Hi

I am not here to say that PHP is better or the opposite, I am here to
ask, how web development in Ruby compared to PHP. Does Ruby use the same
tools? for example MySQL and Apache?

And the most interesting point, which language can create a web
application with less code? (I am talking about the languges not the
frameworks).

Thanks.

···

--
Posted via http://www.ruby-forum.com/.

But Ruby with Rails does create a web app with much less code than others.

···

2010/11/4 Ruby Me <i_baseet@hotmail.com>:

And the most interesting point, which language can create a web
application with less code? (I am talking about the languges not the
frameworks).

Hi

I am not here to say that PHP is better or the opposite, I am here to
ask, how web development in Ruby compared to PHP. Does Ruby use the same
tools? for example MySQL and Apache?

yes it works with the same DBs and others, not sure what you mean by same tools?

And the most interesting point, which language can create a web
application with less code? (I am talking about the languges not the
frameworks).

Thanks.

Why not do something in PHP and then try doing the same thing in Ruby & Rail, what speaks to you will be the better choice for you!

Here is a rails 3 screencast to give you an idea about rails 3

http://rubyonrails.org/screencasts/rails3

···

On 10-11-03 09:49 PM, Ruby Me wrote:

--
Kind Regards,
Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1

If you use eRuby, then the two are very similar in the way you code, the
way you inter-operate with middleware, and in the amout of code needed.

···

--
Posted via http://www.ruby-forum.com/.

I am not here to say that PHP is better or the opposite, I am here to
ask, how web development in Ruby compared to PHP. Does Ruby use the same
tools? for example MySQL and Apache?

I went from PHP to Rails and have never looked back. I recommend using Rails 3. It easily connects to MySQL and PostgreSQL. Running development code is quick as it comes with a built-in web server and database.

I don't know if you're using the Zend framework, but Rails is a MVC framework. Zend's framework is relatively new and came out after I made my switch to Rails. I also haven't compared Rails to Python's Django. I have used WebObjects though, and I find Rails to be extremely elegant with respect to that system.

And the most interesting point, which language can create a web
application with less code? (I am talking about the languges not the
frameworks).

Ruby, the language that facilitates Rails and all the other favorite frameworks, is unequivocally less code. It's a big reason why I won't go back to PHP.

Jose
.......................................................
Jose Hales-Garcia
UCLA Department of Statistics
jose.halesgarcia@stat.ucla.edu

···

On Nov 3, 2010, at 6:49 PM, Ruby Me wrote:

Thank you guys,

It would be helpful if anyone writes any conde in PHP and then writing
it in Ruby? I want to see the difference and how the code will be less.

···

--
Posted via http://www.ruby-forum.com/.

For creating a web application, you need to use ruby on rails and not
simply ruby. of course you can create application with much less code
and you don't have to write sql queries as in PHP; database interface
can be handled with object relational mapping in RoR.

···

--
Posted via http://www.ruby-forum.com/.

Ruby Me wrote:

And the most interesting point, which language can create a web
application with less code? (I am talking about the languges not the
frameworks).

Ruby cause of the high dynamic approach and a cleaner language design.

Ruby allows you to build DSLs (Rails is such a thing) to make things
shorter. You have to understand that the Ruby language itselfs can be
modified (not the whole language but parts).

A important thing is DRY, don't repeat yourself. Ruby allows you to
write programs where you don't have to double your code many times.

In many languages you can see, how people have to copy'n'paste code and
modifiy only small things. It's not the way how to do this in ruby.

Yes, you can repeat yourself in Ruby, but you don't have to as much as
in other languages.

I read the online documentation about ruby and thought: Great, this
people made concepts first and tried to repeat this concepts in every
piece of the language. So you have an very consistent language with less
pit falls.

One thing is: Everything is an object. Yes, it means, everything is an
object and you can use the pattern of an object everywhere.

Another thing is: Everything is dynamic. So you can change an object and
a class at runtime (a class is an object too but at a higher level), can
define new methods. Yes, the internals of the language are objects and
you can work with them like any other object.

This is simply GREAT. With this dynamic approach you can build your own
DSL.

And the third thing is very important: Every piece of code can be
handled as an object. So you can write methods, which expects code as a
argument. This is a very heavy used concept in Ruby and is called
"blocks" where the given code is the so called block.

You write for example an algorithm for traversing a data structure. And
you have code which can handle the or some elements of the structure. In
Ruby you can easily split this code into two parts. You should do this
because the two problems, knowledge about the data structure and
knowledge about the elements are complete independent from each other.

You could exchange the elements with other types of elements and you had
to traverse the data structure the same way.

Or you could use the elements somewhere else in another data structure.

So you should split the code and ruby supports you very well on that
task.

So you can write shorter, cleaner and less error prone code. And yes,
writing ruby code is much more fun than writing PHP. You can feel the
support for abstraction. On the other side writing PHP code feels like
walking through a shelter. You feel thick walls everywhere. The language
controls you very hard.

Regards
Oli

···

--
Man darf ruhig intelligent sein, man muss sich nur zu helfen wissen

wrote in <1cd601a47b01edd27940e192d7465996@ruby-forum.com>:

I am not here to say that PHP is better or the opposite, I am here to
ask, how web development in Ruby compared to PHP. Does Ruby use the same
tools? for example MySQL and Apache?

As others have said, yes. There are Ruby libraries to allow you to
use most, possibly even all, of the external resources that you're
used to using from PHP. Examples include MySQL, PostreSQL,
ImageMagick, encryption libraries, etc.

And the most interesting point, which language can create a web
application with less code? (I am talking about the languges not the
frameworks).

That's not really a useful question, as it's fairly uncommon to create
web applications without a framework of some sort these days.

Having worked with both, I'll tell you why I like Ruby a lot more than
PHP.

1. PHP is a poorly designed language that suffers from a number of
problems, including design by committee and the misguided effort to
"make programming easy for nonprogrammers". Google "PHP sucks" and
you'll find plenty of detailed articles enumerating the issues with
PHP. Some of these have been corrected (or at least deprecated) in
version 5 and more will be corrected in version 6, but others are
still there, notably the horrible inconsistencies in the standard
library.

2. PHP's support (in version 5) for OO programming is rather anemic.
You get single inheritance only; there is no support for multiple
inheritance or mixins. While you can use __get() and __set() to
implement properties
<http://en.wikipedia.org/wiki/Property_(programming)>, this is
nasty and can lead to huge switch statements on classes of any
complexity. The standard library is still heavily procedural. It
doesn't support namespaces.

Ruby has mixins, which makes multiple inheritance less necessary and
properties (called attributes). Namespaces can be faked using
modules. Finally, Ruby was designed to be an OO language from the
beginning, while PHP has tacked OO features onto a procedural
language.

3. PHP uses weak typing, which leads to all sorts of problems with
ensuring that code behaves the way that you intended. Ruby uses
strong, though dynamic, typing.

4. There are a ton of very cool tools surrounding Ruby that can make
your life a lot easier. PHP has many fewer of these.

5. Ruby attracts smart, experienced programmers. PHP attracts people
who are new to programming. Don't underestimate this one. If you're
going to interact with a community and learn from people, which of
these would you pick?

···

On Wed, 3 Nov 2010 20:49:22 -0500, Ruby Me <i_baseet@hotmail.com>

--
Charles Calvert | Software Design/Development
Celtic Wolf, Inc. | Project Management
http://www.celticwolf.com/ | Technical Writing
(703) 580-0210 | Research

PHP has more lines of code in the actual File than ruby. If you take a
controller (in Rails) and compare it to a PHP program, PHP has more
lines of code. However Ruby has libraries to do most of this code for
you, if you include the libraries that you use Ruby has much more lines
of code.

But because people who program Object Oriented Code tend to consider
library code to not part of the actual program (as it is part of the
API) they see it as "the actual code you write is less".

Having large libraries of code (coupled with the fact that Ruby has a
slow interpreter) does make Ruby somewhat slower performance wise,
however a Ruby programer would argue that because Ruby language is more
efficient that PHP by re-using code and by using symbols where necessary
instead of strings that makes up for it's slow rendering time.

···

--
Posted via http://www.ruby-forum.com/.

I wrote programs in Assembly.
I wrote programs in BASIC (i know...but it was considered IN during
the 70s/early 80s), then PASCAL, JAVA, and now Ruby.

If you have develop programs in Assembly before, then you'd know you
have write so many lines in order for it to do so little...

Thus comparing number of lines is really pointless, because if you
want, you could add a lot more lines yourself by not using any
"standard libraries"

This is one of the reasons why OOP is the mainstream now -- re-
usability.
But the trade off of this re-usability is "performance". This is due
to all the overheads you added by using the "standard libraries" But
this could be neglected with better hardware performance...

So to answer your question, you have to tell us WHY you want to create
a web application with less code? If you answer is "Performance,"
then you picked a wrong measurement (# of lines). Instead you should
use "number of cycles"

Kenneth Leung

···

On Nov 3, 5:49 pm, Ruby Me <i_bas...@hotmail.com> wrote:

Hi

I am not here to say that PHP is better or the opposite, I am here to
ask, how web development in Ruby compared to PHP. Does Ruby use the same
tools? for example MySQL and Apache?

And the most interesting point, which language can create a web
application with less code? (I am talking about the languges not the
frameworks).

Thanks.

--
Posted viahttp://www.ruby-forum.com/.

Mike Stephens wrote in post #959251:

If you use eRuby, then the two are very similar in the way you code, the
way you inter-operate with middleware, and in the amout of code needed.

That's true, but I'd say that most ruby app designers don't write their
app logic within eruby.

To try a different way of doing things, have a look at Sinatra. A
starter Sinatra app is 4 lines:

require "sinatra"
get "/" do
  "Hello world!"
end

Run your app standalone from the commandline, or from within Apache or
Nginx using Phusion Passenger.

Your next step would be to use templates for response pages - templates
can either be stored inline, or in separate files - and helper methods
for code snippets to be called within templates. Then connect it to a
database using an ORM layer of your choice.

eruby is one of many choices for template languages (I prefer HAML), but
what you're trying to do is keep your request processing logic out of
the template, and centralised in your application code.

···

--
Posted via http://www.ruby-forum.com/.

you must be sitting in agony trying to decide between php and ruby =P, code is only half the battle, with rails it comes with code generators and rake tasks which make life really easy for a web developer! you're not going to see this if some cut-n-paste static code!

please don't ask a ruby or rails developer to write php code samples for you, it's just inhumane! =P

···

On 10-11-04 10:11 PM, Ruby Me wrote:

Thank you guys,

It would be helpful if anyone writes any conde in PHP and then writing
it in Ruby? I want to see the difference and how the code will be less.

--
Kind Regards,
Rajinder Yadav | DevMentor.org | Do Good! ~ Share Freely

GNU/Linux: 2.6.35-22-generic
Kubuntu x86_64 10.10 | KDE 4.5.1
Ruby 1.9.2p0 | Rails 3.0.1

As someone who has written a fair bit of both PHP and Ruby for the Web
over the years -- and very little of the Ruby actually using something
like Rails -- I think I know something about the subject when I say this:

1. Code snippets will not give you a good idea of how much one or the
other might save you any total code weight in the final version. Pick
one small task that can be represented in a small snippet, and one
language wins; pick another, and the other small task wins. In fact, for
the smallest tasks, PHP will almost certainly win because of its
literally *thousands* of core functions -- which, by the way, is *not* a
sign of good language design. Last I checked, there were about 3100 core
functions, which is *obscenely* complex for a procedural language, and
pollutes the main namespace of the language to an insane degree.

2. Final code weight to accomplish a specific task is nowhere near the
same thing as the amount of code you have to *write*, anyway. A lot of
code that gets written for any given non-trivial project is ultimately
deleted, usually to be replaced by other code. One of the benefits of
Ruby is that it tends to lend itself to finding the "right" idiom for a
given task sooner rather than later. PHP is not as good at that, and
tends to require a heck of a lot of refactoring as it scales up past the
size of a relatively trivial application. A lot of projects simply do
not do that much refactoring, but the end result is a largely
unmaintainable mess of an application, like WordPress. Reading the
source of WordPress is a bit like using thumbtacks for contact lenses.

3. Ruby's object model lends itself to far better code organization than
anything PHP offers. This means that, even in cases where Ruby might
have the same amount of source code (or even more) to accomplish the same
task, it's a lot easier to understand because of the way it can be
divided up into discrete chunks that make sense. PHP's unreasonable
facsimile of an object model and bolted-on half-baked namespace support,
by contrast, tends to creak under its own weight when developing any
nontrivial application.

All told, PHP is easier to use for the most trivial, single-page dynamic
templates, and harder to use to accomplish for anything more meaningful.
If all you're going to do is maintain a simplistic Website that contains
nothing but a little bit of simple logic in otherwise static pages,
perhaps populating some content areas from a couple of extra files, and
learn as little as possible, you might want to go with PHP. If you're
going to do some real programming, though, I recommend Ruby; it'll
facilitate development more on larger projects, it'll encourage better
coding practices, and it'll be more fun.

A lot of people complain about the superficial ugliness of Perl. PHP,
however, inherits pretty much all of Perl's flaws as a language, and
almost none of its benefits. Ruby inherits a substantial percentage of
Perl's benefits, and not so many of its flaws -- even by the markedly
uncharitable opinion of what constitutes a "flaw" that may Pythonistas
would give you.

I have recently stumbled across a brilliant characterization of PHP as
training wheels without the bike. It's hilarious -- and having used Ruby
for a while, it feels pretty true, too. I suppose your mileage may vary.

Note that a lot of this has been a liberal mix of opinion and fact. I
encourage you to *think* about what I said and do a little investigating
to confirm what I've said for yourself, rather than just taking my word
for it. If you want my opinion, though, it's easily summed up:

I'm glad I don't have to write PHP these days.

···

On Fri, Nov 05, 2010 at 11:11:18AM +0900, Ruby Me wrote:

Thank you guys,

It would be helpful if anyone writes any conde in PHP and then writing
it in Ruby? I want to see the difference and how the code will be less.

--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]

Correction: You *can* use Rails or any other Ruby-based webframework,
but you don't *have* to, nor do you *need* no.

···

On Mon, Nov 8, 2010 at 2:56 PM, Andola Soft <call@andolasoft.com> wrote:

For creating a web application, you need to use ruby on rails and not
simply ruby. of course you can create application with much less code
and you don't have to write sql queries as in PHP; database interface
can be handled with object relational mapping in RoR.

--
Phillip Gawlowski

Though the folk I have met,
(Ah, how soon!) they forget
When I've moved on to some other place,
There may be one or two,
When I've played and passed through,
Who'll remember my song or my face.

Charles Calvert wrote in post #960599:

Ruby uses
strong, though dynamic, typing.

Can you explain what you mean? That seems a contradiction in terms.

···

--
Posted via http://www.ruby-forum.com/.

Ruby Me wrote in post #959480:

Thank you guys,

It would be helpful if anyone writes any code in PHP and then writing
it in Ruby? I want to see the difference and how the code will be less.

I had 15 years of programing after me when I ended my programing carrier
and got a job as system administrator. My skills were mostly with
languages with little code to write. I Started with RPG on IBM
mainframes and ended with Clipper on DOS and windows.

But since programming is like a hobby I tried to learn something new and
in early 2000 PHP looked like a good language(Java to me is like a
Cobol. Too much lines about nothing). But I never got really into it. As
example I had a program which has created dates to schedule Backup Exec
jobs for a whole year and write result to file. About 60 lines in
Clipper. It took me about 3 days when I start learning PHP and I ended
up with 150 lines. But I never did anything sirius in PHP.

Few years later I heard about Ruby. It looked really cool. I had the
same program written after 4 hours of learning and in 35 lines. And
after that I didn't done any program again in any other language. 3
months later I installed rails and done my first web application after
another month (I knew something about HTML before).

I've been using ruby for 5 years now. And I don't use anything else. I
script Linux, Windows, web apps with rails. It is so simple. I have
programmed Intranet application in my company which connects to Oracle,
MS-SQL, Postgres (my favorite). And thats from the guy who never thought
that would ever make a program for Internet.

by
TheR

···

--
Posted via http://www.ruby-forum.com/.

Cool story, bro

···

On Mon, Nov 15, 2010 at 2:45 AM, James Vince <me@jamesvince.net> wrote:

PHP has more lines of code in the actual File than ruby. If you take a
controller (in Rails) and compare it to a PHP program, PHP has more
lines of code. However Ruby has libraries to do most of this code for
you, if you include the libraries that you use Ruby has much more lines
of code.

But because people who program Object Oriented Code tend to consider
library code to not part of the actual program (as it is part of the
API) they see it as "the actual code you write is less".

Having large libraries of code (coupled with the fact that Ruby has a
slow interpreter) does make Ruby somewhat slower performance wise,
however a Ruby programer would argue that because Ruby language is more
efficient that PHP by re-using code and by using symbols where necessary
instead of strings that makes up for it's slow rendering time.

--
Posted via http://www.ruby-forum.com/.

--
Tony Arcieri
Medioh! A Kudelski Brand

PHP has more lines of code in the actual File than ruby. If you take a
controller (in Rails) and compare it to a PHP program, PHP has more
lines of code. However Ruby has libraries to do most of this code for
you, if you include the libraries that you use Ruby has much more lines
of code.

That sounds convincing on first sight yet I am missing hard facts.
Can you put figures on this for a concrete application? We could
start with versions of Ruby and PHP you are comparing here.

But because people who program Object Oriented Code tend to consider
library code to not part of the actual program (as it is part of the
API) they see it as "the actual code you write is less".

Which is true of course. You only need to write and test your own
code and can rely on the library author's QA for their code. Of
course, from time to time you'll find a bug in library code as well.

Having large libraries of code (coupled with the fact that Ruby has a
slow interpreter) does make Ruby somewhat slower performance wise,
however a Ruby programer would argue that because Ruby language is more
efficient that PHP by re-using code and by using symbols where necessary
instead of strings that makes up for it's slow rendering time.

Again, this sounds convincing on first sight but it actually isn't.
Using a library does not automatically mean that more code is executed
or an application is slower. Without hard facts all these statements
stand on a very shaky ground and I would certainly not base my choice
of language or framework on what you wrote.

Kind regards

robert

···

On Mon, Nov 15, 2010 at 10:45 AM, James Vince <me@jamesvince.net> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

PHP has more lines of code in the actual File than ruby. If you take a
controller (in Rails) and compare it to a PHP program, PHP has more
lines of code. However Ruby has libraries to do most of this code for
you, if you include the libraries that you use Ruby has much more lines
of code.

This is not entirely true. PHP does not have a "standard library",
instead all functionality is either built into the interpreter or
comes in an extension. If you take PEAR into account then the higher
number of LOCs that is characteristic of PHP will change the picture.
As for frameworks, Zend looks pretty bloated to me for what it does.
Rails might be bigger, LOC wise, but it does a lot more too.

But because people who program Object Oriented Code tend to consider
library code to not part of the actual program (as it is part of the
API) they see it as "the actual code you write is less".

I believe Ruby's libraries tend to have less code than PHP's
libraries. Even though I don't have numbers to back this up, I have a
hunch that mixins in Ruby, which PHP doesn't have, play a role in
reducing the LOC count in libraries.

Having large libraries of code (coupled with the fact that Ruby has a
slow interpreter) does make Ruby somewhat slower performance wise,
however a Ruby programer would argue that because Ruby language is more
efficient that PHP by re-using code and by using symbols where necessary
instead of strings that makes up for it's slow rendering time.

Large libraries of code do not necessarily mean lower performance
overall. Ruby's parser is very fast, and once the is code loaded, and
cached by the OS/FS, the effect of it's size on performance is
negligible. Unless the code is being reloaded on every rendering
request, of course, which should not be done if one is concerned with
performance.

Regards,
Ammar

···

On Mon, Nov 15, 2010 at 11:45 AM, James Vince <me@jamesvince.net> wrote: