Ruby

Post anything related to programming or technology here. (Topics can be bumped at any time)
Forum rules
View them here. Make sure you read and agree to abide by the rules before posting.

Re: Ruby

Postby DarkFlame on Wed Jul 22, 2009 3:47 pm

stykzman wrote:
DarkFlame wrote:ok nevermind, I found how to do it in Python:

Code: Select all
import string
words = string.split("Hello World!")
len(words)


The output would be:
Code: Select all
2

Cool... it looks like you don't need to provide a character to split on; Python assumes a space unless you provide a delimiter, right?

:stykz:

i'm pretty sure, i don't remember how to add that parameter, i think you just add it as an optional second string in the parenthises.

EDIT: I could break it down to two lines like so:
Code: Select all
>>> import string
>>> len(string.split("Hello World!"))
2
>>>




EDIT2:
An new example: writing to and reading from a file
Code: Select all
file = open("filename.txt", "w")
file.write("Hello World!/n This is a new line")
file.close()
file = open("filename.txt", "r")
file.read()

And the output would be:
Code: Select all
Hello World!
This is a new line
Image
User avatar
DarkFlame
* Most Helpful Person 2010 *
 
Posts: 3038
Joined: Sat Feb 21, 2009 2:43 pm

Re: Ruby

Postby eilios on Fri Jul 24, 2009 10:03 pm

Python code:

Code: Select all
import string
words = string.split("Hello World!")
len(words)

A code that does the EXACT same thing, with less length, less confusion, and all on one line.
Code: Select all
"Hello world!".split.length


EDIT: I'm not good with file manipulation, so i'll get back to you after that.


If you want to see some GUI examples, i'd be glad to show you. I'm better with GUI applications then CLI applications, lol.
User avatar
eilios
Regular
 
Posts: 79
Joined: Thu Feb 26, 2009 7:58 pm

Re: Ruby

Postby Chris on Sat Jul 25, 2009 8:17 am

Well what I do know is that php is much easier then python. Python is much easier then ruby. Runrev is easier then ruby. Runrev is easier then python. Yeah :3:3
(:
User avatar
Chris
* Most Active Member 2010 *
 
Posts: 1549
Joined: Mon Jan 05, 2009 11:31 pm
Location: Iowa

Re: Ruby

Postby DarkFlame on Sat Jul 25, 2009 1:23 pm

Chris wrote:Well what I do know is that php is much easier then python. Python is much easier then ruby. Runrev is easier then ruby. Runrev is easier then python. Yeah :3:3

php and python are practically the same thing. But Python is much more powerful. php is used to create dynamic webpages, while Python can do the same and more.
Image
User avatar
DarkFlame
* Most Helpful Person 2010 *
 
Posts: 3038
Joined: Sat Feb 21, 2009 2:43 pm

Re: Ruby

Postby stykzman on Sat Jul 25, 2009 3:41 pm

Chris wrote:Well what I do know is that php is much easier then python. Python is much easier then ruby. Runrev is easier then ruby. Runrev is easier then python. Yeah :3:3

It may be easier in a lot of ways, but it's also more verbose. For example, the find the number of words in the string "Hello World", Python lets you do (as we've seen):
Code: Select all
"Hello world!".split.length

whereas the same code in Revolution is:
Code: Select all
put the number of words of "Hello world!"

Easier to understand, but more characters to type... many times it's a tradeoff of efficiency vs. clarity. That's why I'm interested in how Python and Ruby do things because when creating StykScript, I want to borrow the best from the languages out there.

:stykz:
:stykz:
User avatar
stykzman
Site Admin
 
Posts: 1870
Joined: Wed Jul 30, 2008 10:59 pm

Re: Ruby

Postby eilios on Sat Jul 25, 2009 4:38 pm

Ruby is much easier to use object orientation, because Python requires users to have an __init__ method, which is very tedious and often results in newbies not understanding how object oriented programming works. Ruby is also a lot easier to code then Python, because Ruby programming makes sense if you look at it. It isn't as readable, but you will know exactly how to do things. It's great for scripting languages as well, because if you look at Rpg Maker VX(which uses Ruby as it's scripting language) you can see a lot of original games have been made with it.


php and python are practically the same thing. But Python is much more powerful. php is used to create dynamic webpages, while Python can do the same and more.


Far from it. Python isn't as good for making API as Rails and PHP are, it's because Ruby is more elegant, and that means your coding will be faster, and simpler. PHP and Python have totally different syntax, PHP has much less whitespace. Rails is a whole different thing, it's a completely object oriented web framework, and it works surprisingly well(Proof: Twitter and Kongregate are both made with Rails).
User avatar
eilios
Regular
 
Posts: 79
Joined: Thu Feb 26, 2009 7:58 pm

Re: Ruby

Postby DarkFlame on Sat Jul 25, 2009 4:58 pm

eilios wrote:Ruby is much easier to use object orientation, because Python requires users to have an __init__ method, which is very tedious and often results in newbies not understanding how object oriented programming works. Ruby is also a lot easier to code then Python, because Ruby programming makes sense if you look at it. It isn't as readable, but you will know exactly how to do things. It's great for scripting languages as well, because if you look at Rpg Maker VX(which uses Ruby as it's scripting language) you can see a lot of original games have been made with it.


php and python are practically the same thing. But Python is much more powerful. php is used to create dynamic webpages, while Python can do the same and more.


Far from it. Python isn't as good for making API as Rails and PHP are, it's because Ruby is more elegant, and that means your coding will be faster, and simpler. PHP and Python have totally different syntax, PHP has much less whitespace. Rails is a whole different thing, it's a completely object oriented web framework, and it works surprisingly well(Proof: Twitter and Kongregate are both made with Rails).

FYI: Python doesn't require you to have an __init__ method. It just makes it easier. that and, __init__ methods are very simple anyway. It just sets up variables.
And personally, I don't see how the Ruby syntax for a word count is simpler than Python. To me it makes much less sense.
Image
User avatar
DarkFlame
* Most Helpful Person 2010 *
 
Posts: 3038
Joined: Sat Feb 21, 2009 2:43 pm

Re: Ruby

Postby eilios on Sat Jul 25, 2009 5:06 pm

DarkFlame wrote:
eilios wrote:Ruby is much easier to use object orientation, because Python requires users to have an __init__ method, which is very tedious and often results in newbies not understanding how object oriented programming works. Ruby is also a lot easier to code then Python, because Ruby programming makes sense if you look at it. It isn't as readable, but you will know exactly how to do things. It's great for scripting languages as well, because if you look at Rpg Maker VX(which uses Ruby as it's scripting language) you can see a lot of original games have been made with it.


php and python are practically the same thing. But Python is much more powerful. php is used to create dynamic webpages, while Python can do the same and more.


Far from it. Python isn't as good for making API as Rails and PHP are, it's because Ruby is more elegant, and that means your coding will be faster, and simpler. PHP and Python have totally different syntax, PHP has much less whitespace. Rails is a whole different thing, it's a completely object oriented web framework, and it works surprisingly well(Proof: Twitter and Kongregate are both made with Rails).

FYI: Python doesn't require you to have an __init__ method. It just makes it easier. that and, __init__ methods are very simple anyway. It just sets up variables.
And personally, I don't see how the Ruby syntax for a word count is simpler than Python. To me it makes much less sense.


"Hello world!".split.length

Let's say that aloud, shall we?

"Hello world" split length.

So, hello world is being split, and we are finding the length.

Not very hard, isn't it?
Code: Select all
import string
words = string.split("Hello World!")
len(words)

And that's easier for a beginner to learn?
User avatar
eilios
Regular
 
Posts: 79
Joined: Thu Feb 26, 2009 7:58 pm

Re: Ruby

Postby DarkFlame on Sat Jul 25, 2009 5:09 pm

eilios wrote:
DarkFlame wrote:
eilios wrote:Ruby is much easier to use object orientation, because Python requires users to have an __init__ method, which is very tedious and often results in newbies not understanding how object oriented programming works. Ruby is also a lot easier to code then Python, because Ruby programming makes sense if you look at it. It isn't as readable, but you will know exactly how to do things. It's great for scripting languages as well, because if you look at Rpg Maker VX(which uses Ruby as it's scripting language) you can see a lot of original games have been made with it.


php and python are practically the same thing. But Python is much more powerful. php is used to create dynamic webpages, while Python can do the same and more.


Far from it. Python isn't as good for making API as Rails and PHP are, it's because Ruby is more elegant, and that means your coding will be faster, and simpler. PHP and Python have totally different syntax, PHP has much less whitespace. Rails is a whole different thing, it's a completely object oriented web framework, and it works surprisingly well(Proof: Twitter and Kongregate are both made with Rails).

FYI: Python doesn't require you to have an __init__ method. It just makes it easier. that and, __init__ methods are very simple anyway. It just sets up variables.
And personally, I don't see how the Ruby syntax for a word count is simpler than Python. To me it makes much less sense.


"Hello world!".split.length

Let's say that aloud, shall we?

"Hello world" split length.

So, hello world is being split, and we are finding the length.

Not very hard, isn't it?
Code: Select all
import string
words = string.split("Hello World!")
len(words)

And that's easier for a beginner to learn?

say this aloud:

len(split("Hello World!"))

length split hello world

length of split hello world


Makes more sense to me.
Image
User avatar
DarkFlame
* Most Helpful Person 2010 *
 
Posts: 3038
Joined: Sat Feb 21, 2009 2:43 pm

Re: Ruby

Postby eilios on Sat Jul 25, 2009 6:07 pm

DarkFlame wrote:
eilios wrote:
DarkFlame wrote:
eilios wrote:Ruby is much easier to use object orientation, because Python requires users to have an __init__ method, which is very tedious and often results in newbies not understanding how object oriented programming works. Ruby is also a lot easier to code then Python, because Ruby programming makes sense if you look at it. It isn't as readable, but you will know exactly how to do things. It's great for scripting languages as well, because if you look at Rpg Maker VX(which uses Ruby as it's scripting language) you can see a lot of original games have been made with it.


php and python are practically the same thing. But Python is much more powerful. php is used to create dynamic webpages, while Python can do the same and more.


Far from it. Python isn't as good for making API as Rails and PHP are, it's because Ruby is more elegant, and that means your coding will be faster, and simpler. PHP and Python have totally different syntax, PHP has much less whitespace. Rails is a whole different thing, it's a completely object oriented web framework, and it works surprisingly well(Proof: Twitter and Kongregate are both made with Rails).

FYI: Python doesn't require you to have an __init__ method. It just makes it easier. that and, __init__ methods are very simple anyway. It just sets up variables.
And personally, I don't see how the Ruby syntax for a word count is simpler than Python. To me it makes much less sense.


"Hello world!".split.length

Let's say that aloud, shall we?

"Hello world" split length.

So, hello world is being split, and we are finding the length.

Not very hard, isn't it?
Code: Select all
import string
words = string.split("Hello World!")
len(words)

And that's easier for a beginner to learn?

say this aloud:

len(split("Hello World!"))

length split hello world

length of split hello world


Makes more sense to me.

But that's not the code...
User avatar
eilios
Regular
 
Posts: 79
Joined: Thu Feb 26, 2009 7:58 pm

PreviousNext

Return to Programming & Tech

Who is online

Users browsing this forum: No registered users and 0 guests

cron