mahiwaga

I'm not really all that mysterious

serious geekery

Well, this is a fun little puzzle from Google Blogoscoped

I’ve translated them to Ruby-esque code fragments (with some Rails-isms sprinkled in.)

  1. original:
    // idiom 1  
    cop[0].goodInPercent = 100;  
    cop[1].goodInPercent = 0;  
    my version:
    GoodCop=cop[0]  
    BadCop=cop[1]  
    return GoodCop + BadCop  
  2. original:
    // idiom 2  
    isCrowd = personCounter >= 3;  
    my version:
    assert (3 == isCrowd)
  3. original:
    // idiom 3  
    injury += insult;  
    my version:
    return (insult + injury)
  4. // idiom 4  
    1: board.draw();  
    goto 1;  
    my version:
    def Board.back    
      Board.type = 'drawing'  
    end     
  5. original:
    // idiom 5  
    if (bird[1].feather == bird[2].feather) {  
        bird[1].flock(bird[2]);  
    }  
    my version:
    flock.collect {|bird| feathers.each {|feather| bird.find_by_feather(feather)}}  
  6. original:
    // idiom 6  
    a = getThickness('blood');  
    b = getThickness('water');  
    assert(a > b);  
    Blood.SpecificGravity = 1.0506 # reference: http://www.clinchem.org/cgi/content/abstract/20/5/615    
    Water.SpecificGravity = 1.0000  
    assert (Blood.SpecificGravity > Water.SpecificGravity)  

    (See: [Specific Gravity of Blood and Plasma at 4 and 37°C][2]) [2]: http://www.clinchem.org/cgi/content/abstract/20/5/615 “Trudnowski and Rico · “Specific Gravity of Blood and Plasma at 4 and 37°C” · Clinical Chemistry 1974 20(5):615”

  7. original:
    // idiom 7  
    a_spade_a_spade();
    my version:
    class Spade  
      def Spade.call(value)   
        Spade.name = value  
      end  
    end  
    
    Spade.call ('Spade')
  8. original:
    // idiom 8  
    die(1000);  
    function die(max) {  
        for (i = 1; i <= max; i++) {  
            cut();  
        }  
    }
    my version:
    Death.find_by_cut('1000')
  9. original:
    // idiom 9  
    prey = 'worm';  
    time = getCurrentTime();  
    if (time >= 4 && time <= 8) {  
        bird.catch(prey);  
    }  
    my version:
    bird = Creature.new(:shift => 'early')  
    worm = Creature.new  
    if bird.shift == 'early'   
      bird.catch(worm)  
    end  
  10. original:
    // idiom 10  
    while ( rome.fire() ) {  
        doFiddle();  
    }  
    my version:
    Nero(:instrument => 'fiddle') while Rome.is_burning?  
  11. original:
    // idiom 11  
    function getValue(garbage) {  
        return garbage;  
    }
    my version:
    Value.In(:Garbage)  
    print Value.Out    
    ==>Garbage  
  12. original:
    // idiom 12  
    take(salt * .01);  
    my version:
    Salt.take(:mass => 0.06479891, :unit => 'gram')  
  13. original:
    // idiom 13  
    var here = false;  
    var there = false;  
    my version:
    assert (!(here or there) == true)  
  14. original:
    // idiom 14  
    if (i == 2) {  
        tango();  
    }
    my version:
    def self.takes(value)   
      if value == 2 then self.tango();  
    end  
    </li>
  15. original:
    // idiom 15  
    days = 365;  
    for (day = 1; day <= days; day++) {  
        if ( random(0,100) <= 50 ) apple++;  
    }  
    if (apple <= days) doctor();
    my version:
    year.collect {|day| if day.apple_count > 0 then doctor.keep_away()}
  16. original:
    // idiom 16  
    if ( !dogs.sleep() ) {  
        disturb(dogs);  
    }  
    my version:
    if dog.is_asleep? then dog.lay()  
  17. original:
    // idiom 17  
    function tunnel() {  
        var dark;  
        for (i = 0; i < 10; i++) {  
            dark = true;  
        }  
        dark = !dark;  
        return dark;  
    }
    my version:
    Class Tunnel   
      def self.is_there_light?   
        return (self.position == END)
      end  
    end  
  18. original:
    // idiom 18  
    if ( ape.inLineOfSight(it.x, it.y) ) ape.do(it);
    my version:
    if monkey.does_see?(:actor) then monkey.do(Monkey.action_seen(:actor))  
  19. original:
    // idiom 19  
    return way.my || way.high;
    my version:
    return way(:my) || way(:high)  
  20. original:
    // idiom 20  
    hay[ random(0, hay.length - 1) ] = 'needle';
    my version:
    hay = Stack.new  
    hay.find('needle')  
  21. original:
    // idiom 21  
    a = 0;  
    b = 1;  
    hand[a].wash(hand[b]);  
    hand[b].wash(hand[a]);
    my version:
    hand['left'].wash(hand['right'])  
    hand['right'].wash(hand['left'])  
  22. original:
    // idiom 22  
    function getGain(pain) {  
        return pain >= 1;  
    }
    my version:
    if (pain.level == 0) then gain.level = 0  
  23. original:
    // idiom 23  
    if (cooks >= 3) {  
        broth = null;  
    }
    my version:
    if cook.count >= 3 then broth.is_spoiled? = true  
  24. original:
    // idiom 24  
    if (a != 'cake') a.eat();
    my version:
    Class Cake  
      def Cake.have()    
        Cake.is_had? = Cake.is_eaten? ? false : true  
      end 
    
      def Cake.eat()   
        Cake.is_eaten? = Cake.is_had? ? false : true  
      end
    end  
  25. original:
    // idiom 25  
    doesStand = you == me;
    my version:
    if We.is_united? then We.stand()  
    if We.is_divided? then We.fall()  
  26. original:
    // idiom 26  
    var location = getLocation();  
    if (location == 'rome') {  
        do( location.getCitizen() );  
    }
    my version:
    if person.locale == 'Rome' then person.behavior(:Roman)
  27. </ol>
initially published online on:
page regenerated on: