Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Ruby or Python?
Index -> General Programming
Goto page 1, 2, 3, 4  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MrHippo




PostPosted: Wed Dec 05, 2007 5:19 pm   Post subject: Ruby or Python?

Hey!

I'm a beginner in programming, and I'm wondering what I should explore first. I was thinking of python, but Ruby seems to have a pretty good rep as a beginner language so I'm in a state of indecision right now and any help would be greatly appreciated Smile

Also, is it better to try to learn through simply reading online tutorials or to try to set a goal in terms of writing a program and then do what you can to reach the goal (using said tutorials)? I heard something about MIT having online material regarding computer science at a beginner level too, is that worth exploring?? [edit] In fact, I actually checked out the OpenCourseWare, and the very beginner's course seems like something I might be able to do outside of school (I'm in gr. 12). It uses Scheme though, would that be worth doing or is it better to stick to internet resources?

Thanks a lot in advance!

-MrHippo
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Wed Dec 05, 2007 6:33 pm   Post subject: RE:Ruby or Python?

Scheme, Ruby or Python, eh? Tough call.

Learn them all.
Clayton




PostPosted: Wed Dec 05, 2007 7:24 pm   Post subject: RE:Ruby or Python?

Like wtd says, learning each of those languages does not go amiss. However, I know that not everyone can just pick up three languages immediately.

Personally, I would advise you to learn Ruby. It's elegancy and easy to read nature makes it a perfect fit for a beginner programmer. Plus, it's got enough interesting stuff going on later that can keep even the most experienced programmer happy for quite some time.

However, unfortunately, while I'd like to brainwash you into using Ruby, that's just not what's going to happen, so instead, I suggest that you take a look at each of the languages, learn a the basic key concepts in each of those languages and make your decision based on that.

Good Luck!
HeavenAgain




PostPosted: Wed Dec 05, 2007 7:49 pm   Post subject: RE:Ruby or Python?

A lot of university are teaching Python first year? at least i know UoT is, might be a good choice, but still depend on yourself. I would learn them all Smile NOT!!!! :p
MrHippo




PostPosted: Wed Dec 05, 2007 9:54 pm   Post subject: RE:Ruby or Python?

Learning everything sounds good, though difficult =(

I tried out the free on-line lectures from MIT and it's pretty interesting, thought I think they use Scheme as well. My main goal was to learn about the concepts of programming through an easy-to-learn language and then apply the knowledge in order to "master" something like C++.

That seems pretty far down the road though...
HeavenAgain




PostPosted: Wed Dec 05, 2007 10:06 pm   Post subject: RE:Ruby or Python?

getting the concepts is hard, switching to a new lanuage is not TOO hard, most syntax are pretty alike, just how you use it is different, remember programming language is only a tool, the tool master is still your head, if you get the idea, of doing things, changing to an efficient tool isnt that hard.
my suggestion is, dont aim to master one language, but instead master the logic and algorithm behind it, because language can always be out of date, but concepts cant Very Happy just my cookies
wtd




PostPosted: Thu Dec 06, 2007 2:20 pm   Post subject: RE:Ruby or Python?

You could learn in parallel, comparing and contrasting as you go.

For instance, simple values like integers:

Ruby, Python and Scheme:

code:
1
2
-3
42


Pretty simple stuff. Now, for real numbers (those with some decimal value:

Ruby, Python and Scheme:

code:
1.0
2.13528
3.01
-0.45


Binding a value to some name.

Ruby and Python:

code:
answer_to_everything = 42
bad_pi_approximation = 3.14


Scheme:

code:
(define answer-to-everything 42)
(define bad-pi-approximation 3.14)


Printing "Hello, world!"

Ruby:

code:
puts "Hello, world!"


Python:

code:
print "Hello, world!"


Scheme:

code:
(begin
  (display "Hello, world!")
  (newline))


Defining a function to do that.

Ruby:

code:
def hello_world
  puts "Hello, world!"
end


Python:

code:
def hello_world():
  print "Hello, world!"


Scheme:

code:
(define (hello-world)
  (begin
    (display "Hello, world!")
    (newline)))


Calling those functions.

Ruby:

code:
hello_world


Python:

code:
hello_world()


Scheme:

code:
(hello-world)


Creating a function that takes a name and displays an appropriate greeting, and then calling that function for "Bob".

Ruby:

code:
def hello(name)
  puts "Hello, #{name}!"
end

hello("Bob")


Python:

code:
def hello(name):
  print "Hello, %s!" % name

hello("Bob")


Scheme:

code:
(define (hello name)
  (begin
    (display (string-append "Hello, " name "!"))
    (newline)))

(hello "Bob")


Using a local variable to hold the greeting text.

Ruby:

code:
def hello(name)
  greeting = "Hello, #{name}!"
  puts greeting
end


Python:

code:
def hello(name):
  greeting = "Hello, %s!" % name
  print greeting


Scheme:

code:
(define (hello name)
  (begin
    (let ((greeting (string-append "Hello, " name "!")))
      (display greeting))
    (newline)))


Or perhaps:

code:
(define (hello name)
  (let ((greeting (string-append "Hello, " name "!")))
    (begin
      (display greeting)
      (newline))))


There, a few different concepts, in all three languages. That wasn't so bad, was it? Smile
MrHippo




PostPosted: Thu Dec 06, 2007 3:53 pm   Post subject: RE:Ruby or Python?

Hehe thanks a lot! =) Seems like a bit more work, but also sounds like it's definitely worth it in the long run!

We'll see how it goes... however, Scheme does seem less user-friendly (for beginners) than the other two, I wonder why places like Waterloo use it in some of the beginner courses instead of the others...
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Thu Dec 06, 2007 3:57 pm   Post subject: RE:Ruby or Python?

And just because I'm bored...

Changing the message depending on what name is given. I'll also use a second function to generate the greeting.

Ruby:

code:
def greeting(name)
  if name == "Clarence"
    "Hi!  Did your parents hate you?"
  elsif name == "Sid"
    "Hola!  That's a nice short name."
  else
    "Hello, #{name}!"
  end
end

def hello(name)
  puts greeting(name)
end


Or:

code:
def greeting(name)
  case name
    when "Clarence"
      "Hi!  Did your parents hate you?"
    when "Sid"
      "Hola!  That's a nice short name."
    else
      "Hello, #{name}!"
  end
end

def hello(name)
  puts greeting(name)
end


Python:

code:
def greeting(name):
  if name == "Clarence":
    return  "Hi!  Did your parents hate you?"
  elif name == "Sid":
    return "Hola!  That's a nice short name."
  else:
    return "Hello, %s!" % name

def hello(name):
  print greeting(name)


Scheme:

code:
(define (greeting name)
  (cond ((string=? name "Clarence")
         "Hi!  Did your parents hate you?")
        ((string=? name "Sid")
         "Hola!  That's a nice short name.")
        (else
         (string-append "Hello, " name "!"))))

(define (hello name)
  (begin
    (display (greeting name))
    (newline)))


But that doesn't account for a name like "clarence" where all of the characters are lowercase.

code:
def greeting(name)
  case name.downcase
    when "clarence"
      "Hi!  Did your parents hate you?"
    when "sid"
      "Hola!  That's a nice short name."
    else
      "Hello, #{name}!"
  end
end

def hello(name)
  puts greeting(name)
end


Python:

code:
def greeting(name):
  if name.lower() == "clarence":
    return  "Hi!  Did your parents hate you?"
  elif name.lower() == "sid":
    return "Hola!  That's a nice short name."
  else:
    return "Hello, %s!" % name

def hello(name):
  print greeting(name)


Scheme:

code:
(define (greeting name)
  (cond ((string-ci=? name "Clarence")
         "Hi!  Did your parents hate you?")
        ((string-ci=? name "Sid")
         "Hola!  That's a nice short name.")
        (else
         (string-append "Hello, " name "!"))))

(define (hello name)
  (begin
    (display (greeting name))
    (newline)))
Flikerator




PostPosted: Thu Dec 06, 2007 4:09 pm   Post subject: Re: RE:Ruby or Python?

MrHippo @ Thu Dec 06, 2007 4:53 pm wrote:
Hehe thanks a lot! =) Seems like a bit more work, but also sounds like it's definitely worth it in the long run!

We'll see how it goes... however, Scheme does seem less user-friendly (for beginners) than the other two, I wonder why places like Waterloo use it in some of the beginner courses instead of the others...


Waterloo uses its own Scheme languages to teach students (As the course goes on, the languages progress to more and more complex language variations). Also, a considerable amount of people already have programming experience so its an easy switch from OOP to functional (at least it was for me). For instance, hello world can be as simple as;

code:
"Hello World"


A function starts as;

code:
(define (sum n1 n2)
 (+ n1 n2))


and ends up as

code:
(define sum
 (lambda (n1 n2)
  (+ n1 n2)))
PaulButler




PostPosted: Thu Dec 06, 2007 4:18 pm   Post subject: RE:Ruby or Python?

Python and Ruby are both quite similar in terms of what you can do with them, at least as a beginner. Both are simple to learn and have a friendly beginner community. Choosing between the two is really just a matter of preference. Personally, I prefer Python, but either are an excellent choice for a beginner.

I don't disagree with the idea of learning them in parallel, but keep in mind that you may initially find it easier to lean them one at a time. Otherwise, you may find yourself confusing the syntax a lot and getting frustrated when your programs won't run.

Scheme is a very cool language as well, but you may find that it takes you more time and effort to create programs you can actually use (for example, a simple game) and this might reduce your motivation to learn. If you want to learn Scheme, "Teach Yourself Scheme in Fixnum Days" is a good reference, and so is "How to Design Programs" (both are available for free online).
MrHippo




PostPosted: Thu Dec 06, 2007 4:20 pm   Post subject: RE:Ruby or Python?

X_X Seems like it could get pretty confusing, especially if I approach more advanced concepts. However, no point speculating!

*off to learn some programming*

Thanks!

-MrHippo
PaulButler




PostPosted: Thu Dec 06, 2007 4:26 pm   Post subject: Re: RE:Ruby or Python?

Flikerator @ Thu Dec 06, 2007 4:09 pm wrote:

Waterloo uses its own Scheme languages to teach students (As the course goes on, the languages progress to more and more complex language variations). Also, a considerable amount of people already have programming experience so its an easy switch from OOP to functional (at least it was for me).


Waterloo uses DrScheme, which is available for free and it is something you should look into if you decide to go with Scheme. Calling it Waterloo's own is a bit misleading, it is not made for Waterloo and a good number of other universities use it as well.
wtd




PostPosted: Thu Dec 06, 2007 5:13 pm   Post subject: RE:Ruby or Python?

Scheme is less user-friendly?

Perhaps you are referring to the parentheses, and feel intimidated by them. The beauty of Scheme is that there is very little in the way of syntax, and very very little ambiguity.

In Ruby, for instance:

code:
puts 5 + 4 + 3 - 2


What is the order of precedence? Does "puts 5" get evaluated first, or "5 + 4 + 3 - 2".

Of course, with an interactive interpreter it's easy enough to find out, but Scheme does not have this ambiguity at all.

code:
(display (- (+ 5 4 3) 2))
wtd




PostPosted: Thu Dec 06, 2007 5:28 pm   Post subject: Re: RE:Ruby or Python?

Flikerator @ Fri Dec 07, 2007 5:09 am wrote:
and ends up as

code:
(define sum
 (lambda (n1 n2)
  (+ n1 n2)))


Nawww... it hardly ends there. Imagine you want to sum a variable number of integers.

code:
(define (sum . args)
  (letrec ((reduce (lambda (init f lst)
                     (if (empty? lst)
                         init
                         (reduce (f init (car lst)) f (cdr lst))))))
    (reduce 0 + args)))


Smile
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 4  [ 50 Posts ]
Goto page 1, 2, 3, 4  Next
Jump to:   


Style:  
Search: