1. 1

    Non-Ruby developer here. Is there any difference between a Ruby yield and just passing in a lambda as an argument?

    1. 2

      Yes, though there are a few aspects in play here. First, a block parameter is a special argument and in order to pass a lambda in as a block parameter you must use the & operator (this operator will attempt to coerce non-proc objects to procs, so this is why symbols are sometimes used in this way).

      When you have a block in ruby, the lifetime of the lexical context is tied to the call-frame that is created upon invocation. This might sound like an implementation detail but it allows the runtime to avoid allocating a proc object to hold the closed over lexical environment (aka. faster and lighter). Generally, if you know you’re receiving a block, it can be an advantage to stick with yield and the implicit parameter rather than pull out the proc as a value and use #call (or an alias of #call like #[]) on the object (this has been optimized more recently in some cases to allow lazy allocation of the object if you only forward it to another call).

      The other difference is around parameter behavior. Blocks and Procs don’t require the arity of the block and the yield to match. So you can take fewer or more arguments than are passed and the extra fields will either be dropped or set to nil. Lambdas however, require the arity to match, much like a method call (distinctly constructed using lambda or -> “stabby” syntax). This can be a good thing but I’ll avoid writing half an article here.

      One more advanced case that many are unaware of, you can capture a proc using the constructor without a block, so these end up working in a similar way:

      def a_is_42(a, &callable)
        callable.call if a == 42 && callable
      end
      
      def b_is_42(b)
        Proc.new.call if b == 42 && block_given?
      end
      

      Of course, it’s a contrived example on the second because we could just use yield there, but it does show that we can build the proc object lazily which can be a big win in some hot paths for Ruby code. There are some more optimization techniques but this gives a little taste of the range of differences between the proc world and the block world. If people are curious, I can write up more about this stuff.

      TL;DR, you can avoid a lot of allocation and call overhead by keeping things in block form.

      1. 1

        That makes sense, thanks!

      2.  

        The only difference is that your lambda will be an instance of the class Proc which is in charge of storing and executing the piece of code associated to your lambda.

        It’s a bit more complicated than this, but let’s keep it simple if you’re not familiar with Ruby. ;-)

        I invite you to read this article to dive into the specificities of the Proc class and lambdas in Ruby.

        1.  

          Which article?

      1. 15

        I bought the limited edition hardcopy, this is a super-fun game.

        If you like this game, you will likely enjoy the other zachtronics games.

        If you enjoyed writing assembly in DOS, TIS-100 is your best bet.

        If you like graphical/visual programming, try Opus Magnum.

        For the games listed above, you can see the cost of your Steam friends’ solutions. Once you’ve solved a puzzle, it’s surprisingly much fun to try to beat the scores of people you know.

        1. 10

          Shenzhen I/O is pretty rad too; bought the feelies for that one, and get asked about the binder routinely :D

          1. 6

            If verilog/VHDL is your kink, MHRD is a lot of fun.

            1. 3

              That’s been on my steam wish list for a very long time. I’ll have to check it out when I “finish” EXAPUNKS.My brief interaction with Verilog was mind-opening. I’d really enjoy a game with a similar medium but the right constraints.

              1. 1

                Funny, I’m just teaching myself verilog right now! I’m still in the random walk stage but hopefully soon I’ll have a clue.

            1. 5

              Spacechem was the game that got me hooked into this genre and ever since I’ve purchased every Zachtronics release. Each game has it’s only unique character.

              One interesting thing I’ve noticed is how rewarding it can be to watch your machine solve the problem. Sometimes it’s terribly hacky and other times it’s like a perfectly timed dance. An example from EXAPUNKS is the binary tree search level (I forget the name give in game). An optimized solution looks for more balanced than a quick and dirty one.

              While there is something very familiar to day-to-day programming in these games, the unique constraints are what drives interest for me. Using some general purpose instruction set or code would destroy a lot of the fun for me. In EXAPUNKS this includes things like abusing termination conditions, creative use of SWIZ, and so on. In a game like TIS-100 it was register constrained so it was all about signal timing. Spacechem had a few unique tricks like running the wally into a wall to allow one block to be executed every cycle.

              Anyway, if any of that sounds interesting, I’d explore the zachtronics.com site. There are a few free games and then many of the ones mentioned in this thread.

              1. 3

                I recently built a planck (MIT layout, kit finally shipped via Massdrop from January). I’ve been trying various QMK customization but I’m a little unhappy with some of the default behaviors I have to override in QMK, so I’ll probably need to spend time over a coming weekend to dig deeper. Overall, I really like the ortholinear setup but I do find my muscle memory is still needing some training with it.

                Outside of that keyboard, I use a trio of vortex boards: vibe, core, and racer3. I really like the simplicity of on-hardware reprogramming despite the limitations and the build quality is great. I have Cherry MX Brown switches on all of these (I’m sure I could get something closer to ideal but these switches have been great for me).

                Of course, I also recently replaced my laptop with a Thinkpad T480 and I’m very happy with that keyboard when I’m in a quiet space or don’t have a table to put a keyboard and mouse on in front of me.

                Re: QMK, I’m almost tempted to just write my own firmware from scratch, both as a learning experience but also to get around some of the annoyances I have with how QMK deals with layering (at least for the planck keyboard).

                1. 7

                  This is my first time posting here.

                  I am looking into hardening certain aspects of Wallaroo’s Python API and improving the error messages when improper pipelines are set up. Hopefully this will round out many of the sharp edges I hit when getting up to speed with Wallaroo’s python support.

                  After that I’m working on some benchmarks to identify bottlenecks in horizontal scaling of clusters. This work is a bit open ended but I expect to be doing a lot of profiling and system call tracing once we’ve narrowed things down. There are a lot of knobs to test and turn here but we’ll start by creating a simple baseline with cheap computations and then find where our current sweet spot is when sending work across the cluster (for extremely cheap computations, I/O overhead dominates). I’ll look forward to reporting back next week.