News for hackers. Stuff that matters.

Mon_Ouie

Re:Ruby 2.0.0 Released on Monday February 25, 2013 @05:51AM (#5278287)
A very common use case for Module#prepend is for mixins that want to decorate methods.

For example, say I have a class that can process stuff, and a mixin that attempts to log calls to the #process method:

     class Processor
       def process
         puts "Very important stuff here"
       end
     end

     module Logger
       def process
         puts "Entering process."
         super
         puts "Leaving process."
       end
     end
If you just ``include Logger`` in Processor it won't work: Processor#process is looked up before Logger#process. However, if you use Module#prepend, the ancestry chain will change and calls to Process#process will be decorated as expected.
Re:Evil Ruby on Wednesday January 23, 2013 @07:19AM (#5102697)
Methods that simply behave differently depending on whether or not an argument is given. For example, passing nil (or any other object) to inject is different from passing nothing.

     [1, 2, 3].inject(:+)
     [1, 2, 3].inject(0, :+)
     [1, 2, 3].inject(nil, :+) # doesn't work
Rubinius uses a magic ``undefined`` value for this:

     def inject(initial=undefined, sym=undefined, &block)
Re:Typing Practice for Programmers on Wednesday August 22, 2012 @05:38PM (#4419728)
It seems to me that any character that needs to be typed using alt gr can't be detected (using Firefox as my browser and BÉPO as my keyboard layout).
Re:I Google everything on Monday August 20, 2012 @11:02AM (#4407906)
What I find funny in that is that when I'm in a social circle, we usually don't have quick access to the Internet.

Is using a phone for browsing (I guess that's the only way you could) during a conversation that common?

Re:Cling: Running C++ in an interpreter on Sunday August 12, 2012 @04:02PM (#4373472)
Although getting an interactive environment definitely is a nice thing, I'd argue you don't have to create a whole project directory, etc. to play with an idea; I usually write it in a single file.
Re:Racket v5.3 on Tuesday August 07, 2012 @02:09PM (#4351382)
I always have mitigated feelings about these tools. On the one hand, those features are really appealing. On the other hand, leaving my regular editor prevents me from using its (sometimes heavily configured) text- and code-editing capabilities. Plus I can access all the code I've written for other projects from Emacs, regardless of the language.
This reminds me of one of the math teachers I had, who used a technique I found quite interesting and effective compared to how other teachers taught us about new concepts.

He would rarely come up with some theorem, ask us to solve a few exercises, and go on to the next chapter. When he wanted to introduce a new concept, he'd usually ask us to solve an equation or a more concrete probleme (I can remember something like the fence problem mentioned in the article, which was used to introduce us to finding the maximal output of a 2nd degree expression). After that, we would either find a solution through some struggle — and then try to figure out a more efficient approach — or we'd stumble on a problem by trying to use approaches we'd been taught before — and therefore try to find a better way to represent the problem.

On an amusing sidenote, while we were each working individually, he'd walk around in the class, looking at what we were doing, and crossing out with a red marker pen mistakes we'd made.

Re:The price of a messy codebase: No LaTeX on the iPad on Tuesday November 22, 2011 @02:40PM (#3267004)
As there is an app[1] that allows to run Lua code typed by the user, the most likely changed their policy about interpreting code.

[1] Codify: http://itunes.apple.com/us/app/codify/id439571171?mt=8

Re:Ray, a Ruby game library on Sunday July 17, 2011 @06:20PM (#2774364)
Just in case you (or someone else) would like to know, Ray has been tested with both JRuby and Rubinius.
Re:Ray, a Ruby game library on Sunday July 17, 2011 @03:44PM (#2774003)
There's a method to check for collisions between rectangles (which can be called on sprites too).
Re:Ray, a Ruby game library on Sunday July 17, 2011 @03:42PM (#2774002)
Yes, the heavy work is done in C. So it should be fast enough for many games.