SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question What can Ruby do that PHP can't?

    Sorry if this is a stupid question. I have looked through beginners guides about how to use Ruby. But I am still confused on what Ruby can do that PHP can't. Should I only use Ruby? Should I use PHP and Ruby? I am confused.

    Thanks for your help.
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ruby can do pretty much the same things as PHP, the difference is the amount of effort you have to put in.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Klagenfurt / Austria
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you mean Ruby on Rails and not Ruby in general, well, there are also quite a few MVC-frameworks written in PHP out there. If you mean Ruby in general I guess it comes down to two things: (1) Which language you like more (for whatever reason) and (2) if there are any libraries you want to use.

    When it comes to libraries Ruby has some advantages to PHP thanks to namespaces support and so on, but this is only relevant if you want to use those features. PHP on the other hand has the advantage, that if you just want to have a small site it's probably easier to find a cheap host that gives you PHP support than Ruby on Rails support.

    Just try both and then take what fits your needs and what you enjoyed more ;-)

  4. #4
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take a look at enumerable module. It makes iterating through collections a snap. It's like the difference between the following in php:

    for($i = 0; $i < $arr.length; $i++)
    foreach($arr as $value)

    The latter doesn't seem like you're saving much effort but it helps keep you in flow as you're programming. Likewise, the enumerable methods handles the repetitive parts of the transversal so you can focus on the differences that make a difference.

    # Returns [1, 2]
    [1, 2, 7, 8].select {|i| i < 5 }

    # Returns [7, 8]
    [1, 2, 7, 8].select {|i| i > 5 }

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Fenrir2 View Post
    Ruby can do pretty much the same things as PHP, the difference is the amount of effort you have to put in.
    This is basically it. A lot of lower-level actions (i.e. looping through collections and returning a single value) can be done with less effort on your part as a programmer in Ruby over PHP.

    I also think Ruby's standard library/functions are more organized and consistent than PHP but some people don't agree with me

  6. #6
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    A language is built from 3 things:

    1) the primitive operations
    2) the means of combination
    3) the means of abstraction

    You can build combinations from primitives. Say your primitives are foo and bar. You can combine them like this:

    Code:
    foo(bar(4))
    This is a combination. The means of combination in many languages is parameter passing and sequencing (execute some functions in a sequence):

    Code:
    baz(3);
    foo(5)
    With abstraction you can give names to combinations, like this:

    Code:
    def xyz(n)
      foo(bar(n))
    end
    
    def zyx(n)
      baz(n);
      foo(n)
    end
    Ruby is not very much like PHP qua primitive operations. The means of combination & abstraction (functions, classes) are very much the same, but Ruby has blocks (I won't mention continuations), which add some (minor) power.

    Regular expressions are very different:

    - primitives: literal characters, numbers, etc. "a", "1", "%", etc.
    - means of combination:
    1) 2 literals next to each other "aa", "12"
    2) or: "a|b", "34|576"
    n) some other things
    - abstraction: there is no abstraction in regular expressions, you cannot gives names to combinations to reuse them.

    It's interesting to look at languages (e.g. CSS, SQL) because you'll see that most popular general purpose languages only differ in the primitives.

  7. #7
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Generally, all programming languages targeted to the same platform (like Internet/web) can be made to do all the same things. There is nothing really "magical" that one language can do that others cannot. It's all about implementation and personal preference. Some languages make it easier to do specific tasks, and others may require a little more work to get there. But as a general principle, all programming languages for a specific platform (like Internet/Web) can be built to achieve the same end result.

  8. #8
    SitePoint Evangelist optl's Avatar
    Join Date
    Oct 2004
    Location
    Washington DC
    Posts
    415
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I understand a bit better now. I just think Ruby is over-hyped.
    For the phrase "Bethesda home architect", my clients
    websites occupy 6 of the first 8 results
    on the 1st page of Google. My Secret SEO Strategy Revealed

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    Klagenfurt / Austria
    Posts
    77
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Everything that is hyped is overhyped IMO

  10. #10
    Your daddy. WALoeIII's Avatar
    Join Date
    Apr 2001
    Location
    USA
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ruby's biggest advantage is that it doesn't suckô.

  11. #11
    SitePoint Addict jpease's Avatar
    Join Date
    Jul 2002
    Location
    In the network.
    Posts
    217
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by optl View Post
    Ok I understand a bit better now. I just think Ruby is over-hyped.
    Maybe. But until you have actually coded a project you can't really know for sure. After about two years of Ruby programming, it is my preference. If you like it better, is it hype?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •