wismer / sunnyside-citywide

sunnyside-citywide
MIT License
1 stars 1 forks source link

/lib housecleaning #5

Open pruett opened 10 years ago

pruett commented 10 years ago

Feel free to weigh in guys, but I feel like cleaning up the /lib folder would help with readability/maintainablity as you extend the library. Instead of listing all of the .rb files within /lib, a common convention is to have your main file, probably named sunnyside.rb along with a folder that contains all your library files, so a folder named /sunnyside. The sunnyside.rb file would contain much of the requireing of files, setup, etc. that refer to your source files, now under the /lib/sunnyside directory

Again this is mostly for readablility and housecleaning, but could help in organizing not only your files, but your code. I would start by organizing your files in a way that relates to your menu file. Also, following this convention and requireing all files within sunnyside.rb means you can just require /path/to/sunnyside.rb in your menu file

/lib
  |-- sunnyside.rb <- setup and require files within /sunnyside directory
  |-- /sunnyside
          |-- /folder1
                |-- file1.rb
                |-- file2.rb
          |-- /folder2
                |-- file3.rb
                |-- file4.rb
          file5.rb
          file6.rb
wismer commented 10 years ago

So no need for require_relative?

pruett commented 10 years ago

this could be false, but i see less use of require_relative when compared to relative. i'm not sure if one is preferred over the other, but i tend to stick with require. you may need to update your load path in order to properly require files. a line like this is very common:

$:.unshift File.join(File.dirname(__FILE__), '..', 'lib') This is a fairly cryptic (in my opinion) way of saying "add ../lib to the load path so i can can call require on files from this directory"

That said, if require_relative is working and require isn't, i would stick to what's working. This is more of a housekeeping/structure opinion.

Here is an example of this type of structure from the warden repo: https://github.com/hassox/warden/tree/master/lib

kylemac commented 10 years ago

The pattern that @pruett suggests is very much close to the rubygems pattern of loading code. This will help you if you do go the route of packaging this into a gem.

As far as resources on rubygems, this is an oldie but a goodie

pruett commented 10 years ago

:+1: for @kylemac's resources. these are really good