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

    Optimization Tips

    Scheduled Pinned Locked Moved Developers' Forum
    110 Posts 22 Posters 168.8k Views 22 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.
    • thomthomT Offline
      thomthom
      last edited by

      Agree - whitespace eating of ruby has bothered me as well. Will ask if it can be changed.

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

      1 Reply Last reply Reply Quote 0
      • AdamBA Offline
        AdamB
        last edited by

        @thomthom said:

        Didn't realise Ruby would recreate the variables for each iteration. I'd thought it'd keep them for the duration of the loop...

        The closure you create with curly braces is handled as a first class object and passed as an argument to the iterator. This means the scope of any variables you mention inside that block is limited to that block - it must create them each time. 😞

        Developer of LightUp Click for website

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

          Is that why each is slow?

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

          1 Reply Last reply Reply Quote 0
          • GaieusG Offline
            Gaieus
            last edited by

            Guys, Thom asked if we can do something with these white spaces but I have to say it is most probable that we cannot. I is hard coded somewhere in the php script of the forum software and even if we could tweak that, it would be impossible to keep it through upgrades (which is very due soon anyway).

            Is the code tag not good (apart from that scrolling annoyance)?

            Gai...

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

              It's ok. I just hoped there was a config UI for BBCode tags on the forum. Thought it was normal. The code tag is ok, just figured if it could be changed...

              I don't suppose there are forum plugins that can be installed? having the code block apply syntax highlighting would be a delight for us coders. Such as this:

              http://code.google.com/p/syntaxhighlighter/

              http://syntaxhighlighter.googlecode.com/files/Overview01.png

              Edit: what version of phpBB does SCF run? I'm looking at this: http://www.phpbb.com/kb/article/adding-custom-bbcodes-in-phpbb3/ from this it appear to be that it'd be a matter of setting the HTML replacement for the ruby tag to not collapse white space using CSS.

              Replacement sample something like this:
              <span style="white-space:pre;">{TEXT}</span>

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

              1 Reply Last reply Reply Quote 0
              • GaieusG Offline
                Gaieus
                last edited by

                I can imagine you would like that syntax highlight! I use Notepad++ and know what a difference it is!

                Coen and Tavi should be spoken to about these things.

                Gai...

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

                  @adamb said:

                  I see a lot of SU scripts using some of the more compact iterators Ruby iterators. So they might read nice, but they're often slower than just simple for-loops.

                  shingara.fr

                  This domain may be for sale!

                  favicon

                  (blog.shingara.fr)

                  In regard to this should one init the variables used by for in to speed up things? or is that not needed?

                  Would this
                  ` x = 0
                  for x in collection

                  ...

                  endbe faster than for x in collection

                  ...

                  end`

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

                  1 Reply Last reply Reply Quote 0
                  • AdamBA Offline
                    AdamB
                    last edited by

                    no

                    Developer of LightUp Click for website

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

                      I've always thought for used each under the hood.

                      http://blog.grayproductions.net/articles/the_evils_of_the_for_loop

                      for loops do not have their own scope - the loop variable and any variables created in the loop become available (or are over-written) in the current scope.

                      With .each, variables are local to the block {..}

                      Hi

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

                        @jim said:

                        I've always thought for used each under the hood.

                        http://blog.grayproductions.net/articles/the_evils_of_the_for_loop

                        for loops do not have their own scope - the loop variable and any variables created in the loop become available (or are over-written) in the current scope.

                        If you click the method names in the Ruby API manual you get to see the sourcecode:
                        http://ruby-doc.org/core/classes/Array.html#M002173

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

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

                          That's showing a for loop in the c language.

                          Hi

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

                            That's what it's doing under the hood.

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

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

                              @thomthom said:

                              That's what it's doing under the hood.

                              Right, so where is the definition for the for function?

                              The answer is there isn't one because for is not a function, but is "sugar". The for loop in Ruby really uses the .each method behind the scenes.

                              Although, I can't recall where I learned that. The link to the blog article mentions it, though.

                              Hi

                              1 Reply Last reply Reply Quote 0
                              • tbdT Offline
                                tbd
                                last edited by

                                speaking of each vs for :

                                loop1 = []
                                loop2 = []
                                
                                calls = ["one", "two", "three"]
                                
                                calls.each do |c|
                                  loop1 << Proc.new { puts c }
                                end
                                
                                for c in calls
                                  loop2 << Proc.new { puts c }
                                end
                                
                                loop1[1].call #=> "two"
                                loop2[1].call #=> "three"
                                

                                SketchUp Ruby Consultant | Podium 1.x developer
                                http://plugins.ro

                                1 Reply Last reply Reply Quote 0
                                • Dan RathbunD Offline
                                  Dan Rathbun
                                  last edited by

                                  @jim said:

                                  The for loop in Ruby really uses the .each method behind the scenes. ... Although, I can't recall where I learned that.

                                  'Pick-Axe' > For ... In expressions

                                  I'm not here much anymore.

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

                                    I guess to get back on topic, for loops are not faster then .each iterators. The performance must have to do with how the for loop variables are not loop scoped, as in each.

                                    Hi

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

                                      Came across this link:
                                      http://www.h3rald.com/articles/efficient-ruby-code-shortcut-review/

                                      On that list it says
                                      @unknownuser said:

                                      Use parallel assignment (a, b = 5, 6) where applicable

                                      while at this link:
                                      http://www.hxa.name/articles/content/ruby-speed-guide_hxa7241_2007.html

                                      @unknownuser said:

                                      Avoid parallel assignment

                                      πŸ˜’

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

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

                                        @thomthom said:

                                        Came across this link:
                                        http://www.h3rald.com/articles/efficient-ruby-code-shortcut-review/

                                        On that list it says
                                        @unknownuser said:

                                        Use parallel assignment (a, b = 5, 6) where applicable

                                        while at this link:
                                        http://www.hxa.name/articles/content/ruby-speed-guide_hxa7241_2007.html

                                        @unknownuser said:

                                        Avoid parallel assignment

                                        πŸ˜’

                                        I just bought the ebook and that review summary was wrong - parallel assignments are not recommended for performance important tasks.
                                        Interesting read that book btw.

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

                                        1 Reply Last reply Reply Quote 0
                                        • M Offline
                                          MartinRinehart
                                          last edited by

                                          Let's see - for performance I'm going to avoid iterations, arrays, hashes and objects.

                                          What's left?

                                          Author, Edges to Rubies - The Complete SketchUp Tutorial at http://www.MartinRinehart.com/models/tutorial.

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

                                            @martinrinehart said:

                                            What's left?

                                            puts "Hello World" πŸ˜„

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

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

                                            Advertisement