1. Лучший говнокод

    В номинации:
    За время:
  2. C++ / Говнокод #20295

    +1

    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
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    std::deque<std::pair<int, int>> Pathing::findPath(int sx, int sy, int fx, int fy) const
    {
        std::list<Node> openNodes;
        std::list<Node> closeNodes;
    
        const Node startNode{nullptr, sx, sy, 0, 0, 0};
        openNodes.push_back(startNode);
    
        auto cells = gameMap->getCells();
    
        auto findNode = [](auto&& list, int x, int y)
        {
            return std::find_if(std::begin(std::forward<decltype(list)>(list)),
                                std::end(std::forward<decltype(list)>(list)),
                    [x, y](auto n) {return n.x == x && n.y == y;});
        };
    
        auto isNodeInList = [findNode](auto&& list, int x, int y)
        {
            return findNode(std::forward<decltype(list)>(list), x, y) != list.cend();
        };
    
        auto processNode = [&](auto iterCurrentNode, int x, int y)
        {
            const auto nx = iterCurrentNode->x + x;
            const auto ny = iterCurrentNode->y + y;
    
            if (cells[nx][ny].passable && !isNodeInList(closeNodes, nx, ny))
            {
                const auto G = iterCurrentNode->G + (x && y ? 14 : 10);
                const auto H = (std::abs(fx - nx) + std::abs(fy - ny)) * 10;
                const auto F = G + H;
    
                auto node = findNode(openNodes, nx, ny);
    
                if (node == openNodes.cend())
                {
                    openNodes.push_back({&(*iterCurrentNode), nx, ny, G, H, F});
    
                    if (nx == fx && ny == fy)
                        return true;
                }
                else
                {
                    if (G < node->G)
                    {
                        node->parent = &(*iterCurrentNode);
                        node->G = G;
                        node->H = H;
                        node->F = F;
                    }
                }
            }
    
            return false;
        };
    
        while (!openNodes.empty())
        {
            auto iterMinF = std::min_element(openNodes.cbegin(), openNodes.cend(),
                    [](auto n1, auto n2) {return n1.F < n2.F;});
    
            closeNodes.push_back(*iterMinF);
            auto iter = closeNodes.insert(closeNodes.cend(), *iterMinF);
    
            openNodes.erase(iterMinF);
    
            if (processNode(iter,  1,  0) ||
                processNode(iter,  1,  1) ||
                processNode(iter,  0,  1) ||
                processNode(iter, -1,  1) ||
                processNode(iter, -1,  0) ||
                processNode(iter, -1, -1) ||
                processNode(iter,  0, -1) ||
                processNode(iter,  1, -1))
                break;
        }
    
        auto finalNode = findNode(openNodes, fx, fy);
        if (finalNode == openNodes.cend())
            return {};
    
        std::deque<std::pair<int, int>> route{{finalNode->x, finalNode->y}};
        const Node* temp = finalNode->parent;
    
        while (temp)
        {
            route.push_front({temp->x, temp->y});
            temp = temp->parent;
        }
    
        return route;
    }

    jangolare, 30 Июня 2016

    Комментарии (0)
  3. C++ / Говнокод #20258

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    auto getMaxSize = [](const auto &vec) {
        if (vec.size() == 0)
            return 0;
        const auto &max = *std::max_element(
                    vec.begin(),
                    vec.end(),
                    [](const auto &lhs, const auto &rhs){
            return lhs.size() < rhs.size();
        });
        return max.size();
    };

    Раньше я не понимал актуальность шутки:
    In C++14, you just write auto auto(auto auto) { auto; } The compiler infers the rest from context

    Antervis, 23 Июня 2016

    Комментарии (30)
  4. Java / Говнокод #20214

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    PreparedStatement ps = conn.prepareStatement(
    					"SELECT * FROM Task;");
    			ResultSet rs = ps.executeQuery();
    			while (rs.next()) {
    				logger.info(rs.getInt(1));
    				this.projects = new ProjectCollection.Project[rs.getInt(1)];			
    			}

    rs.getInt(1) - индексный столбец

    arny, 16 Июня 2016

    Комментарии (0)
  5. Java / Говнокод #20161

    +1

    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
    // can only do five hundred at a time. can't find documentation
        // for this number, but if I do more than that I get an error
        // message
    	for (five_hundred <- pageranks.grouped(500))
    	{
    	  try
    	  {
    	    upload(five_hundred)
    	  }
    	  catch
    	  {
    	    // the datastore is not entirely reliable. for less than 1% of the
    	    // calls it seems to fail randomly. which is a bit annoying if
    	    // you're uploading a lot of data and don't want to stop when half of
    	    // it is already stored
    	    case ex : Throwable =>
    	    {
    	      try
    	      {
    	        ex.printStackTrace()
    	        // try a second time
    	        upload(five_hundred)
    	      }
    	      catch
    	      {
    	        // don't try a third time. just continue
    	        case ex : Throwable => ex.printStackTrace()
    	      }
    	    }
    	  }
    	}

    Наткнулся на пост, в котором некий Ph. D рекламировал scala в качестве замены питону

    Fike, 09 Июня 2016

    Комментарии (5)
  6. C# / Говнокод #20145

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    string tempFolder = DateTime.Now.Year.ToString("0000") 
    	+  DateTime.Now.Month.ToString("00")
    	+ DateTime.Now.Day.ToString("00")
    	+ "-" + DateTime.Now.Hour.ToString("00")
    	+ DateTime.Now.Minute.ToString("00")
    	+ DateTime.Now.Second.ToString("00");

    Kronic, 07 Июня 2016

    Комментарии (3)
  7. PHP / Говнокод #20144

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (!CModule::IncludeModule("iblock")) die();//7-оборудование. 8-отрасли. 5-разработки. 6-проекты.
    $a=0;if(strpos($_SERVER['REQUEST_URI'], '/development/')!==false) $a=5;
    elseif(strpos($_SERVER['REQUEST_URI'], '/projects/')!==false) $a=6;
    elseif(strpos($_SERVER['REQUEST_URI'], '/serial-production/')!==false) $a=13;
    elseif(strpos($_SERVER['REQUEST_URI'], '/control-systems/')!==false) $a=7;
    elseif(strpos($_SERVER['REQUEST_URI'], '/industry/')!==false) $a=8;

    Классика битрикс - разработки в индусском стиле. Проект стоил 500к+ дерева, не считая поддержки.

    ajiko, 07 Июня 2016

    Комментарии (13)
  8. PHP / Говнокод #20135

    +1

    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
    public function selectValueType($value)
        {
            $type = null;
            if (App::helperPhone()->parseMobile($value)) {
                $type = 1; //телефон    
            }
            if (App::helperEmail()->validate($value)) {
                $type = 2; //email
            }
            return $type;
        }
    
    
    
    А потом  в десятке методов:
    
     public function getLogin($value)
        {
            $type = $this->selectValueType($value);
            switch ($type) {
                case 1:
                    $type = 'phone';
                    break;
                case 2:
                    $type = 'email';
                    break;
            }
            if ($type) {
                $value = $type == 'phone' ? App::helperPhone()->parseMobile($value) : $value;
               // ... прочий говнокод
            }
    }

    Вот такие перлы достались в наследство. Приходится проводить полный рефакторинг :((

    Panda, 06 Июня 2016

    Комментарии (0)
  9. Куча / Говнокод #20131

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /* This is the famous internal descriptor that UDFs can use, too. */
    typedef struct paramdsc {
        ISC_UCHAR	dsc_dtype;
        signed char		dsc_scale;
        ISC_USHORT		dsc_length;
        short		dsc_sub_type;
        ISC_USHORT		dsc_flags;
        ISC_UCHAR	*dsc_address;
    } PARAMDSC;

    Комментарии сохранены

    LispGovno, 03 Июня 2016

    Комментарии (7)
  10. PHP / Говнокод #20116

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <ul>
        {foreach $сity as $c}
            {if Core::model()->getValue($c,'name') === $form->city_name}
                {assign $form->city_id $c['id']}
            {/if}
            <li data-value="{$c['id']}" class="{if $c['id']===$form->city_id}active{/if}"><span>{Core::model()->getValue($c,'name')}</span></li>
        {/foreach}
    </ul>

    Типичный шаблон на фреймворках PHP, в данном случае Yii 1.1

    M-A-X, 01 Июня 2016

    Комментарии (21)
  11. PHP / Говнокод #20100

    +1

    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
    public function timeDiff( $time, $now = null ) {
    		if ( ! is_int( $time ) )
    			$time = strtotime( (string) $time ) + ( get_option( 'gmt_offset' ) * 3600 - 10800 );
    		if ( is_null( $now ) )
    			$now = time();
    		if ( $now == $time )
    			return __( 'right now', Challonge_Plugin::TEXT_DOMAIN );
    		if ( $now < $time )
    			/* translators:
    				%s is an approximate relative amount of time (eg. "2 days")
    			*/
    			return sprintf( __( 'in %s', Challonge_Plugin::TEXT_DOMAIN ), human_time_diff( $time, $now ) );
    		/* translators:
    			%s is an approximate relative amount of time (eg. "2 days")
    		*/
    		return sprintf( __( '%s ago', Challonge_Plugin::TEXT_DOMAIN ), human_time_diff( $time, $now ) );
    	}

    -10800
    починил блять!

    pstnkv, 30 Мая 2016

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