Begining programmer questions

On May 14, 2006, at 6:49 PM, Michael G. wrote:

Corey -

A strongly type language would insist that you declare everything
before
use.

Ruby is strongly typed, it’s not statically typed. C has weaker types
than ruby (Oh look, I just cast an int to a pointer). A statically
typed language would insist you declare the types of everything
before use. That is unless you have type inference.

e.g. at an ocaml prompt:

let f x = x + 1;;

val f : int -> int =

You’ll note I did not declare the type of x, nor the return type of
the function, yet OCaml correctly deduced it. But that’s tangential.
Note also that typing doesn’t necessarily determine whether or not
you need to declare something before use. In both Javascript and Perl
you can declare variables:

var x;

my $x;

Likewise, while I can’t think of any languages that do this, I’m sure
one could devise a statically typed language with no declarations.

‘gets’ will read a string from input and build a new string object.

When you did ‘info = gets.chomp’, you wiped out your array and made it a
simple String object.

‘exit’ is being stored because your program logic is placing the string
into
the Array, and then checking to see if the last retrieved value is
‘exit’.

You may be better off using a temporary variable first, checking it, and
then storing it.

so gets changes the array into a string object during each loop and then
just keeps changing the what is in that string object ok i understand
that. I still dont understand the issue with “exit” thouse i dont see
how i am putting exit into anything, i am just testing to see if info is
== to exit i thought. I dont know maybe i should stick with networking,
lol this stuff is frustrating i dont know how a person could do this 8
hours a day.

Michael G. wrote:

‘gets’ will read a string from input and build a new string object.

When you did ‘info = gets.chomp’, you wiped out your array and made it a
simple String object.

‘exit’ is being stored because your program logic is placing the string
into
the Array, and then checking to see if the last retrieved value is
‘exit’.

You may be better off using a temporary variable first, checking it, and
then storing it.

If you keep at it, and keep reading, it will click.

The key (for me, at least) is gaining an understanding for what is
happening
underneath.

Keep asking the questions you are asking.

Also, I recommend “Learning to Program” by Chris P. (I picked this up
for
a friend, and she loves it) as well as “Programming Ruby”. Read them,
and
work through the excercises. It’ll come together.

Here is the code I am going by:

def input
puts “Enter some info”
info = []
info << gets.chomp
while info.last != “exit”
info << gets.chomp
end
info.sort
puts info
end

Now, take a look at the while loop.

You start the loop, put data in to ‘info’, and then start over. At the
top
of the loop, you have to see what is stored in ‘info’.

that actually is the book i am having so many problems with
understanding, lol Learning to program by Chris P…

Michael G. wrote:

If you keep at it, and keep reading, it will click.

The key (for me, at least) is gaining an understanding for what is
happening
underneath.

Keep asking the questions you are asking.

Also, I recommend “Learning to Program” by Chris P. (I picked this up
for
a friend, and she loves it) as well as “Programming Ruby”. Read them,
and
work through the excercises. It’ll come together.

On May 14, 2006, at 7:33 PM, corey konrad wrote:

this stuff is discouraging, lol. Since i started learning to program i
feel like i am mentally retarded or something. Is it normal to have
this
many problems with understanding simple things when you learn this
stuff, for some people it seems to just come naturally like they were
born into it.


Posted via http://www.ruby-forum.com/.

There’s a big hump the first time you learn to program. Once it
clicks though, a whole bunch of other stuff becomes easier. I don’t
know if ruby is necessarily the best programming language for a
beginner either, since it was designed by Matz. for Matz. (And I’m
pretty sure Matz. isn’t a beginning programmer). The problem is I
can’t think of a better one. Every language out there has it’s own
quirks that are detrimental to the learning of how to just program,
for the very first time. I think someone should write a procedural
language with a simple, forgiving syntax (i.e. whitespace is not
significant, and as few funny characters as possible), with garbage
collection and dynamic typing. Kind of a subset of perl with a ruby-
like syntax. It should also have a very rich runtime introspection
capabilities, not necessarily for the students, so that you can step
through code and have the data structures visualized( sort of like
[1] but they should be shown more like a diagram out of a text book).

[1] DDD - Data Display Debugger - GNU Project - Free Software Foundation (FSF)

corey konrad wrote:

this stuff is discouraging, lol. Since i started learning to program i
feel like i am mentally retarded or something. Is it normal to have this
many problems with understanding simple things when you learn this
stuff, for some people it seems to just come naturally like they were
born into it.

Haha, that’s totally normal. Nobody was born into it.
Some learn faster, but mostly, they just study longer.

Hal

Thanks for the help and encouragment i appreciate it

corey konrad wrote:

that actually is the book i am having so many problems with
understanding, lol Learning to program by Chris P…

Michael G. wrote:

If you keep at it, and keep reading, it will click.

The key (for me, at least) is gaining an understanding for what is
happening
underneath.

Keep asking the questions you are asking.

Also, I recommend “Learning to Program” by Chris P. (I picked this up
for
a friend, and she loves it) as well as “Programming Ruby”. Read them,
and
work through the excercises. It’ll come together.

yeah a friend of mine said that PHP would be a good language to learn as
a beginner.

Logan C. wrote:

On May 14, 2006, at 7:33 PM, corey konrad wrote:

this stuff is discouraging, lol. Since i started learning to program i
feel like i am mentally retarded or something. Is it normal to have
this
many problems with understanding simple things when you learn this
stuff, for some people it seems to just come naturally like they were
born into it.


Posted via http://www.ruby-forum.com/.

There’s a big hump the first time you learn to program. Once it
clicks though, a whole bunch of other stuff becomes easier. I don’t
know if ruby is necessarily the best programming language for a
beginner either, since it was designed by Matz. for Matz. (And I’m
pretty sure Matz. isn’t a beginning programmer). The problem is I
can’t think of a better one. Every language out there has it’s own
quirks that are detrimental to the learning of how to just program,
for the very first time. I think someone should write a procedural
language with a simple, forgiving syntax (i.e. whitespace is not
significant, and as few funny characters as possible), with garbage
collection and dynamic typing. Kind of a subset of perl with a ruby-
like syntax. It should also have a very rich runtime introspection
capabilities, not necessarily for the students, so that you can step
through code and have the data structures visualized( sort of like
[1] but they should be shown more like a diagram out of a text book).

[1] DDD - Data Display Debugger - GNU Project - Free Software Foundation (FSF)

Yeah isn’t everything a first class object in Ruby.

Looked to me as though the issue was the scope since he originally
declared it in
the def rather than in the scope of the caller where he wants to
refer to it.

On 5/15/06, corey konrad [email protected] wrote:

yeah a friend of mine said that PHP would be a good language to learn as
a beginner.

Aargh! I mean, erm, no, I definitely think you’re on the right track
with
Ruby. I know it doesn’t feel like it, but you seems quite close to
“getting” it. You’re just missing the idea that variable names kinda
“point” at objects.

The object pointed at might be an array, or a string, or whatever… with
a
whiteboard it’s quite easy to illustrate the idea, but let’s try this:

when you say:
info = “hello there”

…that makes a pointer from the variable “info” to the string “hello
there”. Here’s a picture:

info ----------> String “hello there”

When you say:

info = []

…that makes a pointer from the variable “info” to a new, empty array.
Doesn’t matter what info used to “point” to… it’s now pointing at an
array. Like this:

info ----------> Array []

Hope that helps a bit!

;D

they should change the = to -----> then maybe i would have gotten it
right away, lol.

corey konrad wrote:

oh ok i remember reading that in the book about pointers the = method or
operator whatever it is, makes something point to something else. So the
only way to truly change the variable is to change what it points too.
So i should remmeber that any time i use the = method i am causing
something to point to something else otherwise i might run into trouble,
that kind of makes sense. The pointer graphic -----------> helps, lol.

oh ok i remember reading that in the book about pointers the = method or
operator whatever it is, makes something point to something else. So the
only way to truly change the variable is to change what it points too.
So i should remmeber that any time i use the = method i am causing
something to point to something else otherwise i might run into trouble,
that kind of makes sense. The pointer graphic -----------> helps, lol.

Daniel B. wrote:

On 5/15/06, corey konrad [email protected] wrote:

yeah a friend of mine said that PHP would be a good language to learn as
a beginner.

Aargh! I mean, erm, no, I definitely think you’re on the right track
with
Ruby. I know it doesn’t feel like it, but you seems quite close to
“getting” it. You’re just missing the idea that variable names kinda
“point” at objects.

The object pointed at might be an array, or a string, or whatever… with
a
whiteboard it’s quite easy to illustrate the idea, but let’s try this:

when you say:
info = “hello there”

…that makes a pointer from the variable “info” to the string “hello
there”. Here’s a picture:

info ----------> String “hello there”

When you say:

info = []

…that makes a pointer from the variable “info” to a new, empty array.
Doesn’t matter what info used to “point” to… it’s now pointing at an
array. Like this:

info ----------> Array []

Hope that helps a bit!

;D

See, Corey. You’re getting it. It just takes time, and soon enough
you’ll
be answering our questions.

On 5/15/06, corey konrad [email protected] wrote:

oh ok i remember reading that in the book about pointers the = method or
operator whatever it is, makes something point to something else. So the
only way to truly change the variable is to change what it points too.
So i should remmeber that any time i use the = method i am causing
something to point to something else otherwise i might run into trouble,
that kind of makes sense. The pointer graphic -----------> helps, lol.

You know, originally i’d typed a shorter arrow → but it seemed to make
more sense if it was really long! I’m glad I could help… like Michael
G
says, you’re getting it.

Good luck

;Daniel

yup i’ll get it, need a break now though, you know when you read tacos
as a misspelling of “to cos” that you have been studying programming and
math all day.

Daniel B. wrote:

On 5/15/06, corey konrad [email protected] wrote:

oh ok i remember reading that in the book about pointers the = method or
operator whatever it is, makes something point to something else. So the
only way to truly change the variable is to change what it points too.
So i should remmeber that any time i use the = method i am causing
something to point to something else otherwise i might run into trouble,
that kind of makes sense. The pointer graphic -----------> helps, lol.

You know, originally i’d typed a shorter arrow → but it seemed to make
more sense if it was really long! I’m glad I could help… like Michael
G
says, you’re getting it.

Good luck

;Daniel

yeah that would something, corey konrad ruby expert, maybe i’ll extend
the language and call it diamond, or better yet clam that way perl could
fit inside it, lol.

Michael G. wrote:

See, Corey. You’re getting it. It just takes time, and soon enough
you’ll
be answering our questions.

On 5/14/06, corey konrad [email protected] wrote:

this stuff is discouraging, lol. Since i started learning to program i
feel like i am mentally retarded or something. Is it normal to have this
many problems with understanding simple things when you learn this
stuff, for some people it seems to just come naturally like they were
born into it.

I started learning Ruby a couple of years ago, but I started
programming somewhere around 1981. By the time I found Ruby, yeah, it
sort of ‘came naturally’ to me. So yeah, some people are ‘naturals’,
and it looks like you might be one of them. The part where it ‘comes
naturally’ happens later.

It’s driving you nuts, but you still keep doing it. Why?
You must figure out what you are doing wrong.
You must find a way to make it do what you want.
To me, that sounds like a ‘natural’ :wink:

Since nobody’s mentioned it (I think), most Ruby users are coming from
other languages. Granted, that can be true for many languages, but I
think the ratio is higher for Ruby.

Until Rails, it was relatively unknown in the US. Certainly far below
perl, Java, PHP, Python, etc. Most of the people (like myself) who
looked into Ruby were already programmers, and probably knew more than
one language. That’s part of all the ‘Ruby is wonderful’ hype. It
may take experience with other languages to see that part.

I’m not saying it’s not a good language to learn first, I have no idea
if it is or not, I don’t think enough people (US at least) have
learned it as their first language to decide that case. What I’m
saying is, once you learn another language (after you learn Ruby that
is), then you’re more likely to see the ‘beauty’ that is Ruby.

On the bright side, once ‘it clicks’, and you get Ruby (or any other
language for that matter), learning other languages becomes easier.
Personally, I think that once you’ve learned 3 languages, you’ll be
convinced that you can learn any language.


Posted via http://www.ruby-forum.com/.

You might as well just sign up for the list, it’s your destiny :wink:
http://www.ruby-lang.org/en/20020104.html

On 5/14/06, corey konrad [email protected] wrote:

yup i’ll get it, need a break now though, you know when you read tacos
as a misspelling of “to cos” that you have been studying programming and
math all day.

Yeah, definitely a natural. It won’t be long before you wake up
dreaming of code :wink: