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

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

    +80

    1. 1
    2. 2
    3. 3
    if (!driver.findElement(By.id(DD_LAUNCH_ID)).equals(null)) {
        pause(1000);
    }

    Тогда уж почему не null.equals(...)?

    Actine, 25 Сентября 2014

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

    +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
    public class CookieHelper {
        public static Cookie getCookie(String name, Http.Request request) {
            Cookie cookie = null;
            if (request.cookies != null) {
                for (Entry<String, Cookie> entry : request.cookies.entrySet()) {
                    if (name.equals(entry.getKey())){
                        cookie = entry.getValue();
                    }
                }
            }
            return cookie;
        }
    }

    request.cookies - это конечно же Map<String, Cookie>

    kostoprav, 23 Июня 2014

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

    +80

    1. 1
    private HttpClient httpServer = new DefaultHttpClient();

    У нас в приложении есть свой сервер!!1

    javahutt, 21 Июня 2014

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

    +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
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    Procedure ChangeDataBase(var phone:cellphone);
    var ch:char;
    
    Begin clrscr;
    With Phone do
              Begin Line;
    	  TextColor(Cyan); Writeln(' Выберите тип аппарата: '); TextColor(White);
    	  Writeln(' [0-Телефон | 1-Смартфон]');
    
    	  Repeat
    	  Ch:=Readkey;
    	  if (Ch in [#48,#49]) then
    	                                            Begin
    	                                            if (Ch = #48) then Types:=('Телефон');
    	                                            if (Ch = #49) then Types:=('Смартфон');
    	                                            end
    	                                     else
    	                                            Begin
    	                                            TextColor(Red); Writeln(' ОШИБКА: Неверный диапазон! Повторите ввод...')
    	                                            end;
              Until (Ch in [#48,#49]);
    
              TextColor(Cyan); Write(' Тип аппарата: ');TextColor(Yellow); Writeln(Types); Line;
              TextColor(Cyan); Write(' Производитель: '); TextColor(Yellow); Readln(Maker);
              TextColor(Cyan); Write(' Модель: '); TextColor(Yellow); Readln(Model);
              Line;
    
              TextColor(Cyan); Writeln(' Выберите тип корпуса: '); TextColor(White);
              Writeln(' [0-Классический | 1-Раскладной | 2-Слайдер]');
              
              Repeat
              Ch:=Readkey;
              if (Ch in [#48..#50]) then
    	                                              Begin
    	                                              if (Ch = #48) then Body:=('Классический');
    	                                              if (Ch = #49) then Body:=('Раскладной');
    	                                              if (Ch = #50) then Body:=('Слайдер');
    	                                              end
    		                              else
    	                                              Begin
    	                                              TextColor(Red); Writeln(' ОШИБКА: Неверный диапазон! Повторите ввод...')
    	                                              end;
              Until (Ch in [#48..#50]);
    
              TextColor(Cyan); Write(' Тип корпуса: ');TextColor(Yellow); Writeln(Body); Line;
    
              TextColor(Cyan); Writeln(' Выберите операционную систему: '); TextColor(White);
              Writeln(' [0-Asha | 1-Android | 2-Bada OS | 3-iOS | 4-Symbian ]');
    	  Writeln(' [5-Windows Phone 7 | 6-Windows Phone 8 | 7-Другая]');
    	 
              Repeat
    	  Ch:=Readkey;
    	  if (Ch in [#48..#55]) then
    	                                              Begin
    	                                              if (Ch = #48) then Os:=('Asha');
    	                                              if (Ch = #49) then Os:=('Android');
    	                                              if (Ch = #50) then Os:=('Bada OS');
    	                                              if (Ch = #51) then Os:=('iOS');
    	                                              if (Ch = #52) then Os:=('Symbian');
    	                                              if (Ch = #53) then Os:=('Windows Phone 7');
    	                                              if (Ch = #54) then Os:=('Windows Phone 8');
    	                                              if (Ch = #55) then Os:=('Другая');
    	                                              end
    		                              else
    	                                              Begin
    	                                              TextColor(Red); Writeln('ОШИБКА: Неверный диапазон! Повторите ввод...')
    	                                              end;
              Until (Ch in [#48..#55]);
              TextColor(Cyan); Write(' Операционная система: ');TextColor(Yellow); Writeln(Os); Line;
    
              TextColor(Cyan); Write(' Цена: '); TextColor(Yellow); Readln(Price);
    end;
    LastGlobalMenu; {Возврат в основное меню}
    end;

    Serjant, 22 Апреля 2014

    Комментарии (0)
  6. Pascal / Говнокод #15761

    +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
    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
    function thttp.Get(URI: string): string;
    var
      newlocation:string;
      redirect:integer;
      contenttype:string;
      i:integer;
      contentencoding:string;
      test:string;
      host:string;
    begin
      redirect:=0;
      headers.clear;
      document.clear;
    
      uri:=stringreplace(uri,'\','/',[rfreplaceall]);
    
      // building the host///
      if request.host <> '' then
      headers.Add(format('Host:%s',[request.host]))
      else
      begin
        i:=pos('://',uri);
        if i>0 then
        begin
          host:=copy(uri,i+3,maxint);
          i:=pos('/',host);
          if i>0 then
          host:=copy(host,1,i-1);
          request.host:=host;
        end
        else
        begin
          i:=pos('/',uri);
          if i>0 then host:=copy(uri,1,i-1)
          else
          host:=uri;
          request.host:=host;
        end;
      end;
    
      if request.referer <> '' then
      headers.Add(format('Referer:%s',[request.referer]));
    
      if request.useragent <> '' then
      headers.Add(format('User-Agent:%s',[request.useragent]));
    
      if request.AcceptEncoding <> '' then
      headers.Add(format('Accept-Encoding:%s',[request.AcceptEncoding]));
    
      if request.contenttype <> '' then
      headers.Add('Content-Type:'+request.contenttype);
    
      if request.connection <> '' then
      headers.add('Connection:'+request.connection);
    
      HTTPMethod('GET',uri);
    
      if allowredirects=true then
      begin
        while (resultcode>=300) and (resultcode<400) do
        begin
          if (maxredirects <> -1) and (redirect > self.MaxRedirects) then break;
          document.clear;
          newlocation:=trim(Headers.Values['Location']);
          if newlocation='' then break;
          if (rightstr(request.host,1) <> '/') and (copy(newlocation,1,1) <> '/') then
          newlocation:='/'+newlocation;
          headers.clear;
          document.clear;
          HTTPMethod('GET',host+newlocation);
          host:=trim(headers.Values['host']);
          if host <> '' then
          request.host:=host;
          inc(redirect);
        end;
      end;
      contenttype:=Headers.Values['Content-Type'];
      contentencoding:=Headers.Values['Content-Encoding'];
      request.contentencoding:=contentencoding;
      request.contenttype:=contenttype;
      if pos('gzip',ansilowercase(contentencoding))>0 then
      begin
        mstream.clear;
        try
          GZDecompressStream(Document, MStream);
          document.Clear;
          document.LoadFromStream(mstream);
          document.Position:=0;
        except
        end;
      end;
      result:=memorystreamtostring(Document);
      if pos('charset=utf-8',ansilowercase(contenttype))>0 then
      test:=utf8toansi(result);
      if test <> '' then
      result:=test;
    end;

    У Булгакова есть цикл рассказов "Записки на манжетах".
    Мой цикл называется "Записки на туалетной бумаге салфетках".

    Итак, "Записки на салфетках. Как я обертывал Synapse".

    brutushafens, 16 Апреля 2014

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

    +80

    1. 1
    2. 2
    if (!getBaseContext().getResources().getConfiguration().locale.getLanguage().equals(((ApplicationController)getApplication()).lang) )
    ((ApplicationController)getApplication()).setLocale(((ApplicationController)getApplication()).lang);

    Ехал дроид через дроид, видит дроид дроид дроид

    govnozmey, 16 Января 2014

    Комментарии (8)
  8. Pascal / Говнокод #14318

    +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
    procedure WriteString(ST: Ansistring);
    var
      leng: dword;
      I: dword;
      ss: Ansistring;
      stk: Ansistring;
    begin
      leng := Length(ST);
      for I := 1 to leng do
      begin
        ss := Copy(ST, I, 1);
        stk := stk + ss;
      end;
      filestream1.Write(stk[1], Length(stk));
    end;

    Процедура записи строки в файл.
    Использование:

    var
    filestream1: TfileStream;

    begin
    filestream1 := TfileStream.Create('file.dat', fmcreate);
    WriteString('bla bla bla');
    filestream1.Destroy;
    end;

    ka3ax, 06 Января 2014

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

    +80

    1. 1
    new

    TarasB, 13 Ноября 2013

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

    +80

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    ...
    SomeObject o = null;
    try {
        o = someGetOperation();
    } catch (Exception e) {}
    
    try {
        o.doSomeMethod();
        ...
    } catch (Exception e) {}
    ...

    1. второй try/catch это просто защита от NPE, который возникнет, если не прошел первый try
    2. catch-секции приведены как они есть в проекте - пустые и ловится всегда Exception

    в 95% проекта (>1000 классов) используются такие конструкции

    tir, 02 Октября 2013

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

    +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
    /**
       * Форматирует double, c arround кол-вом знаков после запятой
       * @param d double
       * @param arround int
       * @return String
       */
      public static String formatDouble(double d, int arround) {
        if (arround > 6) {
          throwIllegalFormat();
        }
        StringBuffer sb = new StringBuffer(10);
        boolean minus = d < 0;
        if (minus) {
          d = -d;
        }
        for (int i = 0; i < arround; i++) {
          d *= 10;
        }
        long l = (long) (d + 0.000000001);
        do {
          char digit = (char) ('0' + (l % 10));
          l = l / 10;
          sb.append(digit);
          if (--arround == 0) {
            sb.append('.');
          }
        } while (l != 0 || arround >= 0);
        if (minus) {
          sb.append('-');
        }
        return sb.reverse().toString();
      }

    glprizes, 02 Октября 2013

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