POETIC END

Circumstances at my telephone job have me working overtime and we’re
nowhere near Christmas yet…  So I decided now’s as good a time
as any since it’s getting to be too close to the holiday season to be
able to do so later in the year.  I put my notice in to quit last
Monday, and because of the way the boss decided to calculate my
vacation time remaining, she didn’t schedule me to work next week- so
as I’m typing this I just finished my last day.

It was a lazy day, mostly.  Not a lot of traffic.  I don’t
think we made our goals for the day.  The boss wasn’t in good
shape, she spent much of the time in back sitting down in the office
trying to get her sore back to feel better…  and in keeping with
proper traditions when it came time to close after this slow day, a
large family of certain ethnicity entered and extended that last day a
little longer.

Thankfully, most of the close duties were done, the store was clean and we got out very quickly.

I don’t feel as bad right now as the day I put my notice in, though I’m
still really sad.  The job I had for a bit over  eight years
is done.

Typically, I’d come home from work to make myself a bowl of soup and
unwind at the PC before bed.  The lady I rented the extra bedroom
from…  My family in the midwest, for all intents…  she’d
often be watching tapes of Andromeda or Buffy or Xena depending on the
era…

I got home tonight, made myself some soup, and it just happened that
the dish isn’t working tonight.  My brother was watching a tape of
Andromeda.

Thanks for the comment.

The iPod and clones are awesome machines- I’d own one if I still rode
the bus every day.  Since everybody has to drive to go anywhere
down here, I’d rather get a car stereo that can do mp3.  As it is,
I use a Rio Volt I’ve had for a while, through a tape adapter in the
stock car stereo.  We’ll see how long that lasts.

EVERYBODY’S GHETTO ABOUT SOMETHING

I wish I could properly credit the person I heard say, “Everybody’s a geek about something.”

Everybody has their likes and dislikes, there’s no accounting for
taste, and so on… and as a result, there’s always something every
individual on earth will know a little bit more than necessary about.

The level of this knowledge may vary, and is debatable, but relative to
the other things the individual knows, it’s …  significantly
high.

I have a kind of counter-statement, perhaps “juxtaposition” is the right word for this, or not…

Everybody’s ghetto about something.  Every individual has a necessity they detest having to spend money on.

This can show itself in the form of poorly dressed men, people that
drive rusty, beater cars, or a terrible sounding stereo system, or it
could be more subtle, like people that use that Scott’s 1000-sheet “I
Can’t Believe It’s Not Sandpaper” toilet paper.

The things I’m most ghetto about are socks (identical, crew, white, and
normally, cheap) and underwear (who really sees my underwear?), but I’m
sure I’ll think of more in good time.

RUBY AND THE ART OF JAPANESE COMPACT CAR TUNING, PART 1 — THE B16A4 MOTOR

I kept saying I would share this code on the internet someday, and
indeed I will, but, I’ve been lazy and I don’t want to post a whole
program that doesn’t have its bulletproofing in place yet.  Heaven
forbid one of you try to balance your checkbook with my program,
accidentally typing a letter in the dollar-amounts field and blowing
the program up…

Instead, I guess I can talk about the foundation work.

The program in question is a simple program designed to keep track of
my checking account, replacing my checkbook and giving me a nifty
up-to-date balance.  It is written in the object-oriented
scripting language called Ruby.

Ruby was created by Yukihiro Matsumoto, who, if I understand correctly,
wanted a language that was as powerful and programmer-fun as Larry
Wall’s Perl, but is fully object-oriented, without feeling stripped
down or enforcing restrictions on how you type your whitespace like
Guido Rossum’s Python.

Object-oriented programming is a programming abstraction where you show
the computer a structure of objects and teach the computer what objects
are, what they are used for, and what they can and can’t do.  You
create a simulation of sorts, where you are asking things to do work on
other things, instead of thinking about how your computer would
accomplish it at a machine’s level.

If you understood that correctly, that means that instead of having
functions or commands that you perform on data, you have methods which
you perform on objects, or methods that objects perform on themselves,
because the objects do the work, not the PC.

In accomplishing this ideal, Ruby treats everything, even a number you put down as a command, as an object.

Now, I don’t know if this is Matsumoto’s way of keeping the language
pretty and easy to read, or if it’s a preference because he is
Japanese, but Ruby has virtually no punctuation.  (If you are sick
of the parentheses of LISP, try Ruby.)

When object-oriented programming was explained to me in a way that
finally made sense, it occured to me that I missed the cute little
checkbook program that was in my Handspring Visor, which was on the
fritz at the time.  It’d be easy to think of a checkbook in terms
of objects, and indeed, it is.

I started by defining a collection of transactions, since everything the checkbook does is work with transactions:

class Transaction # Every account has a transaction roll.
  def initialize
  @date = [] # This is the date written in by the user
  @datestamp = [] # These two are for the actual update times
  @timestamp = []
  @note = []
  @ttype = []
  @amount = []
  end

The keyword ‘class’ says this is a definition for an object, ‘class’ is
the word chosen in every object-oriented language I’ve ever
encountered.  I predictibly named mine ‘Transaction’.  It’s
important to make this sort of code read as much like plain english as
possible.

The keyword ‘def’ is a definition of a “method,” or a command that an
object can perform.  This one is named ‘initialize’ because that’s
the name it has to have, it is the name of the constructor in Ruby.

Constructors are methods that are run when a new object is created, so
“initialize” is what will run whenever I need to make a new Transaction.

The next line define “fields,” kinds of variables living in the
Transaction object.  Fields don’t have to be variables in the
classic sense, and in fact, a field in Ruby may point to any object,
including another one that you’ve created.  In these lines, I’ve
created empty arrays, denoted by the empty brackets to the right of the
equal sign.

The keyword ‘end’ stops the definition.  Ruby does not need braces
and ignores whitespace, so this word is the only way the Ruby
interpretter can tell that it is the end of the definition.

Since all the fields are empty arrays, the creation of new transactions
is accomplished by adding transaction information to these arrays.

  def deposit(amount,note,date)
  @datestamp.push Time.now.strftime(“%m/%d/%Y”)
  @timestamp.push Time.now.strftime(“%H:%M:%S”)
  @date.push(date)
  @note.push(note)
  @ttype.push(‘Deposit’)
  @amount.push(amount)
  end
 
  def withdrawal(amount,note,date)
  @datestamp.push Time.now.strftime(“%m/%d/%Y”)
  @timestamp.push Time.now.strftime(“%H:%M:%S”)
  @date.push(date)
  @note.push(note)
  @ttype.push(‘Withdrawal’)
    if amount==amount.abs
          @amount.push(-(amount))
    else
          @amount.push(amount)
    end
  end
 
  def check(amount,note,date,checkno)
  @datestamp.push Time.now.strftime(“%m/%d/%Y”)
  @timestamp.push Time.now.strftime(“%H:%M:%S”)
  @date.push(date)
  @note.push(note)
  @ttype.push(sprintf(“Check %04d”,checkno))
    if amount==amount.abs
          @amount.push(-(amount))
    else
          @amount.push(amount)
    end
  end
 
  def adjust(amount,note,date)
  @datestamp.push Time.now.strftime(“%m/%d/%Y”)
  @timestamp.push Time.now.strftime(“%H:%M:%S”)
  @date.push(date)
  @note.push(note)
  @ttype.push(‘Adjustment’)
  @amount.push(amount)
  end

All of these definitions put the information pertaining to a certain
type of transaction onto the arrays that make up the Transaction
roll.  Because Ruby automatically assigns methods that allow you
to treat arrays as if they are stacks, I can ‘push’ and ‘pop’
transactions on and off the roll.  All of these methods push new
transactions onto the end of the roll.

Once we’ve filled the roll with transactions, we simply need a way to read them out, and a way to add up the balance.

  def list # Returns the whole transaction log
  output = []
  c = 0
  @note.each { |i|
      output.push
sprintf(“%10s     :%20s    
:%20s     :   %0.2f”,@date[c],
     
                                          
@note[c],
     
                                          
@ttype[c],
     
                                          
@amount[c])
      c = c + 1
      }
  return output
  end

  def tally
  output = 0
  @amount.each {|i| output = output + i }
  return output
  end

 
And since nobody’s perfect, we need to make a way to get rid of
transactions we didn’t mean, or actually voided at the bank, and a way
to make corrections for mistakes.

  def void!(transaction) # nukes a single transaction, returning a hash
                        
# representing what was destroyed, for undo-ing
                        
# purposes
  output = {‘date’ => @date.slice!(transaction),
            ‘note’ => @note.slice!(transaction),
            ‘type’ => @ttype.slice!(transaction),
            ‘amount’ => @amount.slice!(transaction),
            ‘datestamp’ => @datestamp.slice!(transaction),
            ‘timestamp’ => @timestamp.slice!(transaction)}
  @date.compact
  @note.compact
  @ttype.compact
  @amount.compact
  @datestamp.compact
  @timestamp.compact
  return output
  end
 
  def edit!(transaction,params={}) # makes a change to a single transaction
                                  
# returning a hash representing the
                                  
# transaction prior to changes.
  output = {‘date’ => @date[transaction],
            ‘note’ => @note[transaction],
            ‘type’ => @ttype[transaction],
            ‘amount’ => @amount[transaction],
            ‘datestamp’ => @datestamp[transaction],
            ‘timestamp’ => @timestamp[transaction]}
  @date[transaction] = params[‘date’] if params.has_key?(‘date’)
  @note[transaction] = params[‘note’] if params.has_key?(‘note’)
  if params.has_key?(‘amount’)
      if (@ttype[transaction]==’Withdrawal’ or @ttype[transaction]=~/^Check.*$/)
          and params[‘amount’]==params[‘amount’].abs
              @amount[transaction]=-(params[‘amount’])
      else
          @amount[transaction]=params[‘amount’]
      end
  end
  return output
  end

An ‘end’ keyword immediately after that wraps up the class.

This is the “business end” of my checkbook program, all the real work happens here.

The next class I called Account, whose fields represent its Transaction
roll, its name, its balance, and what the current check number is.

The entire rest of the program is dedicated to drawing stuff on the
screen so that this little bit of business can get done.  I can
write any kind of interface I want around these classes, which is the
way object-oriented programming is supposed to work.  I plan on
replacing the interface I wrote because its code is dodgy and I’m
certain I can do better, just as an example.

I’ll get into that later.

Hope everybody’s doing well.

See you next time.

Advertisements

2 thoughts on “

  1. Hey, it’s good to read one of your posts; a nice long one too. I do get a bit tired with these slouchy little entries people leave, slackers. 8 years, hell. My record is something more like 8 weeks, which is a pain in the ass, really, because looking for work and going through that whole thing is a nightmare – I assume that’s your next step. So good luck. Sadly, I think I’m pretty much ‘ghetto’ about most tactile things like socks and cars and whatnot – the last car I drove had pools of water in the cabin that would slosh around when cornerning, and sometimes if I took a corner particulary fast water would go in my shoe and make socks wet. Horrible. I couldn’t digest your bit on programming and code. My brain tunes out whether I like or not. Sorry.P.S – I got this via email subscription, I dont post on my site anymore – (see picture of alf for verification!) – keep it up!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s