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

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    public static String cutN(String s,int n) { 
            char [] chars = s.toCharArray(); 
            String result = ""; 
            if (chars.length<n) throw new RuntimeException(); 
            for (int l=0; l<n;l++) { 
                result += chars[l]; 
            } 
            return result; 
        }

    http://www.linux.org.ru/forum/development/4858351

    qnikst учит новичка говнокодить.

    bbk123, 08 Мая 2010

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    bool b = false;
    while (!b) {
      // ...
    }

    guest, 27 Июня 2009

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    try{
    			$dbh->exec($sql);
    			return true;
    		}catch(Exception $e){
    			throw $e;
    		}

    эксепшены - это круто :)

    guest, 06 Мая 2009

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

    +80.5

    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
    <?php
            else
            {
                $invalid_user_name_chars = array();
                $invalid_user_name_chars[] = '/';
                $invalid_user_name_chars[] = '\\';
                $invalid_user_name_chars[] = '?';
                $invalid_user_name_chars[] = '@';
                $invalid_user_name_chars[] = '*';
                $invalid_user_name_chars[] = '[';
                $invalid_user_name_chars[] = ']';
                $invalid_user_name_chars[] = '(';
                $invalid_user_name_chars[] = ')';
                $invalid_user_name_chars[] = '{';
                $invalid_user_name_chars[] = '}';
                $invalid_user_name_chars[] = '<';
                $invalid_user_name_chars[] = '>';
                $invalid_user_name_chars[] = '-';
                $invalid_user_name_chars[] = '+';
                $invalid_user_name_chars[] = '=';
                $invalid_user_name_chars[] = '.';
                
                for ($i = 0; $i < count($invalid_user_name_chars); $i ++)
                {
                    if (stristr($_POST['user_name'], "$invalid_user_name_chars[$i]"))
                    {
                        $err = $lang['user_name_invalid'] . ' ( <span class="signup-invalid-char">' . $invalid_user_name_chars[$i] . '</span> )';
                        break;
                    }
                }
            }

    очередной индусокод
    решается 1ой строкой регекспа, но они легких путей не ищут.

    guest, 18 Мая 2009

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

    +80.4

    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
    StringBuilder sb = new StringBuilder();
    
    sb.append( "?" + BasePaymentSystem.CHECKPAYMENT_PARAM_NAME + "=true&" + WebMoneyXmlSystem.CUSTOMER_WMID_PARAM_NAME + "="
    		+ getCustomerWMID() + "&" + WebMoneyXmlSystem.CURRENCY_PARAM_NAME + "=" + getCurrency().toString() + "&"
    		+ WebMoneyXmlSystem.SELLER_WMID_PARAM_NAME + "=" + _sellerWMID + "&" + WebMoneyXmlSystem.PURSE_PARAM_NAME + "=" + _purse
    		+ "&" + WebMoneyXmlSystem.DESCRIPTION_PARAM_NAME + "=" + getDescription() + "&" + WebMoneyXmlSystem.INVADDRESS_PARAM_NAME
    		+ "=" + _invAddress + "&" + WebMoneyXmlSystem.PERIOD_PARAM_NAME + "=" + _period + "&"
    		+ WebMoneyXmlSystem.EXPERATION_PARAM_NAME + "=" + _experation + "&" + WebMoneyXmlSystem.DATECRT_PARAM_NAME + "="
    		+ dateCreateMills.toString() + "&" + WebMoneyXmlSystem.DATEUPD_PARAM_NAME + "=" + dateUpdateMills.toString() + "&wmInvId="
    		+ _wmInvId + "&requestN=" + String.valueOf( _requestn ) + "&" + BasePaymentSystem.PROJECTID_PARAM_NAME + "="
    		+ _projectId.toString() + "&" + BasePaymentSystem.USERID_PARAM_NAME + "=" + _userId.toString() );
    
    return new String( sb );

    Формирование строки GET запроса.

    spbAngel, 21 Октября 2009

    Комментарии (9)
  7. Куча / Говнокод #1700

    +80.3

    1. 1
    // here must be english equivalent for simple russian 'nahuya?'

    Bobby, 27 Августа 2009

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

    +80

    1. 1
    return payments.isEmpty() ? create ? store ? addPayment(serviceProvider) : createPayment(serviceProvider) : null : payments.iterator().next();

    экономим на строчках

    Lure Of Chaos, 04 Апреля 2015

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

    +80

    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
    public Object convert(Object entity) {
            
            Object result = null;
            
            //TUser to UserDTO
            if(entity.getClass().isInstance(TUser.class)) {
                result = new UserDTO();
                ((UserDTO)result).setId(((TUser)entity).getId());
                ((UserDTO)result).setLogin(((TUser)entity).getLogin());
                ((UserDTO)result).setPassword(((TUser)entity).getPassword());
            } 
            
            //TState to StateDTO
            if(entity.getClass().isInstance(TState.class)) {
                result = new StateDTO();
                ((StateDTO)result).setId(((TState)entity).getId());
                ((StateDTO)result).setAlias(((TState)entity).getAlias());
                ((StateDTO)result).setCaption(((TState)entity).getCaption());
            } 
            
            //TSale to SaleDTO
            if(entity.getClass().isInstance(TSale.class)) {
                result = new SaleDTO();
                ((SaleDTO)result).setId(((TSale)entity).getId());
                ((SaleDTO)result).setBuyerInfo(((TSale)entity).getBuyerInfo());
                ((SaleDTO)result).setCreateDate(((TSale)entity).getCreateDate());
                ((SaleDTO)result).setNumber(((TSale)entity).getNumber());
                TState state = ((TSale)entity).getStateId();
                ((SaleDTO)result).setState((StateDTO)convert(state));
                TGoods goods = ((TSale)entity).getGoodsId();
                ((SaleDTO)result).setGoods((GoodsDTO)convert(goods));
            } 
            
            //TImage to ImageDTO
            if(entity.getClass().isInstance(TImage.class)) {
                result = new ImageDTO();
                ((ImageDTO)result).setId(((TImage)entity).getId());
                ((ImageDTO)result).setPath(((TImage)entity).getPath());
                TGoods goods = ((TImage)entity).getGoodsId();
                ((ImageDTO)result).setGoods((GoodsDTO)convert(goods));
            } 
            
            //TGoods to GoodsDTO
            if(entity.getClass().isInstance(TGoods.class)) {
                result = new GoodsDTO();
                ((GoodsDTO)result).setId(((TGoods)entity).getId());
                ((GoodsDTO)result).setName(((TGoods)entity).getName());
                ((GoodsDTO)result).setPrice(((TGoods)entity).getPrice());
                ((GoodsDTO)result).setDescription(((TGoods)entity).getDescription());
                TCategory category = ((TGoods)entity).getCategoryId();
                ((GoodsDTO)result).setCategory((CategoryDTO)convert(category));
            } 
            
            //TCategory to CategoryDTO
            if(entity.getClass().isInstance(TCategory.class)) {
                result = new CategoryDTO();
                ((CategoryDTO)result).setId(((TCategory)entity).getId());
                ((CategoryDTO)result).setDescription(((TCategory)entity).getDescription());
                ((CategoryDTO)result).setName(((TCategory)entity).getName());
            } 
            return result;
        }

    Выдавил из себя преобразование из Entity в DTO

    carapuz, 08 Марта 2015

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

    +80

    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
    public class лаба22 {
    	int i;
    	лаба22(int k){
    	
    		i=k;}
    	
    	int [] a = new int [i];
    	
    	void длина(){
    		System.out.println(a.length);
    	}
    	public static void main(String[] args) {
    		лаба22 s = new лаба22(5);
    		s.длина();
    	}
    }

    Студеньтики... тупоголовые как и их преподы

    argamidon, 24 Февраля 2015

    Комментарии (40)
  11. Pascal / Говнокод #17219

    +80

    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
    procedure TInventory.removeItem(userid: integer; invid: integer;amount: integer = 1);
    var
      MyRes: TInvItemArray;
      CurrItem: TInvItem;
      I,len: integer;
    begin
      if (amount <= 0) then
        exit;
      if (amount = 1) then
        begin
         db.removeItemFromUserInventory(GetItems(GetIndexByInvId(invid)),userid);
         FInventoryList.Remove(GetIndexByInvId(invid));
        end else
        begin
          if (amount >= finventorylist.Size) then
            exit;
          MyRes:=GetResources(invid);
          len:=length(myres);
          if (len = 0) then
            exit;
          if (amount > len) then
            exit;
          for i:=0 to len - 1 do
           begin
             curritem:=MyRes[i];
             db.removeItemFromUserInventory(GetItems(GetIndexByInvId(curritem.InvId)),userid);
             FInventoryList.Remove(GetIndexByInvId(curritem.invid));
           end;
         Setlength(myres,0);
        end;
    
    end;
    
    function TInventory.GetResources(invid: integer): TInvItemArray;
    function ToResult(var Return: TInvItemArray; const Item: TInvItem): Integer;
    begin
      Result := Length(Return);
      SetLength(Return, Result + 1);
      Return[Result] := Item;
    end;
    var
      item,sameitem: TInvItem;
      Resource: TItem;
      i: integer;
    begin
      SetLength(result,0);
      item:=GetItem(invid);
      if (item = nil) then
        exit;
      if (item.item <> nil) then
        begin
         // if (item.itemю = 30) then
         //   begin
              for i:=0 to FInventoryList.Size - 1 do
               begin
                 sameitem:=TInvItem(FInventoryList.Items[i]);
                  if (sameitem = nil) then
                    continue;
                 resource:=sameitem.item;
                  if (resource = nil) then
                    continue;
                  if (item.item.itemid = resource.itemid) then
                    ToResult(result,sameitem);
               end;
           // end;
        end;
    end;

    По сути - удалить объект из списка. OMG!

    Cynicrus, 29 Ноября 2014

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