Jump to content

Ruby vs. Python?


Unity+

Recommended Posts

So, I have been conflicted on what language to use: Ruby or Python?

 

There are many sites that probably have comparisons, but I want to ask if anyone, in experiencing any of the two languages, if they could give their take on their pros and cons. Is there some benefit using one or the other? Is it merely style? Is one more powerful than the other? Or is one just easier to work with?

 

Here is some categories when posting comparisons:

 

  • Dealing with data sets(lists)
  • Recursion issues
  • Dynamics
  • Syntax
  • Other

 

 

Link to comment
Share on other sites

what do you want to use it for?

i prefer python just because of the origination of its name...

good old slapstick humor is where it is at...

and you will need that humor for some things.

Well, I am implementing a protocol that I developed that requires sending data when it is requested from a server. It involves sending two pieces of data at the sametime as the user requests one of these pieces of data.

Link to comment
Share on other sites

Well, I am implementing a protocol that I developed that requires sending data when it is requested from a server. It involves sending two pieces of data at the sametime as the user requests one of these pieces of data.

Using interpreted language for such task is one of the most stupid things I heard about (sorry).. (can you imagine making apache http server using python??)

It might be done for non-commercial private test use, but when somebody pays you for doing so, you definitely should use C/C++ code to handle packets, to have as fast as possible rate of handling data..

Or even create separate threads for each connected client to have as high as possible transfer..

If you won't do so (create thread), you're running into problem that single-thread code is doing its stuff (handling packet) while other client tries to connect to server (that's busy and doesn't respond)..

You would have to test hundred or thousands clients per second trying to connect to your service to see it though.

Check time your code is spending on handling single packet..

Edited by Sensei
Link to comment
Share on other sites

Hey Gregg,

 

remember when you commented on Popcorn's smugness? I think some of it rubbed off on you :P .

 

If you're writing a networking protocol that's going to hang around on not-particularly-powerful single-board computers like the Raspberry Pi, I'd recommend using C (or C++ if you need). The reason being that C compilers are being optimized to this day, since the language's beginnings for writing Unix, and so programs written in it are some of the fastest you can make. Further, because C is a low level language and many operating systems (including Raspbian) are designed by and written in it, you can implement your own low-level assembly optimizations and access networking hardware as needed, without having to go through layers and layers of API's and bog.

 

I suppose if you just want to test whatever idea you have you can use Python—why did Ruby even come up? Some Googling will show you they both have similar expressiveness and benchmarks, Ruby often winning on the former and Python on the latter, but not to any significant extent that I can tell, not having worked with Ruby, but if you want to actually implement your protocol for production, then I'd recommend writing it in C.

Link to comment
Share on other sites

i think he realizes certain differences in the two and is doing a brake check... lol

i personally like python due to my familiarity with it and the fact that you can apply it elsewhere without having to pick up yet another language.

Edited by davidivad
Link to comment
Share on other sites

Hey Gregg,

 

remember when you commented on Popcorn's smugness? I think some of it rubbed off on you :P .

 

If you're writing a networking protocol that's going to hang around on not-particularly-powerful single-board computers like the Raspberry Pi, I'd recommend using C (or C++ if you need). The reason being that C compilers are being optimized to this day, since the language's beginnings for writing Unix, and so programs written in it are some of the fastest you can make. Further, because C is a low level language and many operating systems (including Raspbian) are designed by and written in it, you can implement your own low-level assembly optimizations and access networking hardware as needed, without having to go through layers and layers of API's and bog.

 

I suppose if you just want to test whatever idea you have you can use Python—why did Ruby even come up? Some Googling will show you they both have similar expressiveness and benchmarks, Ruby often winning on the former and Python on the latter, but not to any significant extent that I can tell, not having worked with Ruby—, but if you want to actually implement your protocol for production, then I'd recommend writing it in C.

I don't know what you mean. :P

 

I don't like Python because of its syntax and handling of stuff. Ruby seems better from what I have tried out with it. However, I don't particularly know how well it deals with data structures, which is why I asked.

 

I guess C could be used, but that would be used on a different aspect of it because I am merely dealing with filesystems, such as removing wrongly placed files in the server folder and uploading files to a server. To implement the actual protocol, I would probably use C to allow the files to be transferred to the device requesting the information.

Using interpreted language for such task is one of the most stupid things I heard about (sorry).. (can you imagine making apache http server using python??)

It might be done for non-commercial private test use, but when somebody pays you for doing so, you definitely should use C/C++ code to handle packets, to have as fast as possible rate of handling data..

Or even create separate threads for each connected client to have as high as possible transfer..

If you won't do so (create thread), you're running into problem that single-thread code is doing its stuff (handling packet) while other client tries to connect to server (that's busy and doesn't respond)..

You would have to test hundred or thousands clients per second trying to connect to your service to see it though.

Check time your code is spending on handling single packet..

Doesn't Ruby support multithreading? I know Python does, but Ruby is a different story I think.

Edited by Unity+
Link to comment
Share on other sites

Many such services are implemented in interpreted languages ... PHP, Perl, Python, Ruby, Javascript ...

 

PHP script is typically executed by server when somebody (client) visited url, and extremely quickly sends result output to client that requested it (web browser).

 

JavaScript is executed by web browser internally, while user is watching url. Then when he goes other url, it's gone.. Total time of execution calculated in seconds or minutes, as long as browser window/tab is open..

 

Unity+ wants to create his own *server* that has loop waiting for clients packets at some port.

Client connects to f.e. 80 port, send packet, and code made by Unity+ have to process that packet and send response.

That code has to work hours and hours waiting for clients...

 

There is example of daemon in PHP docs.

http://php.net/manual/en/function.socket-accept.php

This usleep(100) and set_time_limit() "nicely" summarize usage of this language for such task..

You *have* to explicitly tell PHP to not automatically shut-down by using

set_time_limit(0);

at beginning of script.

 

(default shut-down time is.. 30 seconds)

 

"Warning

This function has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini."

 

Edited by Sensei
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.