sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Procs and lambdas

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 116 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • jolranJ Offline
      jolran
      last edited by

      Ok I'm touching a little on the subject of Procs and lambda, they are quite new to me.
      I guess if I started programming outside Sketchup I would have stumbled upon this earlier..

      Tried to gather some information about the subject and tested a little.
      But since Sketchup enviroment is a little special, I wonder if there are some best practices
      to follow or even if one should avoid using them.

      I havent found any answers for:

      Can they get overused? Should Procs only be used with short codeblocks?

      So in practice I was iterating a Hash and wanted to reuse this iteration in the same method
      for another Hash.
      1st impulse was to create another method and call it from inside this method, but I notice the argumentlist became quite long and started to wonder if this will have major impact on the performance since there might be a lot of elements iterated.
      Tried using Proc.new inside the method, and yeay it worked. But everything good has a downside, right?

      So just keep sticking to def happyMethod end, or have I entered the dark side of programming and found a jewel? πŸ˜„

      Edit: Hm guess not. 😞 (probably not using the Proc in a correct way)

      Proc.new is actually slightly slower than using a simple method call, when testing
      with some denser geometry(in my case).
      So I can only guess it costs more to create the Proc object then sending variables to an outside method? And maybe Procs are not meant to be used like a "function"?

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        If you are concerned about performance: test, test and re-test. Only thing that will give you correct answers. There are so many things where I'd never have guessed what would have been the fastest way around it.

        In general, creating objects in ruby is expensive. Reuse as much as you can.

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • jolranJ Offline
          jolran
          last edited by

          Yeah, that is probably what I have to do.

          In this case I backed of a little and removed some features, and speed is more resonable.
          I guess one can't be to greedy in Ruby.

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            What does "reuse the iteration" mean?

            Hi

            1 Reply Last reply Reply Quote 0
            • jolranJ Offline
              jolran
              last edited by

              @unknownuser said:

              What does "reuse the iteration" mean?

              Hm. maybe my explanations and english where bad. Hash.each{|k, v| v.do something } is called an "iteration", right?

              Iterate a Hash. Depending on something do the same iteration on other Hash with different values. πŸ˜•
              Seams like waste retyping the same code again..

              I know you are asking why I don't pass in a nested Hash, or array and just do everything in 1 go. In this case I just cant.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement