1. C++ / Говнокод #12543

    +12

    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
    class DimensionAction : public PlmAction {
     public:
       virtual const std::type_info& type() const {
         return typeid( DimensionAction );
         }
    
      };
    
    class Object { // Где-то  в недрах иерархии...
      ...
      virtual const std::type_info& type() const = 0;
      ...
      };

    Зачем?! Почему?

    Try, 06 Февраля 2013

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

    +16

    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
    BOOL EnsureThreadIsSuspended (HANDLE hThread, Thread* pThread)
    {
        STATIC_CONTRACT_NOTHROW;
        STATIC_CONTRACT_GC_NOTRIGGER;
    
        WRAPPER_CONTRACT;
    
        CONTEXT ctx;
        ctx.ContextFlags = CONTEXT_INTEGER;
        BOOL ret;
        ret = ::GetThreadContext(hThread, &ctx);
    
        return ret;
    }

    А ведь и правда, никто не гарантирует, что поток будет остановлен к тому моменту, когда SuspendThread() вернет управление...

    Ccik, 06 Февраля 2013

    Комментарии (23)
  3. JavaScript / Говнокод #12541

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    function renderLayout(layout, column, colidx, restrictions) {
            //...
            if (!colidx) {
                    var flag = 1 << 0 | 1 << 1 | layout.title.type << 3;
                    if (layout.title.split) flag |= 1 << 2;
            }
            //...
    }

    Магические преобразования... или как стать незаменимым сотрудником!

    Eugene, 05 Февраля 2013

    Комментарии (20)
  4. Си / Говнокод #12540

    +139

    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
    long __stdcall wndproc(HWND wnd, unsigned int message, WPARAM wparam, LPARAM lparam)
    {
    	switch(message)
    	{
    	case WM_USER + 100:
    		{
    			char data[128];
    			fill_data(data);
    			PostMessage(wnd, WM_USER + 666,  0, (LPARAM)data);
    			return 0;
    		}
    	case WM_USER + 666:
    		{
    			char * data = (char *)lparam;
    			use_data(data);
    			return 0;
    		}
    //etc

    Wandering of the pointer или как выжить вне стека.

    Xom94ok, 05 Февраля 2013

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

    +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
    try {
    	// Store settings in the database as a JSON string
    	machine.setSettings(CustomJacksonRepresentation.createCanonicalObjectMapper().writeValueAsString(
    			request.getSettings()));
    } catch (final JsonMappingException e) {
    	// We obtained request by parsing JSON in the first place,
    	// no way it can fail to be serialized back o_O
    	throw new AssertionError(e);
    } catch (final JsonGenerationException e) {
    	// See above
    	throw new AssertionError(e);
    } catch (final IOException e) {
    	// Why does writeValueAsString throw IOException anyway? How CAN you fail to write to a String?
    	// Seriously, what were the writers of Jackson smoking that they exposed IOException in the API
    	// in a method specifically designed to serialize to String, just because the underlying implementation
    	// uses StringWriter (which doesn't really throw IOException anyway)?
    	// I mean, I understand if the string is too long to fit in memory, but that's an OutOfMemoryError
    	throw new AssertionError(e);
    }

    someone, 05 Февраля 2013

    Комментарии (1)
  6. JavaScript / Говнокод #12538

    +148

    1. 1
    document.getElementById('siF20').disabled=(this.checked==true)?false:true;

    kasthack, 05 Февраля 2013

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

    +137

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    SqlConnection connection = new SqlConnection(connectionString);
                SqlCommand command = connection.CreateCommand();
                using (connection = new SqlConnection(connectionString))
                {
                    command.CommandText = storedProcedure;
                }
    
                command.Connection.Open();

    Открывает соединение с сервером.

    kore_sar, 05 Февраля 2013

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

    +103

    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
    private static bool IsSourceField(DataRow row, string fieldName)
            {
                try
                {
                    object fieldValue = row[fieldName];
    
                    return false;
                }
                catch
                {
                    return false;
                }
            }

    Бизнес логика.

    kore_sar, 05 Февраля 2013

    Комментарии (20)
  9. JavaScript / Говнокод #12535

    +183

    1. 1
    while (c.charAt(0)==' ') c = c.substring(1,c.length);

    Особый ltrim

    3.14159265, 04 Февраля 2013

    Комментарии (44)
  10. Си / Говнокод #12534

    +111

    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
    /* ..от молодых, дерзких и успешных,
    форматирование и комментарии сохранены. */
    void zanulit_massiv ()
    {
    	int i;
    	for(i=0;i<27;i++) // dlja vseh elementov massiva
    	{
    		switch (i)   // perebiraem
    		{
    		case 0: mass_znach[0]=3;
    		case 1: mass_znach[0]=5;
    		case 2: mass_znach[0]=6;
    		case 3: mass_znach[0]=1;
    		case 4: mass_znach[0]=2;
    		case 5: mass_znach[0]=3;
    		case 6: mass_znach[0]=4;
    		case 7: mass_znach[0]=5;
    		case 8: mass_znach[0]=6;
    		case 9: mass_znach[0]=31;
    		case 10: mass_znach[0]=2;
    		case 11: mass_znach[0]=1;
    		case 12: mass_znach[0]=1;
    		case 13: mass_znach[0]=1;
    		case 14: mass_znach[0]=33;
    		case 15: mass_znach[0]=15;
    		case 16: mass_znach[0]=13;
    		case 17: mass_znach[0]=8;
    		case 18: mass_znach[0]=43;
    		case 19: mass_znach[0]=2;
    		case 20: mass_znach[0]=9;
    		case 21: mass_znach[0]=14;
    		case 22: mass_znach[0]=17;
    		case 23: mass_znach[0]=21;
    		case 24: mass_znach[0]=22;
    		case 25: mass_znach[0]=8;
    		case 26: mass_znach[0]=5;
    		default: break; // objazatelno v sluchae neizvesnogo znacheniya
    		}
    	}
    }

    Не могу больше :|

    neudachnik, 03 Февраля 2013

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