1. Java / Говнокод #16193

    +73

    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
    // Current Month Days
                for (int i = 1; i <= _nDaysInMonth; i++) {
                    if (_myPrefs.getIfConfigured()) {
                        if (_regionWithHolidays != null && _regionWithHolidays.length > 0) {
    
                            String holidayDateStringFormat = String.valueOf(i) + "-" + getMonthAsString(nCurrentMonth) + "-" + _strCurrentSelectedYear;
                            for (int index = 0; index < _regionWithHolidays.length; index++) {
                                if (_regionWithHolidays[index].getHolidayDate().equals(holidayDateStringFormat)) {
                                    list.add(String.valueOf(i) + "-RED" + "-" + getMonthAsString(nCurrentMonth) + "-" + yy);
                                }
                            }
                        }
                    }
    
                    if (i == getCurrentDayOfMonth()) {
                        list.add(String.valueOf(i) + "-BLUE" + "-" + getMonthAsString(nCurrentMonth) + "-" + yy);
                    } else {
                        list.add(String.valueOf(i) + "-WHITE" + "-" + getMonthAsString(nCurrentMonth) + "-" + yy);
                        if (_myPrefs.getIfConfigured()) {
                            if (_regionWithHolidays != null && _regionWithHolidays.length != 0) {
                                String otherDates = String.valueOf(i) + "-" + getMonthAsString(nCurrentMonth) + "-" + _strCurrentSelectedYear;
                                for (int index = 0; index < _regionWithHolidays.length; index++) {
                                    if (_regionWithHolidays[index].getHolidayDate().equals(otherDates)) {
                                        list.remove(String.valueOf(i) + "-WHITE" + "-" + getMonthAsString(nCurrentMonth) + "-" + yy);
                                    }
                                }
                            }
                        }
                    }
                }
    
                // some code
    
                for (int i = 1; i <= _nDaysInMonth; i++) {
                    String[] day_color = list.get(i).split("-");
                    if (day_color[1].equals("WHITE")) {
                        //active dates in current month
                        dayNumberView.setTextColor(getResources().getColor(R.color.darkGrey_font));
                    } else if (day_color[1].equals("BLUE")) {
                        //current date in current month
                        holder.tvTime.setTextColor(getResources().getColor(R.color.whitetranslucent));
                        dayNumberView.setTextColor(getResources().getColor(R.color.whitetranslucent));
                        cell.setBackgroundResource(R.color.blue_font);
                    } else if (day_color[1].equals("RED")) {
                        //active dates in current month
                        dayNumberView.setTextColor(getResources().getColor(R.color.red));
                    }
                }

    Это приложение с десятками тысяч пользователей. Мне выпала честь править в нем баги. На сколько я могу судить задача этого куска была отобразить календарь на текущий месяц на экране и подсветить WHITE - обычные дни, BLUE - текущий, RED - выходные и праздничные. Итак в чем соль:
    1) сама соль метода - в одном цикле создается список строк вида НОМЕР-ЦВЕТ-МЕСЯЦ-ГОД, чуть ниже в аналогичном цикле эти строки разбиваются по "-" и сравнивается по строковому значению цвета. Кроме того день может быть или текущим или праздничным, но никак не одновременно.
    2) два практически одинаковых куска кода по 10 строк - строки 4-13 и 19-28, первый при определенных условия добавляет ПРАЗДНИЧНЫЙ день в календарь, потом день в 16-18 строках день всегда добавляется еще раз этот день, либо обычный(WHITE) либо текущий(BLUE), и выполняется второй кусок и если проходят те же условия т.е. фактические если был добавлен праздничный день(RED) то удаляется добавленный ОБЫЧНЫЙ день. Баг был в том что если текущий день был еще и праздничным то они задваивались. Сделать по нормальному - если день уже добавлен, не добавлять еще раз или сделать continue главному циклу. Не говоря уже о том чтобы добавить break после 9 строки, видно автор не знал про эти операторы.

    TAX, 19 Июня 2014

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

    −168

    1. 1
    decode(coalesce(d.modif19,'0'),'0','0',d.modif19)

    siv163, 19 Июня 2014

    Комментарии (12)
  3. Pascal / Говнокод #16191

    +86

    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
    function IsMemoryCommitByAdress(const AAddress: Pointer): Boolean;
    var
      MemoryInfo: TMemoryBasicInformation;
    begin
      Result := False;
      if not Assigned(AAddress) then
      Exit;
      VirtualQuery(AAddress, MemoryInfo, SizeOf(MemoryInfo));
      Result := MemoryInfo.State and MEM_COMMIT <> 0;
    end;
    
    function IsPointerToVMT(const APointer: Pointer): Boolean;
      var
      VMTPointer, VMTPointerSelf: Pointer;
    begin
      Result := False;
      if not IsMemoryCommitByAdress(APointer) then
      Exit;
      VMTPointer := APointer;
      VMTPointerSelf := Pointer(Integer(VMTPointer) + vmtSelfPtr);
      if not IsMemoryCommitByAdress(VMTPointer) then
      Exit;
      if not IsMemoryCommitByAdress(VMTPointerSelf) then
      Exit;
      if not IsMemoryCommitByAdress(PPointer(VMTPointerSelf)^) then
      Exit;
      Result := PPointer(VMTPointerSelf)^ = VMTPointer;
    end;
    
    function IsBadptr(apointer:pointer):boolean;
    begin
      Result := IsMemoryCommitByAdress(APointer) and IsPointerToVMT(PPointer(APointer)^);
    end;

    Функция, для определения качества указателя, в ситуации "один объект - несколько указателей".
    Гк в том, что нет надежности - это все равно, что юзать IsBadReadPtr и аналогичные.

    Почему-то никто не пытается использовать операторы is и as (я узнал о них благодаря Тарасу, спасибо ему), чтобы сравнить качество приведения.

    brutushafens, 19 Июня 2014

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

    +138

    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
    bool ExcludeCase4(int iDepth)
            {
                MyNodeType pN = mPath[iDepth];
                if (pN != null)
                    if (pN.AuxField.bRed) return false;
    
                MyNodeType pP = mPath[iDepth - 1];
                    if (!pP.AuxField.bRed) return false;
    
                MyNodeType pS;
    
                if (LeftSon(iDepth))
                    pS = pP.pRight;
                else
                    pS = pP.pLeft;
    
                if (pS == null)
                {
                    pP.AuxField.bRed = false;
                    iDepthBad = -1;
                    return true;
                }
    
                if (pS.AuxField.bRed) return false;
    
                MyNodeType pSL = pS.pLeft;
                if (pSL != null)
                    if (pSL.AuxField.bRed) return false;
    
                MyNodeType pSR = pS.pRight;
                if (pSR != null)
                    if (pSR.AuxField.bRed) return false;
    
                pS.AuxField.bRed = true;
                pP.AuxField.bRed = false;
    
                iDepthBad = -1;
                
                return true;
    // Дерево стало хорошим. Корректировать больше не надо.
            }
    
            bool ExcludeCase6(int iDepth)
            {
                MyNodeType pN, pP, pS;
                bool bLeft, bRedP;
    
                pN = mPath[iDepth];
                if (pN != null)
                if (pN.AuxField.bRed) return false;
    
                pP = mPath[iDepth - 1];
                bRedP = pP.AuxField.bRed;
    
                bLeft = LeftSon(iDepth);
    
                if (bLeft)
                    pS = pP.pRight;
                else
                    pS = pP.pLeft;
    
                if (pS == null) return false;
                if (pS.AuxField.bRed) return false;
    
                MyNodeType pSL, pSR, p2, p3;
    
                pSL = pS.pLeft;
                pSR = pS.pRight;
    
                if (bLeft)
                {
                    if (pSR == null || pSR != null && !pSR.AuxField.bRed)
                    {
                        if (pSL == null) return false;
                        if (!pSL.AuxField.bRed) return false;
    // Сюда попали => это Случай 5.
    
                        p2 = pSL.pRight;
                        pSL.pRight = pS;
                        pS.pLeft = p2;
                        pSL.AuxField.bRed = false;
                        pS.AuxField.bRed = true;
    
                        pP.pRight = pSL;
                        pSR = pS;
                        pS = pSL;
                    }
                    else
                    if (!pSR.AuxField.bRed) return false;
    
    // Сюда попали => это Случай 6.
    
               ,......}

    кусочек красно-черного дерева, необходимый, но не достаточный

    lavrov, 18 Июня 2014

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

    +87

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public BarrierAssessment(int id, Client client, int homephone, int mobile, int email, int transport, int licence, boolean notInWorkForce, boolean unpaidWork, boolean cdeProgram, boolean notWorkingBut, int paidWork, 
    String employerOcc, String reason, int highlevel, String further, int stableAccomodation, int loneParent, int livingWith, int policeProblems, int courtPending, int preventFrom, int medical, int drugTest, int currentBusy, 
    String scurrentBusy, String reasonForNotGettingJob, int startTomorrow, String jobGoals, int currentResume, int canvasLetter, int referees, int interviewClothing, String otherBarriers, int ec, LastModified lastModified, 
    Date datestamp, Date bupdated, String disabilityBarriers, Date licenceDueToExpire, Date licenceDueBack, String currentSkills, String possibleSkills) {
     
    ...
     
    }

    Мать всех конструкторов!

    Meegoo, 18 Июня 2014

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

    +74

    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
    import java.io.*;
    import java.util.*;
    
    public class Solution
    {
        public static void main(String[] args) throws Exception
          { Scanner scanner = new Scanner(System.in);
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            int z = scanner.nextInt();
            if (a < b && a < c && a < z)
            {  if (b < c && b < z)
                {if (c < z)
                    {System.out.println(z + " " + c + " " + b + " " + a);}
                    else
                    {System.out.println(c + " " + z + " " + b + " " + a);} }
                else if (c < b && c < z)
                { if (b < z)
                    {System.out.println(z + " " + b + " " + c + " " + a);}
                    else
                    {System.out.println(b + " " + z + " " + c + " " + a);} }
                else if (z < c && z < b)
                { if (c < b)
                    {System.out.println(b + " " + c + " " + z + " " + a);}
                    else
                    {System.out.println(c + " " + b + " " + z + " " + a);} } }
            else if (b < a && b < c && b < z)
            { if (a < c && a < z)
                { if (c < z)
                    {System.out.println(z + " " + c + " " + a + " " + b);}
                    else
                    {System.out.println(c + " " + z + " " + a + " " + b);} }
                else if (c < a && c < z)
                { if (a < z)
                    {System.out.println(z + " " + a + " " + c + " " + b);}
                    else
                    {System.out.println(a + " " + z + " " + c + " " + b);} }
                else if (z < a && z < c)
                { if (a < c)
                    {System.out.println(c + " " + a + " " + z + " " + b);}
                    else
                    {System.out.println(a + " " + c + " " + z + " " + b);} } }
            else if (c < a && c < b && c < z)
            { if (a < b && a < z)
                { if (b < z)
                    {System.out.println(z + " " + b + " " + a + " " + c);}
                    else
                    {System.out.println(b + " " + z + " " + a + " " + c);} }
                else if (b < a && b < z)
                { if (a < z)
                    {System.out.println(z + " " + a + " " + b + " " + c);}
                    else
                    {System.out.println(a + " " + z + " " + b + " " + c);} }
                else if (z < a && z < b)
                { if (a < b)
                    {System.out.println(b + " " + a + " " + z + " " + c);}
                    else
                    {System.out.println(a + " " + b + " " + z + " " + c);} } }
            else if (z < a && z < b && z < c)
            { if (a < c && a < b)
                { if (c < b)
                    {System.out.println(b + " " + c + " " + a + " " + z);}
                    else
                    {System.out.println(c + " " + b + " " + a + " " + z);} }
                else if (c < a && c < b)
                { if (a < b)
                    {System.out.println(b + " " + a + " " + c + " " + z);}
                    else
                    {System.out.println(a + " " + b + " " + c + " " + z);} }
                else if (b < a && b < c)
                {
                    if (a < c)
                    {System.out.println(c + " " + a + " " + b + " " + z);}
                    else
                    {System.out.println(a + " " + c + " " + b + " " + z);} } }
    }
    }

    Ня!

    dagonlaf, 18 Июня 2014

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

    +136

    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
    static string[] ArrayFuller(string pathToFile)
            {
    
                int rr = 0;
                StreamReader sr=new StreamReader(pathToFile);
                while(!sr.EndOfStream){
                sr.ReadLine();
                rr++;
                }
                StreamReader sr2 = new StreamReader(pathToFile);
                string[] arrayBox = new string[rr];
                for (int i = 0; i < rr; i++)
                {
                    arrayBox[i] = Convert.ToString(sr2.ReadLine());
                }
                sr2.Close();
                return arrayBox;
            }

    vladb9582, 18 Июня 2014

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

    +79

    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
    public Long getRecordCount() {
            long result = 0;
            if(pfrFile != null){
                if(pfrFile.getПачкаВходящихДокументов().getРАСЧЕТ_ПО_СТРАХОВЫМ_ВЗНОСАМ_НА_ОПС_И_ОМС_ПЛАТЕЛЬЩИКАМИ_ПРОИЗВОДЯЩИМИ_ВЫПЛАТЫ_ФЛ() != null){
                    result++;
                }
                if(pfrFile.getПачкаВходящихДокументов().getРСВ1() != null){
                    result++;
                }
                if(pfrFile.getПачкаВходящихДокументов().getРАСЧЕТ_ПО_СТРАХОВЫМ_ВЗНОСАМ_НА_ОПС_И_ОМС_ПЛАТЕЛЬЩИКАМИ_СВ_ПРОИЗВОДЯЩИМИ_ВЫПЛАТЫ_ФЛ_НАЧИНАЯ_С_2012_ГОДА() != null){
                    result++;
                }
                if(pfrFile.getПачкаВходящихДокументов().getРАСЧЕТ_ПО_СТРАХОВЫМ_ВЗНОСАМ_НА_ОПС_И_ОМС_ПЛАТЕЛЬЩИКАМИ_СВ_ПРОИЗВОДЯЩИМИ_ВЫПЛАТЫ_ФЛ_НАЧИНАЯ_С_2013_ГОДА() != null){
                    result++;
                }
    ...
            return result;
    }

    :D

    skobets, 18 Июня 2014

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

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    /**
     * Some UI hacks for JRuby Facet
     */
    public class NiiChAVOUtil { 
    }

    Слова лишнии

    vistall, 18 Июня 2014

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

    +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
    string parser(string chto, string chem)
                {
                    int dlina = chem.Length;
                    int kol = chto.Length;
                    string ret = null;
                    int shet = 0;
                    int r = 0;
                    int nom = 0;
                    for (int i = 0; i < kol; i++)
                    {
                        if (chto[i] == chem[0] && shet == 0)
                        {
                            for (int j = i; j < dlina + i; j++)
                            {
                                if (chto[j] == chem[r])
                                {
                                    r++;
                                    shet++;
                                    nom = j;
                                }
    
                            }
                            if (shet != dlina)
                            {
                                shet = 0;
                                r = 0;
                                nom = 0;
                            }
                        }
                    }
                    int schet = nom + 3;
                    while (chto[schet] != '<')
                    {
                        ret += chto[schet];
                        schet++;
                    }
                    return ret;
                }

    Функция для парсинга подстроки

    vladb9582, 18 Июня 2014

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