Ruby vs Python default parameters

Ruby and Python have more similarities than differences, but one gotcha that usually gets Ruby hackers is how Python’s default parameters are evaluated.

Let’s first look at an example in Ruby:

irb(main):001:0> def list_of_stuff(stuff=[])
irb(main):002:1>   stuff << "Junk"
irb(main):003:1>   for item in stuff
irb(main):004:2>     puts item
irb(main):005:2>   end
irb(main):006:1> end
=> nil
irb(main):007:0> list_of_stuff  
Junk
=> ["Junk"]

If we call list_of_stu

Continue reading...


Singing with Sinatra

Last week I started playing around with a very cool Ruby web framework called Sinatra. It is an easy way to create a fast RESTful ruby web application with few lines of code that is easy to setup.

Sinatra is built on top of Rack, which provides a minimal API for connecting web servers and web frameworks. Read Chris Neukirchen

Continue reading...


GitHub

Last night I signed up with GitHub, which had their official public launch yesterday.

As I mentioned before Git rocks, it’s a fast, efficient, distributed version control system.

GitHub is not just Git hosting it is also social networking for geeks. I was amazed how fast I was up and running.

  1. Signed up for an account.
  2. Ran
Continue reading...


Self documenting code

I program in both Ruby and Python and love both languages. Python is great because it fast and easy for most developers to understand, but when it comes to building great expressive DSL‘s my heart is with Ruby, well most of the time.

I have been doing some shared hacking on Ruby DSL project with a friend of mine. He is a very experienced C/Python developer, but fairly new to Ruby.

Yesterday, he pinged me with a question:

*“Carlos, I have a dumb question, that is pissing me off, how do y

Continue reading...


Spaceship operator

While developing applications I strive to make my code more concise and expressive. Using comparison operators helps make my code clearer and more declarative.

Let’s say that we have an application that tracks personal expenses. We would like to be able to compare our expenses using simple comparison operators like > and <. To do this we will use the Ruby module Comparable which makes it easy to compare objects by mixing in

Continue reading...


Ruby Arrays

With all of the new Ruby web frameworks, and people realizing their is more to Ruby then Rails, it is more important then ever to call yourself a Ruby hacker not a Rails programmer.

Now I know most experienced Rails developers already are great Rubyist, but for people new to Ruby through Rails I always think it is important to point out that Ruby makes Rails cool not the other way around.

One thing that I recommend to peopl

Continue reading...


Hot Ruby

<script type="text/ruby">
class Design
  def approach &block
	block.yield "simple"
  end
end
class Programming
  NAME = ' - Albert Einstein'
  def main
    Design.new.approach do |msg|
      puts "Make everything as " 
            + msg + " as possible, but not " 
            + msg + "r." + NAME
    end
  end
end
Programming.new.main
</script>

Hot Ruby is a project which aims to port the Ruby Virtual Machine over to ECMAScript

Continue reading...


The Ruby Mix

At my first job fresh out of college I was doing mostly C++ programming. I remember that one thing I had a love hate relationship was with Multiple inheritance. On the one hand there were many situations where it was the perfect fit for my application, but due to increased complexity and ambiguity in most situations, I tended to design without. Now that I do programming in Ruby, mixins have given me the power of multiple inheritance without th

Continue reading...


Merb

I have been playing around with Merb which is a very cool Ruby MVC framework similar to Rails, but Merb is ORM-agnostic, JavaScript library agnostic, template language agnostic, and thread-safe. The merb core has a very small footprint, but for any features that aren’t covered in the core, there are plugins. Rather than reinvent the wheel with a custom plugin framework, these are implemented as RubyGems.

Continue reading...





« Previous Entries

who am I..

I'm Carlos Gabaldon, and this is my hack blog. It's mainly about programming but my liberal views tend to come out from time to time. I've been a professional programmer for over 10 years. I like to hack on open source projects and I seem to rewrite this blog in a new language every couple of years. cgabaldon[at][cox][dot][net]

what I am doing..

Zenopsis calabro

what is on this site..

Welcome, guest, login

what people are saying..