1. Список говнокодов пользователя malleus

    Всего: 4

  2. Ruby / Говнокод #10622

    −84

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    def self.allow_some_behaviour?
      # better safe than sorry.
      bool = !false ? !false : !!false
    
      # type checking
      if bool
    
        # short circuit just in case
        return !true;
      elsif !bool
        return !false
      end
    end

    найдено в реальном проекте, работало в течении года где то. зачем это сделано - непонятно. почему не выпилили, тоже неясно.

    malleus, 08 Июня 2012

    Комментарии (4)
  3. Ruby / Говнокод #7857

    −96

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    <%products = Array.new
      count = Product.count(:conditions => "novelty = 'true'")
      while products.size < 10 do
        products << Product.find(:first, :conditions => "novelty = 'true'",:offset => rand(count))
        products.uniq!
      end-%>

    при количестве новинок меньше 10 получаем бесконечный цикл. счастье в продакшене, там sql запросы не пишутся в лог)

    malleus, 13 Сентября 2011

    Комментарии (14)
  4. Ruby / Говнокод #7199

    −98

    1. 1
    amount = ('-' + batch['settleAmount'].to_s).to_i

    работа с платежными системами требует вдумчивости и оригинальности.

    malleus, 07 Июля 2011

    Комментарии (12)
  5. Ruby / Говнокод #3394

    −92

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    def get_next_line(max_level, current_level, current_line_items)
            next_line_items = []
            result_string = ''
    
            if current_level == 1
                    next_line_items.push(1)
                    result_string = "1\n"
            else
                    current_line_number = false
                    current_line_number_count = 0
                    current_index = 0
    
                    current_line_items.each do |line_number|
                            if current_index == 0
                                    current_line_number = line_number
                                    current_line_number_count = 1
                            else
                                    if line_number == current_line_number
                                            current_line_number_count = current_line_number_count + 1
                                    else
                                            next_line_items.push(current_line_number_count)
                                            next_line_items.push(current_line_number)
    
                                            current_line_number_count = 1
                                            current_line_number = line_number
                                    end
                            end
    
                            if current_index >= current_line_items.length - 1
                                    next_line_items.push(current_line_number_count)
                                    next_line_items.push(current_line_number)
                            end
    
                            current_index = current_index + 1
                    end
    
                    result_string = next_line_items.join(' ') + "\n"
            end
    
            if current_level < max_level
                    result_string = result_string + get_next_line(max_level, current_level + 1, next_line_items).to_s
            end
    
            # return result
            result_string
    end
    
    puts 'Input max level:'
    level = gets
    
    puts ''
    puts get_next_line(level.to_i, 1, [])

    реальное тестовое задание кандитата.
    задача - вывести несколько членов последовательности
    1
    11
    21
    1211
    ....

    malleus, 04 Июня 2010

    Комментарии (62)