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

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

    +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
    constexpr Fraction operator+(const Fraction& fraction) const noexcept
        {
            const Fraction max_fraction_by_denominator{denominator > fraction.denominator ? *this : fraction};
            const Fraction min_fraction_by_denominator{denominator < fraction.denominator ? *this : fraction};
            const bool is_sim_denominator = max_fraction_by_denominator.denominator %
                                            min_fraction_by_denominator.denominator == 0;
            int sim_denominator = is_sim_denominator ?
                max_fraction_by_denominator.denominator : (max_fraction_by_denominator.denominator *
                min_fraction_by_denominator.denominator);
            const int nominator1 = is_sim_denominator ? (min_fraction_by_denominator.nominator *
                max_fraction_by_denominator.denominator / min_fraction_by_denominator.denominator) :
                min_fraction_by_denominator.nominator * max_fraction_by_denominator.denominator;
            const int nominator2 = is_sim_denominator ? max_fraction_by_denominator.nominator :
                max_fraction_by_denominator.nominator * min_fraction_by_denominator.denominator;
            int nominators_sum = nominator1 + nominator2;
            int while_parts_sum = while_part + fraction.while_part;
    
            while (nominators_sum >= sim_denominator)
            {
                nominators_sum -= sim_denominator;
                ++while_parts_sum;
            }
    
            if (!nominators_sum)
                sim_denominator = 0;
    
            return {while_parts_sum, nominators_sum, sim_denominator};
        }

    jangolare, 06 Апреля 2016

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

    +4

    1. 1
    2. 2
    3. 3
    typedef class foo_c{
    ...
    } foo_t;

    Почему мне хочется использовать такой синтаксис?

    mittorn, 04 Апреля 2016

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

    +4

    1. 1
    phases.Where(phase => phase == null || phase.Trim().Length == 0)

    Нашёл в своём проекте, эта строка прошла code review. phase - это строка.

    gogishvilli001, 03 Апреля 2016

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    class Panel
    {
    // ...
    friend class Panel;
    // ...
    }

    Нашёл такое в хедерах VGUI1 -- игрового тулкита от Valve для Gold Source.
    Объясните, умные люди, зачем?

    a1batross, 01 Апреля 2016

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

    +4

    1. 1
    http://cs543107.vk.me/v543107084/f49c/quBsGLPz-lE.jpg

    Программирование по-русски глазами американцев...
    Сериал: "Агенты Щ.И.Т."; Сезон: 3; Эпизод: 13

    LispGovno, 29 Марта 2016

    Комментарии (19)
  7. JavaScript / Говнокод #19662

    +4

    1. 1
    2. 2
    this.navigator = navigator.userAgent || navigator.vendor || window.opera;
    this.mobile = /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(this.navigator) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(this.navigator.substr(0,4));

    substr(0,4), Карл

    makc3d, 20 Марта 2016

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

    +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
    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
    {- This code intentionally was made slightly cryptic -}
    {-# LANGUAGE GADTs, StandaloneDeriving, UnicodeSyntax, KindSignatures, FlexibleInstances, LambdaCase, CPP, BangPatterns #-}
    import System.Exit
    import Data.Functor
    import Control.Monad.IO.Class
    import Control.Monad.Trans.Cont
    import System.Random
    import System.Posix.Signals
    import System.Environment
    import Control.Concurrent.MVar
    
    instance Eq (Int → Int) where
      _ == _ = True -- It's a hack
    
    infixl 7 :.
    
    data T ∷ * where {J, Â, Â', S, K ∷ T; (:.) ∷ T → T → T; Ψ ∷ {σ ∷ String} → T
                     ;F ∷ (Int → Int) → T; N ∷ Int → T; Ø ∷ String → T}
    
    parse ∷ String → [T] → T
    parse ('f':'u':c) t = parse c (J:t)
    parse ('b':'a':'r':c) t = parse c (Â:t)
    parse ('~':c) (a:b:t) = parse c (b:.a:t)
    parse ('~':_) _ = error "Parse error: missing operand(s)"
    parse (_:c) t = parse c t
    parse [] (h:_) = h :. Ψ []
    parse [] [] = error "Parse error: empty program"
    
    s ∷ T → T
    s (J :. x) = (x :. S) :. K
    s (K :. x :. _) = x
    s (S :. x :. y :. z) = (x :. z) :. (y :. z)
    s (F f :. N i) = N $ f i
    s (F f :. F g) = F $ f . g
    s (Â' :. N i :. ψ @ (Ψ {})) = ψ {σ = toEnum i : σ ψ}
    s (Â :. n :. ψ @ (Ψ {})) = Â' :. (n :. F (+1) :. N 0) :. ψ
    -- Other cases
    s (a :. b) = (s a) :. (s b)
    s x = x
    
    eval ∷ (T → t) → (T → t) → T → t
    eval fp done t | t == t'   = done t
                   | otherwise = fp t'
        where t' = s t
    
    ψs a@Ψ{σ=s} = [(a, s)]
    ψs (a:.b) = ψs a ++ ψs b
    ψs _ = []
    
    r' ∷ T → [(T, String)]   -- Very inefficient; should be rewritten
    r' a | null t = [(a, s)] where ((_, s):t) = ψs a
    r' (a :. b) = r' a ++ r' b
    r' _ = []
    
    r ∷ T → IO (Maybe T)
    r t = case r' t of
            [] → return Nothing
            t' → ((t' !!) <$> randomRIO (0, length t' - 1)) >>= \case
               (Ψ{}, s) → putStrLn (reverse s) >> return Nothing
               (t'', s) → putStrLn (reverse s) >> return (Just t'')
    
    setMVar v = (tryTakeMVar v >>) . putMVar v
    
    loop v f n = callCC $ \done → loop1 done (\fp → f fp done) n
      where loop2 interrupt f' n = do
              n' ← liftIO (readMVar v) >>= \case
                0 → f' interrupt n
                _ → callCC $ \fp → f' fp n
              liftIO $ modifyMVar_ v $ (\k → return $ k-1)
              loop2 interrupt f' n'
            loop1 done f' n = do
              n' ← callCC $ \int → loop2 int f' n
              liftIO $ putStrLn "Measure (m) Abort (a) Continue (c) Run steps (number)"
              (liftIO getLine) >>= \case
                "a" → f' done n' >> return ()
                "c" → liftIO $ setMVar v (-1)
                "m" → liftIO (r n') >>= \case
                  Nothing → liftIO exitSuccess
                  Just n'' → loop1 done f' n'' >> return ()
                a → case readsPrec 0 a of
                       (n,_):_ → liftIO $ setMVar v n
                       _ → liftIO $ putStrLn "Not understood."
              loop1 done f' n'
    
    main ∷ IO ()
    main = do
      (file, n) ← getArgs >>= \case
        [f] → return (f, -1)
        ["-s", n, f] → case readsPrec 0 n of
                        (n',_):_ → return (f, n')
                        _ → error "Argument of -s should be a number"
        _ → error "Insufficient arguments. Expected [-s NUMBER_OF_STEPS] FILE"
      cnt ← newMVar n
      installHandler keyboardSignal (Catch $ setMVar cnt 0) Nothing
      void $ (r =<<) (evalContT $ loop cnt eval =<< (parse <$> readFile file))

    больше трясин богу тьюринг-полноты
    1) литературное программирование
    2) зайчатки REPL
    3) чисто функциональное IO без манад и uniq-types
    4) "квантовые" вычисления
    5) только два комбинатора

    CHayT, 18 Марта 2016

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

    +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
    program Project2;
    
    procedure test1;
    var
      arr:array[0..32] of char;
    begin
      fillchar(arr,sizeof(arr),'A');
    end;
    
    procedure test2;
    var
      arr:array[0..32] of char;
    begin
      fillchar(arr,sizeof(arr) div 2,'B');
      writeln(arr);
    end;
    
    begin
      test1;
      test2;
      //BBBBBBBBBBBBBBBBAAAAAAAAAAAAAAA
      readln;
    end.

    http://ideone.com/qJajnb

    fajes_rown, 15 Марта 2016

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

    +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
    <div class="col-sm-3">
    	<select class="form-control" id="year">
    		<option <?php if($explode[0] == 2002) Echo "selected"; ?> value="2002">2002</option>
    		<option <?php if($explode[0] == 2001) Echo "selected"; ?> value="2001">2001</option>
    		<option <?php if($explode[0] == 2000) Echo "selected"; ?> value="2000">2000</option>
    		<option <?php if($explode[0] == 1999) Echo "selected"; ?> value="1999">1999</option>
    		<option <?php if($explode[0] == 1998) Echo "selected"; ?> value="1998">1998</option>
    		<option <?php if($explode[0] == 1997) Echo "selected"; ?> value="1997">1997</option>
    		<option <?php if($explode[0] == 1996) Echo "selected"; ?> value="1996">1996</option>
    		<option <?php if($explode[0] == 1995) Echo "selected"; ?> value="1995">1995</option>
    		<option <?php if($explode[0] == 1994) Echo "selected"; ?> value="1994">1994</option>
    		<option <?php if($explode[0] == 1993) Echo "selected"; ?> value="1993">1993</option>
    		<option <?php if($explode[0] == 1992) Echo "selected"; ?> value="1992">1992</option>
    		<option <?php if($explode[0] == 1991) Echo "selected"; ?> value="1991">1991</option>
    		<option <?php if($explode[0] == 1990) Echo "selected"; ?> value="1990">1990</option>
    		<option <?php if($explode[0] == 1989) Echo "selected"; ?> value="1989">1989</option>
    		<option <?php if($explode[0] == 1988) Echo "selected"; ?> value="1988">1988</option>
    		<option <?php if($explode[0] == 1987) Echo "selected"; ?> value="1987">1987</option>
    		<option <?php if($explode[0] == 1986) Echo "selected"; ?> value="1986">1986</option>
    		<option <?php if($explode[0] == 1985) Echo "selected"; ?> value="1985">1985</option>
    		<option <?php if($explode[0] == 1984) Echo "selected"; ?> value="1984">1984</option>
    		<option <?php if($explode[0] == 1983) Echo "selected"; ?> value="1983">1983</option>
    		<option <?php if($explode[0] == 1982) Echo "selected"; ?> value="1982">1982</option>
    		<option <?php if($explode[0] == 1981) Echo "selected"; ?> value="1981">1981</option>
    		<option <?php if($explode[0] == 1980) Echo "selected"; ?> value="1980">1980</option>
    		<option <?php if($explode[0] == 1979) Echo "selected"; ?> value="1979">1979</option>
    		<option <?php if($explode[0] == 1978) Echo "selected"; ?> value="1978">1978</option>
    		<option <?php if($explode[0] == 1977) Echo "selected"; ?> value="1977">1977</option>
    		<option <?php if($explode[0] == 1976) Echo "selected"; ?> value="1976">1976</option>
    		<option <?php if($explode[0] == 1975) Echo "selected"; ?> value="1975">1975</option>
    	</select>
    </div>

    Суровые челябинские программисты продолжают кодить :)

    by133312, 13 Марта 2016

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

    +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
    private static void Main(string[] args)
            {
                var c1 = 1; var c2 = 0;
                Task.Run(() =>
                {
                    var f = new Func<int, int, int, int>((p, q, w) =>
                    {
                        Console.WriteLine(p + " " + q + " " + w);
                        Thread.Sleep(p);
                        Console.Beep(q + 264, w);
                        return 1;
                    });
                    int bi, a1, a2, a3;
                    bi = 33554432;
                    while (true)
                        bi = (int) Math.Pow(2, 24 - c2) + (a1 = 125) - a1 +
                             (a2 = (67075013 & bi) == bi
                                 ? ((63945802 & bi) == bi
                                     ? ((57539367 & bi) == bi ? 0 : 33)
                                     : ((57539367 & bi) == bi ? 88 : 66))
                                 : ((63945802 & bi) == bi ? ((57539367 & bi) == bi ? 132 : 176) : 202)) - a2 -
                             (a3 = c1%288 != 0
                                 ? (c1 *= 2) - c1 +
                                   (c1%64 == 0
                                       ? 1000 + (c1 /= 64) - c1 + (c1 *= 3) - c1
                                       : c1%8 == 0 ? 500 : (a1 = 250) - 125)
                                 : (c1%125 == 0 ? 1001 - (c1 /= 36000) : c1%25 == 0 ? 500 : c1%5 == 0 ? 125 : 250) +
                                   (c1 *= 5) - c1) + a3*f(a1, a2, a3) + ++c2 - c2 + (c2 %= 26) - c2 +
                             (c1 = c1 == 160 ? 1 : c1) - c1;
                });
                Console.ReadKey();
            }

    Вот так.

    qwe345asd, 07 Марта 2016

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