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

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

    +76

    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
    private void spreadBullets() {
            bulletItemsWip.clear();
            for (AbstractInventoryItem item : inventoryItemsSortedByValue) {
                if (item instanceof RangeBulletItem) {
                    bulletItemsWip.add((RangeBulletItem) item);
                }
            }
    
            rangeUnitsQueueWip.clear();
            for (Unit unit : areaObject.getUnits()) {
                if (unit.getSpecialization().equals(Unit.UnitSpecialization.RANGE)) {
                    rangeUnitsQueueWip.add(unit);
                }
            }
    
            while (rangeUnitsQueueWip.size > 0 && bulletItemsWip.size > 0) {
                Iterator<Unit> unitsIterator = rangeUnitsQueueWip.iterator();
                while (unitsIterator.hasNext()) {
                    // find suitable bullets or remove unit from queue
                    Unit rangeUnit = unitsIterator.next();
    
                    RangeBulletItem foundBulletItemInInventoryForUnit = searchBulletFor(rangeUnit);
                    if (foundBulletItemInInventoryForUnit == null) {
                        // remove unit from bullets queue
                        unitsIterator.remove();
                    } else {
                        //  bullet was found
                        RangeBulletItem unitBulletsItem = rangeUnit.getEquipment().getRangeBulletsItem();
                        if (unitBulletsItem == null) {
                            unitBulletsItem = foundBulletItemInInventoryForUnit.split(1);
                            rangeUnit.getEquipment().setRangeBulletsItem(unitBulletsItem);
                        } else {
                            if (unitBulletsItem.getClass().equals(foundBulletItemInInventoryForUnit.getClass())){
                                if (!unitBulletsItem.isFull()) {
                                    foundBulletItemInInventoryForUnit.moveQuantity(1, unitBulletsItem);
                                } 
                            } else {
                                rangeUnit.getEquipment().dropRangeBullets();
                                unitBulletsItem = foundBulletItemInInventoryForUnit.split(1);
                                rangeUnit.getEquipment().setRangeBulletsItem(unitBulletsItem);
                            }
                        }
    
                        if (foundBulletItemInInventoryForUnit.isEmpty()) {
                            // remove item from inventory
                            bulletItemsWip.removeValue(foundBulletItemInInventoryForUnit, true);
                            remove(foundBulletItemInInventoryForUnit);
                        }
    
                        if (unitBulletsItem.isFull()) {
                            // remove unit from bullets queue
                            unitsIterator.remove();
                        }
    
                        if (bulletItemsWip.size == 0) {
                            // stop spreading
                            break;
                        }
                    }
                }
            }
    
            // sync quantities to inventory
            for (AbstractInventoryItem item : bulletItemsWip) {
                getItem(item.getClass()).setQuantity(item.getQuantity());
            }
        }

    Раздать пули отряду...

    dmli, 01 Марта 2015

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

    +81

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    class GetDataFromMySQL extends AsyncTask<String, String, String> {
    
     protected String doInBackground(String[] params) {
    
         runOnUiThread(new Runnable() {
            public void run() {
            ...
            ... 
          //абсолютно вся логика здесь.
            }

    Мастер многопоточного ПОГРОМмирования под Ондроид...

    argamidon, 01 Марта 2015

    Комментарии (1)
  4. Python / Говнокод #17704

    −114

    1. 1
    2. 2
    cur.execute("""SELECT EXTRACT(dow from DATE %(date)s)""", {"date" : datetime})
    week = cur.fetchone()

    Я конечно знаю, что ГК про даты это плохой тон, но такого я еще не видел.

    heyzea1, 27 Февраля 2015

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

    +76

    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
    private List< String > extractMetaDataLines()
    {
       final ArrayList< String > metaDataLines = new ArrayList< String >();
       int currentLineIndex = 0;
       int start = 0;
       int end = 0;
    
       for ( final String line : getLines() )
       {
          if ( line.contains( METADATA_TAG ) )
          {
             if ( line.contains( "</" ) )
             {
                end = currentLineIndex
                      - ( getLines().get( currentLineIndex - 1 ).contains( "]]>" ) ? 1
                                                                                  : 0 );
                if ( line.contains( "<fx" )
                      || line.contains( "<mx" ) )
                {
                   start = end;
                }
                break;
             }
             if ( line.contains( "<" ) )
             {
                start = currentLineIndex
                      + ( getLines().get( currentLineIndex + 1 ).contains( "CDATA[" ) ? 2
                                                                                     : 1 );
             }
          }
          currentLineIndex++;
       }
       metaDataLines.addAll( getLines().subList( start,
                                                 end ) );
       return metaDataLines;
    }

    build.xml:413: java.lang.IllegalArgumentException: fromIndex(12) > toIndex(11)
    at java.util.ArrayList.subListRangeCheck(ArrayList.java:964)
    at java.util.ArrayList.subList(ArrayList.java:954)
    at com.adobe.ac.pmd.files.impl.MxmlFile.extractMetaDataLines(MxmlFile.java:262)
    at com.adobe.ac.pmd.files.impl.MxmlFile.copyScriptLinesKeepingOriginalLineIndices(MxmlFile.java:191)

    Адоб, как обычно, порадовал. (Это типа линт, который должен проверять мелкие ошибки / стиль). В проекте примерно 300 файлво в которых есть тег "метадата", пойди пойми на каком оно валится... Самому собрать это говно - нереально сложно изза каких-то уебищных зависимостей, конфликтов версий мейвена и т.п.

    wvxvw, 15 Февраля 2015

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    null != localStorage.getItem("lock") && "2" == localStorage.getItem("lock") &&
        ($(".up_link").css("bottom", 0), $(".popular").removeClass("open")),
        e.find(".door").on("click", function() {
            return "2" == localStorage.getItem("lock") ?
                ($(".up_link").css("bottom", 80), e.addClass("open"),
                    localStorage.setItem("lock", "1")) :
                ($(".up_link").css("bottom", 0), e.removeClass("open"),
                    localStorage.setItem("lock", "2")), !1
        });

    Пример кода с echo.msk.ru

    Vnr, 13 Февраля 2015

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

    +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
    {
       ...
       _tswfstring contentID = fileName;
       _tswfstring::size_type index = fileName.find_last_of ( _T("\\")  );
       if ( index != -1 )
          contentID.erase(0, index + 1);
    
       TCHAR name[10] = {0};
       memcpy(name, contentID.c_str() + contentID.length() - 9, 9 * sizeof(TCHAR));
       if(name[6] == _T('B') || name[6] == _T('b')) //to upper case if .bmp
       {
          name[6] = _T('B');
          name[7] = _T('M');
          name[8] = _T('P');
       }
    }

    blackhearted, 11 Февраля 2015

    Комментарии (1)
  8. Python / Говнокод #17617

    −109

    1. 1
    2. 2
    if form.cleaned_data.has_key('replace_id') and type(form.cleaned_data['replace_id']) == type(32):
        ...

    Логично, чо

    larikov, 11 Февраля 2015

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    ...
    $personInfos = $query->getResult();
    foreach ($personInfos as $personInfo) {
        return $personInfo;
    }
    /* we lost our person */
    return false;

    Ребята-оутсорсеры насмешили наш отдел))

    zinovyev, 06 Февраля 2015

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    var saveButtonStatus = (saveBtn.length != 0 && (!saveBtn.hasClass('disabled') && !saveBtn.is(':disabled') && !saveBtn.hasClass('ignore')) ) ? true : false;   
    
    if(saveButtonStatus) {
    	return true;
    }
    ....

    Валидация

    Edd, 05 Февраля 2015

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

    −122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    def contract_params
      if params[:contract][:contract_type].to_i == 1
        field = :contractor_id
      else
        field = :legal_entity_id
      end
      params.require(:contract).permit(
          :contract_type,
          :paid_expectation,
          field
      )
    end

    Much strong, very params.

    FancyDancy, 04 Февраля 2015

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