Nov 7, 2017
Over the last few years, I’ve become progressively more interested in tabletop games. As a result, I’ve been playing more of them—and thus rolling more dice. Now, as with any game of chance, occasionally luck isn’t in my favor and and I’ll consistently do much lower damage than I feel like I should. When you do 5 damage on an attack that averages 16, it feels pretty awful. I, however, wanted to know more. I wanted to know exaclty how unlucky I was getting. Being a programmer, my solution, naturally, was to write some code to do so.
Sep 28, 2017
In today’s blog post, we’re going to discuss the idea of a
value_ptr. Basically, the idea is that it’s pointer with value semantics. Why would you want this? Well, polymorphism for one. For another, you could conceivably want to allocate a very large number of some very large objects on the stack (perhaps recursively), and you don’t want to cause an overflow.
This has been implemented before, but I didn’t actually read the source for that. Instead, I’ll write it myself.
May 8, 2017
I was screwing around with Ruby Coroutines, and the concept of coroutines in general, when I came across this page. It talks about how you can use coroutines to memoize functions. Ruby has native coroutines. You can guess what happened next.
Here’s what I came up with:
class Object def self.fiber_memoize(method_name) meth = self.instance_method(method_name) self.send(:define_method, method_name) do f = Fiber.new do |s| result = meth.bind(self).call loop do Fiber.yield(result) end end self.send(:define_singleton_method, method_name) do f.resume end f.resume end end end
This works on an instance-level, which a naive implementation wouldn’t. It also works by re-defining methods on a per-instance basis when you call them, which is just another example of how much Ruby rocks.
Here’s how to use it:
class Factorial def initialize(num) @num = num end def result puts "This run is not memoized" (1..@num).inject(:*) || 1 end fiber_memoize :result end f = Factorial.new(100) puts f.result #=> Prints the not memoized message, then the result puts f.result #=> Prints the (now memoized) result
Interesting, this is also a way to do memoization in ruby without any conditionals, which is pretty neat.
Please never use this in any kind of production environment. I’m begging you.
Feb 2, 2017
I’m a well-known Ruby fanboy among my circle of friends. Even people who aren’t into programming will occasionally make a comment about it, which I think is an indication that I talk about how great the language is too often.
In truth, it’s not surprising that people might know this about me. I really, really like Ruby. I don’t think it’s perfect for all tasks—hell, I think it’s downright terrible in some contexts—but I do think it is a fantastic language, and it’s probably my favorite to write. This blog post is going to serve as a bit of a high-level introduction to Ruby as a language, as well as a justification for my fanboy-ism.
Sep 27, 2016
As I mentioned in my previous post, I’ve been spending the past few months working on a novel. Along the way I’ve hit the general bumps and roadblocks: outline issues, stress about characterization, plot reworks, and so on. Still, I think I’ve been at least mildly productive. Recently, especially, I feel like I’ve hit a flow. I can sit down, and with a relatively small amount of effort, I can get into the story and set to work on expanding it. It’s not perfect, or particularly easy, but it’s productive.
Writing a novel while working on ImageHex has been a sort of strange experience. Not necessarily because the act of coding and the act of writing are dissimilar—indeed, I’ve always maintained that the opposite was true, and that programming is a lot closer to fiction writing than most people would expect. Instead, it has been strange because of the two types of art I must focus on: visual art, such as drawing or painting, and writing.
When I work on ImageHex I need to think about the experience of an artist. I need to think about what problems an artist may have and what the solutions to those problems can be. I’ve actually sent messages to a few artists requesting a bit of help on that front, and I’ve been very grateful for the responses I’ve received.
When working on the novel, however, I am living the experiences of a writer. An amateur writer, sure, and somebody who is likely to never get anywhere with their writing, but still a writer in the technical sense of the word.
Writing and artwork have a strange, intertwined relationship: similar in some ways, vastly different in others. My current life has given me a lot of time to think about these differences.