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

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

    +71

    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
    public class AuthorizedUserObservervable implements Runnable {
    
        private long sleepTime = 1000;
        private HashMap<AuthorizedUserObserver, HashMap<AuthorizedUser, Integer>> observers = new HashMap<AuthorizedUserObserver, HashMap<AuthorizedUser, Integer>>();
        
        
        private void setSleepTime(long sleepTime) {
            this.sleepTime = sleepTime;
        }
        
        
        public void add(AuthorizedUserObserver auo) {
            HashMap<AuthorizedUser, Integer> userCache = new HashMap<AuthorizedUser, Integer>();
            for (AuthorizedUser user : auo.getUsers()) {
                userCache.put(user, null);
            }
            observers.put(auo, userCache);
        }
    
        public void beginObservation() {
            new Thread(this).start();
        }
    
        @Override
        public void run() {
            while (true) {
                try {
                    for (Map.Entry<AuthorizedUserObserver, HashMap<AuthorizedUser, Integer>> observer : observers.entrySet()) {
                        for (Map.Entry<AuthorizedUser, Integer> user : observer.getValue().entrySet()) {
                            int newPostsCount = user.getKey().getNewPostsCount();
                            if (user.getValue() == null || newPostsCount != user.getValue()) {
                                HashMap<AuthorizedUser, Integer> userCache = new HashMap<AuthorizedUser, Integer>();
                                userCache.put(user.getKey(), newPostsCount);
                                observers.put(observer.getKey(), userCache);
                                observer.getKey().notify(user.getKey(), newPostsCount);
                            }
                        }
                    }
    
    
                    Thread.sleep(sleepTime);
                } catch (InterruptedException ex) {
                    Logger.getLogger(UserObservervable.class.getName()).log(Level.SEVERE, null, ex);
                } catch (AuthenticationException e) {
                    Thread.currentThread().stop(e);
                }
            }
        }
    }

    Чего стоит гибкость.

    manyrus, 13 Ноября 2011

    Комментарии (2)
  3. ActionScript / Говнокод #8484

    −112

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    function READ_MAIL() {
    	if (mc_MESS._currentframe==1) {
    		if (mails_body.substr((mails_num - 1) * 9, 1) == "1") {// sys mail
    			GET_SYS_MAIL(mails_body.substr((mails_num - 1) * 9 + 1, 8))
    		}else if (mails_body.substr((mails_num - 1) * 9, 1) == "2") {// user mail
    			GET_USER_MAIL(mails_body.substr((mails_num - 1) * 9 + 1, 8))
    		}else if (mails_body.substr((mails_num - 1) * 9, 1) == "5") {//present
    			GET_PRESENT_MAIL(mails_body.substr((mails_num - 1) * 9 + 1, 8))
    		}
    	}
    }

    Читаем данные...

    kyzi007, 11 Ноября 2011

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

    +123

    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
    public static string ConvertToBinary( ushort value )
    {
    	StringBuilder builder = new StringBuilder( 19 );
    
    	int mask = (1 << 15);
    
    	for ( int j = 0; j < 4; j++ )
    	{
    		for ( int i = 0; i < 4; i++ )
    		{
    			builder.Append( ((value & mask) != 0) ? ("1") : ("0") );
    
    			mask = mask >> 1;
    		}
    
    		if ( j < 3 )
    		{
    			builder.Append( " " );
    		}
    	}
    
    	return builder.ToString();
    }

    ivan-petrov, 08 Ноября 2011

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

    +125

    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
    /// <summary>
    		/// Конвертирование String - Decimal
    		/// </summary>
    		/// <param name="text"></param>
    		/// <param name="value"></param>
    		/// <returns></returns>
    		public static decimal GetDecimal(this string text)
    		{
    			decimal number;
    			CultureInfo culture = null;
    
    			if (String.IsNullOrEmpty(text))
    				throw new ArgumentNullException("The input string is invalid.");
    
    			try
    			{
    				culture = CultureInfo.CurrentCulture;
    				number = decimal.Parse(text, culture);
    				return number;
    			}
    			catch
    			{
    			}
    
    			try
    			{
    				culture = culture.Parent;
    				number = decimal.Parse(text, culture);
    				return number;
    			}
    			catch
    			{
    			}
    
    			culture = CultureInfo.InvariantCulture;
    			try
    			{
    				number = decimal.Parse(text, culture);
    				return number;
    			}
    
    			catch (FormatException e)
    			{
    				throw new FormatException(String.Format("Unable to parse '{0}'.", text), e);
    			}
    		}

    Это финиш.

    fr0mrus, 02 Ноября 2011

    Комментарии (2)
  6. PHP / Говнокод #8339

    +159

    1. 1
    2. 2
    3. 3
    // this fucking motherfucker is because fucking popup (don't want to remake whole authorisatio system)
    		if (isset($_SERVER['HTTP_REFERER']) && !preg_match("/\/$/", $_SERVER['HTTP_REFERER']))
    			$_SERVER['HTTP_REFERER'] .= "/";

    И блядь по 10 таких кусков кода на 1 файл.

    testtest, 28 Октября 2011

    Комментарии (2)
  7. Perl / Говнокод #8301

    −116

    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
    sub addOrUpdateContr {
    	my $doc   =  shift;
    
    	my( $id ) = $common->dbh->selectrow_array( 
    		qq|SELECT contrid FROM... | );
    
    	$id = $id || 0; 
    
    	if ( $id ) {
                 # вариант действий 1 ....
                 return $id;
    	}
    
    	if( !$id ) {
                 # вариант действий 2 (делает INSERT)....
                 return $id;
    	} else {
                 # вариант действий 3 ....
                 return $id;
    	}  
    
    	return $id;
    }

    Просто красивая функция.
    И то, что при названии addOrUpdateContr никакого апдэйта она не делает в ней далеко не самое замечательное.

    Mihard, 26 Октября 2011

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

    +80

    1. 1
    2. 2
    3. 3
    4. 4
    getBtnContent().setEnabled(enable);
    if (getGridConfig().isContentEnabled()) {
           getBtnContent().setEnabled(enable);
    }

    Программист со стажем, всегда хочет быть уверен что кнопка будет доступна на 150%

    pvtPyle, 22 Октября 2011

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

    +161

    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
    ...
    
      public function getLocations($fresh = 0)
        {
            $tld =& $this->varGet('tld');
            $domain =& $this->varGet('domain');
            
            // if website is viewed via IP
            $noWWWButIP =& $this->varGet('noWWWButIP');
    
            $memCacheKey = 'getLocations';
    
            if (!$fresh) {
                // already fetched and stored in vars?
                if (is_array($this->varGet('arrLocations')))
                    $arrLocations = $this->varGet('arrLocations');
                // lets try fetching from memcache
                else
                    $arrLocations = kd()->lib('kdCache')->get($memCacheKey);
            }
            // regenerate
            unset($arrLocations);
    
            if (!is_array($arrLocations)) {
    ...

    Кэшируем))

    kovel, 21 Октября 2011

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

    +118

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (mainWareHouseId.HasValue && mainWareHouseId.Value.ToString() == this._locationList.SelectedValue)
    {
        return false;
    }
    else
    {
        return location == null ? true : !location.RegionalFulfillment;
    }

    abatishchev, 21 Октября 2011

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

    −143

    1. 1
    2. 2
    1С.................
    Когда копро уже не вставляет.

    ReallyBugMeNot, 13 Октября 2011

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