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

    В номинации:
    За время:
  2. Куча / Говнокод #20481

    +103

    1. 1
    http://we.easyelectronics.ru/uploads/images/00/40/39/2016/05/16/ad076cf168.jpg

    HaskellGovno, 06 Августа 2016

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

    +9

    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
    int naive_show_int(int x) {
        char buf[32];
        char *p = buf + sizeof(buf);
        *--p = 0;
        int negative = 0;
        if (x < 0) {
            x = -x;
            negative = 1;
        }
        while (x > 0) {
            if (x <= 0)
                return -1;
            int digit = '0' + x % 10;
            if (digit < '0' || digit >= '9')
                return -1;
            *--p = digit;
            x /= 10;
        }
        if (negative)
            *--p = '-';
        puts(p);
        return 0;
    }

    Допустишь один UB - ничто уже не спасёт твою прогу...

    http://ideone.com/EFGoBi

    bormand, 02 Февраля 2016

    Комментарии (37)
  4. JavaScript / Говнокод #19294

    +1

    1. 1
    2. 2
    3. 3
    while ((math == (math = Math)).toString() == "true") {
       ...
    }

    программист-дотер

    mikamika83, 12 Января 2016

    Комментарии (37)
  5. Python / Говнокод #18552

    −74

    1. 1
    2. 2
    3. 3
    4. 4
    def foreigned(to_db='default', in_db="operator_main_dbs"):
        u""" декоратор для foreign tables """
        
        assert to_db == 'default' and in_db == "operator_main_dbs"

    Вариативность

    parabellum, 30 Июля 2015

    Комментарии (37)
  6. Java / Говнокод #18055

    +144

    1. 1
    Шёл 2015 год, а SQLite на ведре так и не научился сравнивать не ASCII'шные строки без учёта регистра...

    Или это у меня руки из жопы растут?

    bormand, 24 Апреля 2015

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

    +43

    1. 1
    2. 2
    3. 3
    for each (ToolStripMenuItem ^item in пользователиToolStripMenuItem->DropDownItems) {
    	item->Enabled = true;
    }

    Это C++, и это работает!

    hdkeeper, 22 Октября 2014

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

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
    
    VAR = MixedCaseText
    LOWER_VAR = $(call lc,$(VAR))
    
    all:
            @echo $(VAR)
            @echo $(LOWER_VAR)

    как реализовать портабельно lowercase функцию в GNU Make.

    как же я тебя временами лублу, мэйк.

    ЗЫ было случайно найдено в http://stackoverflow.com/questions/664601/in-gnu-make-how-do-i-convert-a-variable-to-lower-case

    Dummy00001, 06 Октября 2014

    Комментарии (37)
  9. ActionScript / Говнокод #16640

    −92

    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
    public class MathAndGeometryUtils
    {
    	public static function roundToHalf(value:Number):Number 
    	{
    		var multiplied:int = Math.round(value * 10);
    		if (multiplied / 5 == Math.round(multiplied / 5))
    		{
    			return multiplied / 10;
    		}
    		else
    		{
    			var noComma:Number = Math.floor(multiplied / 10) * 10;
    			var divaider:int = multiplied - noComma;
    			if (divaider >= 3 && divaider <= 7)
    				return (noComma + 5) / 10;
    			else
    				return Math.round(value);
    		}
    	}
    }

    На сколько я смог понять задумку, человеку хотелось чтобы функция возвращала значения типа 0, 0.5, 1, 1.5 и т.д. и вот он придумал такое самобытное решение.

    wvxvw, 04 Сентября 2014

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

    +17

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    ~Guard(){
      if(std::uncaught_exception())
        try{
        }catch(...){
          error_output<<"prevented exception!!!"<<endl;
        };
    }

    LispGovno, 03 Июня 2014

    Комментарии (37)
  11. Haskell / Говнокод #15821

    −107

    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
    import System.Exit
    import Graphics.UI.GLUT
    import Control.Monad
    import Control.Applicative
    import Control.Arrow
    import Control.Concurrent
    import Graphics.Rendering.OpenGL 
    import Data.IORef
    import Data.List
    import Data.Maybe
    initial = ((0,0),(0.005,-0.03),(0,0),([(-0.4,-0.9),(-0.4,-0.85),(0.4,-0.85),(0.4,-0.9),(-0.4,-0.9)],(0,0)),liftM2 (,) [-0.9,-0.7..0.9] [0.5,0.7,0.9])
    ws = dzip [(-1,-1),(-1,1),(1,1),(1,-1)] ; r = 0.1 :: GLfloat
    main = initialWindowSize $= Size 777 777 >> initialWindowPosition $= Position 100 100 >> initialDisplayMode $= [DoubleBuffered] >> createWindow "ursula" >> 
    	newIORef initial >>= \ior -> keyboardMouseCallback $= Just (kbd ior) >> displayCallback $= dlay ior >> idleCallback $= Just (anime ior) >> mainLoop
    dlay ior = clearColor $= Color4 1 1 1 1 >> clear [ColorBuffer] >> readIORef ior >>= drawDoxyq >> swapBuffers
    kbd _ (Char 'q') Down _ _ = exitWith ExitSuccess			
    kbd s (Char x) Down _ _   = modifyIORef' s $ \(a,b,t,(d,e),cs) -> (a,b,t,(d,(if x == '[' then -0.05 else if x == ']' then 0.05 else fst e,0)),cs)
    kbd _ _ _ _ _ = return ()
    draw c = renderPrimitive c . mapM_ (vertex . uncurry Vertex2)
    touch xy s xy' = guard ((xy ==== xy') <= r+r && (s .*. (xy.-.xy')) <= 0) >> Just (xy.-.xy')
    drawDoxyq ((x,y),_,(t,_),(bd,_),cs) = currentColor $= Color4 0.3 0.4 0.8 0 >> mapM_ (mapM_ (draw LineLoop) . sta) cs >> 
    	currentColor $= Color4 0.7 0.1 0.2 1 >> mapM_ (draw LineStrip) swa >> currentColor $= Color4 0 0 0 1 >> draw Polygon bd  where
    	swa = [[(x,y),(x + r/1.8*cos (th+pi/4),y + r/1.8*sin (th+pi/4)),(x + r/1.2*cos th,y + r/1.2*sin th)] | th <- [t,t+pi/2..t+1.6*pi]]
    	sta (x,y) = [[(x,y+r/2),(x-r/2,y-r/2),(x+r/2,y-r/2)],[(x+r/2,y+r/2-0.03),(x-r/2,y+r/2-0.03),(x,y-r/2-0.03)]]
    frame (xy,v,(tt,tr),(b,s),cs) = if snd xy <= r-0.99 || null cs then error "GAME OVER" else (xy.+.v',v',(tt+tr',tr'),(b',s'),cs') where 
    	v' = listy v (\us -> rV (2*negv v .>. foldl1' (.+.) us + tr/11) $ negv v) $ mapMaybe (cutSect xy v) (ws ++ dzip b') ++ mapMaybe (touch xy v) cs
    	s' = 0.93 *. if any ((1<=) . (*signum (fst s)) . fst) b then negv s else s
    	b' = map (.+.s') b ; cs' = filter (isNothing . touch xy v) cs
    	tr' = if v .=. v' then tr else (v' .>. v)/19
    listy d f x = if null x then d else f x
    rV t (x,y) = (x*cos t - y*sin t,y*cos t + x*sin t)
    anime ior = modifyIORef' ior frame >> threadDelay 30000 >> postRedisplay Nothing
    cutSect xy s c@(u,v) = guard (xy ./ l <= r && w `oncut` c && (s .*. (xy.-.w)) <= 0) >> Just (xy.-.w) where 
    	l = ln u (u.-.v) ; w = xy .-| l
    oncut u (v,w) = 0 <= (u.-.v) .*. (w.-.u) && 0 <= (u.-.w) .*. (u.-.w) && ((u.-.w) .<>. (v.-.w)) # 0
    ln xy w = (snd w,-fst w,w.<>.xy)
    (x,y) .-| (a,b,c) = ((b^2*x - a*c - a*b*y)/(a^2 + b^2),-(b*c + a*b*x - a^2*y)/(a^2 + b^2))
    p ./ ln = p ==== p .-| ln ; pop f (a,b) (c,d) = (f a c,f b d)		
    (.+.) = pop (+) ; (.-.) = pop (-)  ; (.=.) = (uncurry (&&) .) . pop (#) 
    (*.) = tmap . (*) ; (.*.) = (uncurry (+) .) . pop (*)
    (.<>.) = (uncurry (-) .) . (. uncurry (flip (,))) . pop (*) ; v .>. u = atan2 (v .<>. u) (v .*. u) 
    norm = sqrt . join (.*.) ; a ==== b = norm $ a.-.b ; negv = tmap negate
    infix 4 #,*. ; infix 3 .+.,==== ; infix 8 .>.
    x # y = abs (x-y) < 0.00001 ; tmap = join (***)
    dzipWith = (<*> drop 1) . zipWith ; dzip = dzipWith (,)

    Вся суть выразительности Haskell

    jkhne4pijgberg, 22 Апреля 2014

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