On the subject of selective loading...

43 views
Skip to first unread message

James Harton

unread,
May 30, 2012, 6:30:50 PM5/30/12
to bubbl...@googlegroups.com
Okay, so this morning at 6am my four year old climbed into bed with me dressed as a pirate and started "arrrr!!"ing and "I'll make ye walk the plank!"ing at me, so I rolled over, grabbed my phone and quickly scanned through all the email I got overnight - a lot of it from or about BubbleWrap.  Matt made some suggestions about selective loading, and about what the core of BubbleWrap should be.  I thought about this while I was steaming in the shower and making porridge for my horde of midgets and the following ideas came fully formed into my head:

The bubble-wrap gem:
  - When required should populate only a base API, perhaps the App, Device and Screen modules? Infrastructure only, would be my suggestion.

  - It should also provide an API to it's manipulations of App.files, something like `BubbleWrap.register` which registers the current file into App.files, perhaps it could optionally take a config block for managing App config, something like:
        BubbleWrap.register do |config|
          config.depends_on 'bubble-wrap/http'
          config.requires_framework 'CoreMIDI'
        end
    we can then place this at the top of every file and they'll be individually loadable by requiring them in the project Rakefile or (even better) Bundler.  This way we can even split off the other components of BubbleWrap into separate gems (bubble-wrap-http, bubble-wrap-json) etc.

So those are my thoughts. Are they good ones?

--
James Harton
@jamesotron

Francis Chong

unread,
May 30, 2012, 10:12:18 PM5/30/12
to bubbl...@googlegroups.com
Totally agree with just loading the core by default.

I was thinking a simpler approach, add a few files in root similar to bubble-wrap.rb, user just need to:

require 'bubble-wrap'

To get the core and...

require 'bubble-wrap-extended'

To get everything.

On Thursday, May 31, 2012 6:30:50 AM UTC+8, James Harton wrote:
> Okay, so this morning at 6am my four year old climbed into bed with me dressed as a pirate and started "arrrr!!"ing and "I'll make ye walk the plank!"ing at me, so I rolled over, grabbed my phone and quickly scanned through all the email I got overnight - a lot of it from or about BubbleWrap.  Matt made some suggestions about selective loading, and about what the core of BubbleWrap should be.  I thought about this while I was steaming in the shower and making porridge for my horde of midgets and the following ideas came fully formed into my head:
>
> </div>
> The bubble-wrap gem:</div>
>   - When required should populate only a base API, perhaps the App, Device and Screen modules? Infrastructure only, would be my suggestion.</div>
>
> </div>
>   - It should also provide an API to it&#39;s manipulations of App.files, something like `BubbleWrap.register` which registers the current file into App.files, perhaps it could optionally take a config block for managing App config, something like:</div>
>         BubbleWrap.register do |config|</div>
>           config.depends_on &#39;bubble-wrap/http&#39;</div>
>           config.requires_framework &#39;CoreMIDI&#39;</div>
>         end</div>
>     we can then place this at the top of every file and they&#39;ll be individually loadable by requiring them in the project Rakefile or (even better) Bundler.  This way we can even split off the other components of BubbleWrap into separate gems (bubble-wrap-http, bubble-wrap-json) etc.</div>
>
> </div>
> So those are my thoughts. Are they good ones?</div>
>
> </div>
> --</div>
> James Harton</div>
> <a href="http://sociable.co.nz" target="_blank">sociable.co.nz</a></div>
> +64226803869</div>
> @jamesotron</div>

James Harton

unread,
Jun 2, 2012, 8:13:16 AM6/2/12
to bubbl...@googlegroups.com
Hey all.

Take a look at the `wip-splitsville` branch[1]; I've completely replaced the way that bubble-wrap insinuates itself in the build process so that it's reusable by other gems.

This is still very much a work-in-progess and I really want some feedback on how its done - I'm planning to go back and refactor and add some test coverage soon, as this was simply a "see if it can be done this way" first pass.

I've added a really simple DSL for use in rubygems.  The nice thing about Rubygems is that it always and only looks for code in the lib path of the gem.  I've taken advantage of this and moved the actual RubyMotion code into app/ (since this seems to be a RM convention), although it could be put anywhere - and included a description of what to require in lib/bubble-wrap.rb:

BW.require('app/**/*.rb') do 
  file('app/bubble-wrap/device/screen.rb').depends_on 'app/bubble-wrap/device.rb'
  file('app/bubble-wrap/pollute.rb').depends_on 'app/bubble-wrap/ns_index_path.rb'
  file('app/bubble-wrap/pollute.rb').depends_on 'app/bubble-wrap/ui_control.rb'
end

So, you can call BW.require with a glob and it will push all the files it finds into the files config of the build task, you can optionally pass in a block describing the dependencies for particular files.

So, in line with this I will be starting work in a bubble-wrap-midi[2] gem, which will provide a Ruby abstraction to CoreMIDI.  I've created a skeleton which does nothing at the moment but depend on bubble-wrap and set the BW.require to the contents of app/

Please let me know what you think of this approach, as I think it's the right way to go, but I'm happy to be proven wrong :)

--
You received this message because you are subscribed to the Google Groups "BubbleWrap" group.
To view this discussion on the web visit https://groups.google.com/d/msg/bubblewrap/-/74cVdGXJ7sAJ.
To post to this group, send email to bubbl...@googlegroups.com.
To unsubscribe from this group, send email to bubblewrap+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/bubblewrap?hl=en.

Matt Aimonetti

unread,
Jun 4, 2012, 6:10:34 PM6/4/12
to bubbl...@googlegroups.com
Sorry I didn't check the "email" me button when I was invited to this group and only saw the messages now.

I think I agree with most of what you suggested. A few small things tho:
Let's not put stuff in the app folder, we aren't building an app but a lib ;)

The BW.require seems like a good idea but maybe a tad confusing.

What about having plain simple loaders and require them:

require 'bubble-wrap/core'
require 'bubble-wrap/http'
require 'bubble-wrap/whatever'

Dependencies would then be defined in these loader files.

For the midi wrapper, I think it should live inside bubble-wrap and just not be required by default. As a developer, I'd prefer to just install one gem and pick what I want to use from there. If we have an easy and solid convention, that shouldn't be a problem.

Thoughts?

- <att

To unsubscribe from this group, send email to bubblewrap+unsubscribe@googlegroups.com.

James Harton

unread,
Jun 4, 2012, 6:21:33 PM6/4/12
to bubbl...@googlegroups.com
Hi Matt

I think you're right, but BW.require is only available in the build system, and so I think only gem maintainers will use it, apps can still manage their own app config via the Rakefile.

I pretty much agree with you, so my thoughts were that for example lib/bubble-wrap/core.rb would contain nothing but

    BW.require 'app/core/**/*.rb'

Obviously "app" is a little contentious, but I wanted to make sure that there is a clear and visible difference between the gem code, which is only used in the build system (which rubygems looks for in lib/) and the RubyMotion implementation files. What about "impl/" or "rm/" ?

Regarding putting the MIDI code into BW, that's not a problem, but I think we need to foster the community to create bubble-wrap-* gems because otherwise we're going to wind up being a) the arbiters of taste and b) trying to keep a potentially large number of sub-projects in line and passing tests for releases.  I thought the MIDI code might serve as an example of how to do this.

-- 
James Harton
@jamesotron
+64226803869

To view this discussion on the web visit https://groups.google.com/d/msg/bubblewrap/-/6HZp88ct-xMJ.

To post to this group, send email to bubbl...@googlegroups.com.
To unsubscribe from this group, send email to bubblewrap+...@googlegroups.com.

Matt Aimonetti

unread,
Jun 4, 2012, 6:31:35 PM6/4/12
to bubbl...@googlegroups.com
I pretty much agree with you, so my thoughts were that for example lib/bubble-wrap/core.rb would contain nothing but
    BW.require 'app/core/**/*.rb'

Awesome!

I wanted to make sure that there is a clear and visible difference between the gem code, which is only used in the build system (which rubygems looks for in lib/) and the RubyMotion implementation files. What about "impl/" or "rm/" ?

What about motion vs lib?

I think we need to foster the community to create bubble-wrap-* gems because otherwise we're going to wind up being a) the arbiters of taste and b) trying to keep a potentially large number of sub-projects in line and passing tests for releases.

I agree that it could be a problem but I don't think we are there yet and I'd prefer to having a strong & interesting library that others will follow and build stuff on top of instead of starting splitting the lib before we are even successful. Now, that said, if you think your lib will be more successful outside of BW, go for it, it will certainly help build a better integration API.

- Matt

James Harton

unread,
Jun 4, 2012, 6:53:26 PM6/4/12
to bubbl...@googlegroups.com
That's all done.  Are you happy for it to be merged?  The only difference to your suggestions is that require 'bubble-wrap' will require 'bubble-wrap/core' by default.

-- 
James Harton
@jamesotron
+64226803869

Matt Aimonetti

unread,
Jun 4, 2012, 7:00:48 PM6/4/12
to bubbl...@googlegroups.com, bubbl...@googlegroups.com
If specs are passing and the doc is updated, I'm fine with it. I can do a quick review tomorrow and push the new gem (0.4).

- Matt

Marin Usalj

unread,
Jun 5, 2012, 1:42:10 AM6/5/12
to bubbl...@googlegroups.com
This scheme with require/*something is awesome!

My suggestion is only that /bubble-wrap includes everything (I prefer that everything just works out of the box),
and if someone wants to be selective, then /bubble-wrap/core , /bubble-wrap/http, etc.

Best
Marin

Matt Aimonetti

unread,
Jun 5, 2012, 4:02:20 AM6/5/12
to bubbl...@googlegroups.com, bubbl...@googlegroups.com
Seems fair, how about the Rails approach:
require 'bubble-wrap/all'
?

- Matt (via a mobile device)
To view this discussion on the web visit https://groups.google.com/d/msg/bubblewrap/-/cqo48amyHm8J.

To post to this group, send email to bubbl...@googlegroups.com.
To unsubscribe from this group, send email to bubblewrap+...@googlegroups.com.

James Harton

unread,
Jun 5, 2012, 6:01:46 AM6/5/12
to bubbl...@googlegroups.com
I like having everything I need by default included by require 'bubble-wrap', mainly because I'm just sticking `Bundler.require` at the top of my project Rakefile.

-- 
James Harton
@jamesotron
+64226803869

Matt Aimonetti

unread,
Jun 5, 2012, 6:32:38 AM6/5/12
to bubbl...@googlegroups.com
Agreed, `require 'bubble-wrap'` should load everything.

- Matt

Matt Aimonetti

unread,
Jun 5, 2012, 7:59:39 AM6/5/12
to bubbl...@googlegroups.com
Alright, it looks like we have 'bubble-wrap' 'bubble-wrap/core' and 'bubble-wrap/http' working, I'm pushing v0.4 which hopefully will be the last release before 1.0

- Matt
Reply all
Reply to author
Forward
0 new messages