Forum: Ruby program writing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Corey K. (Guest)
on 2006-05-23 00:25
i think i understand the basic syntax of ruby, now what do i do with it?
I open up my text editor and draw a blank. How do i get ideas and
actually start programming? Its alot of different than poetry or art
where i can basically start anywhere and just go wild with creativity. I
guess i just dont understand the creative side of programming. I also
dont understand why when i look at o ther peoples code i have no idea
what is going on. its like i learned the syntax from the book and yet i
cant read source code and understand what is happening. Its kind of
frustrating. I thought when i learned the keywords and syntax of a
computer language that it would open up a new door of creativity but i
just have no idea what to do with it.
Tim H. (Guest)
on 2006-05-23 00:35
corey konrad wrote:
> i think i understand the basic syntax of ruby, now what do i do with it?
> I open up my text editor and draw a blank. How do i get ideas and
> actually start programming? Its alot of different than poetry or art
> where i can basically start anywhere and just go wild with creativity. I
> guess i just dont understand the creative side of programming. I also
> dont understand why when i look at o ther peoples code i have no idea
> what is going on. its like i learned the syntax from the book and yet i
> cant read source code and understand what is happening. Its kind of
> frustrating. I thought when i learned the keywords and syntax of a
> computer language that it would open up a new door of creativity but i
> just have no idea what to do with it.

Programming is not so much an art like poetry as a craft, like making a
chair. I don't think you can just open up an editor and start typing
code until you have an end in sight. You need an itch to scratch, a need
to fill, a problem to solve. What drew you to the idea of learning
programming to begin with? What did you hope to accomplish?
Diego Cano L. (Guest)
on 2006-05-23 00:45
(Received via mailing list)
> just have no idea what to do with it.
>

I would say, first thing you need is a goal. Remember that a computer
language is not a door of creativity, it's a tool to create something
(as
well as a pen and a paper could be). The creativity is inside yourself;
it's the ideas you catch. Once you have a nice goal, then you can use
Ruby
to give it shape.
I Heard Decay (Guest)
on 2006-05-23 00:45
(Received via mailing list)
You really need to have a little project that you want to do. Or you
may have a project, written in another language, that you want to re-
write.

If you really get stuck for something to write then checkout http://
www.rubyquiz.com/. Try quiz 14 which I thought was quite easy. My
program worked fine but looked nothing like the other solutions.

The more programming that you do the easier it becomes. Honest!
Ryan L. (Guest)
on 2006-05-23 00:46
(Received via mailing list)
I understand what you are going through. I frequently see cool Ruby
projects released and think "man, why didn't I think of that!"

Basically when it comes to programming you need a problem that you
want to solve. For example let's say there is some repetitive thing
you always do with your computer (downloading and organizing photos
from a digital camera, ripping your CDs into mp3s, downloading stuff
from the internet, etc.) You can make your life easier by writing a
Ruby script to automate something like that.

If you just have an empty text editor but no pressing need to solve a
certain problem, of course you will draw a blank. If you were an
author of novels and didn't have even a basic idea of what you wanted
to write about, how much do you think you would write?

As a personal example of using Ruby to solve a problem, I wrote a
script that uses WWW:Mechanize to log into my local library's web-site
and automatically renew books or DVDs that are due. If something
cannot be renewed the script emails me. I have this loaded on my web
host to run via cron every day. Before I had this I would frequently
forget about books that were due and would then have to make a special
trip to the library to return overdue books and pay needless fees. Now
I can count on the script to let me know when things HAVE to be
returned, and live my life normally otherwise.

That is the kind of problem you need to think about solving.
Technology should make your life easier.

Regarding reading source code, like any language, your reading
comprehension will improve over time. Still, code is frequently much
harder to read than any human language, and even Ruby can be hard to
read if it is written badly. But most of us like Ruby so much because
it is one of the easiest to read programming languages.

Ryan
Elliot T. (Guest)
on 2006-05-23 00:49
(Received via mailing list)
write a game. like tic tac toe or a text adventure game.

or write a script to make something you frequently do on your
computer go faster. for example i wrote a script that takes all the
warcraft 3 replays on my desktop (where they download to) and puts
them in the right folder.

On May 22, 2006, at 1:26 PM, corey konrad wrote:

> cant read source code and understand what is happening. Its kind of
> frustrating. I thought when i learned the keywords and syntax of a
> computer language that it would open up a new door of creativity but i
> just have no idea what to do with it.
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

-- Elliot T.
http://www.curi.us/blog/
Corey K. (Guest)
on 2006-05-23 00:52
I guess i thought that would just sort of click after i learned a
language, but i guess that isnt how it works. I didnt really begin
learning ruby for any reason other than wanting to know how to program.
I tried getting my first internship doing programming and they said they
wanted someone with an extensive portfolio of software they have
developed. I have no idea what software to work on. I have looked at
some of the open source projects being done and i dont understand what i
am looking at....yet i understood the exercises form the book i was
learning from which went over the syntax and key words etc. Its pretty
confusing its almost like you have to run a program and try to figure
out wht part of a program is doing what even after you know a language.
Programming languages are pretty small things but what you can do with
them is amazing. Just a few words and some syntax rules and you can
build entire operating systems and video games etc. I just thought it
would be a more flowing process i guess. Like ok i am going to sit down
and write a music player all of my own or something but it doesnt work
that way, i think it would take me like a year to make something like
that if not longer. I think my expectations of programming were a bit
unrealistic.


> Programming is not so much an art like poetry as a craft, like making a
> chair. I don't think you can just open up an editor and start typing
> code until you have an end in sight. You need an itch to scratch, a need
> to fill, a problem to solve. What drew you to the idea of learning
> programming to begin with? What did you hope to accomplish?
Bill G. (Guest)
on 2006-05-23 01:03
(Received via mailing list)
On 5/22/06, corey konrad <removed_email_address@domain.invalid> wrote:
> out wht part of a program is doing what even after you know a language.
> Programming languages are pretty small things but what you can do with
> them is amazing. Just a few words and some syntax rules and you can
> build entire operating systems and video games etc. I just thought it
> would be a more flowing process i guess. Like ok i am going to sit down
> and write a music player all of my own or something but it doesnt work
> that way, i think it would take me like a year to make something like
> that if not longer. I think my expectations of programming were a bit
> unrealistic.
>

Possibly.  I blame the book stores:
http://www.norvig.com/21-days.html
Corey K. (Guest)
on 2006-05-23 01:03
hmm i dont really have any problems in life that could solved by
programming. Everything i can think of writing is something that already
exists. It would be kind of rediculous to write a program in ruby that
already exists in another language wouldnt it? I think i would fall
asleep from boredom doing that kind of translation. I dont know i guess
i thought it would be more of a creative and exciting thing to get into
that would fill my head with ideas. I thought i would be able to do
anything on my computer i guess is what i mean, like just deciding to
write a paint program that does something that other paint programs dont
do, but i realize now that a project like that would probably take years
of experience and alot of people working many hours. Like i said i think
my expectations of programming were unrealistic



Ryan L. wrote:
> I understand what you are going through. I frequently see cool Ruby
> projects released and think "man, why didn't I think of that!"
>
> Basically when it comes to programming you need a problem that you
> want to solve. For example let's say there is some repetitive thing
> you always do with your computer (downloading and organizing photos
> from a digital camera, ripping your CDs into mp3s, downloading stuff
> from the internet, etc.) You can make your life easier by writing a
> Ruby script to automate something like that.
>
> If you just have an empty text editor but no pressing need to solve a
> certain problem, of course you will draw a blank. If you were an
> author of novels and didn't have even a basic idea of what you wanted
> to write about, how much do you think you would write?
>
> As a personal example of using Ruby to solve a problem, I wrote a
> script that uses WWW:Mechanize to log into my local library's web-site
> and automatically renew books or DVDs that are due. If something
> cannot be renewed the script emails me. I have this loaded on my web
> host to run via cron every day. Before I had this I would frequently
> forget about books that were due and would then have to make a special
> trip to the library to return overdue books and pay needless fees. Now
> I can count on the script to let me know when things HAVE to be
> returned, and live my life normally otherwise.
>
> That is the kind of problem you need to think about solving.
> Technology should make your life easier.
>
> Regarding reading source code, like any language, your reading
> comprehension will improve over time. Still, code is frequently much
> harder to read than any human language, and even Ruby can be hard to
> read if it is written badly. But most of us like Ruby so much because
> it is one of the easiest to read programming languages.
>
> Ryan
Corey K. (Guest)
on 2006-05-23 01:11
well actually i read the learn to program book and most of the
programming ruby book.



Bill G. wrote:
> On 5/22/06, corey konrad <removed_email_address@domain.invalid> wrote:
>> out wht part of a program is doing what even after you know a language.
>> Programming languages are pretty small things but what you can do with
>> them is amazing. Just a few words and some syntax rules and you can
>> build entire operating systems and video games etc. I just thought it
>> would be a more flowing process i guess. Like ok i am going to sit down
>> and write a music player all of my own or something but it doesnt work
>> that way, i think it would take me like a year to make something like
>> that if not longer. I think my expectations of programming were a bit
>> unrealistic.
>>
>
> Possibly.  I blame the book stores:
> http://www.norvig.com/21-days.html
Corey K. (Guest)
on 2006-05-23 01:23
maybe i shoud look at opengl or something like that, is it possible to
integrate opengl with ruby or is it even necessary, i could write a text
game i guess but where would i start is what i dont understand. i just
dont get how to begin something like that because i dont understand what
is involved. How do i write a method to allow people to connect to the
program and play the game etc i just have no idea i would have to look
at other peoples source code and rack my brain over it for a couple
weeks to try and figure out how it works but then i would just be doing
something that has already been done. There are hundreds of those games
all over the internet i find it hard to get excited about things like
that. I dont know maybe i should just stick with art, i would like to
get into graphics programming and actually be one of the people who
works on programming things like maya and poser etc but i cant even
begin to fathom how all of that is done is there a grahics api for ruby?



Elliot T. wrote:
> write a game. like tic tac toe or a text adventure game.
>
> or write a script to make something you frequently do on your
> computer go faster. for example i wrote a script that takes all the
> warcraft 3 replays on my desktop (where they download to) and puts
> them in the right folder.
>
> On May 22, 2006, at 1:26 PM, corey konrad wrote:
>
>> cant read source code and understand what is happening. Its kind of
>> frustrating. I thought when i learned the keywords and syntax of a
>> computer language that it would open up a new door of creativity but i
>> just have no idea what to do with it.
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>>
>>
>
> -- Elliot T.
> http://www.curi.us/blog/
Jeffrey M. (Guest)
on 2006-05-23 01:37
(Received via mailing list)
I like to do my command line scripts like this:

file: reports.rb

class Reports
 def self.run(args)
  process_args(args)

  self.do_stuff
 end

 private
 def process_args(args)
  unless args.is_a?(Hash)
   @args = Hash[*args.collect{ |arg| arg.split(/\s|=/) }.flatten]
  else
   @args = args
  end
 end
end

at_exit do
  if File.expand_path($0) == File.expand_path(__FILE__)
    Reports.run(ARGV)
  end
end

Now if I want to run on the command line I can, like normal, but I can
also require 'reports', and interact with it from another script where
it behaves differently.

If I were you I'd start out by creating some tools to help you
program better, like a custom Logger class that emails you when errors
occur, or a reminder program that sends yourself text messages, you
could use that in your Logger also for critical errors.

I find myself having to always go back to stuff I wrote a long time
ago and add better error notification code.

-Jeff
Jake McArthur (Guest)
on 2006-05-23 01:37
(Received via mailing list)
Ask your friends then. :)
Ashley M. (Guest)
on 2006-05-23 01:37
(Received via mailing list)
Hi Corey

On May 22, 2006, at 10:04 pm, corey konrad wrote:

> hmm i dont really have any problems in life that could solved by
> programming. Everything i can think of writing is something that
> already
> exists. It would be kind of rediculous to write a program in ruby that
> already exists in another language wouldnt it?

Actually, no... you can write such beautiful code with Ruby sometimes
it is worth rewriting stuff for the sake of it.  Of course, you need
an understanding of what the program is trying to *do* before you can
write it yourself.  You also need to understand all the features of
the Ruby to take advantage of them.  And the catch 22 is you have to
write code to understand how to do it.

Someone suggested you look at past Ruby Q.zes and I think that's
the right idea.  Maybe you should search out some programming puzzles
that will teach you programming ideas.  I remember the book "The C
Programming Language" had loads of questions at the end of each
chapter (some REALLY hard!).  Something like that would get you
started... perhaps not that book though.


> years
> of experience and alot of people working many hours. Like i said i
> think
> my expectations of programming were unrealistic


Writing anything with a GUI is a big job.  I wouldn't even think
about writing a desktop application right now!  You'd have more luck
with Ruby on Rails, but even that is not simple (it's simple if you
already write web applications, but that's just not an easy job).

Good luck
Ashley
James G. (Guest)
on 2006-05-23 02:24
(Received via mailing list)
On May 22, 2006, at 4:04 PM, corey konrad wrote:

> hmm i dont really have any problems in life that could solved by
> programming.

I don't believe that for a second.  Computers are all about
repetition.  We all have such tasks.

> Everything i can think of writing is something that already
> exists. It would be kind of rediculous to write a program in ruby that
> already exists in another language wouldnt it?

Not at all.  This process is called "porting" and it is extremely
popular.  Just one of the many great things it can do is to bring
powerful libraries to Ruby that are currently only available in other
languages.

> I dont know i guess i thought it would be more of a creative and
> exciting thing to get into
> that would fill my head with ideas. I thought i would be able to do
> anything on my computer i guess is what i mean...

It can.  Give it a shot!

> but i realize now that a project like that would probably take years
> of experience and alot of people working many hours.

Then get started today!  ;)

One cool aspect of taking on a project that takes a lot of effort is
that you learn so much along the way.  You'll become a better
programmer and you will learn much more about whatever problem domain
you decide to attack.  Plus, with us here to help when you need us,
you can't lose!  How cool is that?

Ditch the negative attitude.  You're a programmer now!  Master of the
(computer) universe.  You are all-powerful and can do ANYTHING!  Go
forth spreading joy into the world...

James Edward G. II
Timothy H. (Guest)
on 2006-05-23 02:55
(Received via mailing list)
corey konrad wrote:

>of experience and alot of people working many hours. Like i said i think
>my expectations of programming were unrealistic
>
>
I won't say it's true for every programmer, but it's true for every
programmer I know: once you try programming the problem is not thinking
what to do, it's finding time to do everything you want to do. I wrote
my first program 27 years ago and I still write code almost every day of
my life.

So programming doesn't click for you? Go do something else. I spent a
summer learning to kayak and finally realilzed I hated kayaking. My wife
spent a summer learning to scuba and finally realized she hated scuba.
Life's too short to waste your time doing stuff that doesn't reward you.
Logan C. (Guest)
on 2006-05-23 03:29
(Received via mailing list)
On May 22, 2006, at 6:23 PM, James Edward G. II wrote:

> Ditch the negative attitude.  You're a programmer now!  Master of
> the (computer) universe.  You are all-powerful and can do
> ANYTHING!  Go forth spreading joy into the world...

I found it amusing that you used the words "forth" [1] and "joy" [2]
in the same sentence, while talking about programming, but didn't
mention the word "stack" once.

[1] http://en.wikipedia.org/wiki/Forth
[2] http://en.wikipedia.org/wiki/Joy_programming_language
Alex G. (Guest)
on 2006-05-23 05:25
(Received via mailing list)
On 23 May 2006, at 06:23, corey konrad wrote:

> doing
> something that has already been done. There are hundreds of those
> games
> all over the internet i find it hard to get excited about things like
> that. I dont know maybe i should just stick with art, i would like to
> get into graphics programming and actually be one of the people who
> works on programming things like maya and poser etc but i cant even
> begin to fathom how all of that is done is there a grahics api for
> ruby?

There's more to computer/algorithmic art than just writing tools
(like Maya and Poser) for other artists to use. A friend of mine at
work wanted to learn some graphics programming, so he wrote a short
program that could take a bitmap and a few parameters on the command
line and generate a new distorted image. It was simple and dumb, but
we had a fun (and creative!) afternoon sticking photos of our faces
into the algorithm and seeing what weird effects we could come up
with. This was written in C, but there's no reason why Ruby couldn't
do something similar with the SDL or even OpenGL interfaces.

http://raa.ruby-lang.org/project/ruby-sdl/
http://raa.ruby-lang.org/project/opengl/

If you're more interested in music then I'd recommend SuperCollider3:
it uses Smalltalk-like (and hence vaguely Ruby-like) syntax to
generate music/sounds. There's a whole new learning curve to tackle,
but it might be fun along the way if you have an interest in music. I
don't know if there's anything similar for Ruby itself.

http://supercollider.sourceforge.net/

Playing around with these tools is OK, but to progress you WILL need
to get a project to work on. Even if (to start with) it's something
totally stupid and made-up. As one of the previous replies mentioned,
there are very few novelists who can just sit down and write without
having a larger plan in mind.

Dr Alex G.
Post-Doctoral Researcher

Bioinformatics Center
Institute for Chemical Research
Kyoto University
Gokasho, Uji, Kyoto 611-0011
Japan
Hal F. (Guest)
on 2006-05-23 09:44
(Received via mailing list)
corey konrad wrote:
> just have no idea what to do with it.
>

The creativity comes only when you have mastered the basics, not
when you've just been exposed to them.

Think of it as like playing an instrument. You're a beginner.
Take it slow.

I recommend finding some freshman-level programming exercises
and trying them out.

You have to play "Mary Had a Little Lamb" with confidence
before you can jump on stage with Miles Davis and improvise.



Hal
Pistos C. (Guest)
on 2006-05-23 18:45
corey konrad wrote:
> i think i understand the basic syntax of ruby, now what do i do with it?
> I open up my text editor and draw a blank. How do i get ideas and
[snip]
> computer language that it would open up a new door of creativity but i
> just have no idea what to do with it.

Something I suggest to beginning programmers is to find some existing
project which you really like or admire or find very useful, then find
some tiny aspect about it that you think could use some improvement.
Then open up the source code and tweak it so that it works the way you'd
like.

It could be something as trivial as making a textual change, such as
changing the name of a main character in a game.

Many open source projects maintain issue/bug trackers to list problems
and feature requests.  You could skim them, and maybe find one that
looks simple.  After writing (and testing), you could submit a patch,
and help the open source universe.  :)

Pistos
Randy K. (Guest)
on 2006-05-23 20:09
(Received via mailing list)
On Monday 22 May 2006 04:26 pm, corey konrad wrote:
> i think i understand the basic syntax of ruby, now what do i do with it?
> I open up my text editor and draw a blank. How do i get ideas and
> actually start programming?

That is (could be) a good question. ;-)

I think that in most cases, programmers program something to accomplish
something.  If you work for someone, you program to accomplish something
they
want.  If you're not working for someone, you can program to accomplish
something you want, or participate in a free / open source project.

As far as pure creativity, I guess you can do things like create
computer
generated art (e.g., Mandelbrot? curves) or music.

Or create some new program to achieve some new purpose that no one has
ever
achieved.

The real purpose of my response is to say that if you really can't think
of
anything, you could work on one of my projects (which, in general, I'd
plan
to release under an open source license, although I might do some
legal/ethical "tricks" in an attempt to make money (for example, do
something
like keep my code proprietary but then when releasing a new version (or
after
x years), re-release the old version as open source)).

One of those projects involves "driving" various web browsers (or HTML
"widgets") (first on my list is tkHTML, 2nd is kHTML, eventually all or
most
browsers/widgets) from a Ruby program (which would also be set up as a
server
(I think that's the right word--I want it to stay "memory resident" so
there
is no startup time when updates come from the source (initially nedit).

I don't want to completely describe the project(s) at this time,
partially in
hopes of eventually finding a way to make some money with them, but if
you
(or anyone else) is interested, among the first things to do are:

   * learn how to create a "server" in Ruby
   * learn how to "drive" tkHTML and then kHTML via Ruby (and/or other
browsers / HTML "widgets")

> Its alot of different than poetry or art
> where i can basically start anywhere and just go wild with creativity. I
> guess i just dont understand the creative side of programming.

I'm more of a utilitarian type person, but even so, aside from things
like
computer generated art or music, I'm not sure you can have the "just go
wild"
style of creativity.

In most cases (maybe all, when I think about it) a programmer has a
goal.  The
creativity comes in choosing the path to that goal.

> I also
> dont understand why when i look at o ther peoples code i have no idea
> what is going on. its like i learned the syntax from the book and yet i
> cant read source code and understand what is happening. Its kind of
> frustrating. I thought when i learned the keywords and syntax of a
> computer language that it would open up a new door of creativity but i
> just have no idea what to do with it.

I suspect that you are fairly new to programming and Ruby.  One thing I
think
you need is more experience.  Even if you have your own ideas for goals
to
accomplish via programming, you may do well to spend time on some other
projects to get more experience.  (Maybe my projects are not the best
choice
for that--I'm looking for help for things I can't (rather, so far
haven't
been able to) do--I can't offer much guidance on how to get them
done--on
other projects you may be able to get more guidance.

Randy K.
Randy K. (Guest)
on 2006-05-23 20:22
(Received via mailing list)
On Monday 22 May 2006 05:04 pm, corey konrad wrote:
> of experience and alot of people working many hours. Like i said i think
> my expectations of programming were unrealistic

Don't give up (at least not yet--I mean, it's possible that you're not
cut out
for programming, but)--unrealistic expectations are (can be) a good
thing.
Maybe you can help figure out how to write a paint program (with new
features)  in very short order.  Maybe Ruby (or some new libraries in
Ruby)
would be the key.  Maybe some other language (or approach) would be the
key.

Randy K.

PS: Just following up on my previous post, one of my projects is, in
some
sense, a translation.  It is implementing some functionality that exists
on
Windows but does not exist on Linux.  (Or, at least, did not exist when
I
conceived the project.  It still doesn't exist on Linux, but more
workarounds
are available.  I still think what I want to build will be better, but I
was
wrong once before.   (I thought I was wrong once, but it turned out I
was
wrong about that ;-)
This topic is locked and can not be replied to.