[Home]Ruby

ec2-13-58-252-8.us-east-2.compute.amazonaws.com | ToothyWiki | RecentChanges | Login | Webcomic

A new cool funky programming language in the Perl / Python type family... seen by some (such as DHH of Ruby on Rails fame) as the next generation after Perl. Takes its love to town.

You can [Try and learn Ruby online] without installing it. Ruby is the main language in [Hackety Hack], an environment for teaching kids programming.

Here is an example of a Ruby WebServer as a one liner:
require 'socket';s = TCPServer.new 80;loop{c=s.accept;c << "\n" + IO.read( c.gets[/\/(.*) /,1].gsub(/\.{2,}/) { } ) rescue 404;c.close}
and expanded:
require 'socket';
s = TCPServer.new 80;
loop
{
 c=s.accept;
 c << "\n" + IO.read( c.gets[/\/(.*) /,1].gsub(/\.{2,}/) { } ) rescue 404;
 c.close
}


I.. don't understand why this should function as a WebServer. TCPServer accept just returns raw TCP sockets, right? That's what I'd expect from a library object with that name in a sane language. So where would the HTTP headers in the response come from? You'd need to prepend at least the response code and two CRLFs to the file you read from disk, and also a Content-Type header if you want any browser other than MSIE to do anything sane with it. Can someone with Ruby installed confirm this really works and explain why? Googling for docs turns up pages like [this].. - MoonShadow, lack of Ruby clue
Yeah it works. Works in Firefox at least, and works with the following in telnet --RobHu
robert-hulmes-power-mac-g5:~ robhu$ telnet 192.168.0.250 80
Trying 192.168.0.250...
Connected to 192.168.0.250.
Escape character is '^]'.
GET /podsnumber HTTP/1.0

File contents....
Connection closed by foreign host.

..file contents, but not the HTTP headers. So it's a server of some sort, but not a WebServer. You can't use it to serve web pages to a browser. Or you shouldn't be able to, according to the RFC. Hm. I guess the browsers are a little too lax in what they accept, then.. - MoonShadow
It may not be RFC compliant, but it is a WebServer --RobHu
Scratch that, it is compliant: "A Simple-Response should only be sent in response to an HTTP/0.9 Simple-Request or if the server only supports the more limited HTTP/0.9 protocol. If a client sends an HTTP/1.0 Full-Request and receives a response that does not begin with a Status-Line, it should assume that the response is a Simple-Response and parse it accordingly. Note that the Simple-Response consists only of the entity body and is terminated by the server closing the connection." (http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#Response) --RobHu
Ah, OK - my bad; hadn't looked that far back. Sorry ^^; - MoonShadow



Ruby encourages beautiful programming: http://media.rubyonrails.org/presentations/pursuitofbeauty.pdf

those all look very nice in the middle of little slides, but what happens when you have ten squillion billion of them scattered throughout the hundreds of file sof your project, all of them almost identical but not quite?
Mah, learning to view a new language always takes a bit of getting used to for a new language.  It's basically advocating programming by contract.  Where, at least, the code is visible (you have to read the arguments) rather than C++ style where all the magic happens between the interfaces.  --Vitenka
For some strange reason, when you write programs with Ruby you tend to finish long before you have ten squillion billion functions. Confer: http://c2.com/cgi/wiki?RubyVsJava . Two large, industrial-strength modules, and one has 10% the lines as the other. --PhlIp
All that shows is that Java is a bloated monstrosity. --Angoel
(PeterTaylor) It doesn't even show that. It shows that log4j is probably a bloated monstrosity, which doesn't surprise me because it's an Apache project.

Ruby has gained a lot of publicity recently because of RubyOnRails? framework.

(PeterTaylor) Well, it certainly seems to allow just as incomprehensible code as PERL.
Matz designed Ruby to compete with Perl and Smalltalk. Unlike with Perl, you don't _have_ to write incomprehensible code! --PhlIp
I deny that Perl code _has_ to be incomprehensible. - MoonShadow, Perl junkie
A lot of Perl will work in Ruby too as the languages are similar enough - Ruby doesn't force you to write beautiful code but it is quite easy to (e.g. http://media.rubyonrails.org/presentations/pursuitofbeauty.pdf) --RobHu
I thought line-endings (i.e. ';') we not used in Ruby?  And, being a little sceptical, isn't the above just an example of "Here is my magic library, look how my magic library solves this in two lines"? --K
The whole point of NextGeneration? languages (whatever your generation) is that they take care of stuff automagically for you that previously you had to hassle with.  But yes, that line above is singularly unreadable.  --Vitenka  (Let's see, gsub is global substitution...)
Well, if one takes the POV that very few people these days will be writing truly original software - and how many do? - Massive Magic Library of Doom is not *totally* implausible. If that's the goal, though, then rather than [competing on the size of a particular app], proponents should try to compete with the number of items in their suites of (<n)-line task implementations. - MoonShadow
WebSense? strikes again: The above link is blocked under the "Non-Traditional Religions and Occult and Folklore" category... ^^;; --K
It's yet another "P2P in 6 lines". A Google search will get you any number of mirrors. I suppose "Non-Traditional Religion" is not *too* poor a fit.. ^^;; - MoonShadow
Why on earth is "Non-Traditional Religions and Occult and Folklore" blocked?  Are your employers worried that you might learn Voodoo curses? --Edwin



OP=RobHu
CategoryComputing CategoryLanguage

ec2-13-58-252-8.us-east-2.compute.amazonaws.com | ToothyWiki | RecentChanges | Login | Webcomic
This page is read-only | View other revisions | Recently used referrers
Last edited June 8, 2007 11:44 am (viewing revision 31, which is the newest) (diff)
Search: