HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free and registered users see less advertising! If you just want to browse through the existing questions, just select the forum that you want to visit from the selection below. Otherwise, click here to register!. We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Re: Tell me...

Nobody's forcing you to use Python. I rather like it. I may try ruby someday if I get time, but it's not a very high priority, especially with the other things I have going on (setting up home network, converting mp3s to oggs, learning perl, etc).

Re: Tell me...

GnuVince said:

How about just one?

Feztaa said :

Because then the language would be really boring and restrictive. Different methods of doing things can provide different functionality.

While true Feztaa, this also means that it creates hell for the programmer that comes behind you and has to debug your work. Why waste 10 lines of code with something that you can accomplish with just 1?

Re: Tell me...

While true Feztaa, this also means that it creates hell for the programmer that comes behind you and has to debug your work. Why waste 10 lines of code with something that you can accomplish with just 1?

Possibly because the 10 line method provides additional functionality that you wouldn't otherwise have in the 1 line method.

Or, possibly because the 10 line method was written by a bad programmer

Re: Tell me...

I'm continuing to experiment Python. *I've gotten to the point that the syntax almost doesn't bother me anymore. *But, I must say that I would like the python indent file of Vim to be a little bit more featureful.

I submitted a Rock-Paper-Cisor example to codeexamples.org, here it is, tell me what you think.

Re: Tell me...

For people who are interested, here's the same thing in Ruby (it's been sumbitted too):

Code:

#!/usr/bin/env ruby
=begin
*rpc.rb - copyright (c) 2001, Vincent Foley-Bourgon &lt;gnuvince@yahoo.ca&gt;
*This program is lisenced under the GNU General Public License (GPL)
*&lt;http://www.gnu.org/copyleft/gpl.html&gt;
=end
# I use global variables for the scores. *Some may say it's bad programming
# practice, but it's still useful to know how to do them. *In Ruby, just put
# a '$' sign before the name
$score_player = 0
$score_cpu = 0
# This function will display an error message and will then wait for the user
# to press Enter
def error_msg
*puts &quot;\nInvalid option&quot;
*puts &quot;Press Enter to continue...&quot;
*gets
end
# This function will determine who is the winner of the current round
# We recieved the weapon of player and of the computer
def determine_winner(player, cpu)
*# If both players have the same weapon, we return &quot;Tie!&quot;
*if player == cpu
* *&quot;Tie!&quot;
*# OK, this is a tricky part. *We created a hash that tells what wins over
*# what. *'put Winners[&quot;Rock&quot;]' will print &quot;Cisor&quot;. *So we check if the
*# weapon of the computer is the same as what the Weapon of the player beats
*# If it beats it, we give one point to player and we return &quot;Player Wins!!&quot;
*elsif Winners[player] == cpu
* *$score_player += 1
* *&quot;Player Wins!!!&quot;
*# Same thing than above except that now we check if the player lost.
*elsif Winners[cpu] == player
* *$score_cpu += 1
* *&quot;Computer wins... :(&quot;
*end
end
# MAIN FUNCTION
# The weapons that we can use
Weapons = [&quot;Rock&quot;, &quot;Paper&quot;, &quot;Cisor&quot;]
# What weapon beats whatr other weapon
Winners = Hash[&quot;Rock&quot; =&gt; &quot;Cisor&quot; , &quot;Paper&quot; =&gt; &quot;Rock&quot; , &quot;Cisor&quot; =&gt; &quot;Paper&quot;]
# We initialize option, else we will get a bug on the next line
option = nil
# While the user doesn't input 0, we keep looping (playing)
while option != 0 do
*# Clear screen and put a nice and dumb menu
*system(&quot;clear&quot;)
*print &quot;\t\t\t Rock-Paper-Cisor Ruby\n\n&quot;
*puts &quot;1. Rock&quot;
*puts &quot;2. Paper&quot;
*puts &quot;3. Cisor&quot;
*puts &quot;\n0. Quit&quot;
*print &quot;\nOption: &quot;
*# We make sure that the user only inputs digits. *There are two ways to do
*# this. *I left the first one in comment
*# *First way: input filter with a regular expression: we check if the user
*# *only input one integer (there may be spaces around). If not we display
*# *an error message
*#
*# *if not option = /^\s*(\d)\s*$/.match (gets) then
*# * *error_msg
*# * *next
*# *end
*# Here I used an exception. *Right now, I am forced to put gets.chomp,
*# because if the user inputs '0', Kernel#Integer will think that it's the
*# beginning of an octal number. This has been fixed in a very recent version
*# of Ruby
*#
*# So we get our option and try to transform it into an integer. *If this
*# fails, we display an error message and we go to the 'end do' which will
*# bring us our menu back.
*begin
* *option = Integer(gets.chomp)
*rescue
* *error_msg
* *next
*end
*
*# We give the user the weapon of his choice
*weapon_player = case option
* *when 1 then Weapons[0]
* *when 2 then Weapons[1]
* *when 3 then Weapons[2]
* *when 0 then break
* *else
* * *error_msg
* * *next
*end
*# We get the weapon for the computer
*weapon_cpu = Weapons[rand(3)]
*
*# We call the function determine_winner to know who wins. *We send that
*# function 2 parameters: the weapon of the player and of the computer
*result = determine_winner(weapon_player, weapon_cpu)
*# We display who won
*puts &quot;\nPlayer chose: #{weapon_player}&quot;
*puts &quot;Computer chose: #{weapon_cpu}&quot;
*puts result; gets
end
# Print final score
puts
puts &quot;Final Score&quot;
puts &quot;Computer : #{$score_cpu}&quot;
puts &quot;Player : #{$score_player}&quot;