Computer Science Canada

Ruby or Python?

Author:  MrHippo [ 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

Author:  wtd [ Wed Dec 05, 2007 6:33 pm ]
Post subject:  RE:Ruby or Python?

Scheme, Ruby or Python, eh? Tough call.

Learn them all.

Author:  Clayton [ 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!

Author:  HeavenAgain [ 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

Author:  MrHippo [ 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...

Author:  HeavenAgain [ 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

Author:  wtd [ 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

Author:  MrHippo [ 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...

Author:  wtd [ 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)))

Author:  Flikerator [ 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)))

Author:  PaulButler [ 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).

Author:  MrHippo [ 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

Author:  PaulButler [ 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.

Author:  wtd [ 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))

Author:  wtd [ 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

Author:  wtd [ Thu Dec 06, 2007 10:00 pm ]
Post subject:  RE:Ruby or Python?

And for fun, a little more. Tell me to stop if this becomes irritating. I may or may not listen to such a suggestion. Wink

Greeting a name thrice.

Ruby:

code:
def greet_thrice(name)
  3.times do
    puts "Hello, #{name}!"
  end
end


Python:

code:
def greet_thrice(name):
  for i in 1..3:
    print "Hello, %s!" % name


Scheme:

code:
(define (greet-thrice name)
  (letrec ((loop (lambda (n f)
                   (when (> n 0)
                     (f n)
                     (loop (- n 1) f))))
           (greet (lambda (name)
                    (display (string-append "Hello, " name "!"))
                    (newline))))
    (loop 3 (lambda (n) (greet name)))))


Now, to greet any number of times...

Ruby:

code:
def greet_n(name, n)
  n.times do
    puts "Hello, #{name}!"
  end
end


Python:

code:
def greet_n(name, n):
  for i in 1..n:
    print "Hello, %s!" % name


Scheme:

code:
(define (greet-n name n)
  (letrec ((loop (lambda (n f)
                   (when (> n 0)
                     (f n)
                     (loop (- n 1) f))))
           (greet (lambda (name)
                    (display (string-append "Hello, " name "!"))
                    (newline))))
    (loop n (lambda (n) (greet name)))))

Author:  HeavenAgain [ Thu Dec 06, 2007 10:09 pm ]
Post subject:  RE:Ruby or Python?

learning all 3 at once, dont stop!!

in ruby: puts "dont stop"
in python: print "dont stop"
in scheme :
(begin
(display "dont stop")
(newline))
Very Happy

Author:  Geminias [ Fri Dec 07, 2007 1:31 am ]
Post subject:  RE:Ruby or Python?

Hmm... The beauty of scheme may be that it eliminates ambiguity of the order of operations, but at a high, in-fact, intolerable price.

The price is this: unreadability.

There's a difference between reading code, and figuring code out. The difference can't be described, except to say, when you are reading code it's like a story unfolding before your eyes, figuring out code is more like watching the letters trail by your eyes. Ruby is the former, Scheme is the ladder. Not to say that if you program in Ruby its needless to learn how to architect code and write maintainable code because the language is so descriptive... These things come part and parcel with writing any code in any language, but Ruby, and even Python as a tool provide the advantage over Scheme in terms of the outline it provides to enable a programmer to write self-documenting code.

Why is this so important? The most important thing in writing any software is managing complexity. Languages like Scheme add unnecessary mental hurdles to the already difficult process of managing complexity. I know that everyone knows what I'm talking about and I don't need to express how it does this, as it is so blatantly obvious.

If you are really concerned with the order in which code is processed, you can use brackets in most languages and not worry about it. And in cases where you can't use brackets there is but a quick google involved.

This over the time you spend adding and removing brackets at random to get your program to merely compile, as well as, the extra time it takes to understand what the code is doing... Well, I leave it to you to decide which is more efficient.

DON'T PROGRAM IN SCHEME LISP etc...
These languages are dumb.

EDIT: Unless you find Scheme reads nicer than any other language you've ever seen. (But I've never known anyone who has found this, probably because the only people I know are humans.) But, by all means, if you can read Scheme easier than the other languages out there, don't listen to a word I've said.

Author:  Tony [ Fri Dec 07, 2007 3:02 am ]
Post subject:  Re: RE:Ruby or Python?

Geminias @ Fri Dec 07, 2007 1:31 am wrote:

This over the time you spend adding and removing brackets at random to get your program to merely compile
...
DON'T PROGRAM IN SCHEME LISP etc...

What you have described (random brackets), is clearly not a process of programming. If your only intention is throwing together enough code to merely compile, then perhaps HTML is a better suited type of work Wink

Author:  PaulButler [ Fri Dec 07, 2007 11:38 am ]
Post subject:  Re: RE:Ruby or Python?

Geminias @ Fri Dec 07, 2007 1:31 am wrote:
Hmm... The beauty of scheme may be that it eliminates ambiguity of the order of operations, but at a high, in-fact, intolerable price.

The price is this: unreadability.


If you only have experience reading imperative languages, yeah, LISP and Scheme will look very foreign, and code in them might be hard to follow. Scheme's syntax does more than just eliminating ambiguity. Macros, for example, are a powerful concept, that would be difficult without a LISP-like syntax (Dylan is the only language I know of that has real macros without a LISP syntax). Eliminating ambiguity is not the beauty of Scheme, it is merely a side-effect of Scheme's beauty.

Geminias wrote:

There's a difference between reading code, and figuring code out. The difference can't be described, except to say, when you are reading code it's like a story unfolding before your eyes, figuring out code is more like watching the letters trail by your eyes. Ruby is the former, Scheme is the ladder. Not to say that if you program in Ruby its needless to learn how to architect code and write maintainable code because the language is so descriptive... These things come part and parcel with writing any code in any language, but Ruby, and even Python as a tool provide the advantage over Scheme in terms of the outline it provides to enable a programmer to write self-documenting code.

Why is this so important? The most important thing in writing any software is managing complexity. Languages like Scheme add unnecessary mental hurdles to the already difficult process of managing complexity. I know that everyone knows what I'm talking about and I don't need to express how it does this, as it is so blatantly obvious.


I will give it to you that Scheme adds mental hurdles. They may be unnecessary, but they pay off in the end. Scheme doesn't increase complexity, if anything it reduces it. Being functional, Scheme allows levels of abstraction that purely imperative languages simply can't.

Geminias wrote:

If you are really concerned with the order in which code is processed, you can use brackets in most languages and not worry about it. And in cases where you can't use brackets there is but a quick google involved.


Err, you are missing the point of Scheme again.

Geminias wrote:

EDIT: Unless you find Scheme reads nicer than any other language you've ever seen. (But I've never known anyone who has found this, probably because the only people I know are humans.) But, by all means, if you can read Scheme easier than the other languages out there, don't listen to a word I've said.


Scheme won't read nicer until you have used it. By all means, choose a language like Ruby or Python to start with if you want more immediate results. But don't discard the idea of ever learning Scheme because it is hard. (And trust me, once you get started, it isn't as hard as it looks.)

EDIT: fixed up quote syntax

Author:  wtd [ Fri Dec 07, 2007 11:58 am ]
Post subject:  RE:Ruby or Python?

It should be noted that the last example points out something important about Scheme. There are no loops.

Yes, you heard me right. There are no loops in Scheme.

But, I still managed to do something repeatedly. Instead of an imperative loop, I used recursion.

Let's consider the anatomy of an imperative loop.

code:
for (int i = 0; i > 3; i++)
{
  std::cout << i << std::endl;
}


You have a starting state.

code:
int i = 0


You have a terminating condition.

code:
i > 3


You have an update.

code:
i++


And of course, you have the thing done.

Now... let's take a look at a looping function in Scheme.

code:
(define (loop initial-value end-loop? update body)
 (when (not (end-loop? initial-value))
    (body initial-value)
    (loop (update initial-value) end-loop? update body)))


Here the condition, the update and the body are all functions passed to the loop function. This could be done more elegantly with macros, but this is conceptually simpler.

And how do we use this to replicate the previous imperative example? Well, we pass lambda (unnamed) functions to loop.

code:
(loop 0
      (lambda (n) (> n 3))
      (lambda (n) (+ n 1))
      (lambda (n)
        (display n)
        (newline)))

Author:  wtd [ Fri Dec 07, 2007 12:02 pm ]
Post subject:  Re: RE:Ruby or Python?

Geminias @ Fri Dec 07, 2007 2:31 pm wrote:
This over the time you spend adding and removing brackets at random


If you're adding and removing parentheses at random, then you don't know the language, and if you've not taken time to understand it, then you are hardly one to critique it.

The irony is that you hold Ruby up as a paragon of productivity. Ruby owes a great deal of its success to ideas borrowed from Scheme.

Author:  Geminias [ Fri Dec 07, 2007 3:13 pm ]
Post subject:  RE:Ruby or Python?

I've never programmed in scheme or ruby so I'm not one to critique either. PaulButler I'll take your points into consideration, although I won't concede that it's necessary to create such a bad syntactic scheme for a programming language to achieve whatever it is that Scheme achieves... Macros I believe you said it was? It's quite likely that there's a better way to do it.

Can anyone name a successful large scale software application that was created in Scheme? Can you name more than one?

(10 000) LOC+ ?

I'm not claiming to be right here: I just can't wrap my head around 5 or more consecutive brackets. If I was to program in Scheme or Lisp, I'm pretty certain that there would be many times where I'd be missing a bracket, and I'd be adding brackets and removing them trying to figure out where I am missing the bracket. That's what I meant by adding random brackets. (Or are you guys such great programmers you never forget closing brackets?)

Author:  Mazer [ Fri Dec 07, 2007 4:22 pm ]
Post subject:  Re: RE:Ruby or Python?

Geminias @ Fri Dec 07, 2007 1:31 am wrote:
DON'T PROGRAM IN SCHEME LISP etc...
These languages are dumb.

Geminias wrote:
I've never programmed in scheme or ruby


What.

Author:  rdrake [ Fri Dec 07, 2007 4:59 pm ]
Post subject:  Re: RE:Ruby or Python?

Geminias @ Fri Dec 07, 2007 3:13 pm wrote:
I'm not claiming to be right here: I just can't wrap my head around 5 or more consecutive brackets. If I was to program in Scheme or Lisp, I'm pretty certain that there would be many times where I'd be missing a bracket, and I'd be adding brackets and removing them trying to figure out where I am missing the bracket. That's what I meant by adding random brackets. (Or are you guys such great programmers you never forget closing brackets?)
An editor which highlights corresponding brackets is your best friend.

Author:  PaulButler [ Fri Dec 07, 2007 9:22 pm ]
Post subject:  Re: RE:Ruby or Python?

Geminias @ Fri Dec 07, 2007 3:13 pm wrote:
Macros I believe you said it was? It's quite likely that there's a better way to do it.


Perhaps there is, but rather than wait for someone to come up with one, I'm content using Scheme (and learning Dylan).

Geminias wrote:

Can anyone name a successful large scale software application that was created in Scheme? Can you name more than one?


I use a computer algebra system called Maxima on a near-daily basis. It was created in LISP. Also, ITA Software powers some online travel brokers, and they have been successful using LISP.

It may not be the massive set of successful, huge Scheme projects you were hoping for, but it does show that having a language with a whole lot of parenthesis doesn't hold one back from making successful, large software. LISP and Scheme are not and will never be as popular as C/Java/Ruby/Python/etc., but assuming that they are inferior because of that is a mistake.

Paul Graham, probably LISP's best known evangelist, has written a lot in favor of LISP.

Author:  wtd [ Sat Dec 08, 2007 2:09 am ]
Post subject:  RE:Ruby or Python?

Now, back to your regularly scheduled education. Let's say you want to print a number before each iteration.

Ruby:

code:
def greet_n(name, n)
  n.times do |n|
    puts "#{n + 1}. Hello, #{name}!"
  end
end


Python:

code:
def greet_n(name, n):
  for i in 1..n:
    print "%d. Hello, %s!" % (i, name)


Scheme:

code:
(define (generic-loop initial-value end-loop? update body)
  (when (not (end-loop? initial-value))
    (body initial-value)
    (generic-loop (update initial-value) end-loop? update body)))

(define (loop-n-times n body)
  (generic-loop 0
                (lambda (m) (>= m n))
                (lambda (m) (+ m 1))
                (lambda (m) (body m))))

(define (greet-n name n)
  (loop-n-times n
                (lambda (m)
                  (display (+ m 1))
                  (display (string-append ". Hello, " name "!"))
                  (newline))))

Author:  wtd [ Sat Dec 08, 2007 3:21 am ]
Post subject:  RE:Ruby or Python?

But if we try to print out 10 names, the numbers will no longer be lined up correctly.

Ruby:

code:
def greet_n(name, n)
  n_digits = n.to_s.length
  n.times do |m|
    puts "#{(m + 1).to_s.rjust(n_digits)}. Hello, #{name}!"
  end
end


Python:

code:
def greet_n(name, n):
  n_digits = len(str(n))
  for i in 1..n:
    print "%s. Hello, %s!" % (str(i).rjust(m_digits), name)


Scheme:

code:
(define (generic-loop initial-value end-loop? update body)
  (when (not (end-loop? initial-value))
    (body initial-value)
    (generic-loop (update initial-value) end-loop? update body)))

(define (loop-n-times n body)
  (generic-loop 0
                (lambda (m) (>= m n))
                (lambda (m) (+ m 1))
                (lambda (m) (body m))))

(define (number-of-digits n)
  (if (< n 10)
      1
      (+ 1 (number-of-digits (/ n 10)))))

(define (greet-n name n)
  (let ((n-digits (number-of-digits n)))
    (loop-n-times n
                  (lambda (m)
                    (let ((m-digits (number-of-digits (+ m 1))))
                      (loop-n-times (- n-digits m-digits)
                                    (lambda (x) (display #\space)))
                      (display (+ m 1))
                      (display (string-append ". Hello, " name "!"))
                      (newline))))))

Author:  McKenzie [ Sat Dec 08, 2007 10:00 am ]
Post subject:  Re: RE:Ruby or Python?

Oops, minor mistake. These Python for loop need range():

Python:
code:

  for i in 1..range(n):

Author:  PaulButler [ Sat Dec 08, 2007 10:48 am ]
Post subject:  Re: RE:Ruby or Python?

McKenzie @ Sat Dec 08, 2007 10:00 am wrote:
Oops, minor mistake. These Python for loop need range():

Python:
code:

  for i in 1..range(n):


I think you mean
code:

  for i in range(1,n):

Author:  wtd [ Sat Dec 08, 2007 11:32 am ]
Post subject:  Re: RE:Ruby or Python?

McKenzie @ Sat Dec 08, 2007 11:00 pm wrote:
Oops, minor mistake. These Python for loop need range():

Python:
code:

  for i in 1..range(n):


Quite right. Thanks for catching that.

Author:  Geminias [ Sat Dec 08, 2007 1:24 pm ]
Post subject:  Re: Ruby or Python?

What I gather is Scheme/LISP can be used to produce elegant solutions in select cases. But, given the lack of large scale applications created with this language, it appears I was correct that Scheme has a syntax that creates mental hurdles, which makes code harder to maintain. Can we all agree on that?

EDIT: By the way have any of you actually studied software engineering or do you think that because you can write complex one-lined code that no one else can figure out you are brilliant coders?

From an engineering perspective my opinions are justified. You don't need to be a guru of a language to point out that it's syntax can cause maintainability issues.

Author:  Naveg [ Sat Dec 08, 2007 1:56 pm ]
Post subject:  RE:Ruby or Python?

You're missing the point. To anyone who knows scheme, the brackets make perfect sense. In fact, I've always been of the opinion that brackets make things clearer - in almost any language. I've never been a fan of memorizing operator precedence tables, for example, when I can just avoid any possible problems by using more brackets.

Author:  gvc [ Sat Dec 08, 2007 2:06 pm ]
Post subject:  ~

Geminias @ Sat Dec 08, 2007 1:24 pm wrote:
What I gather is Scheme/LISP can be used to produce elegant solutions in select cases. But, given the lack of large scale applications created with this language, it appears I was correct that Scheme has a syntax that creates mental hurdles, which makes code harder to maintain. Can we all agree on that?



Definitely not. The examples in this thread are bogus, as are the Scheme solutions, as is the assumption that no large software projects are written in Lisp/Scheme.

Here's an excerpt from an email I received the other day from the former CTO of a company that was sold for 1.3 billion dollars:

http://groups.google.com/group/uw.cs.cs241/browse_thread/thread/6d1f732e0a6faf1e#858fd6e11b5caa6d

Draw your own conclusions. As for printing "hello" three times:

(define (print-hello x)
(printf "hello ~a\n" x)
(printf "hello ~a\n" x)
(printf "hello ~a\n" x))

To print n times.

(define (print-hello x n)
(cond ((> n 0)
(printf "hello ~a\n x)
(print-hello (- n 1)))))

I'll leave it as an exercise to you to figure out the printf codes
to line up the output. You don't seriously think that that is a
reason for selecting a particular language?

The point about Scheme is that the core language is extremely
simple and precisely defined. You can do anything you want in
the core language, and there are libraries for every conceivable
hacker-type thing you might want to do, like writing a web server
or a video game or whatever.

Python, Ruby and the like have a complicated set of builtin stuff
that make writing *certain* problems simple, aren't themselves
necessarily easy to understand or to apply to non-trivial problems.

Now two of my examples that you can feel free to translate so
as to show us how Ruby or Python trivializes them.

(1) trivial example: read 3 integers and print their sum

(+ (read) (read) (read))

(2) less trivial example: the compiler prototype for cs241 at Waterloo

http://www.student.cs.uwaterloo.ca/~cs241/a09/wlgen.ss

here's a Java version if you prefer

http://www.student.cs.uwaterloo.ca/~cs241/a09/WLGen.java

Author:  gvc [ Sat Dec 08, 2007 2:25 pm ]
Post subject:  Scheme textbook

You can dowload Dr. Scheme here: http://www.plt-scheme.org/

Follow the link "How to design computer programs" to find an on-line copy
of the introductory text that is used at Waterloo. It assumes no programming
experience and teaches both Scheme and Computer Science from scratch.

If you already know how to program you can read the first dozen chapters
fairly quickly but you should read them as Scheme requires a different
mind-set from what you might have acquired by learning other languages.

Author:  PaulButler [ Sat Dec 08, 2007 3:28 pm ]
Post subject:  Re: Ruby or Python?

Geminias @ Sat Dec 08, 2007 1:24 pm wrote:
What I gather is Scheme/LISP can be used to produce elegant solutions in select cases. But, given the lack of large scale applications created with this language, it appears I was correct that Scheme has a syntax that creates mental hurdles, which makes code harder to maintain. Can we all agree on that?


I provided a few examples of successful, large LISP apps that I knew of, which I think is enough to show that it is possible to write a LISP app of that scale (existential proof?). If you require evidence that lots of people are using LISP, you aren't going to find it, because LISP just isn't that common. So if you want to use popularity as a measure of how good a language is, LISP will not be that appealing.

I will admit that Scheme/LISP does add mental hurdles. But these mental hurdles didn't scare me away from learning Scheme, because I recognized them as the same sort of hurdles that I encountered when I went from BASIC to C (no GOTO? How do I program without GOTO?) and C to Java/C++ (object-oriented programming).

Geminias wrote:

EDIT: By the way have any of you actually studied software engineering or do you think that because you can write complex one-lined code that no one else can figure out you are brilliant coders?


I am in CS at UWaterloo, as are at least a few of the others in this discussion. I never claimed to be a brilliant coder, but writing complex one-lined code that no one can read is a skill I have acquired and am quite proud of Razz.

Geminias wrote:

From an engineering perspective my opinions are justified. You don't need to be a guru of a language to point out that it's syntax can cause maintainability issues.


Maybe not a guru, but having some experience in it would help your case rather than just deciding that it is unmaintainable based on ugly syntax. LISP is known for being more expressive than imperative languages, at least in some cases. I don't know a whole lot about real-world maintainability (do you?), but it would seem to me that in theory less code would mean more maintainable code.

Author:  wtd [ Sat Dec 08, 2007 5:11 pm ]
Post subject:  Re: ~

gvc @ Sun Dec 09, 2007 3:06 am wrote:
The examples in this thread are bogus


They are trivial, yes. But I like to keep early stuff small so it's easy to fit into a student's brain.

A series of small victories, leading to something larger is perhaps the best way to look at my approach.

Author:  Geminias [ Sat Dec 08, 2007 6:55 pm ]
Post subject:  RE:Ruby or Python?

Grr.. I hate when people mutilate my sentences. Or perhaps you are too young to know that "lack of" does not mean "none". If i had meant no large scale applications have been created with Scheme I would have said something to the effect of: "No large scale applications were created in Scheme." Yes my tone is condescending right now, so feel free to be pissed off cause you're an idiot! (Does not apply to those who know what 'lack of' means.)

To be fair, I can't with certainty say that Scheme code is less maintainable than: insert_language_name_here. Because for one thing there are far less programmers who use Scheme than C.

However, there isn't exactly an overwhelming amount of large scale (and successful) applications written in Scheme as I already pointed out...

I agree I can always learn more about Scheme and perhaps I underestimate it's usefulness, but after writing my own emacs extensions in LISP I always had the sense that I was lost when I read through the Emacs source code. I don't think any amount of knowledge is going to convince me that Scheme has a syntax as conducive to maintainability as python and even C. I suppose Scheme is a step up from IA32 assembly but I'd still place it in between asm and C in terms of how easy it is to write maintainable code.

Well, that's my two cents anyway. Note I never said nothing could change my mind, its just I doubt anything will.

Author:  wtd [ Sat Dec 08, 2007 7:31 pm ]
Post subject:  RE:Ruby or Python?

Do not mistake the complexity of an API (which is what Emacs LISP amounts to) for inherent complexity of the core language. I am not familiar with Emacs LISP, so I suspect that if I were to just jump into it, I'd feel rather lost as well.

Keep in mind that Scheme and Lisp programmers work from a somewhat different frameset than programmers in other languages. Typically, a programmer takes a problem and breaks it down to a point where it can be expressed in the desired programming language.

A Lisper frequently builds up the language to a point where it is more convenient to express the solution for the given program. You'll hear the term "domain specific languages" thrown around. Scheme and Lisp's syntax is highly flexible, lending it to this kind of customization.

Author:  PaulButler [ Sat Dec 08, 2007 8:32 pm ]
Post subject:  Re: RE:Ruby or Python?

Geminias @ Sat Dec 08, 2007 6:55 pm wrote:
Grr.. I hate when people mutilate my sentences. Or perhaps you are too young to know that "lack of" does not mean "none". If i had meant no large scale applications have been created with Scheme I would have said something to the effect of: "No large scale applications were created in Scheme."


I never denied that there is a lack of LISP/Scheme applications. In fact, I outwardly admitted it when I said "If you require evidence that lots of people are using LISP, you aren't going to find it [...]". Instead, I argued that there were enough examples of applications that worked to show that these languages can be used on a large scale. Again, if you want evidence that a lot of people are using these languages, you will not find it. If you are choosing languages by popularity, LISP and Scheme don't even make the list.

Geminias wrote:

Yes my tone is condescending right now, so feel free to be pissed off cause you're an idiot! (Does not apply to those who know what 'lack of' means.)


A condescending tone and personal attacks don't bother me coming from someone who has never met me, if you think it helps you get the point across. But I would disagree with you there as well.

Geminias wrote:

To be fair, I can't with certainty say that Scheme code is less maintainable than: insert_language_name_here. Because for one thing there are far less programmers who use Scheme than C.

However, there isn't exactly an overwhelming amount of large scale (and successful) applications written in Scheme as I already pointed out...


There are many more C programmers than Schemers. If that is what matters for you, by all means, go with C. Picking food by the same criteria would get you McDonald's.

(I'm not comparing C with McDonald's; C is a useful language)

Geminias wrote:

I agree I can always learn more about Scheme and perhaps I underestimate it's usefulness, but after writing my own emacs extensions in LISP I always had the sense that I was lost when I read through the Emacs source code. I don't think any amount of knowledge is going to convince me that Scheme has a syntax as conducive to maintainability as python and even C. I suppose Scheme is a step up from IA32 assembly but I'd still place it in between asm and C in terms of how easy it is to write maintainable code.

Well, that's my two cents anyway. Note I never said nothing could change my mind, its just I doubt anything will.


If you want to avoid Scheme, it's none of my business. I just don't like seeing someone tell beginners not to learn a certain language that they have never used because they don't like the syntax.

It's more fun to defend LISP without resorting to quoting Paul Graham, but some people might be interested in an essay of his called Beating the Averages.

Author:  Geminias [ Sat Dec 08, 2007 9:30 pm ]
Post subject:  RE:Ruby or Python?

Quote:
Do not mistake the complexity of an API (which is what Emacs LISP amounts to) for inherent complexity of the core language.


Yes this is always the truth. But I know I'm not the only one who gets lost in brackets.


Quote:
A Lisper frequently builds up the language to a point where it is more convenient to express the solution for the given program. You'll hear the term "domain specific languages" thrown around. Scheme and Lisp's syntax is highly flexible, lending it to this kind of customization.


This is the best point I've heard so far. Paul Butler raised some good points and so did a few others. I take back my advice about not learning Scheme. I find the syntax of Scheme disagreeable, but I cannot suggest a replacement language, therefore I'm forced to concede I gave bad advice. Thanks to all who helped change my mind Smile

Author:  MrHippo [ Sun Dec 09, 2007 1:54 am ]
Post subject:  Re: Ruby or Python?

Well thanks for the advice (though it did get a bit off-topic =P)

I decided to focus on Ruby for now simply because I want to be able to participate in the CCC and that doesn't give me much time to fiddle around with 3 (or even 2) languages at once.
Not sure if Ruby is the best choice, but it's better than sitting and thinking which one to choose hehehe...

Thanks again!

-MrHippo

Author:  McKenzie [ Sun Dec 09, 2007 1:26 pm ]
Post subject:  Re: Ruby or Python?

I know you've made your "final" decision, but if it is the CCC you are focused on, I would strongly suggest Python. It breaks a number of problems. A few quick reasons:
- eval
- list comprehensions
- basic functional programming
- translation tables
- automatic handling of "big" integers

I really don't know enough Ruby to judge how good it would be for CCC problems. Also keep in mind that CCC stage 2 only allows C/C++ and pascal.

Author:  wtd [ Sun Dec 09, 2007 1:32 pm ]
Post subject:  RE:Ruby or Python?

Assuming that "translation tables" means "associative arrays", then yes, Ruby does all of these things very well. It also takes functional programming seriously, whereas the Python leadership seems determined to remove it from future implementations.

Author:  MrHippo [ Sun Dec 09, 2007 3:15 pm ]
Post subject:  RE:Ruby or Python?

Hehe I'm really not worried about stage 2. I doubt I could get good enough to beat 2000 other people in 2 months... Don't even know if that's possible starting from no knowledge of computers (at a comp. sci. level)

Python and Ruby seem similar at a glance though..

Author:  PaulButler [ Sun Dec 09, 2007 4:46 pm ]
Post subject:  RE:Ruby or Python?

I think Ruby is a fine choice. McKenzie makes some good points, but I'm not sure how well they apply to the CCC.

- Ruby does have eval (eval "1 + 1" => 2), although I'm not sure if that would come in handy on the CCC.

- I could be wrong about this, but I thought list comprehensions were just syntax. Ruby does have list functions like map, which is one thing that list comprehensions can be used for. I don't know the full power of list comprehensions (yet), so maybe there is more to them that I am missing.

- Ruby has some basic functional capabilities, like closures and higher-order functions. I find Python's lambda more limiting than Ruby's, because Ruby treats all code blocks as the same (IIRC) but Python treats lambdas as a single statement, not a code block (that's my understanding, anyway).

- Automatic handling of big integers is a big one. It's nice to have the math taken care of without any extra effort on your part, and you don't get that in Ruby. If I remember, you don't have to deal with huge numbers in the CCC, but it's something to consider.

Personally I prefer Python myself, but it really comes down to a matter of preference, the languages are so similar in the power they give to a beginner. Maybe at higher levels they differ more, but they seem similar at the bottom.

By the way, good luck with the CCC MrHippo.

Author:  richcash [ Sun Dec 09, 2007 6:24 pm ]
Post subject:  Re: Ruby or Python?

Quote:
- Automatic handling of big integers is a big one. It's nice to have the math taken care of without any extra effort on your part, and you don't get that in Ruby.

Ruby definetely does do that. It's one of its advantages.

As wtd and PaulButler said, I think ruby does everything on mckenzie's list fully well.

I am not qualified to judge, but it seems a bit useless for a beginner to learn both ruby and python simultaneously. They are too similar. Wouldn't you rather learn different types of languages with different concepts?

Author:  PaulButler [ Sun Dec 09, 2007 7:21 pm ]
Post subject:  Re: Ruby or Python?

richcash @ Sun Dec 09, 2007 6:24 pm wrote:
Quote:
- Automatic handling of big integers is a big one. It's nice to have the math taken care of without any extra effort on your part, and you don't get that in Ruby.

Ruby definetely does do that. It's one of its advantages.


Hmm, you're right, it does. It's weird, because I'm sure I remember doing something in irb just the other day that overflowed the number type, but now as hard as I try I can't get an error. I guess it was just my imagination.

Author:  MrHippo [ Sun Dec 09, 2007 8:07 pm ]
Post subject:  RE:Ruby or Python?

I'm checking out Why's Guide and it's pretty interesting and well-written Smile See where it takes me...

Hopefully by the end of December I'll at least have a clue how to program solutions to the easier problems I saw on the CCC website x_x

Thanks for the help everyone!

-MrHippo

Author:  Bobrobyn [ Mon Dec 10, 2007 6:11 pm ]
Post subject:  Re: Ruby or Python?

richcash @ Sun Dec 09, 2007 7:24 pm wrote:
I am not qualified to judge, but it seems a bit useless for a beginner to learn both ruby and python simultaneously. They are too similar. Wouldn't you rather learn different types of languages with different concepts?


I think a beginner would be better off learning one language fully (or close too), and then moving on, rather than two similiar languages like Ruby and Python but not getting as far. I learned Java and assembly in the same semester, but they're so different that they hardly interfered with eachotherr in my head. However, if I had to learn something as similiar as Ruby and Python at the same time, I would totally confuse the syntax. Heh.

My opinion: It doesn't matter which you learn first. Just learn it well, and then learn the one you didn't learn later.


: