Should I Learn Ruby as a First Language?

M

MRH

I never noticed. I use it as a mailing list, and it's also a newsgroup.

I was on the Win XP partition using FF (I dual boot and mostly use
Ubuntu) and it just SLOOOOWWEEED down my machine (it's not that fast
however, I am about to build a new one) plus it was becoming difficult
to select text to clip when replying, and it just felt . . .
resistant? . . . all around . . . now I am back on Ubuntu, using FF
and . . . no more pain . . . :)
 
M

MRH

My two cents worth:

Ruby is a good first language to learn if you are really really young
and you are just learning something, because ruby is designed in a way
that lets us apply regular thinking methods. If you are a child,
5.times do something makes more sense than for (i=0; ....). However,
if you are a little older and are able to grasp concepts, then you
might be better off learning C.

One reason C is advantageous is it forces you to learn algorithms and
the inner working of "methods" in ruby for instance. It is entirely
possible for a person who has only learned ruby to never bother about
how a sort is implemented. This may or may not matter to you in the
end, but learning C, as someone else said earlier, really makes you
appreciate Ruby, Java etc. Also, going from Ruby to C might be hard
because it might seem like you are always writing code for tasks that
are so trivial in Ruby. So I suggest you learn C first.

Hope that helps.

Jayanth

Hello Jayanth,

An interesting and helpful post, thank you. I did find a free online
book on Data Structures and Algorithms in Ruby . . . posted it to
Reddit Ruby, and some folks stated that it did not use idiomatic
Ruby . . . I am going to tackle that one anyway however.

Regards,

Maurice
 
R

Rick DeNatale

To the first point, I'd actually argue that learning the second
foreign language, or a second programing language teaches you more
about the first than you'd even imagine. Maybe it's a mindset, or
maybe it's what languages you're working with, I'm not sure.

I've got no argument with that, my argument is that your first
language can have a big effect on how you learn, or fail to truly
learn the second.
Contrary to what I advised, I learned BASIC first. I was OK in it,
then I learned C++ in school (It took quite awhile for me to be able
to write straight C after that). Learning in that order I've often
felt was not good for me.

But after learning C++, I was so much better in BASIC than I was
before, that I ended up tutoring/teaching it to business students
(this was way back in the day). The only way I could do that was
because learning that second language taught me so much more about
programming.

Although perhaps that makes an argument for learning BASIC (really
really basic, not this VB/business basic junk) or shell script first,
_then_ delving into C, then an abstract language.

In my case, and I suspect that I'm considerably older than the average
participant here, I first learned Fortran I, and quickly branched out
to learn many languages including 1620 assembler, IBM/360 Assembler,
Snobol, Lisp 1.5, PL/I, APL\360, PDP/5 and 8 assembler, Algol, etc.
This gave me a rather broad base before I ever encountered C (In fact
much of this took place before C was born). In addition to language
use, I had a pretty good BS education in CS including data structures,
and compiler construction.

After University, I used mostly PL/S which was IBM's equivalent to C,
it was a slightly higher-level than assembler language with a PL/I
like syntax much like C is a slightly-higher level than assembler
language with a stripped down BCPL syntax.

My exposure to C came a bit later, and I first really used it to
develop a variant called ClassC which was similar in concept to, and
developed concurrently with, and without knowledge of, Objective-C
I still believe that people should learn C though, before embarking on
programming projects, much less careers, even if they don't use C for
it.

While it is important at some point to understand the level of
abstraction at which C lives, I think that it's more important to get
a broad understanding of programming.
As for English and it's horrific grammar, it's a Germanic language
that was busy absorbing Latin, Franco and the occasional Greek words
for 10 centuries. I've heard, but can't find references anywhere
right now, that the grammar itself was latinized shortly after the
advent of cheap printing. Apparently there was an underlying motive
to make it more difficult, since that would make it easier to
distinguish between the educated and the non educated. Evil isn't it?
Just wish I could find a reference.....

I don't know that it was an evil plot. It just reflects the history
of England as a crossroads/invasion target, and the fact that society
is never homogeneous.

It's why for example, English has multiple words for various animals
and their meat, Pig and Pork, Cow and Beef, Calf and Veal...

This comes from the Norman invasion, after which the language of the
Court and Gentry was French.

The former names are germanic in origin and were used by the farmers
who were Anglo Saxons, the latter were French. Notice how we tend to
use these words today to refer to the animal, vs. the meat.

I've seen this effect mentioned several times, and I'm almost certain
one of them was in the book "The Story of English" by Cran, MacNeill,
and McCrum

http://en.wikipedia.org/wiki/The_Story_of_Englis

h
 
M

MRH

Still depends -- for example, if you just want to be able to contribute to the
most FOSS possible, learn C. The vast majority of FOSS projects are in C,
among them some of the better known. It might be nice to know some value of P
in a "LAMP stack" -- Perl/PHP/Python/Ruby -- but pretty much the entire rest
of the stack will be written in C. Maybe a bit of shell scripts, but the
shell itself is written in C.

I see.
If, on the other hand, you want to write brand new apps, from the ground up --
or you want to interface with all these existing apps, but not actually patch
them -- then Ruby is as good a choice as any.

Good to know.
But these don't matter as much, since you've indicated a more academic
curiosity -- you'll probably learn both anyway, and more.

Thank you, that is encouraging.
I suspect that Ruby has more LISPisms than Python.

So have I read, so have I read . . . that is actually one of main
reasons (out of many) why I am interested in Ruby: a rather well known
Lisp hacker has on several instances expressed his opinion that Ruby
is quite similar to Lisp.
Either would be good for
GUI OS X apps and web apps.

Also good to know.
 
M

MRH

So my personal recommendation is, if you have no time pressure
etc... is that you should learn C first, even if ruby is
a lot more fun (because you will learn ruby a lot easier
anyway and it doesnt matter much when you start learning it IMO.) :)

Hi Marc,

Thank you for your post . . .

Cheers,

Maurice
 
K

Kyle Schmitt

In my case, and I suspect that I'm considerably older than the average
participant here, I first learned Fortran I, and quickly branched out
to learn many languages including 1620 assembler, IBM/360 Assembler,
Snobol, Lisp 1.5, PL/I, APL\360, PDP/5 and 8 assembler, Algol, etc.
Errr. Lisp 1.5? I'm going to guess then, you were learning this
stuff in the mid to early sixties?

Yeah. I started as a little kid with C64 basic using sample programs
from "3-2-1 Contact" magazine... I think that was 1983.

Just a little generational gap :)
I've got no argument with that, my argument is that your first
language can have a big effect on how you learn, or fail to truly
learn the second.
Hum. But don't you think that if someone learns, really learns and
uses, the fluid flexible everything-hidden-behind-the-scenes languages
first, that they will have trouble when they eventually have to deal
with the nitty gritty of C or ASM?
one of them was in the book "The Story of English" by Cran, MacNeill,
OK, now I've got something to read some weekend soon.

--Kyle
 
7

7stud --

MRH said:
Hello Group,

I realize this question has been previously asked in different boards,
however, I believe that it is worth asking here owing to the level of
expertise present.

I am a beginner in programming. I have read some fundamental theory
material and mucked around a bit, and now want to move into actually
learning programming and my first language.

Throughout my research into this question, I have seen that the more
credible sources recommend either Python or Ruby, and I am personally
leaning quite heavily toward Ruby, yet I would very much like to read
the thoughts of the group on this question.

I was in the same position as you about a year ago--except I have
experience programming in other languages, and I was leaning the same
way. I read a bunch of articles on Ruby and Python, and I was leaning
towards Ruby. Then I went to the Ruby website, and I did the twenty
minute tutorial, but I found the syntax distasteful. So I did an about
face and began learning Python instead. After spending a year with
Python, which I liked quite a bit, I thought I would learn some Ruby,
which is what I'm doing now.

Ruby people talk about how clean the Ruby syntax is and how Ruby
"doesn't get in your way". But in my opinion, Ruby has barely evolved
beyond Perl as far as ugly syntax goes. A lot of the code posted on
this forum is extremely difficult to decipher. I also find that Ruby
actually gets in my way all the time, and based on the questions posted
in this forum, Ruby seems to get in other people's way too. To be fair,
all computer languages get in your way: there are weird results, quirks,
and edge cases that will stump you when writing programs, but for some
reason the Ruby kool-aid drinkers like to claim that is not the case in
Ruby. Ruby lets you do so many bizarre things that I would guess there
are more quirks and edge cases that will leave you completely bewildered
than in any other language I know.

As far as I can tell, Ruby is a good language for experienced
programmers who don't want to be confined by any rules and don't need
speedy execution. For them, Ruby is an expressive language because they
can write the most bizarre code with it. I also notice that a lot of
Ruby programmers who post on this forum like to cram the equivalent of
ten lines of code into a convoluted one liner whenever they
can--efficiency and clarity be damned.
I suspect that Ruby has more LISPisms than Python.
Either would be good for GUI OS X apps and web apps.

As a beginner, you can pretty much forget about programming GUI apps
with Ruby. Ruby doesn't come with any software that will let you
program GUI apps, so you first have to get some software installed,
which can be a big hassle. Then there is not much documentation or many
tutorials for Ruby GUI programming.

On the other hand, Python includes software that will let you program
GUI apps. It's called Tkinter, and it's simple enough so that beginners
can get their feet wet. The documentation on Tkinter isn't the
greatest, but some python books have sections on Tkinter and there are a
few websites that have decent examples and documentation.

The documentation for the Ruby language and its Standard Library is very
poor. As a result, you need to buy the book Programming Ruby(2nd ed)
just for the documentation section in the second half of the book. As a
beginner, you probably won't use the online docs for reference very
often, so that won't affect you as much. Python's documentation is
better, but I still consider it substandard. php has the best online
documentation I've seen because they allow users to post comments in the
docs. The php users flesh out the descriptions of the functions and
they post examples demonstrating tricky results they encountered. Why
python and ruby don't adopt a similar model for their documentation is
baffling. In essence, the php docs are self documenting, and the php
users create a rich trove of information for free.

Python has a very good beginners book that just came out with a new
edition this year: "Learning Python(3rd ed)".

Based on all of the above, I recommend Python over Ruby. Good luck.
 
7

7stud --

7stud said:
Based on all of the above, I recommend Python over Ruby. Good luck.

I just wanted to add that I started with C++ and Java. Unless you plan
on becoming a computer science student in college, I would not start
with C or C++. It takes a lot of time to learn the language and if you
want to do much more than grind out calculations, it requires complex
programs.

On the other hand, python has a broad application and it allows you to
perform many tasks very easily. For instance, in C++ to get the
contents of a web page and then print out some information contained
therein, you would have to be pretty good with C++, and then you would
have to learn a topic called sockets, which is quite difficult. In the
end, your program would probably be 100+ lines of code and very error
prone.

In python, you can write that same program in less than 20 lines of
code. The reason it's so easy in python is that expert programmers have
done that programming task many times in the past, and their code is
contained in the python libraries. All you have to do is call a few
simple functions to get the benefit of all their hard work and
experience. In C++, there are no equivalent libraries, so every
programmer who wants to get the contents of a web page and print out
some information contained therein has to reinvent the wheel and write
their own program from scratch.

python has a vast number of libraries that cover almost every subject
you can think of, and the code in the libraries was written by expert
programmers. In python, you get access to their programs by calling a
few comparatively simple functions. As a result, complex programming
tasks are reduced to a few lines of code.
 
D

Dave Bass

7stud said:
I also notice that a lot of
Ruby programmers who post on this forum like to cram the equivalent of
ten lines of code into a convoluted one liner whenever they
can--efficiency and clarity be damned.

Hear hear. Clarity should win over compactness every time, IMHO. (Even
in Perl.)

In my own coding I like one idea per line, and one comment every 5-10
lines on average. Seems like everyone else tries to do the exact
opposite.

(Ducks... ;-)
 
L

Lloyd Linklater

Well, I checked my pockets and found a surplus $0.02 and will toss it in
here, if I may.

You can learn to program starting with any language and get things done.
That having been said, all languages are NOT created equal. It is,
therefore, important to know more about what you are seeking.

If you want a job writing windows programs, you will almost certainly
want to investigate C#. There are a good deal of caveats and
frustrations associated with that, but there it is. There are many jobs
to be had therein.

If you want something that is cross platform then you would need Java,
Ruby, PHP, and their ilk. There are a LOT of java jobs and sun has
embraced ruby in the form of jruby and that is very good for the ruby
lovers (us). There are a lot of wonderful java libraries. Those are
things that other people wrote to do things that are commonly done like
file handling and searching through internet sites, etc. Mingling the
two is something that I think important, though this is more of a purist
site so I will behave. :)

In choosing between languages like java, php, and ruby, you need to
think of how you want to do your programming. I know this may be
difficult to grok, but stick with me here. If you want a language where
it does the work for you and all you need to do is describe what needs
doing, then ruby is for you. If you want the control, and attending
execution speed, then you might consider C++.

As an example, sorting an array in ruby is as simple as

my_array = my_array.sort

or

my_array.sort!

You do not need to know HOW it gets done. You just say "do it" and
VOILA! I cannot tell you how many bubble sorts I have written over the
years, though I can still count the quick sorts on my fingers and toes.

So, in summary, you need to decide what you want it to do and see which
language fits how you think then go that way. Ultimately, you should
learn several languages but not at first. At first, you should learn to
program well in one language. Only then should you spread out.

fwiw & imho
 
M

Mark Wilden

Hear hear. Clarity should win over compactness every time, IMHO. (Even
in Perl.)

However, compactness can sometimes add to clarity, simply because you
don't have to read so much code to find out what's going on.
In my own coding I like one idea per line, and one comment every 5-10
lines on average.

I only comment code that's difficult to understand. I try never to
write code that's difficult to understand.

///ark
 
M

Mark Wilden

It's a question of whether you learn top-down, or bottom-up. Different
people have different learning preferences.

The trouble with bottom-up is that it will take you forever to reach
the top. :) With top-down, you start with your ultimate objective, and
stop when you've gone down far enough. That way you don't have to
learn subatomic physics in order to make a cherry pie.

///ark
 
F

forgottenwizard

Hi Dave,

Thank you for your post. As I have mentioned, I believe I will study C
and those texts so as to become acquainted with the lower level
concepts.

Best,

Maurice

FWIW, I would suggest K&R to learn C. It seems to be the standard for
learning C, and along with a copy og the C99 standard, should be able to
get you started in it.
 
F

forgottenwizard

What you should also keep in mind is that if you already
know Ruby well, learning C can be boring, because 95% of
what C does, Ruby does too - shorter and nicer for the
human being.

That goes for any OOP language. Procedural languages like C require more
code to do the more complex task, but generally require less to do
simple things (getchar/scanf vs. messing with an array).
 
D

Dave Bass

Mark said:
With top-down, you start with your ultimate objective, and
stop when you've gone down far enough.

But you never really understand what you're doing; you end up learning a
set of rules and prescriptions instead of basic principles. Do this and
it works; do that and it doesn't.

Of course this could get very philosophical. What do I mean by "really",
"understand" and "basic principles"? ;-)

You can certainly drive a car without knowing what goes on inside the
engine. Millions do. But some of us (especially those from an
engineering background) like to know how it works, at least in outline.

Having said that, I have no wish to delve into Ruby's C source code. But
if I wanted to, I could!
 
E

Eric I.

That goes for any OOP language. Procedural languages like C require more
code to do the more complex task, but generally require less to do
simple things (getchar/scanf vs. messing with an array).

You did say "generally". But since we're talking about Ruby in this
thread and since you're responding to someone who was specifically
comparing Ruby and C, I think it's worth pointing out that Ruby, and
perhaps object-oriented scripting languages in general, are almost
always shorter than C, even for those "simple things".

Since you gave "getchar/scanf vs. messing with an array" as an
example...

C: ====

#include <stdio.h>

int main()
{
printf("How old are you? ");
int age;
scanf("%d", &age);
printf("Next year you will be %d.\n", age + 1);
}

Java: ====

import java.io.*;

public class AgeQuestion
{
public static void main(String[] arguments) throws IOException
{
System.out.print("How old are you? ");
BufferedReader input =
new BufferedReader(new InputStreamReader(System.in));
String age_string;
age_string = input.readLine();
int age = Integer.parseInt(age_string);
System.out.println("Next year you will be " + (age + 1) +
".");
}
}

Ruby: ====

print "How old are you? "
age = gets.to_i
puts "Next year you will be #{age + 1}."

====

So yes, Java is more verbose than C. But C is more verbose than Ruby.

Eric

====

LearnRuby.com offers Rails & Ruby HANDS-ON public & ON-SITE
workshops.
Ruby Fundamentals Wkshp June 16-18 Ann Arbor, Mich.
Ready for Rails Ruby Wkshp June 23-24 Ann Arbor, Mich.
Ruby on Rails Wkshp June 25-27 Ann Arbor, Mich.
Ruby Plus Rails Combo Wkshp June 23-27 Ann Arbor, Mich
Please visit http://LearnRuby.com for all the details.
 
T

Todd Benson

Hello Group,

I realize this question has been previously asked in different boards,
however, I believe that it is worth asking here owing to the level of
expertise present.

That type of thing pops up pretty often on this group.

In engineering, you _need_ to know the fundamentals. With Ruby, it is
somewhat of a gray area. With Rails, you risk giving something to
somebody that is powerful with the side effect of gun-in-baby's-hands
syndrome.

Many questions float to this list about Rails where it becomes really
clear to rubyists that the person has no idea about how to use the
underlying language. This is probably common with other DSL's as well.
And the C guys probably say the same thing about rubyists.

So, where do you start? I'd say skim through the K&R C book,
read/scan through a couple of design oriented books, and then tackle
Ruby/Python/Perl/whatever with an open mind (meaning, awareness of
different programming paradigms -- hanging out in the book store is
not only pragmatic, but also allows you to ogle your
competition/pretty girls or guys/whatever :)

Programming is not entirely Knuth anymore. Although, you could learn
a lot from the guy. On a similar note, a person should avoid trying
to turn Ruby into C or Python like 7stud and some others like to.

Todd
 
M

MRH

Todd,

Thank you for your reply.
That type of thing pops up pretty often on this group.

In engineering, you _need_ to know the fundamentals. With Ruby, it is
somewhat of a gray area. With Rails, you risk giving something to
somebody that is powerful with the side effect of gun-in-baby's-hands
syndrome.

I know what you mean (and what others mean who have voiced analogous
conclusions) I used to translate legal documents professionally, and
was often horrified by translations created using translation software
by people who - even though they were bilingual - had no knowledge of
the underlying principles and subject. It is one of the reasons I left
that market: since those folks would do it for peanuts, companies
began to send me that stuff expecting me to "just clean it up" for 1/3
the going rate since "well, it is more than halfway done" (when in
actuality it takes 200% more work to clean up a mess than to start
from scratch and do it right the first time) . . .
So, where do you start? I'd say skim through the K&R C book,
read/scan through a couple of design oriented books, and then tackle
Ruby/Python/Perl/whatever with an open mind (meaning, awareness of
different programming paradigms -- hanging out in the book store is
not only pragmatic, but also allows you to ogle your
competition/pretty girls or guys/whatever :)

I will keep this approach in mind, it strikes me as very pragmatic and
balanced, I had considered something similar but figured I was wrong
by not knowing enough to reach an accurate conclusion in the first
place. Oh, and btw, it's girls I ogle ;)
Programming is not entirely Knuth anymore. Although, you could learn
a lot from the guy. On a similar note, a person should avoid trying
to turn Ruby into C or Python like 7stud and some others like to.

Will keep in mind . . .

Cheers,

Maurice
 
D

David Masover

Ruby people talk about how clean the Ruby syntax is and how Ruby
"doesn't get in your way". But in my opinion, Ruby has barely evolved
beyond Perl as far as ugly syntax goes.

You obviously haven't seen a lot of Perl.

And to either, I'd say, it's how you use it. It is possible to write beautiful
syntax in Ruby. I'm not convinced it's possible to do so in Perl without a
filter.
To be fair,
all computer languages get in your way: there are weird results, quirks,
and edge cases that will stump you when writing programs, but for some
reason the Ruby kool-aid drinkers like to claim that is not the case in
Ruby.

We're not the only ones:

http://xkcd.com/353/

To be fair, every language has "kool-aid drinkers". There are people who
absolutely love .NET, for whom its their sole reason for staying on Windows.
Ruby lets you do so many bizarre things that I would guess there
are more quirks and edge cases that will leave you completely bewildered
than in any other language I know.

Any Turing-complete language lets you do bizarre things. If you're doing stuff
like this:

class NilClass
def nil?
false
end
end

Expect your irb to crash when you type that, or shortly thereafter.

Personally, I like that you can do stuff like that in Ruby. Doesn't mean you
have to. I like that I can type "rm -rf /" at a Unix prompt, but of course, I
don't. I like having the training wheels off.
As a beginner, you can pretty much forget about programming GUI apps
with Ruby. Ruby doesn't come with any software that will let you
program GUI apps, so you first have to get some software installed,
which can be a big hassle. Then there is not much documentation or many
tutorials for Ruby GUI programming.

If you're learning to program, I should hope that you can also learn to
install software. I haven't looked at the documentation, though...
On the other hand, Python includes software that will let you program
GUI apps. It's called Tkinter, and it's simple enough so that beginners
can get their feet wet. The documentation on Tkinter isn't the
greatest, but some python books have sections on Tkinter and there are a
few websites that have decent examples and documentation.

$ python
Python 2.5.2 (r252:60911, Apr 21 2008, 11:17:30)
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
Type "help", "copyright", "credits" or "license" for more information.Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 41, in <module>
raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package
Whoops. There goes that theory. As long as I'm going to be installing
packages, why not install tcltk for Ruby? Or OpenGL?

And while we're at it, in my experience, gem is much, much better
than "easy-install".
The documentation for the Ruby language and its Standard Library is very
poor.

Really?

http://ruby-doc.org/

Plenty of documentation. Not complete, but not "poor", I think.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top