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

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

    +160.4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    <?php 
    // ...
    $vars = get_class_vars($class_name);
    		if(is_array($vars)) {
    			foreach($vars as $var => $val) {
    				eval('$this->' . $var . ' = \'' . $val . '\';');
    			}
    		}

    некакая UNI-CMS
    это не самое худшее. что я там нашел ... в общем мрак... (

    nicolay-punin, 22 Ноября 2009

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

    +98.6

    1. 1
    private bool IsNamesAreEqual(string itemName, string nodeName) { ... }

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

    plsc_rover, 20 Ноября 2009

    Комментарии (11)
  4. SQL / Говнокод #2146

    −864.2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    select to_char(null) from dual  
    union
    select to_number(null) from dual
    
    ORA-01790:	expression must have same datatype as corresponding expression

    Когда смотришь на пустую чашку, то можно сказать, что в ней нет, например, чая или ,например, нет кофе. Но нельзя сказать, что в нет ни чая ни кофе.

    dim1r, 16 Ноября 2009

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

    +164.2

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    while ($rst=mysql_fetch_array($rst_query))
    {
        $clist.="," . $rst["es_id"];
        $thislist="-1," . $rst["es_id"];
        while ($rst=mysql_fetch_array($rst_query))
        {
            $clist.="," . $rst["es_id"];
            $thislist.="," . $rst["es_id"];
        }
        $rst_query=mysql_query("Select * from esb2b_categories where es_pid in (" . $thislist . ")" );
    }

    разрыв мозга
    made by какой-то индус

    primpil, 16 Ноября 2009

    Комментарии (11)
  6. Си / Говнокод #2135

    +136.8

    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
    ...
    
    // TODO: remove this godless "switch()"!
                    switch(tuntype) { // TODO: Important: do as in documentation instead of reverse-ingeniering!
    #define PACKET_TRY {\
                    if(packet->ip_v == 4) {\
                            hl=packet->ip_hl<<2;\
                            if(hl>=sizeof(*packet))\
                                    break;\
                            /* TODO: Check in RFC something about of ICMP send-back in this case */\
                            fprintf(stderr, "Got too short IP-header (%i)...\n",hl);\
                    }\
                    if((packet->ip_v&IPV6_VERSION_MASK) == IPV6_VERSION) {\
                            break;\
                    }\
    }
    #define NEXT(a) tuntype=a;\
                    if(tuntry>=2)\
                            goto tun_process_switch_end;\
                    tuntry++;
    #define CASE(a) NEXT(a);\
            case a
    tun_process_switch:
    //              switch(tuntype) {
                            case TUNTYPE_NORM:              // NetBSD-like?
                                    packet=(typeof(packet))ptr;
                                    PACKET_TRY;
                            CASE(TUNTYPE_EXT):              // FreeBSD-like?
                                    packet=(typeof(packet))((char *)ptr + 4);
                                    if(s>4)
                                            if(*ptr==0x02)
                                                    PACKET_TRY;
                            CASE(TUNTYPE_ETH):              // Ethernet? TODO: Implement VLAN-tagging
                                    packet=(typeof(packet))((char *)ptr + sizeof(*eth));
                                    eth=(typeof(eth))ptr;
                                    if(!teth) {
                                            teth=alloca(sizeof(*teth));
                                            memcpy(&teth->ether_shost, &eth->ether_dhost, sizeof(teth->ether_shost));
                                            memcpy(&teth->ether_dhost, &eth->ether_shost, sizeof(teth->ether_dhost));
                                            teth->ether_type=ETHERTYPE_IP;
                                    }
                                    if(s>sizeof(*eth))
    //                                      if((*(char *)&eth->ether_type==0x08/* not IPv4? */)||(*(char *)&eth->ether_type==0x86/* not IPv6? */))  // TODO: Implement compatibility with all protocols over ethernet
                                                    PACKET_TRY;
                                    NEXT(TUNTYPE_NORM);
                                    goto tun_process_switch;
                            
                            default:                        
                                    tuntype=TUNTYPE_NORM;
                                    goto tun_process_switch;
    //              }
    tun_process_switch_end:
    #undef CASE
    #undef NEXT
    #undef PACKET_TRY
                                    if(tuntry<~0)
                                            tuntry=0;
                                    tuntype=oldtuntype;
                                    fprintf(stderr, "Got unknown packet. Flushing...\n");
                                    FLUSH;  // Flush all. We don't know the length of packet with unknown type.. So, we have to flush the buffer, to probably get new packets from the start.
                                    goto tun_process_while;
                    }
    
    ...

    "Ляпотааааа"... Очень "структурный" switch...

    xaionaro, 11 Ноября 2009

    Комментарии (11)
  7. Си / Говнокод #2105

    +136.2

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    switch( 1 ) 
    {
      default :
        TO_STR( 2, "10" );
    }

    Интересно, откуда и зачем такая конструкция. Может, кто-то что-то подобное встречал?

    nil, 06 Ноября 2009

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

    +164

    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
    $today = getdate();
    $mon ="$today[mon]";
    $year ="$today[year]";
    $mday ="$today[mday]";
    if ($mon{1}==false)
      {
        $mon="0"."$mon";
      }
    if ($mon=="1")
      {
        $mon="0"."$mon";
      }
    
    if ($mday=="1")
      {
        $mday="0"."$mday";
      }
    if ($mday=="2")
      {
        $mday="0"."$mday";
      }
    if ($mday=="3")
      {
        $mday="0"."$mday";
      }
    if ($mday=="4")
      {
        $mday="0"."$mday";
      }
    if ($mday=="5")
      {
        $mday="0"."$mday";
      }
    if ($mday=="6")
      {
        $mday="0"."$mday";
      }
    if ($mday=="7")
      {
        $mday="0"."$mday";
      }
    if ($mday=="8")
      {
        $mday="0"."$mday";
      }
    if ($mday=="9")
      {
        $mday="0"."$mday";
      }

    продолжение шедевра http://govnokod.ru/1048

    marten.spb, 23 Октября 2009

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

    +161.7

    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
    function str_to_up($lo) 
    {
    	$up=array("a"  => "A","a"  => "A","a"  => "A","a"  => "A","a"  => "A","a"  => "A","?"  => "?","c"  => "C","e"  => "E",
    	        "e" => "E","e" => "E","e" => "E","i"  => "I","i"  => "I","i"  => "I","i"  => "I","?"  => "?","n"  => "N",
    	        "o"  => "O","o"  => "O","o"  => "O","o" => "O","o" => "O","?" => "?","o"  => "O","u"  => "U","u"  => "U",
    	        "u"  => "U","u"  => "U","y" => "Y","?" => "?","y" => "?",
    	        "a"  => "A", "b"  => "B", "c"  => "C","d"  => "D","e"  => "E","f"  => "F","g"  => "G","h"  => "H","i"  => "I","j"  => "J",
    	        "k" => "K","l" => "L","m" => "M","n"  => "N","o"  => "O","p"  => "P","q"  => "Q","r"  => "R","s"  => "S",
    	        "t"  => "T","u"  => "U","v"  => "V","w" => "W","x" => "X","y" => "Y","z"  => "Z"
    	    );
    
    	return strtr($lo, $up);
    }
    
    function str_to_lower($up) 
    {
    	$lo=array("А"  => "а","Б"  => "б","В"  => "в","Г"  => "г","Д"  => "д","Е"  => "е","Ж"  => "ж","З"  => "з","И"  => "и",
    			"Й" => "й","К" => "к","Л" => "л","М"  => "м","Н"  => "н","О"  => "о","П"  => "п","Р"  => "р","С"  => "с",
    			"Т"  => "т","У"  => "у","Ф"  => "ф","Х" => "х","Ц" => "ц","Ч" => "ч","Ш"  => "ш","Щ"  => "щ","Ъ"  => "ъ",
    			"Ы"  => "ы","Ь"  => "ь","Э" => "э","Ю" => "ю","Я" => "я",
    			"A"  => "a", "B"  => "b", "C"  => "c","D"  => "d","E"  => "e","F"  => "f","G"  => "g","H"  => "h","I"  => "i","J"  => "j",
    			"K" => "k","L" => "l","M" => "m","N"  => "n","O"  => "o","P"  => "p","Q"  => "q","R"  => "r","S"  => "s",
    			"T"  => "t","U"  => "u","V"  => "v","W" => "w","X" => "x","Y" => "y","Z"  => "z"
    		);
    
    	return strtr($up, $lo);
    }

    anal_opressor, 20 Октября 2009

    Комментарии (11)
  10. C# / Говнокод #1955

    +134.4

    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
    private void TestWorksheetFunction() 
    {
      ...
     
      Excel.WorksheetFunction wsf = ThisApplication.WorksheetFunction;
      ws.get_Range("Min", Type.Missing).Value2 = wsf.Min(rng, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing);
      ws.get_Range("Max", Type.Missing).Value2 = wsf.Max(rng, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing);
      ws.get_Range("Median", Type.Missing).Value2 = wsf.Median(rng,
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing);
      ws.get_Range("Average", Type.Missing).Value2 = wsf.Average(rng, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing);
      ws.get_Range("StDev", Type.Missing).Value2 = wsf.StDev(rng, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing, Type.Missing, Type.Missing, Type.Missing, 
        Type.Missing);
    }

    Если вы - разработчик на C#, вам придется привыкнуть к обилию значений Type.Missing в вызовах методов. Поскольку объектную модель Excel писали в расчете на VBA, многие ее методы принимают необязательные параметры - иногда до 30. Используйте либо многочисленные экземпляры значения Type.Missing или указывайте для каждого параметра определенное значение по умолчанию.
    (c) http://www.gotdotnet.ru/LearnDotNet/NETFramework/22054.aspx

    zerkms, 12 Октября 2009

    Комментарии (11)
  11. Python / Говнокод #1916

    −425.7

    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
    def find_where_ball_collides_on_a_wall(
                                           ball_w, ball_z,
                                           ball_wol, ball_zol,
                                           ball_rad,
                                           wall_type,
                                           wall_w1, wall_z1,
                                           wall_w2, wall_z2,
                                           wall_rad):
        toetoadly = ball_rad + wall_rad
        did_collide = False
        New_ball_w = ball_w + ball_wol
        New_ball_z = ball_z + ball_zol
        angle_hit_at = None
        Relate_ball_w = ball_w - wall_w1
        Relate_ball_z = ball_z - wall_z1
        Relate_wall_w2 = wall_w2 - wall_w1
        Relate_wall_z2 = wall_z2 - wall_z1
        arc_tangeriney = arc_tangent_2D(Relate_wall_w2, Relate_wall_z2)
        Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_Relate_wall_w2, Rotate_Relate_wall_z2 = points_rotated_by_angle_2D(((Relate_ball_w, Relate_ball_z), (Relate_wall_w2, Relate_wall_z2)), 0, 0, arc_tangeriney)
        Rotate_ball_wol, Rotate_ball_zol = point_rotated_by_angle_2D(ball_wol, ball_zol, 0, 0, arc_tangeriney)
        Rotate_Relate_ball_collide_w, Rotate_Relate_ball_collide_z, did_hit_weird_line = Find_where_ball_stops_on_line_w(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, ball_rad, 0, wall_rad)
        if Rotate_Relate_ball_w > -toetoadly and Rotate_Relate_ball_w < toetoadly:
         HE_HE_strange_popper_z = Rotate_Relate_ball_z
        else:
         HE_HE_strange_popper_z = Rotate_Relate_ball_collide_z
        Rotate_angle_hit_at = None
        if   HE_HE_strange_popper_z < Rotate_Relate_wall_z2:
           if ball_is_going_towards_point(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, 0, Rotate_Relate_wall_z2):
            p1_touched, p1_collide_w, p1_collide_z, p1_angle_hit_at = find_where_ball_collides_on_another_ball(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, ball_rad, 0, Rotate_Relate_wall_z2, wall_rad)
            if p1_touched:
             Rotate_Relate_ball_collide_w = p1_collide_w
             Rotate_Relate_ball_collide_z = p1_collide_z
             Rotate_angle_hit_at = p1_angle_hit_at
             did_collide = True
        elif HE_HE_strange_popper_z > 0:
           if ball_is_going_towards_point(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, 0, 0):
            p2_touched, p2_collide_w, p2_collide_z, p2_angle_hit_at = find_where_ball_collides_on_another_ball(Rotate_Relate_ball_w, Rotate_Relate_ball_z, Rotate_ball_wol, Rotate_ball_zol, ball_rad, 0, 0, wall_rad)
            if p2_touched:
             Rotate_Relate_ball_collide_w = p2_collide_w
             Rotate_Relate_ball_collide_z = p2_collide_z
             Rotate_angle_hit_at = p2_angle_hit_at
             did_collide = True
        else:
           if did_hit_weird_line:
            did_collide = True
            if Rotate_Relate_ball_collide_w < 0: Rotate_angle_hit_at = 90
            else: Rotate_angle_hit_at = 270
        if did_collide:
         arc_tangeriney_2 = -arc_tangeriney
         angle_hit_at = Rotate_angle_hit_at + arc_tangeriney
         New_ball_w, New_ball_z = point_rotated_by_angle_2D(Rotate_Relate_ball_collide_w, Rotate_Relate_ball_collide_z, 0, 0, arc_tangeriney_2)
         New_ball_w += wall_w1
         New_ball_z += wall_z1
        return did_collide, New_ball_w, New_ball_z, angle_hit_at  #, is_moving_towards

    Пример написания "физики" на python + pygame. Одна из функций. Всего кода - 900+ строк.
    http://www.pygame.org/docs/ref/draw.html -> смотрим комментарий к pygame.draw.circle

    diok, 30 Сентября 2009

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