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

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

    −195

    1. 1
    2. 2
    // optimization. Should only be used to read it. Never to write it.
    extern CGFloat	__ccContentScaleFactor;

    Может быть, я бунтарь!
    __ccContentScaleFactor = -666;

    tirinox, 20 Июня 2014

    Комментарии (3)
  3. Pascal / Говнокод #16181

    +92

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    type
      TForm1 = class(TForm)
        Button1: TButton;
        Button3: TButton;
        ListBox1: TListBox;
        Button2: TButton;
        Button4: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
      TListThread = class(TThread)
      protected
        procedure Execute; override;
      end;
      TMyThread = class(TThread)
      protected
        procedure Execute; override;
      end;
      TYouThread = class(TThread)
      protected
        procedure Execute; override;
      end;
     
    var
      Form1: TForm1;
      threadList1: TThreadList;
      mythreadRunning, youthreadRunning, listThreadRunning: Boolean;
      globalCount: Integer;
      listProcess: TListThread; { TListThread is a custom descendant of TThread. }
      secondProcess: TMyThread; { TMyThread is a custom descendant of TThread. }
      otherSecondProcess: TYouThread; { TMyThread is a custom descendant of TThread. }
     
    implementation
     
    {$R *.dfm}
     
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if (mythreadRunning = FALSE) then
      begin
        mythreadRunning:= TRUE;
        secondProcess := TMyThread.Create(True); { Create suspended--secondProcess does not run yet. }
        secondProcess.FreeOnTerminate := True; { You do not need to clean up after termination. }
        secondProcess.Priority := tpLower;  // Set the priority to lower than normal.
        secondProcess.Resume; { Now run the thread. }
      end
      else
        MessageDlg('This thread is still running.  You are going to hurt yourself!',
          mtInformation, [mbOk], 0);
    end;
     
    procedure TMyThread.Execute;
    var
      I: Integer;
      myRadio: TRadioButton;
    begin
      for I := 0 to 20 do
      begin
        if (Terminated) then
        begin
          mythreadRunning:= FALSE;
          exit;
        end;
        myRadio:= TRadioButton.Create(Form1);
        globalCount:= globalCount + 1;
        myRadio.Name:= 'RadioButton' + IntToStr(globalCount);
        threadList1.Add(myRadio);
        Sleep(1000);
      end;
      mythreadRunning:= FALSE;
    end;
     
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      if (listthreadRunning = FALSE) then
      begin
        listThreadRunning:= TRUE;
        listProcess := TListThread.Create(True); { Create suspended--secondProcess does not run yet. }
        listProcess.FreeOnTerminate := True; { You do not need to clean up after termination. }
        listProcess.Priority := tpLower;  // Set the priority to lower than normal.
        listProcess.Resume; { Now run the thread. }
      end;
    end;
     
    procedure TListThread.Execute;
    var
      I: Integer;
      Temp: TControl;
      myList: TList;
    begin
      while(True) do
      begin

    http://docwiki.embarcadero.com/CodeExamples/XE5/en/TThreadList_%28Delphi%29
    Беда, когда примеры пишут психически неполноценные люди. Самое ужасное то, что этот "пример" висит на сайте embarcadero.

    brutushafens, 17 Июня 2014

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

    +174

    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
    /*Caused by: java.lang.StackOverflowError
        at com.sun.org.apache.xalan.internal.xsltc.dom.SimpleResultTreeImpl.characters(SimpleResultTreeImpl.java)
        at com.sun.org.apache.xalan.internal.xsltc.dom.SimpleResultTreeImpl.copy(SimpleResultTreeImpl.java:438)
        at com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary.copy(BasisLibrary.java:1317)
        at GregorSamsa.replace()
        at GregorSamsa.replace()
        at GregorSamsa.replace()
        at GregorSamsa.replace()
        at GregorSamsa.replace()
      начали разбираться
    */
        /** 
         * As Gregor Samsa awoke one morning from uneasy dreams he found himself
         * transformed in his bed into a gigantic insect. He was lying on his hard,
         * as it were armour plated, back, and if he lifted his head a little he
         * could see his big, brown belly divided into stiff, arched segments, on
         * top of which the bed quilt could hardly keep in position and was about
         * to slide off completely. His numerous legs, which were pitifully thin
         * compared to the rest of his bulk, waved helplessly before his eyes.
         * "What has happened to me?", he thought. It was no dream....
         */
        protected final static String DEFAULT_TRANSLET_NAME = "GregorSamsa";

    http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java
    transofm, factory, bug - какие начитанные разработчки, а.

    3.14159265, 12 Июня 2014

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

    +150

    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
    <?php
    $subjects = array (
      0 => 
        array (
          'title' => 'ОС Unix',
          'teacher' => 'Вася',
          'mark' => '3'),
      1 => 
        array (
          'title' => 'Компьютерные сети',
          'teacher' => 'Петя',
          'mark' =>'4'),
      2 => 
        array (
          'title' =>  'Алгоритмы',
          'teacher' =>  'Коля',
          'mark' => '4'),
    );?>
    <table>
    <?  foreach ($subjects as $key=>$subject) : 
    $number = $key+1;
    ?>
                <tr>
                    <td><?echo $number;?></td>
    				<td><?echo $subject['title'];?></td>
                    <td><?echo $subject['teacher'];?></td>
                    <td><?echo $subject['mark'];?></td>
                </tr>
    <? endforeach; ?>
    </table>
    <? var_dump($subject)?>

    wiedzal, 31 Мая 2014

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

    +3

    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
    #define BOOST_INTRUSIVE_INTERNAL_STATIC_BOOL_IS_TRUE(TRAITS_PREFIX, TYPEDEF_TO_FIND) \
    template <class T>\
    struct TRAITS_PREFIX##_bool\
    {\
       template<bool Add>\
       struct two_or_three {one _[2 + Add];};\
       template <class U> static one test(...);\
       template <class U> static two_or_three<U::TYPEDEF_TO_FIND> test (int);\
       static const std::size_t value = sizeof(test<T>(0));\
    };\
    \
    template <class T>\
    struct TRAITS_PREFIX##_bool_is_true\
    {\
       static const bool value = TRAITS_PREFIX##_bool<T>::value > sizeof(one)*2;\
    };\
    //

    Ну тут как бы все просто и понятно. Но зачем заканчивают макрос кодом

    \
    //
    ?

    laMer007, 29 Мая 2014

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    panel1.Visible = checkBoxCCF.Checked;
    panel2.Visible = checkBoxReliabilty.Checked;
    panel3.Visible = checkBoxRisk.Checked;
    panel4.Visible = checkBoxSaftey.Checked;
    panel5.Visible = checkBoxSensitivity.Checked;
    panel6.Visible = checkBoxThroughput.Checked;
    panel7.Visible = checkBoxUncertainity.Checked;

    Почему половина переменных нормальные, половина нет? Логика некоторых погромистов зашкаливает...

    kostoprav, 28 Мая 2014

    Комментарии (3)
  8. Lua / Говнокод #16047

    −85

    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
    c1 = true
    c2 = true
    c3 = true
    c4 = true
    c5 = true
    c6 = true
    c7 = true
    c8 = true
    c9 = true
    c10 = true
    c11 = true
    c12 = true
    c13 = true
    next = true
    
    function goForward()
      c1 = c2
      c2 = c3
      c3 = c4
      c4 = c5
      c5 = c6
      c6 = c7
      c7 = c8
      c8 = c9
      c9 = c10
      c10 = c11
      c11 = c12
      c12 = c13
      c13 = next
    end

    Немножко Lua-кода от геймдизайнера.

    kostoprav, 23 Мая 2014

    Комментарии (3)
  9. Java / Говнокод #16045

    +68

    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
    class CircuitBreaker
    {
        boolean broken = false;
        CircuitBreaker() {}
        private void breakCircuit()
        {
            this.broken = true;
        }
        private boolean isBroken()
        {
            return this.broken;
        }
    }
    
    private boolean writeAssetsToDisk()
    {
        CircuitBreaker breaker = new CircuitBreaker();
        writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
        writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
        writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
        writeBase64EncodedAssetToDisk(breaker, "...", getPath(...));
        return !breaker.isBroken();
    }
    
    private void writeBase64EncodedAssetToDisk(CircuitBreaker breaker, String base64String, String filename)
    {
        if (breaker.isBroken()) {
            return;
        }
        ...
        try
        {
            ...
        }
        catch (IOException e)
        {
            breaker.breakCircuit(); return;
        }
        ...
    }

    Используй исключения, Люк. Фрагмент из Amazon Mobile Ads SDK.

    chaoswithin, 23 Мая 2014

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

    +154

    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
    function box_navigation($gc, $num, $id, $function, $act){
    	global $tpl, $page;
    	$gcount = $gc;
    	$cnt = $num;
    	$items_count = $cnt;
    	$items_per_page = $gcount;
    	$page_refers_per_page = 5;
    	$pages = '';		
    	$pages_count = ( ( $items_count % $items_per_page != 0 ) ) ? floor( $items_count / $items_per_page ) + 1 : floor( $items_count / $items_per_page );
    	$start_page = ( $page - $page_refers_per_page <= 0  ) ? 1 : $page - $page_refers_per_page + 1;
    	$page_refers_per_page_count = ( ( $page - $page_refers_per_page < 0 ) ? $page : $page_refers_per_page ) + ( ( $page + $page_refers_per_page > $pages_count ) ? ( $pages_count - $page )  :  $page_refers_per_page - 1 );
    	
    	if(!$act)
    		$act = "''";
    	else
    		$act = "'{$act}'";
    			
    	if($page > 1)
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', '.($page-1).', '.$act.'); return false">«</a>';
    	else
    		$pages .= '';
    				
    	if ( $start_page > 1 ) {
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', 1, '.$act.'); return false">1</a>';
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', '.($start_page-1).', '.$act.'); return false">...</a>';
    			
    	}
    					
    	for ( $index = -1; ++$index <= $page_refers_per_page_count-1; ) {
    		if ( $index + $start_page == $page )
    			$pages .= '<span>' . ( $start_page + $index ) . '</span>';
    		else 
    			$pages .= '<a href="" onClick="'.$function.'('.$id.', '.($start_page+$index).', '.$act.'); return false">'.($start_page+$index).'</a>';
    	} 
    			
    	if ( $page + $page_refers_per_page <= $pages_count ) { 
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', '.($start_page + $page_refers_per_page_count).', '.$act.'); return false">...</a>';
    		$pages .= '<a href="" onClick="'.$function.'('.$id.', '.$pages_count.', '.$act.'); return false">'.$pages_count.'</a>';	
    	} 
    				
    	$resif = $cnt/$gcount;
    	if(ceil($resif) == $page)
    		$pages .= '';
    	else
    		$pages .= '<a href="/" onClick="'.$function.'('.$id.', '.($page+1).', '.$act.'); return false">»</a>';
    
    	if ( $pages_count <= 1 )
    		$pages = '';
    
    	$tpl_2 = new mozg_template();
    	$tpl_2->dir = TEMPLATE_DIR;
    	$tpl_2->load_template('nav.tpl');
    	$tpl_2->set('{pages}', $pages);
    	$tpl_2->compile('content');
    	$tpl_2->clear();
    	$tpl->result['content'] .= $tpl_2->result['content'];
    }

    дали проект чтобы разобрался)

    progsmile, 21 Мая 2014

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

    +11

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    int FCEUI_SetCheat(....)
    {
      ...
      if((t=(char *)realloc(next->name,strlen(name+1))))
      ...
    }

    А пасиму оно на 2 байта меньше выделяет, насяльника?

    http://www.viva64.com/ru/examples/V518/

    gost, 19 Мая 2014

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