Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, February 08, 2007

Ruby Threads

Today, I encountered my first Ruby gripe.

Variables mapped from collection passed into Ruby threads are not independent of one another. If one thread changes the passed variable, all of other threads share the new variable.

Let's suppose I have an Array of items = ["item 1", "item 2", "item 3"]

Here's some code that takes each item in the array and does some processing on it, printing out "finished!" statements after each element is processed.

items.map{|item|
Thread.new(item){
#process with variable execution time goes here
puts "#{item} finished!"
}
}

Let's suppose the map task associated with "item 3" starts last and ends first. Then the output could look like this:

item 3 finished!
item 3 finished!
item 3 finished!

The explanation for this peculiar behavior is detailed in Ruby Central's Pragmatic Programmer's Guide:
"A thread shares all global, instance, and local variables that are in existence at the time the thread starts."

Sunday, January 07, 2007

Dusting Off My Ruby Skills

I just finished writing my first non-trivial Ruby script.

It searches a website (more than a page) for pictures that match given search criteria and downloads the pictures along with meta data.

It's only 61 lines long, and there are a bunch of comments and blank lines. It's not complete yet, but the final version should be less than 100 lines long.

Our Railpad server was up for 288 days before I shut it down yesterday. I haven't coded any significant Ruby code since I worked on Railpad, so this picture grabbing script was a much-needed refresher.

Monday, January 01, 2007

New Year's Resolutions

1. Maintain a sleep schedule
2. Catch up with friends
3. Learn Django
4. Improve Ruby skills
5. _______?

Sunday, October 29, 2006

True Names in the wild!

Yukihiro "Matz" Matsumoto, the guy behind Ruby of Ruby on Rails fame, referenced "True Names" in his talk about Ruby Design Principles.

The Presentation MP3

When he mentions True Names, he's on this slide.

Monday, March 13, 2006

Emacs is pretty sweet

I started copying my resume over from .DOC format to .HTML (perhaps with CSS), and Emacs's syntax highlighting has showed itself to be better than anything I've used before. Why? It doesn't just highlight syntax, it uses the syntax to appropriately format the content. It's like a wannabe WYSIWYG editor, but better.

Monday, March 06, 2006

Sometimes I think about learning emacs


http://unix.rulez.org/~calver/pictures/curves.jpg

Programming Competition

We had a 30 minute Microsoft-sponsored programming event that revolved around the algorithms section of the Imagine Cup tournament.

I got 3rd place out of about 60 people! I won Age of Empires III, but I ended up giving it to my brother since my video card is a wimpy 32mb shared memory ATI x300.

Friday, February 24, 2006

Top Down vs. Bottom Up programming

Programming Styles

Top Down:
A program is created in terms of classes or methods, which are in turn identified by even lower level methods until the program is complete.

Bottom Up:
Build the language up towards the program. Create new functions and operators that make it seem like the language was custom built for the program.

Mine:
Pretend magical parts of the program do certain wonderful and conveneint things, and program off of that. Then go fill out the magic parts when you feel like it.

Sunday, January 29, 2006

Lisp

So, I downloaded the MIT Scheme package. I played around a bit with the command line interpreter -- ahh, the memories...

I don't really have time to write a decent Scheme app atm. Gotta do homework.

Saturday, January 21, 2006

Lisp dream

I just had a dream about Lisp. I was in a programming class: CSE 144. This course doesn't actually exist, but it would have come right after CSE 143, the second CS course required before you can apply to get into the major.

The bearded prof was talking about scheme. At first, I was dissappointed that I would have to use such a parenthesis-filled language to write the assignment, but the professor looked at me funny, and I suppose I must have said, "Hmm, I've actually been thinking about learning Scheme. How convenient!"

Then he gave us our assignment:

When you get a telephone call, the phone rings. Make new emails ring.

I left the class and spoke to some non-CS friend and he said that ringing emails would be annoying. For some reason, I ran back to the classroom to divulge my newfound worries to the class.

Before I could get back the the lecture room, which looked oddly like Mrs. Benzinger's room at ODLE, I had the thought that woke me up: "I should blog this."

Thursday, January 19, 2006

Ok don't laugh

Ok, don't laugh, but I think I just got some insight into LISP. LISP is trees! You stick your inputs at the bottom of the tree (the leaves), and then they "flow" to the top(the root), where you get your answer.

All signs point to LISP?

I guess I've been reading a bit too much Paul Graham and Philip Greenspun lately. I'm considering taking up either LISP or Scheme, the languages of parenthesis doom.

However, I've also seen the power and simplicity of Python (for building web frameworks), and I'll have to admit that I've seen far more impressive Python web apps than LISP ones.

Hmm, Python or LISP?