SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sick and tired of php, wanting to see what all of the ruby "hype" is

    so, I'm making it your job to make me fall in love with ruby

    post a snippet of an example code, and if you know php too, post the equivalent PHP code

    also, I'm unable to find any "good" examples of code on google for RoR
    so, some helpful links would be useful


    oh, and I've found that sometimes when learning a new language I can never find the equivalent to the following PHP things


    md5
    while
    mysql_query
    mysql_fetch_assoc
    mysql_connect
    header
    exit
    _POST
    _GET
    _SERVER
    var_dump
    ..
    ect
    you know, the basic things..

    thanks

  2. #2
    SitePoint Guru Skyblaze's Avatar
    Join Date
    Jul 2005
    Location
    Italy
    Posts
    734
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i started php not so long ago but i left it for good. Go buy sitepoint's rails book and go on

  3. #3
    ☆★☆★ 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 I87 View Post
    oh, and I've found that sometimes when learning a new language I can never find the equivalent to the following PHP things
    Perhaps always thinking in PHP is why you're having such a hard time with other languages.
    Quote Originally Posted by I87
    md5
    Code:
    require 'digest/md5'
    my_hashed_username = Digest::MD5.hexdigest('vgarcia')
    Quote Originally Posted by I87
    while
    for, loop do, while, blocks
    Quote Originally Posted by I87
    mysql_query
    mysql_fetch_assoc
    mysql_connect
    You don't have to worry about these if you're using Rails, look up what ActiveRecord does.
    Quote Originally Posted by I87
    header
    Kinda the same, you set response.headers['whatever_header_here']
    Quote Originally Posted by I87
    exit
    Quote Originally Posted by I87
    _POST
    _GET
    the params hash
    Quote Originally Posted by I87
    _SERVER
    Mostly variables in the request object.
    Quote Originally Posted by I87
    var_dump
    object.inspect

  4. #4
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Skyblaze View Post
    i started php not so long ago but i left it for good. Go buy sitepoint's rails book and go on
    I would, but I have no money at all right now! :{

  5. #5
    Non-Member I87's Avatar
    Join Date
    Mar 2006
    Location
    UK
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vgarcia View Post
    Perhaps always thinking in PHP is why you're having such a hard time with other languages.
    I think you're right.
    but, I've been coding in php for 3-4 years now, so it's quite a large habit to break.


    Code:
    require 'digest/md5'
    my_hashed_username = Digest::MD5.hexdigest('vgarcia')
    I love not having the dollar signs. it looks a lot less messy already

    for, loop do, while, blocks

    You don't have to worry about these if you're using Rails, look up what ActiveRecord does.
    I just read up on it, and the one problem I have is this-
    "Active Record is only 50% slower than going directly to the metal."

    so, does that mean that active record is a lot slower than some other alternatives that are out there? I think speed is one of the most important things to me. Every 0.1 second counts, lol.


    also one more question- what's a good ruby IDE editor for linux? (ubuntu, to be exact)

  6. #6
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Vim, Emacs ;-) Scite.

  7. #7
    ☆★☆★ 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 I87 View Post
    I just read up on it, and the one problem I have is this-
    "Active Record is only 50% slower than going directly to the metal."

    so, does that mean that active record is a lot slower than some other alternatives that are out there? I think speed is one of the most important things to me. Every 0.1 second counts, lol.
    Are you in a position where speed really matters? Most of ActiveRecord's queries end up being stuff like "SELECT * FROM posts WHERE mycondition='blah'", which isn't very database intensive. If you do end up needing to run a custom query and ActiveRecord is making it slow, you can pass the SQL directly. Example:
    Code:
    def really_expensive_method
      @posts = Post.find_by_sql("THIS IS MY REALLY COMPLICATED SQL QUERY")
    end
    You then bypass AR completely and don't get the performance hit. But in the meantime, use ActiveRecord and save yourself coding time.
    Quote Originally Posted by I87
    also one more question- what's a good ruby IDE editor for linux? (ubuntu, to be exact)
    vim/emacs, Scribes


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
  •