1. C# / Говнокод #17684

    +137

    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
    public bool StartListener()
    		{
    			bool flag;
    			try
    			{
    				flag = (this.m_Listener.BeginAccept() ? true : false);
    			}
    			catch (Exception exception)
    			{
    				CAssert.ReportAssert(exception);
    				flag = false;
    			}
    			return flag;
    		}

    Из реального корпоративного проекта.

    Danmer, 23 Февраля 2015

    Комментарии (2)
  2. JavaScript / Говнокод #17683

    +156

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    if(!item.contact.middleInitial)
                  {
                    fullAddress = item.contact.firstName+' '+item.contact.lastName+' '
                    +item.contact.companyName+' '+item.streetLine1 +' '+item.city +', '+item.state +' '+item.postalCode;
                  }
                  else
                  {
                    fullAddress = item.contact.firstName+' '+item.contact.middleInitial+' '+item.contact.lastName+' '
                    +item.contact.companyName+' '+item.streetLine1 +' '+item.city +', '+item.state +' '+item.postalCode;
                  }

    Сабж))

    rainerg, 23 Февраля 2015

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

    +136

    1. 1
    2. 2
    for (j = 0; j < NUM_DMA_BUFFERS; j++)
            *(int *)dev->channel[0].virtDma[j] = 0x1235+j;

    ЯННП

    codemonkey, 23 Февраля 2015

    Комментарии (9)
  4. C++ / Говнокод #17681

    +51

    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
    template<class T, size_t N>
    constexpr size_t sa(T (&)[N])
    {
    	return N;
    };
    
    static std::memory_order mmo[] = 
    {
        memory_order_relaxed,
        memory_order_consume,
        memory_order_acquire,
        memory_order_release,
        memory_order_acq_rel,
        memory_order_seq_cst
    };
    
    std::memory_order current_program_memory_order()
    {
    	return mmo[rand()%sa(mmo)];
    }
    
    void current_program_memory_barier()
    {
    	std::atomic_thread_fence(current_program_memory_order());
    }

    LispGovno, 23 Февраля 2015

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

    +102

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    public class Permuter                                {
        private static void permute(int n, char[] a)     {
            if (n == 0)                                  {
                System.out.println(String.valueOf(a))    ;}
            else                                         {
                for (int i = 0; i <= n; i++)             {
                    permute(n-1, a)                      ;
                    swap(a, n % 2 == 0 ? i : 0, n)       ;}}}
        private static void swap(char[] a, int i, int j) {
            char saved = a[i]                            ;
            a[i] = a[j]                                  ;
            a[j] = saved                                 ;}}

    "I finally figured out how to get those pesky semicolons and curly braces out of my Java code"

    Xom94ok, 22 Февраля 2015

    Комментарии (36)
  6. PHP / Говнокод #17679

    +161

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    there is a reason why opencart is the no.1 most used ecommerce solution in places like china and india, its the easiest code base to understand!
    
    --
    
    many apps servers! what does that mean? you mean different applications running from the same framework?
    you build each application starting from the index.php file and include what ever library classes you require.
    
    --
    
    "I agree with you that it's harder to write simple code, because REPEATING CODE IS HARD TO DEBUG HARD TO READ AND TO CORRECT. so it makes you waste a lot of time."
    
    this is what search and replace is for!

    Создатель опенкарта (Daniel Kerr) исходит на говно, много мякотки
    http://www.techchattr.com/never-use-opencart#comment-1151857248

    Fike, 22 Февраля 2015

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

    +160

    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
    foreach (scandir(DIR.'app'.SLASH.'lib') as $filename) {
        $path = DIR.'app'.SLASH.'lib'.SLASH.$filename;
        if (is_file($path) && substr($filename,strlen($filename)-4,4)=='.php') {
            require_once($path);
        }
    }
    foreach (scandir(DIR.'app'.SLASH.'models') as $filename) {
        $path = DIR.'app'.SLASH.'models'.SLASH.$filename;
        if (is_file($path) && substr($filename,strlen($filename)-4,4)=='.php') {
            require_once($path);
        }
    }
    foreach (scandir(DIR.'app'.SLASH.'ext') as $filename) {
        $path = DIR.'app'.SLASH.'ext'.SLASH.$filename;
        if (is_file($path) && substr($filename,strlen($filename)-4,4)=='.php') {
            require_once($path);
        }
    }

    Начался разбор проблемы со слов заказчика - "сайт долго грузится"

    Crawdaunt, 22 Февраля 2015

    Комментарии (12)
  8. Куча / Говнокод #17677

    +132

    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
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    @echo off
    setlocal EnableDelayedExpansion
    setlocal EnableExtensions
    
    set /a _2=20
    set /a _1=600
    set /a _0=800
    call :mandelbrot _3 0 _0 _1 _2
    echo | set /p ^=!_3!
    
    goto :EOF
    :mandelbrot
    set width_%~2=!%~3!
    set height_%~2=!%~4!
    set max_%~2=!%~5!
    set /a row_%~2=0
    :WHILE_6
    if !row_%~2! LSS !height_%~2! (
      set /a col=0
      :WHILE_5
      if !col! LSS !width_%~2! (
        set /a c_re=^(^(^(!col! - ^(!width_%~2! / 2^)^) * 4^) / !width_%~2!^)
        set /a c_im=^(^(^(!row_%~2! - ^(!height_%~2! / 2^)^) * 4^) / !width_%~2!^)
        set /a x=0
        set /a y=0
        set /a iteration=0
        set /a _9_%~2=0
        if !iteration! LSS !max_%~2! (
          set /a _8_%~2=1
        ) else (
          set /a _8_%~2=0
        )
        set /a _18_%~2=^(1 + %~2^)
        call :or _19_%~2 !_18_%~2! _8_%~2 _9_%~2
        set _10_%~2=!_19_%~2!
        set /a _4_%~2=2
        set _3_%~2=!y!
        set /a _20_%~2=^(1 + %~2^)
        call :pow _21_%~2 !_20_%~2! _3_%~2 _4_%~2
        set _5_%~2=!_21_%~2!
        set /a _1_%~2=2
        set _0_%~2=!x!
        set /a _22_%~2=^(1 + %~2^)
        call :pow _23_%~2 !_22_%~2! _0_%~2 _1_%~2
        set _2_%~2=!_23_%~2!
        set /a _24_%~2=^(1 + %~2^)
        call :plus _25_%~2 !_24_%~2! _2_%~2 _5_%~2
        set _6_%~2=!_25_%~2!
        if !_6_%~2! LEQ 4 (
          set /a _7_%~2=1
        ) else (
          set /a _7_%~2=0
        )
        set /a _26_%~2=^(1 + %~2^)
        call :and _27_%~2 !_26_%~2! _7_%~2 _10_%~2
        set _11_%~2=!_27_%~2!
        :WHILE_4
        if !_11_%~2! EQU 1 (
          set /a x_new=^(^(^(!x! * !x!^) - ^(!y! * !y!^)^) + !c_re!^)
          set /a y=^(^(^(2 * !x!^) * !y!^) + !c_im!^)
          set x=!x_new!
          set /a iteration=^(!iteration! + 1^)
          goto WHILE_4
        )
        if !iteration! LSS !max_%~2! (
          set _14_%~2=!white!
          set _13_%~2=!row_%~2!
          set _12_%~2=!col!
          set /a _30_%~2=^(1 + %~2^)
          call :putpixel _31_%~2 !_30_%~2! _12_%~2 _13_%~2 _14_%~2
          echo | set /p ^=!_31_%~2!
        ) else (
          set _17_%~2=!black!
          set _16_%~2=!row_%~2!
          set _15_%~2=!col!
          set /a _28_%~2=^(1 + %~2^)
          call :putpixel _29_%~2 !_28_%~2! _15_%~2 _16_%~2 _17_%~2
          echo | set /p ^=!_29_%~2!
        )
        set /a col=^(!col! + 1^)
        goto WHILE_5
      )
      set /a row_%~2=^(!row_%~2! + 1^)
      goto WHILE_6
    )
    
    goto :EOF
    :and
    set a_%~2=!%~3!
    set b_%~2=!%~4!
    rem emulation of &&
    if !a_%~2! EQU 1 (
      if !b_%~2! EQU 1 (
        set %~1=1
        goto :EOF
      )
    )
    set %~1=0
    goto :EOF

    Мандельброт (без записи в картинку) на Batch

    asm0dey, 22 Февраля 2015

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

    +54

    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
    class SpinLock
    {
      std::atomic_flag lck;
    public:
      SpinLock(){
        unlock();
      }
      __forceinline void lock(){
        while (lck.test_and_set(std::memory_order_acquire)){
        }
      }
      __forceinline void unlock(){
        lck.clear(std::memory_order_release);
      }
    };

    LispGovno, 22 Февраля 2015

    Комментарии (72)
  10. Python / Говнокод #17675

    −115

    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
    def checkio(res):
        #bruteforce LOL
        if res[0][0] == res[1][0] == res[2][0] == "X":
            return "X"
    
        if res[0][1] == res[1][1] == res[2][1] == "X":
            return "X"
    
        if res[0][2] == res[1][2] == res[2][2] == "X":
            return "X"
    
        if res[0][0] == res[0][1] == res[0][2] == "X":
            return "X"
    
        if res[1][0] == res[1][1] == res[1][2] == "X":
            return "X"  
    
        if res[2][0] == res[2][1] == res[2][2] == "X":
            return "X"
    
        if res[0][0] == res[1][1] == res[2][2] == "X":
            return "X" 
    
        if res[0][2] == res[1][1] == res[2][0] == "X":
            return "X"
    
        if res[0][0] == res[1][0] == res[2][0] == "O":
            return "O"    
    
        if res[0][1] == res[1][1] == res[2][1] == "O":
            return "O"
    
        if res[0][2] == res[1][2] == res[2][2] == "O":
            return "O"
    
        if res[0][0] == res[0][1] == res[0][2] == "O":
            return "O"
    
        if res[1][0] == res[1][1] == res[1][2] == "O":
            return "O"
            
        if res[2][0] == res[2][1] == res[2][2] == "O":
            return "O"
    
        if res[0][0] == res[1][1] == res[2][2] == "O":
            return "O"        
    
        if res[0][2] == res[1][1] == res[2][0] == "O":
            return "O"
    
        return "D"

    Определить результат игры в крестики нолики.

    gost, 22 Февраля 2015

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