Some General Questions about Ruby

Hi !
I think i’ll soon begin to learn programming in ruby, as so many people
find it ( and its buddy RoR ) awesome.
I’m a beginner programmer ( Basic, PHP, Caml, and i’m currently reading
some C/C++ tutorials )

Ruby is an interpreted language, if i’m not wrong, interpreted languages
are slightly slower than compiled ones,
so far i mainly coded web apps, but i may one day do some Desktop apps
programming, and so : are Ruby programs much slower/nearly as fast/ …
as a for example a C-compiled program ( i guess it depends a lot on the
kind of software ) ??

About the possibilities of Ruby, i know Ruby is a generic language, and
that we can program almost every software in Ruby, but almost every
for example, is it possible to develop a peripheral driver in Ruby ??
more generally to access the hardware ? to write a linux kernel module
?? ( i guess it is not possible to write a ruby OS kernel )

thank you

( i’m not a native english speaker, sorry if any mistakes )

Vinh C. wrote:

are Ruby programs much slower/nearly as fast/ …
as a for example a C-compiled program ( i guess it depends a lot on the
kind of software ) ??

Yes, Ruby is quite a bit slower than C. But depending on the program
you’re writing, this may not make much/any difference to the end user.
If there are certain parts of the program that are creating a major
performance hit, you can always write those bits in C and then call your
C module from Ruby.

On 4/4/07, Vinh C. [email protected] wrote:

Hi !
I think i’ll soon begin to learn programming in ruby, as so many people
find it ( and its buddy RoR ) awesome.
I’m a beginner programmer ( Basic, PHP, Caml, and i’m currently reading
some C/C++ tutorials )

Welcome, glad to have you. You may want to check out Chris P.'s
online
tutorial as well:

http://pine.fm/LearnToProgram/

Ruby is an interpreted language, if i’m not wrong, interpreted languages

are slightly slower than compiled ones,
so far i mainly coded web apps, but i may one day do some Desktop apps
programming, and so : are Ruby programs much slower/nearly as fast/ …
as a for example a C-compiled program ( i guess it depends a lot on the
kind of software ) ??

Yes, Ruby is slower than C most/all of the time, but that doesn’t mean
you
can’t do great things with Ruby. For example, there are desktop
applications written in Ruby. Checkout FreeRIDE as an example of what
can
be done.

http://freeride.rubyforge.org/

About the possibilities of Ruby, i know Ruby is a generic language, and

that we can program almost every software in Ruby, but almost every
for example, is it possible to develop a peripheral driver in Ruby ??
more generally to access the hardware ? to write a linux kernel module
?? ( i guess it is not possible to write a ruby OS kernel )

You may want to check out Ruby USB. It is a Ruby library that wraps
libusb.
Michael Hewner presented a session on it at the MountainWest RubyConf
(hope
to have video released soon) where he connected to and communicated with
USB
devices. I believe the library he used is found here:

http://www.a-k-r.org/ruby-usb/

There may be more information about Ruby USB on his blog, but it has the
word “fetish” in the domain so I can’t view it from work. :S

http://technofetish.net/buffaloblog/

thank you

Quick answers:

much slower, but for Web apps and a lot of other interactive apps
where input/output itself creates lots of delays and lots of waiting,
you probably don’t care.

It’s possible to do most or all of those things in Ruby – apart from
the kernel module – but you don’t want to. One reason: an
interpreted language to execute has to bring with it the whole
interpreter, which makes it large. Second, which should probably be
first, speed matters much more in things like peripheral drivers
which lots of other programs use and thus can be chokepoints for the
whole system.

Ruby on Rails is slow even by the standards of Web applications. But
it’s still well worth learning as it makes it much easier to develop
– and more importantly to evolve – powerful applications.

Good luck.

On Thu, Apr 05, 2007 at 04:50:25AM +0900, Vinh C. wrote:

Hi !
I think i’ll soon begin to learn programming in ruby, as so many people
find it ( and its buddy RoR ) awesome.
I’m a beginner programmer ( Basic, PHP, Caml, and i’m currently reading
some C/C++ tutorials )

That’s a pretty good beginning – three languages plus some dabbling.

Ruby is an interpreted language, if i’m not wrong, interpreted languages
are slightly slower than compiled ones,
so far i mainly coded web apps, but i may one day do some Desktop apps
programming, and so : are Ruby programs much slower/nearly as fast/ …
as a for example a C-compiled program ( i guess it depends a lot on the
kind of software ) ??

Technically, it’s not the language that’s slower – it’s the
implementation. It’s true that, all else being equal, intepreted code
runs more slowly than code compiled to a binary executable, but whether
it is interpreted or compiled depends on the implementation you’re
using. For instance, Objective Caml (aka OCaml) allows you to execute
code via an interpreter, to compile to bytecode and run in a VM, or to
compile to an executable binary file native to the platform.

Ruby, of course, is a rather more dynamic language than OCaml, and as
such is not (thus far) really suitable to compilation. As such, it is
executed via an interpreter, and it’s not a very fast interpreter. I’m
mostly just being pedantic here, but I figured I may as well make the
situation as crystal clear as is reasonable.

In any case, Ruby can definitely be used for desktop application
development. You just have to be sure you know where execution speed
will impose an unacceptable bottleneck, and perhaps choose a different
language in such circumstances. For instance, I don’t think I’d want
to implement a Mathematica clone entirely in Ruby, but a light weight
word processor or web browser should be fine.

About the possibilities of Ruby, i know Ruby is a generic language, and
that we can program almost every software in Ruby, but almost every
for example, is it possible to develop a peripheral driver in Ruby ??
more generally to access the hardware ? to write a linux kernel module
?? ( i guess it is not possible to write a ruby OS kernel )

I’d recommend against writing hardware drivers in Ruby, generally
speaking, though I imagine it’s possible. Writing an OS kernel might
prove a bit more difficult, with the interpreter-only implementation(s)
currently available. For that sort of thing, you probably want to stick
to something like C, OCaml, or maybe even Haskell or compiled Lisp.
Ruby (and even Perl) is a bit less practical for such purposes.

On Thu, Apr 05, 2007 at 05:22:00AM +0900, Chad P. wrote:

to something like C, OCaml, or maybe even Haskell or compiled Lisp.
Ruby (and even Perl) is a bit less practical for such purposes.

Although there are specific places where userland programs are intended
to
hook into the kernel, and Ruby is fine for such things. For example,
using
ruby fusefs you can write your own filesystem in Ruby.
http://rubyforge.org/projects/fusefs/

thanks !
@Chad P.
when i said i was a beginner programmer i meant in the desktop softwares
field ;), as so far i mainly coded in php, and maths algorithms with
caml

when i asked if it was possible to develop OS kernels/modules, i am
aware that “i don’t want to”, as it would imply that the kernel includes
the interpreter, that itself has a bunch of prerequisites
but from a theorical point of view, is it possible ? ( can ruby deal
with hardware access, memory management etc … )

I have another question, about the WxRuby toolkit, i never used a gui
toolkit before, but i guess it works like that :
_ for a compiled program ( for example C/C++ ), the toolkit library, is
either already installed on the end user computer, either it is
“included” in the source code and compiled with it
_ but for an interpreted language, how does it work ??? do the end user
have to install a specific wxwidgets library ? or does wxruby provide a
file that we have to bundle with the .rb files ???

thanks again

ok, thanks, i know that ruby is not aimed at developing kernel related
programs, it was just to know if it was theorically possible
bye !

On Thu, Apr 05, 2007 at 06:29:43AM +0900, Brian C. wrote:

currently available. For that sort of thing, you probably want to stick
to something like C, OCaml, or maybe even Haskell or compiled Lisp.
Ruby (and even Perl) is a bit less practical for such purposes.

Although there are specific places where userland programs are intended to
hook into the kernel, and Ruby is fine for such things. For example, using
ruby fusefs you can write your own filesystem in Ruby.
http://rubyforge.org/projects/fusefs/

Agreed. I didn’t mean to suggest that you shouldn’t interact with the
kernel with Ruby – just that it’s usually not the best language for
interacting directly with hardware and writing low-level stuff like
most Linux kernel modules (for instance).