Blog

Feb 26 2007

Comments

Farewell, Codecite

During 2005 and 2006, we developed a simple Rails application called Codecite that we used to deliver presentations and training materials at our private training classes, and at the No Fluff, Just Stuff Java symposiums. As of 2007, codecite is mothballed. Our new course delivery system for 2007 uses a combination of TiddlyWiki and Prototype to present course materials and lab exercises.

If you are looking for Ruby and Rails samples, we have a more polished set of samples with the book Rails for Java Developers. The sample code is a free download.

We will be moving some of the old codecite material into the Code section of the website. If you are looking for some specific code sample that we have not updated yet, contact us and we will get it to you.

Feb 23 2007

Comments

Apache/Cap/Mongrel day at Relevance

Today I am moving 14 Rails applications in various states of very-oldness up to either (1) the dustbin or (2) the modern world of Apache/Capistrano/Mongrel. If you are reading this, the main site is back online, for the moment.

Feb 22 2007

Comments

rcov doesn't like vanilla, digs mocha

The solution to yesterday's rcov problem, it turns out, is to yank flexmock from our test suites. This is a shame, because we like the library so much. However, by removing it and replacing it with mocha/stubba, we were able to get rcov running again. Now, if I could just convince it to quit saying "60.8%"..........

Feb 21 2007

Comments

The rcov that ate Durham

We depend pretty heavily on rcov for keeping us sane in our Ruby projects. To our mild surprise and massive consternation, rcov started failing on us yesterday. Somehow or another, we're getting a Bus error thrown out of the c code. It seems to have something to do with multiple aliases of the initialize method in an AR model. It happens across platforms, and it seems that the only other people to experience it are the rspec folks, and the only solution they've found is to turn off the c-level bindings. Which is PAIIINNNFFFULLLLL.

If anybody has any solutions, please let us know, because right now, we're bummed.

Feb 21 2007

Comments

Relevance is Hiring Two Ruby Developers

Relevance, LLC is seeking Ruby developers in the Durham/Chapel Hill, NC area. We will begin with two full-time contract positions around April 1 and May 1, 2007.

The ideal candidate would have experience with several of the following items, and a passion to learn the rest:

  • Ruby
  • Object-Oriented Design
  • Domain-Specific Languages
  • Test::Unit
  • Rails
  • Streamlined
  • Subversion
  • Trac
  • FlexMock
  • Rcov
  • Mac OS X
  • TextMate

Relevance is a leading developer of enterprise Ruby and Rails applications. Relevance's partners are authors of Rails for Java Developers and Pragmatic Ajax.

Do you want to work with a small, talented team, and develop your skills with the technologies above? Please send a resume and a one-page writing sample to contact@relevancellc.com, subject line "Ruby position."

Feb 20 2007

Comments

The Ruby Way

Summary: If you want to be a serious Ruby programmer and have already devoured the Pickaxe, you should read The Ruby Way.

When reading a programming language book, I look for two things:

  1. Big ideas: What make this language unique? What styles of programming might it enable?
  2. Little details: Any interesting language has hundreds of little idioms, tricks, and quirky corners.

When I finally cracked my copy of The Ruby Way (2nd ed.), I did not expect to find much that was new to me--big or little. After all, I have been using Ruby daily for years, and have worn out the electrons in my PDF copy of the Pickaxe. My expectations bumped up a notch when I saw this in the introduction: "[The Ruby Way] was carefully designed to be complementary to [the Pickaxe] rather than overlapping it." When Chapter 1 jumped into reflection, singletons vs. eigenclass, threequals, and method_missing, I knew I was in for a fun ride.

There is a ton of stuff in The Ruby Way that I have not seen elsewhere in book form. The sections on core classes are not afraid to visit the dimly-lit corners. For example, collection coverage includes not only inject, but also partition and how to write your own n-way partition method. This "how to write you own" theme recurs throughout the book, as Hal moves past what Ruby does into what you might coax Ruby to do.

The Ruby Way covers many things that you might not use every day, but give you a complete utility belt for when you face an unusual challenge. You'll learn about Madeleine, Rinda, ZenTest, GUI toolkits, Rcov, web toolkits (not just R**ls), RMagick, PDF::Writer, and internationalization.

There are a few nits to pick. There could be more about Rake, which is vastly more important than anyone seems to realize. The material on metaprogramming is excellent, but the idioms in a few places are "old school", e.g. append_features is used where included is more appropriate in Ruby 1.8+.

I usually take a page or two of notes when reading a book on a familiar topic. With The Ruby Way I took about fifteen pages. There is a lot of good food for thought here. Dig in.

Feb 20 2007

Comments

Show us your gems

Mike, Chad and Bruce have all opened up their inner repositories and showed us what lies within; I thought I'd show mine too. Here's what's installed on my box:

  action_profiler (1.0.0)
  actionmailer (1.3.2, 1.3.1, 1.3.0, 1.2.5.5848, 1.2.5, 1.2.3, 1.2.1, 1.2.0)
  actionpack (1.13.2, 1.13.1, 1.13.0, 1.12.5.5848, 1.12.5, 1.12.3, 1.12.1, 1.12.0)
  actionwebservice (1.2.2, 1.2.1, 1.2.0, 1.1.6.5848, 1.1.6, 1.1.4, 1.1.2, 1.1.0)
  activerecord (1.15.2, 1.15.1, 1.15.0, 1.14.4.5848, 1.14.4, 1.14.3, 1.14.2, 1.14.0)
  activesupport (1.4.1, 1.4.0, 1.3.1.5848, 1.3.1, 1.3.0)
  acts_as_ferret (0.3.1)
  aws-s3 (0.3.0, 0.0.8952)
  builder (2.0.0)
  capistrano (1.3.1, 1.2.0, 1.1.0)
  cgi_multipart_eof_fix (2.0.2)
  color-tools (1.3.0)
  creditcard (1.0)
  daemons (1.0.4, 0.4.4)
  director (0.1)
  facets (1.8.8, 1.7.46)
  fastercsv (1.2.0)
  fastthread (0.6.3, 0.6.2)
  fcgi (0.8.7, 0.8.6.1)
  ferret (0.10.14)
  flexmock (0.5.0, 0.4.5, 0.4.3, 0.3.0)
  gem_plugin (0.2.2, 0.2.1)
  google-geocode (1.2.1, 1.2.0)
  gruff (0.2.8, 0.1.1)
  hoe (1.1.7)
  icalendar (0.98, 0.97, 0.96.4)
  json (0.4.3)
  Linguistics (1.0.3)
  mailfactory (1.2.3)
  markaby (0.5)
  mime-types (1.15)
  mocha (0.4.0)
  model_security_generator (0.0.9)
  mongrel (1.0.1, 1.0, 0.3.13.4, 0.3.13.1)
  mongrel_cluster (0.2.1)
  mysql (2.7)
  needle (1.3.0)
  net-sftp (1.1.0)
  net-ssh (1.0.10, 1.0.8)
  payment (1.0.1)
  pdf-writer (1.1.3)
  rails (1.2.2, 1.2.1, 1.2.0, 1.1.6.5848, 1.1.6, 1.1.4, 1.1.2, 1.1.0)
  rake (0.7.1)
  rc-rest (2.2.1, 2.1.0, 1.0.0)
  rcov (0.7.0.1)
  RedCloth (3.0.4, 3.0.3)
  redgreen (1.2)
  rspec (0.7.5.1)
  ruby-growl (1.0.1)
  ruby-prof (0.4.1)
  rubycas-client (0.11.0, 0.10.1)
  rubyforge (0.4.0)
  rubygems-update (0.9.2)
  rubyzip (0.9.1)
  ruport (0.8.10)
  s33r (0.5.2, 0.4.1)
  scruffy (0.2.2)
  Selenium (1.0.1)
  simple-rss (1.1)
  sources (0.0.1)
  sparklines (0.4.1, 0.2.7)
  sqlite3-ruby (1.2.0, 1.1.0)
  stomp (1.0.5, 1.0.4, 1.0.2)
  streamlined_generator (0.0.6)
  syntax (1.0.0)
  tattle (1.0.1)
  termios (0.9.4)
  test-spec (0.3.0)
  transaction-simple (1.4.0, 1.3.0)
  trestle_generator (1.1.7.3, 1.1.2)
  tzinfo (0.3.3, 0.2.1)
  xml-simple (1.0.10)
  ZenTest (3.4.3)

That's 73 gems, for those counting at home. Special notes:

  • even though streamlined_generator is still in there, it shouldn't be because we moved to a plugin model with 0.0.7
  • the trestle generator is redundant if you have Rails 1.2
  • there's a bunch of gems in there I've rarely used more than once, but only one designed to be that way

Feb 15 2007

Comments

4000 requests per second with Mongrel

It is certainly helpful for FUDbusting when people post numbers like this.

Feb 03 2007

Comments

Panic at the Exponents!

Stu and I have been promoting our new book over at the JavaRanch all week, and the conversations have been fun. There's one guy over there who seems to have gone from an interested seeker to a Java-defender over the course of the week (even though we are saying, repeatedly, that Java isn't BAD, just that Ruby and Rails are different, with good things to offer). Regardless, he posted this handy little bit:

  try
  2**2**2**2**2
  on Ruby 15 minutes.

He'd made the point earlier in another thread, as well, that it took 15 minutes to compute this in Ruby.

Now, I'm probably just a total idiot, but I looked at that and said "How in the world did it take 15 minutes to compute 2 to the fifth power? What kind of computer is he using, a Commodore Vic20?"

So I fired up irb on my MacBook pro and typed in:

  2**2**2**2**2

and in about a quarter of a second, I got back the answer. I was surprised both by how quick it was, and by the answer I got, which was:

20035299304068464649790723515602557504478254755697514192650169737108940595563114530895061308809333481010382343429072631818229493821188126688695063647615470291650418719163515879663472194429309279820843091048559905701593189596395248633723672030029169695921561087649488892540908059114570376752085002066715637023661263597471448071117748158809141357427209671901518362825606180914588526998261414250301233911082736038437678764490432059603791244909057075603140350761625624760318637931264847037437829549756137 70981604614413308692118102485959152380195331030292162800160568670105651646750568038741529463842244845292537361442533614373729088303794601274724958414864915930647252015155693922628180691650796381064132275307267143998158508811292628901134237782705567421080070065283963322155077831214288551675554073345107213112427399562982719769150054883905223804357045848197956393157853510018992000024141963706813559840464039472194016069517690156119726982337890017641517190051133466306898140219383481435426387306539552 96969138802415816185956110064036211979610185953480278716720012260464249238511139340046435162386756707874525946467090388654774348321789701276445552940909202195958575162297333357615955239488529757995402847194352991354376370598692891375715374000198639433246489005254310662966916524341917469138963247656028941519977547770313806478134230959619096065459130089018888758808473362595606544488850144733570605881709016210849971452956834406197969056546981363116205357936979140323632849623304642106613620022017578 78518574091620504897117818204001872829399434461862243280098373237649318147898481194527130074402207656809103762039992034920239066262644919091679854615157788390603977207592793788522412943010174580868622633692847258514030396155585643303854506886522131148136384083847782637904596071868767285097634712719888906804782432303947186505256609781507298611414303058169279249714091610594171853522758875044775922183011587807019755357222414000195481020056617735897814995323252085897534635470077866904064290167638081 61740550405117670093673202804549339027992491867306539931640720492238474815280619166900933805732120816350707634351669869625020969023162859350071874190579161241536897514808261904847946571736601005892476655445840838334790544144817684255327207315586349347605137419779525190365032198020108764738368682531025183377533908861426184800374008082238104076468878471647552945326947661700424461063311238021134588694532200116564076327023074292426051582811070387018345324567635625951430032037432740780879056283663406 96503084422585596703927186946115851379338647569974856867007982396060439347885086164926030494506174341236582835214480672667684180708375486221140823657980296120002744132443843240233125740354501935242877643088023285085588608996277445816468085787511580701474376386797695504999164399828435729041537814343884730348426190338884149403136613985425763557710533558020662218557706008255128889333222643628198483861323957067619140963853383237434375883085923372228464428799624560547693242899843265267737837317328806 32107532112386806046747084280511664887090847702912081611049125555983223662448685566514026846412096949825905655192161881043412268389962830716548685255369148502995396755039549383718534059000961874894739928804324963731657538036735867101757839948184717984982469480605320819960661834340124760966395197780214411997525467040806084993441782562850927265237098986515394621930046073645079262129759176982938923670151709920915315678144397912484757062378046000099182933213068805700465914583872080880168874458355579 26258465124763087148566313528934166117490617526671492672176128330845273936469244582892571388877839056300482483799839692029222215486145902373478222682521639957440801727144146179559226175083889020074169926238300282286249284182671243405751424188569994272331606998712986882771820617214453142574944015066139463169197629181506579745526236191224848063890033669074365989226349564114665503062965960199720636202603521917776740668777463549375318899587866282125469797102065747232721372918144666659421872003474508 94283091153518927111428710837615922238027660532782335166155514936937577846667014571797190122711781278045024002638475878833939681796295069079881712169068692953824852983002347606845411417813911064856023654975422749723100761513187002405391051091381784372179142252858743209852495787803468370333781842144401713868812424998441861812927119853331538256732187042153063119774853521467095533462633661086466733229240987984925669110951614361860154890974024191350962304361219612816595051866602203071561368473236466 08689050142639139065150639081993788523183650598972991254044794434251667742996598118492331515552728832740283526884424087528112832899806259126736995462473415433335001472314306127503903073971352520693381738433229507010490618675394331307847980156551303847581556852362180104196502555961819349863159132330360964619059902361126811960234418433633345949276319461017166529138237171823942992162725384617760656945422978770713831988170369645886898118632109769003557358846244648357062914530527571012788720279653644 79724025405448132748391794128826423835171949197209797145936887537198729130831738033911016128547415377377715951728084111627597186384924222802373441925469991983672192131287035585307966942713416391033882754318613643490100943197409047331014476299861725424423355612237435715825933382804986243892498222780715951762757847109475119033482241412025182688713728193104253478196128440176479531505057110722974314569915223451643121848657575786528197564843508958384722923534559464521215831657751471298708225909292655 63883665112068194383690411625266871004456024370420066370900194118555716047204464369693285006004692814050711906926139399390273553454556747031490388602202463994826050176243196930564066636662609020704888743889890749815286544438186291738290105182086993638266186830391527326458128678280660133750009659336462514609172318031293034787742123467911845479131110989779464821692250562939995679348380169915743970053754213448587458685604728675106542334189383909911058646559511364606105515683854121745980180713316361 25730796111683438637676673073545834947897883163301292408008363568259391571131309780305164417166825183465736759341980849589479409832925000863897785634946932124734261030627137450772861569225966285738579055332406418490184513282846327092697538308673084091422476594744399733481308109863994173797896570106870267341619671965915995885378348229882701256058423655895396903064749655841479813109971575420432563957760704851008815782914082507777385597901291294073094627859445058594122731948127532251523248015034665 19048228961406646890305102510916237770448486230229488966711380555607956620732449373374027836767300203011615227008921843515652121379215748206859356920790214502277133099987729459596952817044582181956080965811702798062669891205061560742325686842271306295009864421853470810407128917646906550836129916694778023822502789667843489199409657361704586786242554006942516693979292624714524945408858422726153755260071904336329196375777502176005195800693847635789586878489536872122898557806826518192703632099480155 87445557517531273647142129553649408438558661520801211507907506855334448925869328385965301327204697069457154695935365857178889486233329246520273585318853337094845540333656535698817258252891805663548836374379334841184558016833182767683464629199560551347003914787680864032262961664156066750815371064672310846196424753749055374480531822600271021640098058449752602303564003808347205314994117296573678506642140084269649710324191918212121320693976914392336837470922826773870813223668008692470349158684099115 30983154120635661231875043054675369832308279664574176208065931772656858416818379661061449634325441117069417002226578173583512598210807691019610522292638797450490192543119006205619065774524161919131875339840493439768233102984658933183730158095925228292068208622303325852801192664963144413164427730032377922747123306964171499455322610354751456312906688543454268697884477429817774937101176146516241836166802548152963353084908499430067636548061029400946937506098455885580439704859144495844450799784970455 83550685408745163316464118083123079704389849190506587586425810738422420591191941674182490452700288263983057950057341711487031187142834184499153456702915280104485145176055306971441761368582384102787659324662689978418319620312262421177391477208004883578333569204533935953254564897028558589735505751235129536540502842081022785248776603574246366673148680279486052445782673626230852978265057114624846595914210278122788941448163994973881884622768244851622051817076722169863265701654316919742651230041757329 90447353767253684579275436541282655358185804684006936771860502007054724754840080553042495185449526724726134731817474218007857469346544713603697588411802940803961674694628854067917213860122541950381970453841726800639882065632879283958270851091995883944829777564715202613287108952616341770715164289948795356485455355314875497813400996485449863582484769059003311696130376612792346432312970662841130742704620203201336835038542536031363676357521260470742531120923340283748294945310472741896928727557202761 52722682833767413934256526532830684699975970977500055608899326850250492128840682741398816315404564903507758716800740556857240217586854390532281337707074158307562696283169556874240605277264858530506113563848519659189686495963355682169754376214307786659347304501648224329648912707098980766766256715172690620588155496663825738292741820822789606844882229833948166709840390242835143068137672534601260072692629694686727507943461904399966189796119287505194423564026443032717373415912814960561683539881885694 84045342311424613559925272330064881627466723523751234311893442118885085079358163848994487544756331689213869675574302737953785262542329024881047181939037220666894702204258836895840939998453560948869946833852579675161882159410981624918741813364726965123980677561947912557957446471427868624053750576104204267149366084980238274680575982591331006919941904651906531171908926077949119217946407355129633864523035673345588033313197080365457184791550432654899559705862888286866606618021882248602144999973122164 13817065348017551043840662441282280361664890425737764095632648282525840766904560843949032529052633753231650908768133661424239830953080654966187938194912003391948949406513239881664208008839555494223709673484007264270570116508907519615537018626479745638118785617545711340047381076276301495330973517418065547911266093803431137853253288353335202493436597912934128485497094682632907583019307266533778255931433111096384805394085928398890779621047984791968687653998747709591278872747587443980677982496827827 22009264499445593804146087706419418104407582698056880389496546165879839046605876453418102899071942930217745199761044950431968415034555140448209289333786573630528306199900777487269229986082790531716918765788609089418170579934048902184415597910926768627965975839524839267348836347456516870161662406424242412289611180106156823425393921800524834547237792199112285959141918774917938233400100781283265067102817813960291209147201009478787525512633728842223538694900679276645116347581011938753196572421214760 38284774774571704578610417385747911301908583877890152334343013005282797038580359815182929600305682612091950943737325454171056383887047528950563961029843641360935641632589408137981511693338619797339821670761004607980096016024823096943043806956620123213650140549586250615282588033022908385812478469315720323233601899469437647726721879376826431828382603564520699468630216048874528424363593558622333506235945002890558581611275341783750455936126130852640828051213873177490200249552738734585956405160830583 05377073253397155262044470542957353836111367752316997274029294167420442324811387507563131907827218886405337469421384216992886294047963530515056078812636620649723125757901959887304119562622734372890051656111109411174527796548279047125058199907749806382155937688554649882293898540829132512907647838632249478101675349169348928810420301561028338614382737816094634133538357834076531432141715065587754782025245478065730134227747061674424196895261316427410469547462148375628829977180418678508454696561915090 86958742511844358373065909514609804512474094113738999278224929833677960110153870961297497055663016373072027507347599229437923938244274211861582361613178863925530951171884212985083072382597291441422515794038830113590833316518582349672212596218125070581137594955250227472746743698871319266707692991990844671612287388584575846227265733307537355728239516169641751986750126817454293237382941438248143771398619067166575729458078048205595118816871880752129718326364421553367877512747669407901170575098195750 84563565217389544179875074523854455200133572033332379895074393905312918212255259833790909463630202185353848854825062897715616963860712382771725621313460549401770413581731931763370136332252819127547191443450920711848838366818174263342949611870091503049165339464763717766439120798347494627397822171502090670190302469762151278521956142070806461631373236517853976292092025500288962012970141379640038055734949269073535145961208674796547733692958773628635660143767964038430796864138563447801328261284589184 89852804804884418082163942397401436290348166545811445436646003249061876303950235640204453074821024136689519664422133920075747912868380517515063466256939193774028351207566626082989049187728783385217852279204577184696585527879044756219266399200840930207567392536373562839082981757790215320210640961737328359849406665214119818381088451545977289516457213189779790749194101314836854463961690460703010759681893374121757598816512700076126278916951040631585763753478742007022205107089125761236165802680681585 84998526314658780866168007332646768302063916972030648944056281954061906852420030534631566218913273090696873531816410945142880366059952202482488867115544291047219291342483464387053685086487490991788126705656653871910497218200423714927401644609434598453925367061322106165330856620211889682340057526754861014769936887382095845522115719234796868881608536316158628801503959494185294892270744108282071693033878180849362040182552222710109856534448172074707560192459155994310729495781978785905789400525401228 67517142511184356437184053563024181225473266093302710397968091064939272722683035410467632591355279683837705019855234621222858410557119921731717969804339317707750755627056047831779844447637560254637033369247114220815519973691371975163241302748712199863404548248524570118553342675264715978310731245663429805221455494156252724028915333354349341217862037007260315279870771872491234494477147909520734761385425485311552773301030342476835865496093722324007154518129732692081058424090557725645803681462234493 18970813889714329983134761779967971245378231070373915147387869211918756670031932128189680332269659445928621060743882741691946516226763254066507088107103039417886056489376981673415902592519461182364294565266937220315550470021359884629275801252771542201662995486313032491231102962792372389976641680349714122652793190763632613681414551637665655983978848938173308266877990196288693229659737995193162118721545528739417024366988559388879331674453336311954151840408828381519342123412282003095031334105070476 01599879854725291906652224793197154403317948368373732208218857733416238564413807005419135302459439135025545318864547962522602517629283743304651023610575835145507394433396102162296754614157811271970017386114942795014112532806212547758105129720884652631580948066336876701473107335407177108766159358568140982129677307591973829734414452566887708553245708889583209938234321027182241147637327913575686154212528496579033350931527769255058456440105521926445053120737562877449981636463328358161403301758139673 59427327690448920361880386754955751806890058532927201493923500525845146706982628548257883267398735220457228239290207144822219885587102896991935873074277815159757620764023951243860202032596596250212578349957710085626386118233813318509014686577064010676278617583772772895892746039403930337271873850536912957126715066896688493880885142943609962012966759079225082275313812849851526902931700263136328942095797577959327635531162066753488651317323872438748063513314512644889967589828812925480076425186586490 24111112730135719718138160258317850693224400799865663537154408845486639318170839573578079905973083909488180406093595919090747396090441015051632174968141210076571917748376735575100073361692238653742907945780320004233745280756615304292901449578062963413838355178359976470885134900485697369796523869584599459559209070905895689145114141268450546211794502661175016692826025095077077821195043261738322356243760177679936279609936897519139496503335850715541843645685261667424368892037103749532842592713161053 78349807407391586338179676584252580367372064693512486522384813416638080615057048290598906964519364400185971204257230073164100099169875242603773621777634306216167448849308109299010095179745415642512048220867145868492551324442667771278637282113315362243010918243912433802140462422233491535595168908162884879899882736304453724321742802157557779670216663170479697281724833928410156422745072717792693999297403080727703950135815451424940490265361058254093731146531049433824843797186069372144446008267980024 71229489405761853892203425608302697052876621377373594394224114707074072902725461307358541745691419446487624357682397065703184168467540733466346293673983620004041400714054277632480132742202685393698869787607009590048684650626771363070979821006557285101306601010780633743344773073478653881742681230743766066643312775356466578603715192922768440458273283243808212841218776132042460464900801054731426749260826922155637405486241717031027919996942645620955619816454547662045022411449404749349832206807191352 76798674781345820385957041346617793722853494003163159954409368408957253343870298671782977037333280680176463950209002394193149911500910527682111951099906316615031158558283558260717941005252858361136996130344279017381178741206128818206202326384986151565645123004779296756361834576810504334176954306753804111392855379252924134733948105053202570872818630729115891133594201476187266429156403637192760230628384065042544174233546454998705531872688792642410214736369862546374715974435494344389973005174252511 08773578863909468120966734281525859199248576404880550713298142993599114632399191139599267525763590074465728101918058418073422277347213977232182317717169164001088261125490933611867805757223910181861685491085008852722743742120865248523724562486976622453848192986711294529455154970305859193071984971054141816369689761311267440270096486675459345670599369954645005589216280479763656861333165639073957032720343891754152675009150111988568727088481955316769316812728921430313768180164454773675183534978579242 76463354162433601125960252109501612264110346083465648235597934274056868849224458745493776752120324703803035491157544831295275891939893680876327685438769557694881422844311998595700727521393176837831770339130423060958999137314684569010422095161967070506420256733873446115655276175992727151877660010238944760539789516945708802728736225121076224091810066700883474737605156285533943565843756271241244457651663064085939507947550920463932245202535463634444791755661725962187199279186575490857852950012840229 03506151493731010700944615101161371242376142672254173205595920278212932572594714641722497732131638184532655527960427054187149623658525245864893325414506264233788565146467060429856478196846159366328895429978072254226479040061601975197500746054515006029180663827149701611098795133663377137843441619405312144529185518013657555866761501937302969193207612000925506508158327550849934076879725236998702356793102680413674571895664143185267905471716996299036301554564509004480278905570196832831363071899769915 3166679208958768572290600915472919636381673596673959975710326015571920237348580521128117458610065152598883843114511894880552129145775699146577530041384717124577965048175856395072895337539755822087777506072339445587895905719156736

At this point, I realized two things. One, the guy was either running some decrepit computer (or was using Why's hobix in-browser interpreter, which CAN NOT BE a reasonable measure of anything), and two, that I didn't understand how the exponent operator worked in Ruby.

I just assumed that 2**2**2**2**2 would be "two to the fifth", which is 32. Then I looked at it longer and said, no, that can't be right, it must be 65536, or "two squared, then squared again, then squared again, then squared again". But when I got that answer, I realized that the exponents are evaluated right to left, and so what you actually get is "2 to the (2 to the (2 to the (2 to the 2))))" which is "2 to the 65536" which is a darn big number.

Is anybody else surprised by this, or am I just dumb?

Jan 31 2007

Comments

Write for Others as for Yourself

Don's post about the Sellsian Approach is right on. This dovetails nicely with what I love most about Ruby: the ease with which you can give your fellow programmers a domain specific language instead of an API. Last week I found myself leaving a comment "for the next programmer" that looked like this:

  # foo must be a Hash of String to Widgets 

My gag reflex took over, and so a few minutes later I committed the following executable Ruby instead:

  invariant 'foo is a Hash of String to Widgets'

With regular expressions, instance_eval, and threequals, it was trivial to make invariant into a fairly general mechanism.

Popular Tags