New, with an idea, and not sure what to learn next

Hi. I’ve been going through the CodeAcademy courses for Ruby over the
past few weeks, and I spent a couple months last year learning Python
and writing a couple of card game programs. This is my only experience
with programming at all and, despite feeling I have an OK grasp on the
Ruby language, in theory at least, I’m still floundering for where to go
or what to do for practice.

I’ve been thinking lately that I want to design a program, specifically
for me, that keeps track of my finances. Ideally, when I ran this
program, I’d be able to do things like update the number of hours I’ve
worked, what I’ve spent money on, etc. I’d also like to do things that
seem more complicated - for instance, having the program calculate how
much I’ve worked in a given pay period, or how much money I’ve spent on
a certain object in the past month - stuff like that.

My “ability” to do any of this includes opening up an online
interpreter, creating an array with my hours worked in the past week or
so, and being able to come up with a sum of those hours and how much
money they’ve earned me. Which is a step in the right direction, but
when I start thinking about the different things I want the program to
do, I realize that I might need more than just knowledge of the
programming language to get anywhere. I’m happy and eager to spend as
much time as it takes learning new things - I’m developing the program
more for the practice than anything else.

But I want to be able to run this program multiple times… one of my
problems here is that, I can create an array with my hours, then ask for
input (how many hours today? for instance), and add the input into that
array, then sum all of the hours in the array. But once the program is
finished running and I run it again… the array is back to square one.
What kind of knowledge do I need to make it so I can create a program
that would save new data even after I closed it? What do I need to start
googling, above and beyond Ruby syntax, to understand how to do a
project like this? What other sources are there for learning how to do
things like divide time in pay periods and having the program deal with
real-time?

Am I in way over my head? I don’t even really know what questions to
ask… but I have a vision for this program and I want to learn how to
write it. Any help or pointers in the right direction would be greatly
appreciated. :slight_smile:

Thanks!

On Mon, 20 May 2013, Wendy Randquist wrote:

real-time?
You need some form of persistent data storage. For me, I had a similar
problem recently so I set up MySQL and am using the Sequel gem to
provide
a simplistic (and not even relational) data store. Using Sqlite would
be
even easier for your application.

– Matt
It’s not what I know that counts.
It’s what I can remember in time to use.

Am 19.05.2013 22:31, schrieb Matt L.:

project like this? What other sources are there for learning how to do
things like divide time in pay periods and having the program deal with
real-time?

You need some form of persistent data storage. For me, I had a similar
problem recently so I set up MySQL and am using the Sequel gem to
provide a simplistic (and not even relational) data store. Using Sqlite
would be even easier for your application.

For simple file-based storage where no relational database is needed
there’s also e.g.

  • YAML::Store
  • CSV
  • File.open(filename, ‘w’),
    combined with YAML.dump/YAML.load_file or plain text

That’s probably easier to play around with at the beginning
and does not require setting up a MySQL server.

What’s even better than the solution provided by the above person is to
learn to use Marshal. Marshal is a class of Ruby Source Code, you even
don’t have to include it. With Marshal you can save data in binary form
in files with whatever name you want to use. You have some limitations,
for example you can’t save singleton objects, neither IO objects, and
other fews. It’s a very good tool, I’m using it in a big project, I just
don’t want to deal with SQL kind databases; the only bad thing is that
you can’t do requests, like with “SQL tables”, but I think that in this
case you don’t need to do that. Just use Marshal. If you are on windows
check it out the documentation that comes with the Rubyinstaller, if you
don’t have the possibility just check it out in the ruby-doc online.
Kind regards.

Am 20.05.2013 03:34, schrieb Damián M. González:

What’s even better than the solution provided by the above person is to
learn to use Marshal. Marshal is a class of Ruby Source Code, you even
don’t have to include it. With Marshal you can save data in binary form
in files with whatever name you want to use.

Am I the “above person”? :slight_smile:

What I especially like about e.g. YAML::Store is that the files are
human readable and not binary.

stomar

unknown wrote in post #1109536:

Am 19.05.2013 22:31, schrieb Matt L.:

project like this? What other sources are there for learning how to do
things like divide time in pay periods and having the program deal with
real-time?

You need some form of persistent data storage. For me, I had a similar
problem recently so I set up MySQL and am using the Sequel gem to
provide a simplistic (and not even relational) data store. Using Sqlite
would be even easier for your application.

For simple file-based storage where no relational database is needed
there’s also e.g.

  • YAML::Store
  • CSV
  • File.open(filename, ‘w’),
    combined with YAML.dump/YAML.load_file or plain text

That’s probably easier to play around with at the beginning
and does not require setting up a MySQL server.

Thanks! It took a few hours of playing around, but having direction on
things to look up really helped. For now I’m messing around with the
‘File.open’ method. I’m currently dividing minutes from hours (I want to
be able to sum up the total worked) and have two separate blocks of code

  • one dealing with minutes and one with hours - that are basically the
    same. I’ve tried writing a method, but the only way I can think to do
    that is by passing which file I’m using as a parameter and that doesn’t
    seem to work. Should it?

Read and meditate on Object Oriented Design, ActiveRecord / Rails
(railscasts/codeschool), and Data Normalization.

OO will give you an idea of how to structure things for a Ruby program,
Rails is the web framework that has some crazy power, and normalized
data
is database concepts to help you make things more efficient.

On Mon, May 20, 2013 at 3:47 PM, [email protected] wrote:

What I especially like about e.g. YAML::Store is that the files are
human readable and not binary.

Well, but even reading a Marshal file isn’t too hard: just fire up IRB
read
the file and use p or pp to print out interesting parts. You can even
iterate through the structure etc.

Kind regards

robert

Am 21.05.2013 02:24, schrieb Damián M. González:

file or write whatever he wants inside(perhaps crashing the software),
but with YAML he can “tweek” the things, no way to see clearly with
Marshal files, that’s what I like, and is a good thing if you are
developing an application for a client. Kind regards.

IMO there isn’t a “better” or “worse” solution. The point is to
be aware of those differences and then decide what to use based
on your own needs (and taste).

Am I the “above person”? :slight_smile:

What I especially like about e.g. YAML::Store is that the files are
human readable and not binary.

stomar

Yes you are stomar. That’s exactly the good thing that I see in Marshal
files, that the user can’t read(directly) the file, so he can’t change
specific things, of course as with YAML the user simply can delete the
file or write whatever he wants inside(perhaps crashing the software),
but with YAML he can “tweek” the things, no way to see clearly with
Marshal files, that’s what I like, and is a good thing if you are
developing an application for a client. Kind regards.

in our project we store the data in xml files, but the config in yaml,
and the runtime stuff (savegames) is stored in marshal

IMO there isn’t a “better” or “worse” solution. The point is to
be aware of those differences and then decide what to use based
on your own needs (and taste).

Yes of course, you are right. Kind regards.

in our project we store the data in xml files, but the config in yaml,
and the runtime stuff (savegames) is stored in marshal

A great example.