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

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

    +134

    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
    public void OnKillEvent_ServerOnly(PhotonPlayer player)
        {
        case MatchTypeInfo.TDM:
    
                    if (player != null)
                    {
                        var hash = player.customProperties;
    
                        if (hash != null)
                        {
                            var team = (int) hash["team"];
    
                            var realScore = match.GetTeamScores();
    
                            var teamAScor = team == 0 ? realScore.x + TeamDeathScores : realScore.x;
                            var teamBScor = team == 1 ? realScore.y + TeamDeathScores : realScore.y;
    
                            //DebugModule("Kill Processed On Server completed: " + team + "// " + teamAScor + "/" + teamBScor);
    
                            match.ChangeTeamScores((int)teamAScor, (int)teamBScor);
                        }
                        else
                        {
                            Debug.LogError("OnKillEvent_ServerOnly ERROR Team hash");
                        }
                    }
    
                    break;
    }  {
    //через 500 строк кода
       private void LocalUpdate()
        { 
        if (Application.isEditor)
            {
                if (Input.GetKeyDown(KeyCode.Y))
                {
                    switch (MatchType)
                    {
    
                        case MatchTypeInfo.TDM:
                            ChangeTeamScores((int)(_teamScores.x - 1), (int)(_teamScores.y - 1), true);
                            break;   }
    
                    SendTeamScoresToUI();
                }
            }
    
       switch (MatchType)
            {
                case MatchTypeInfo.TDM:
                   // DebugModule("Load TDM type game");
                    break;
    }
    }
    //ещё 500 строк
     public void ChangeTeamScores(int a, int b, bool force = false)
        {
    
            if (PhotonNetwork.isMasterClient)
            {
                // check server rules
                var rules = GetGameRules();
                if (rules != null)
                {
                    if (!rules.CheckPlayerCountRules() && !force)
                    {
                        Debug.LogError("Game is not started, beacuse server has no players: " + rules.MinimumPlayerToPlay + "/" +
                                       PhotonNetwork.room.playerCount);
                        return;
                    }
                }
                else
                {
                    Debug.LogError("Rule error");
                    return;
                }
    
                _teamScores.x = Mathf.Clamp(a, 0, float.MaxValue);
                _teamScores.y = Mathf.Clamp(b, 0, float.MaxValue);
    
                var matchIsCompleted = false;
    
                switch (MatchType)
                {
                    case MatchTypeInfo.TDM:
                        matchIsCompleted = _teamScores.x <= 0 || _teamScores.y <= 0;
                        break;
                }
                   if (matchIsCompleted)
                {
                    Server_CallEndRound();
                }
                else
                {
                    // Call Event??
                  }
    }
    }

    Чтобы я ещё раз полез помогать инди-разработчикам, мать их за ногу.

    noshitleft, 26 Ноября 2014

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

    +135

    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
    public void Login(ClientHandlers<int> actions)
            {
                var request = GetGetRequest("/user/xml/{0}", _login);
    
                var act = new Action<IRestResponse<GetUserInfoResult>>(response =>
                    {
                        if (CheckUserInfo(response))
                        {
                            throw new Exception("Невозможно получить информацию о пользователе\r\nНеобработанное исключение");
                        }
    
                        UserInfo = response.Data.UserInfo;
                        actions.Completed(UserInfo.idUser);
                    });
                _client.ExecuteAsync(request, act);
            }
    
            private bool CheckUserInfo(IRestResponse<GetUserInfoResult> response)
            {
                if (response != null && response.Data != null && response.Data.UserInfo != null && response.Data.UserInfo.idUser != 0)
                {
                    return true;
                }
    
                var message = "Невозможно получить информацию о пользователе";
                if (response == null)
                {
                    message = string.Format("{0}\r\n{1}", 
                                            message, 
                                            "Response is null");
                    throw new Exception(message);
                }
    
                message = string.Format("{0}\r\nResponse data is null\r\nContext: {1}", 
                                        message, 
                                        response.Content);
    
                if (response.Data == null)
                {
                    throw new Exception(message);
                }
    
                message = string.Format("{0}\r\nIs exception: {1}\r\nMessage: {2}", 
                                        message, 
                                        response.Data.IsException, 
                                        response.Data.Message);
    
                if (response.Data.UserInfo == null)
                {
                    throw new Exception(message);
                }
    
                message = string.Format("{0}\r\nSiteName: {1}\r\nUserName: {2}\r\nUserRole: {3}", 
                                        message, 
                                        response.Data.UserInfo.SiteName, 
                                        response.Data.UserInfo.UserName, 
                                        response.Data.UserInfo.UserRole);
                if (response.Data.UserInfo.idUser == 0)
                {
                    throw new Exception(message);
                }
    
                return false;
            }

    Внимательность, внимательность и еще раз внимательность...

    HellMaster_HaiL, 26 Ноября 2014

    Комментарии (3)
  4. SQL / Говнокод #17168

    −864

    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
    sResult:= '';
       select  code||' '||h.longname into sResult
            from tbl1 mo, tbl2 ob, g_cli c, tbl3 h
          where mo.m_dep_id = ob.obj_dep_id and mo.m_id = ob.obj_id
              and ob.dep_id = nDepId and ob.id = nId
              and  mo.cli_dep_id = c.dep_id and mo.cli_id = c.id
              and c.id = h.id and c.dep_id = h.dep_id and p_operday between h.FROMDATE and h.TODATE;
             return sResult; 
      exception
        when NO_DATA_FOUND then return null;
        when TOO_MANY_ROWS then          
              for rec in(   select  distinct code as cli_code, h.longname as cli_name 
            from tbl1 mo, tbl2 ob, g_cli c, tbl3 h
          where mo.m_dep_id = ob.obj_dep_id and mo.m_id = ob.obj_id
              and ob.dep_id = nDepId and ob.id = nId
              and  mo.cli_dep_id = c.dep_id and mo.cli_id = c.id
              and c.id = h.id and c.dep_id = h.dep_id and dT between h.FROMDATE and h.TODATE)
                loop
                  if nvl(length(sResult),0) = 0 then
                    sResult:= rec.cli_code||' '||rec.cli_name;
                  else
                    sResult:= sResult||', '||rec.cli_code||' '||rec.cli_name;
                  end if;
                end loop;
                return sResult;   
         when others then return null;

    ColvirBydlokod, 25 Ноября 2014

    Комментарии (3)
  5. Perl / Говнокод #17073

    −161

    1. 1
    2. 2
    3. 3
    4. 4
    foreach my $i (0 .. (scalar @{ $PARAMS{Input} } - 1) )
    {
    	@{ $PARAMS{Input} }[$i] = expand_filename(@{ $PARAMS{Input} }[$i]);
    }

    Такая то экспрессия

    Anus, 06 Ноября 2014

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

    +145

    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
    int boolToInt(bool b)
    {
    	bool * boolPtr = &b;
    	char * boolToCharPtr = reinterpret_cast<char *>(boolPtr);
    	char * resultCharPtr;
    	resultCharPtr = (char*) malloc(4);
    
    	for (int i = 0; i < sizeof(int); i++)
    	{
    		if (i == 0)
    		{
    			resultCharPtr[i] = boolToCharPtr[0];
    		}
    		if (i == 1)
    		{
    			resultCharPtr[i] = 0x00;
    		}
    		if (i == 2)
    		{
    			resultCharPtr[i] = 0x00;
    		}
    		if (i == 3)
    		{
    			resultCharPtr[i] = 0x00;
    		}
    	}
    
    	int * intPtr = reinterpret_cast<int *> (resultCharPtr);
    	return *intPtr;
    }

    Удобная функция для конвертации bool в int

    lazorg, 29 Октября 2014

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

    −93

    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
    # Source: python3.4/distutils/dir_util.py
    
    
    # cache for by mkpath() -- in addition to cheapening redundant calls,
    # eliminates redundant "creating /foo/bar/baz" messages in dry-run mode
    _path_created = {}
    
    # I don't use os.makedirs because a) it's new to Python 1.5.2, and
    # b) it blows up if the directory already exists (I want to silently
    # succeed in that case).
    def mkpath(name, mode=0777, verbose=1, dry_run=0):
        """Create a directory and any missing ancestor directories.
    
        If the directory already exists (or if 'name' is the empty string, which
        means the current directory, which of course exists), then do nothing.
        Raise DistutilsFileError if unable to create some directory along the way
        (eg. some sub-path exists, but is a file rather than a directory).
        If 'verbose' is true, print a one-line summary of each mkdir to stdout.
        Return the list of directories actually created.
        """
    
        global _path_created
    
        # Detect a common bug -- name is None
        if not isinstance(name, basestring):
            raise DistutilsInternalError, \
                  "mkpath: 'name' must be a string (got %r)" % (name,)
    
        # XXX what's the better way to handle verbosity? print as we create
        # each directory in the path (the current behaviour), or only announce
        # the creation of the whole path? (quite easy to do the latter since
        # we're not using a recursive algorithm)
    
        name = os.path.normpath(name)
        created_dirs = [] 
        if os.path.isdir(name) or name == '':
            return created_dirs
        if _path_created.get(os.path.abspath(name)):
            return created_dirs
        ...

    Мало того, что метод жив на основании того, что os.makedirs был добавлен только в Python 1.5.2 (мама родная, 2.7 скоро закопаем, а говно всё тянется), так его ещё и умудрились наиндусить на 60 строк кода, да ещё и ХХХ секцию аккуратно положили. Ладно, чего это я придираюсь... Ах да, оно кеширует уже созданные директории, так что если создать папку и удалить её, второй раз её уже никак не создашь...

    frol, 23 Октября 2014

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

    +152

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (a == 10)
    {
        <какие-то действия>
    }
    else
    {
        <один в один те же самые действия>
    }

    Безысходность.

    gmihalkov, 19 Октября 2014

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

    +53

    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
    class CClass
    {
    //...
       boost::shared_ptr<CTestData> mpTestData;
    //...
    };
    
    void CClass::setTestData(boost::shared_ptr<CTestData> pTestData)
    {
       if(pTestData.use_count() == 0)
       {
          mpTestData.reset();
       }
       else
       {
          mpTestData = pTestData;
       }
    }

    hedrok, 16 Октября 2014

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

    +156

    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
    class ChargifyNotFoundException extends ChargifyException {
    	var $errors;
    	var $http_code;
    	
    	public function ChargifyNotFoundException($http_code, $error) {
    		$this->http_code = $http_code;		
    
    		$message = '';
    		$this->errors = array();
    		foreach ($error as $key=>$value) {
    			if ($key == 'error') {
    				$this->errors[] = $value;
    				$message .= $value . ' ';
    			}
    		}
    
    		parent::__construct($message, intval($http_code));
    	}	
    }

    Индусам платят за количество строк

    rowdyroad, 14 Октября 2014

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

    +133

    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
    /*Checks whether the path exists and the path is directory, otherwise creates a new directory*/
    RET_VALS check_create_directory(const char* const dir_path, void (*print_func)(int, char *,...))
    {
    	RET_VALS ret_val;
    	struct stat sb;
    
    	ret_val = RET_OK;
    	if (NULL != dir_path)
    	{
    		if(NULL != print_func)
    		{
    			print_func(DBG_INFO, "%s - Checking %s existence\n", __FUNCTION__, dir_path);
    		}
    		else
    		{
    			dbgprintln("Checking %s existence", dir_path);
    		}
    		if (0 != stat(dir_path, &sb) || (false == S_ISDIR(sb.st_mode)))
    		{
    			ret_val |= RET_DIR_MISSING;
    			if(NULL != print_func)
    			{
    				print_func(DBG_INFO, "%s - %s is missing\n", __FUNCTION__, dir_path);
    			}
    			else
    			{
    				dbgprintln("%s is missing", dir_path);
    			}
    			errno = 0;
    			if (0 == mkdir(dir_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH))
    			{
    				ret_val |= RET_DIR_CREATE_OK;
    				if(NULL != print_func)
    				{
    					print_func(DBG_INFO, "%s - %s is successfully created\n", __FUNCTION__, dir_path);
    				}
    				else
    				{
    					dbgprintln("%s is successfully created", dir_path);
    				}
    			}
    			else
    			{
    				char err_msg[_K];
    
    				sprintf(err_msg, "Failed to create %s, error %04d - %s", dir_path, errno, strerror(errno));
    				ret_val |= RET_DIR_CREATE_FAILED;
    				//dbg_ffln(DBG_ERROR, "Failed to create %s", dir_path);
    				if(NULL != print_func)
    				{
    					print_func(DBG_INFO, "%s - %s\n", __FUNCTION__, err_msg);
    				}
    				else
    				{
    					dbgprintln("%s", err_msg);
    				}
    			}
    		}
    		else
    		{
    			ret_val |= RET_DIR_ALREADY_EXIST;
    			if(NULL != print_func)
    			{
    				print_func(DBG_INFO, "%s - %s already exists\n", __FUNCTION__, dir_path);
    			}
    			else
    			{
    				dbgprintln("%s already exists", dir_path);
    			}
    		}
    	}
    	else
    	{
    		ret_val = RET_DIR_MISSING;
    		if(NULL != print_func)
    		{
    			print_func(DBG_ERROR, "%s - No directory name is provided", __FUNCTION__);
    		}
    		else
    		{
    			dbgprintln("No directory name is provided");
    		}
    	}
    	return ret_val;
    }

    Продолжаем раскопки. Вообще весь .с файл можно сюда выложить.

    codemonkey, 12 Октября 2014

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