biasa, enjoy banget ngikutin cheatsheetnya errtheblog
http://feeds.feedburner.com/cheatsheets
saya ketemu pencerahan ini, saya pikir bagusnya kita saling sharing aja disini.
dibawah ini buat poin yang saya berani komentari maka akan saya komentari dalam
bahasa indonesia, kalau yang belum, either saya lupa atau saya malas atau
memang
nggak berani kasih komentar takut dibego'-bego'-i sama senior dan mbah2x
disini.
Jadi tolong kalau saya salah dibetuli sama dilengkapi yg belum-belum ya.
makasih
sebelumnya.
anyway, ini rev.3 suatu hari nanti bisa aja sudah berubah jadi selalu refer ke
original URL source.
* Store sessions in the database.
caranya:
# config/environment.rb:
# config.action_controller.session_store = :active_record_store
# console:
# rake db:sessions:create
* Use a custom configuration file for passwords and API keys instead of storing
them in your Subversion repository. I use YAML and mirror the style of
database.yml.
* Use constants where needed. Instead of repeating strings like the address of
your customer service reply email, set it once in a constant (in environment.rb
or the appropriate environment file) and use that throughout your application.
caranya:
liat contoh coding niwatori di toombila environment.rb deh # kaburr
* Keep time in UTC. A no brainer, and easy to do.
caranya:
$ ruby -e 'puts Time.now.utc'
Fri Sep 14 21:27:43 UTC 2007
$ ruby -e 'puts Time.now'
Sat Sep 15 04:27:49 +0700 2007
* Don't loop through ActiveRecord models inside other models. Use eager loading
if you need to work with multiple associated models. Better yet, write a custom
SQL query and let the database do the work for you.
caranya:
pakai :include atau .find_by_sql saja langsung, f*ck! buat yg bilang tidak
elegan
kalau langsung tembak dengan query SQL langsung
* Beware of binary fields. By default, all fields are returned with queries,
including the full contents of any binary fields. Use :select to pull out only
the fields you need.
caranya:
kalo saya sih kecuali image berpiksel 50-an kali 50-an gak ditaroh jadi blob
field
di DB
* Write tables to cache data for reports that span months and years. It.s much
faster than re-generating a year.s worth of reports every time a page is loaded.
caranya:
*rtfm* baca blognya si tobi (yg bikin typo blog)
* Create a table with a list of country names. By default, Rails uses strings
for selects and lists of countries, which doesn.t work well for reporting or
database consistency between models.
caranya:
udah basi/ada di rails api. yg nggak basi either plugin (itu juga masi non
ajax)
si rick ato bikin aja lagi yg support ajax ato js aja dah yang komplit, mis pas
pilih, jakarta, nongol jakarta selatan, trus klik, nongol lagi, mampang, nongol
lagi, erte, erwe, kelurahan, kode pos. jadi plugin. anyone? kerjasama sama
tukangpos sama siapa lagi nih ya?
* Avoid bloated controllers. Instead of piling actions into a controller, limit
yourself to 10 actions per controller, then rethink your design.
* Keep your controllers and views skinny. In general, most of your code should
be in your models, not your controllers or views.
* Don't store objects in the session. Use integers or short strings if
necessary, then pull the appropriate object out of the database for the duration
of a single request.
* Avoid heavy response processing. Can you mark a record as needing to be
processed, then use a cron job or a messaging server to do the long-running
work? BackgroundRB is also an option. (I use this technique for filtering SPAM
comments on this blog).
* Use ar_mailer to queue bulk emails instead of sending them during the Rails
response cycle.
* Monitor your servers with the exception_notification plugin, munin, monit, or
other tools.
* Don't cut costs on hardware. You.ll quickly lose the money you thought you
were saving if your developers have to spend even one day a month on unexpected
server maintenance due to poor backups or cheap hardware.
* Test-drive your development.
* Use database indexes to speed up queries. Rails only indexes primary keys, so
you.ll have to find the spots that need more attention.
caranya:
jangan lupa untuk add_index :fieldnya, :tabelnya
* Profile your code. The ruby-prof gem and plugin helped me make an application
three times faster with only minimal changes to the code.
* Minimize graphic-related dependencies. If your application only needs to make
a few thumbnails, don.t waste memory by importing large graphics libraries. Look
at mini-magick or image_science for lightweight thumbnailing.
* Avoid excessive repeated rendering of small partials.
* Use CSS instead of inline tags to apply selective styling.
ada yang mau mendebat ini dan membandingkan dengan CSS dan JS inline kriptik2x
yang diimplementasikan di Google? # view source deh.
* Don't use ActiveRecord.s serialize option to store large objects in database
fields.
tips:
pakai ruby marshalling, atau kalau di postgres pasang tipe array field
# ciiiyeh yg lagi mabok ma postgres! baru belajar mulu' dari seabad lalu' :-P
* Use attr_protected :fieldname in models to keep database fields from being
manipulated from forms (or from any calls to
Model.update_attributes(params[:model])).
ya, bikin field "jadi-jadian" (virtual gitu)
* Use Ruby classes and inheritance to refactor repeated controller code.
barangsiapa yang sering pernah pakai eval seperti widi dan arie, jalankan flog,
lihatlah seberapa berdarah-darah kode ruby-nya. hayo bertobatlah!
* Use unobtrusive Javascripting techniques to separate behavior from markup.
* Package self-sufficient classes and modules as plugins or RubyGems.
* Cache frequently accessed data and rendered content where possible.
* Write custom Test::Unit assertions or rSpec matchers to help with debugging
test suite errors.
* Rotate the Rails and Mongrel logfiles using the logrotate daemon on Linux.
* Build a reliable backup system.
* Automate deployment and maintenance with Capistrano or Vlad.
* Keep method bodies short. If a method is more than 10 lines long, it.s time to
break it down and refactor.
* Run flog to determine overly complex methods and clases.
hayyah, baru liat disini ternyata dibahas flog juga, baru terbaca sama gw,
berarti
yg diatas gw baru ngomongin flog, dihapus aja deh, males nghapus.
* Don't use too many conditionals. Take advantage of case statements and Ruby
objects to filter instead of multiply-nested if statements.
contoh:
if(($a=='3') && (preg_match('/eo/i', $eo)) && ($operator=='indosat')) {
if($unknown_arg =~ /eo/) {
if(...
elseif....
else
elseif...
if...
elseif...
else
}
oops.. itu barusan kayaknya bukan codingnya ruby deh -_-
gunakan:
module NcangNcing; blablablah; end
class Mbah
include NcangNcing
end
class Anak < Babe
super mbah
obyek do
yield
end
end
* Don't be too clever. Ruby has great metaprogramming features, but they are
easy to overuse (such as eval and method_missing).
* Become familiar with the most popular plugins. Instead of re-implementing the
wheel, save yourself some time by using well tested, popular plugins.
liatin trus rasain:
http://agilewebdevelopment.com/plugins/top_rated
btw halah! itu kan ada enterprisey padahal di tag bullshit gitu dong kok yah -_-
--
$ ruby-19 -e "puts ({name:'arie', blog:'http://ariekusumaatmaja.wordpress.com',
community:%w(http://groups.yahoo.com/groups/id-ruby
http://www.linkedin.com/in/ariekeren)}).is_a?(Hash).to_s.concat(' erl ghc z Foo
Fighters')"
true erl ghc z Foo Fighters