1. Си / Говнокод #11392

    +141

    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
    int main()
      {
        int i = 0;
        goto A;
        for (;i<3; ++i)
        L:{
            {
              int x;
              x += i;
              if (0) { A: x = 0; goto B; }
              printf("X: %d ",x);
            }
            {
              int y;
              y -= i;
              if (0) { B: y = 10; goto L; }
              printf("Y: %d\n",y);
            }
          }
      }

    Отсюда: http://rsdn.ru/forum/cpp/4812647.flat.aspx Автор походу уверен в гениальности кода.

    slavap, 10 Июля 2012

    Комментарии (41)
  2. C++ / Говнокод #11391

    +24

    1. 1
    2. 2
    3. 3
    Fixed f = 0.2;
    	f = std::abs(f);
    	std::cout << (float)f;

    Угадайте, чему будет равно f?
    Fixed - тип из той же библиотеки, что и в http://govnokod.ru/11294

    TarasB, 10 Июля 2012

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

    +129

    1. 1
    return GetByteArray((Object)obj);

    На всякий случай.

    Em1ss1oN, 10 Июля 2012

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

    +119

    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
    /**
     * Imbues the given {@link Font} with support for fallback fonts,
     * needed to display CJK characters in fonts that do not support them.
     * 
     * This is an ugly mess that depends on internal Sun APIs. Use sparingly!
     *
     * @param font the font
     * @return the composite font UI resource
     */
    public static FontUIResource getCompositeFontUIResource(final Font font) {
    	try {
    		Class<?> klass;
    		
    		try {
    			// Java 7
    			klass = Class.forName("sun.font.FontUtilities");
    		} catch (final ClassNotFoundException e) {
    			// Java 6
    			klass = Class.forName("sun.font.FontManager");
    		}
    		
    		// Invoke static method that wraps the font
    		val method = klass.getMethod("getCompositeFontUIResource", Font.class);
    		return (FontUIResource) method.invoke(null, font);
    	} catch (final ClassNotFoundException e) {
    		// Long block of catches that cannot happen on a Sun JRE
    		throw new AssertionError(e);
    	} catch (final IllegalAccessException e) {
    		throw new AssertionError(e);
    	} catch (final IllegalArgumentException e) {
    		throw new AssertionError(e);
    	} catch (final InvocationTargetException e) {
    		throw new AssertionError(e);
    	} catch (final NoSuchMethodException e) {
    		throw new AssertionError(e);
    	} catch (final SecurityException e) {
    		throw new AssertionError(e);
    	}
    }

    someone, 10 Июля 2012

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

    +48

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function is_array_assoc($arr) {
        if (is_array($arr)) {
            foreach ($arr as $k => $v) {
                if (is_string($k) || (is_int($k) && $k < 0)) {
                    return 1;
                }
            }
            return 0;
        }
        return -1;
    }

    Взята с php.net проверка массива на ассоциативность.
    Типа array(5 => 4, 8=>9, 1 => 3) не ассоциативный?

    mkusher, 09 Июля 2012

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

    +24

    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
    do
        {
    		count++;
    		Xt=X;
    		if (ii==1)
    		{
    			X= dichotomia(a,b, E);
    			fprintf(bnf, "%lf;\n", Xt);
    		}
    		else
    		{
    			if (ii==2)
    			{
    				X=newton(X, E);
    				fprintf(bnf, "%lf;\n", Xt);
    			} 
    			else
    			{
    				if (ii==3)
    				{
    					X=sekuschich(X, b);
    					fprintf(bnf, "%lf;\n", Xt);
    				}
    				else
    				{
    					if (ii==4)
    					{
    						ii==1;
    						ii==2;
    						ii==3;
    					}
    				}
    			}
    		}
    		printf("X=%lf\n", X);
    		if(Func(X)*Func(a)>0)a=X;
    		else b=X;
    	}
    	while(fabs(X-Xt)>=E);

    В общем лаба на численые методы поиска корней.
    После того как я предоставил няшный, полностью удовлетворяющий условиям, после проверки меня попросили "сделать как у парней", и вот участок их высера

    p.s. форматирование сохранить не удалось, да и там совсем бы ничего понятно бы не было

    maksim_ovcharik, 09 Июля 2012

    Комментарии (185)
  7. Python / Говнокод #11382

    −86

    1. 1
    movie_data["genres"][i]["ru"].lower().encode("utf-8").decode("utf-8")

    Хм...

    Yurik, 08 Июля 2012

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

    +72

    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
    public abstract class SomeActivity extends Activity implements SomeEventListener {
    
        @Override
        protected void onResume() {
            super.onResume();
            application.addSomeListener(this);
        }
    
        @Override
        protected void onPause() {
            application.removeSomeListener(this);
            super.onPause();
        }

    В дополнение к #11379
    Вопрос пользователю нужно задать поверх любой нашей активити...

    rat4, 08 Июля 2012

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

    +59

    1. 1
    2. 2
    3. 3
    while (($i <= $additional_limit) && ($i < $available_spaces)) {
        $i++;
       }

    в недрах плагина к wordpress. Прям по-другому минимум двух чисел не найти

    mkusher, 08 Июля 2012

    Комментарии (30)
  10. Java / Говнокод #11379

    +69

    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
    public abstract class SomeActivity extends Activity implements SomeEventListener {
        private volatile Integer someEventAnswer;
    
        @Override
        public Integer onSomeEvent(final Collection<String> someData) {
            final CountDownLatch latch = new CountDownLatch(1);
    
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    showSomeDialog(someData, latch);
                }
            });
    
            try {
                latch.await();
            } catch (InterruptedException ignored) {
            }
    
            Integer ret = someEventAnswer;
            someEventAnswer = null;
            return ret;
        }
    
        private void showSomeDialog(final Collection<String> someData, final CountDownLatch latch) {
            String[] items = someData.toArray(new String[someData.size()]);
    
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Select some data");
            builder.setItems(items, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    someEventAnswer = which;
                    latch.countDown();
                }
            });
    
            Dialog dialog = builder.create();
            dialog.setOwnerActivity(this);
            dialog.show();
        }

    Android API Level 8
    Суть: из фонового потока задать вопрос пользователю

    rat4, 08 Июля 2012

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