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

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

    +68

    1. 1
    2. 2
    char *GetNumRenderedObjectsString() { char *mString = new char [128]; itoa (mNumRenderedObjects, mString, 10); return mString; };
    char *GetNumDiscardedObjectsString() { char *mString = new char [128]; itoa (mNumDiscardedObjects, mString, 10); return mString; };

    Отличная работа с памятью.

    benin, 25 Октября 2009

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

    +126.6

    1. 1
    2. 2
    3. 3
    4. 4
    if (websites.Any() && websites.Count() > 1)
    {
    ....
    }

    Без комментариев

    AndrewK, 20 Октября 2009

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

    +139

    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
    // export in csv - part of the code
    // ...
                foreach (users_view _item in _users_view)
                {
                    _writer.Write(String.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}{0}{8}{0}{9}{0}{10}{0}{11}{0}{12}{0}{13}{0}{14}{0}{15}{0}{16}{0}{17}{0}{18}{0}{19}{0}{20}{0}{21}{0}{22}{0}{23}{0}{24}\n",
                        AppSettingsReader.GetValue("CSVFileSeparator"),
                         @"""" + _item.title_name + @"""", @"""" + _item.first_name + @"""",
                         @"""" + _item.last_name + @"""", @"""" + _item.job_title + @"""",
                        @"""" + _item.user_type_name + @"""",
                                                
                        @""""+_item.company_name+@"""",
                        (_item.telephone != null) ? (@"""" + _item.telephone + @"""") : (""),
                        (_item.fax != null) ? (@"""" + _item.fax + @"""") : (""),
                        @"""" + _item.email + @"""",
                        (_item.account_email != null) ? (@"""" + _item.account_email + @"""") : (""),
                        @"""" + _item.site_address + @"""",
                        @"""" + _item.advertisement_source_name+@"""",
    
                        @"""" + _item.address_1+@"""",
                        (_item.address_2 != null) ? (@"""" + _item.address_2+@"""") : (""),
                        @"""" + _item.country_name+@"""",
                       
                        //_item.email_format_name,
    
                        (_item.postcode != null) ? (@"""" + _item.postcode+@"""") : (""),
                        (_item.county != null) ? (@"""" + _item.county+@"""") : (""),
                        @"""" + _item.town + @"""",
                    //    (_item.is_active == false) ? ("No") : ("Yes"),
    
                        @"""" + _item.username+@"""",
                        @"""" + _item.password+@"""",
                        @"""" + _item.account_type_name + @"""",
    
                        @"""" + _item.creation_date + @"""",
    
                        (_item.is_newsletter_subscriber == false) ? ("No") : ("Yes"),
                        (_item.is_marketing_subscriber == false) ? ("No") : ("Yes")
                        )
                    );
                }

    Вот что нашел :)

    bugotrep, 14 Октября 2009

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

    +81.4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public void checkClass(Object target){
            if (!target.getClass().toString().contains("myBuilder")){
                throw new IllegalArgumentException("Передан объект неверного типа");
            }
        }

    instanceof - это для трусов!

    Jk, 14 Октября 2009

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

    +157

    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
    <?php
        public function run()
        {
            $db = Registry::get('Db');
    
            $db->transaction(Db_Database::START);
    
            $success = $db->query()->update()
                ->table('forum_topics')
                ->set('PostsCount = PostsCount - 1')
                ->set('LastPostID = ('
                    . $db->query()
                        ->select()->fields('ID')
                        ->table('forum_posts')->order('ID', 1) // DESC
                        ->where('TopicID = %d', $this->post->topic->id)
                        ->limit(1)->compile()->getQuery()
                    . ')')
                ->set('FirstPostID = ('
                    . $db->query()
                        ->select()->fields('ID')
                        ->table('forum_posts')->order('ID')
                        ->where('TopicID = %d', $this->post->topic->id)
                        ->limit(1)->compile()->getQuery()
                    . ')')
                ->where('ID = %d', $this->post->topic->id)
                ->compile()->run()->success()
            && $db->query()->update()
                ->table('forum_cats')
                ->set('PostsCount = PostsCount - 1')
                ->set('LastTopicID = ('
                    . $db->query()
                        ->select()->fields('ID')
                        ->table('forum_topics')->order('LastPostID', 1) // DESC
                        ->where('CatID = %d', $this->post->topic->category->id)
                        ->limit(1)->compile()->getQuery()
                    . ')')
                ->where('ID = %d', $this->post->topic->category->id)
                ->compile()->run()->success()
            && $db->query()->update()
                ->table('forum_posts')
                ->set('Deleted = 1')
                ->where('ID = %d', $this->post->id)
                ->compile()->run()->success();
            $db->transaction($success ? Db_Database::COMMIT : Db_Database::ROLLBACK);
            return $success;
        }

    Вот такая вот жесть бывает. Изменение счетчиков на форуме (денормализация) с использованием альфа-версии кверибилдера. по-моему — устрашающе)

    Shock, 13 Октября 2009

    Комментарии (7)
  7. PHP / Говнокод #1960

    +154.8

    1. 1
    2. 2
    3. 3
    4. 4
    final class Graph extends DefaultModule implements IModule {
    ..........
    	protected function getDataByDate() {
    ..........

    Интересно, какой скрытый смысл protected-метода в final-классе...

    darkmyan, 12 Октября 2009

    Комментарии (7)
  8. JavaScript / Говнокод #1956

    +161.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
    14. 14
    15. 15
    //проверка на браузер
    
    var brname=navigator.appName, BrVer='';
    if(brname.substring(0,2)=="Mi")
        BrVer='E';
    
    //реализация
     function showElement(elName)
    {
        if(BrVer!='E') return; //не осёл? и пошли нафиг!
        for (i = 0; i < document.all.tags(elName).length; i++)
        {
            //блаблабла
        }
    }

    типа выпадающее меню. типа только для IE.

    Ad_Astra, 12 Октября 2009

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

    +56.4

    1. 1
    if (tlb[i].VPN2 == 0x70000000) return; //uh uhh right ...

    Из исходника pcsx2 (эмулятор PS2):
    http://code.google.com/p/pcsx2/source/browse/trunk/pcsx2/COP0.cpp?r=1970

    Thomas_55, 06 Октября 2009

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

    +107.9

    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
    if l<9
     then
      if r<10
       then
        s:= inttostr(l)
       else
        s:= '10'
     else
      if l<99
       then
        if r<100
         then
          s:= inttostr(l)
         else
          s:= '100'
       else
        if l<999
         then
          if r<1000
           then
            s:= inttostr(l)
           else
            s:= '1000'
         else
          if l<9999
           then
            if r<10000
             then
              s:= inttostr(l)
             else
              s:= '10000'
           else
            if l<99999
             then
              if r<100000
               then
                s:= inttostr(l)
               else
                s:= '100000'
             else
              if l<999999
               then
                if r<1000000
                 then
                  s:= inttostr(l)
                 else
                  s:= '1000000'
               else
                if l<9999999
                 then
                  if r<10000000
                   then
                    s:= inttostr(l)
                   else
                  s:= '10000000'
                 else
                  if l<99999999
                   then
                    if r<100000000
                     then
                      s:= inttostr(l)
                     else
                      s:= '100000000'
                   else
                    if l<999999999
                     then
                      if r<1000000000
                       then
                        s:= inttostr(l)
                       else
                        s:= '1000000000';

    Нашёл в своём решении какой-то олимпиадной задачи. Долго пытался вспомнить, в каком состоянии был...

    Сан Саныч, 05 Октября 2009

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

    +137.3

    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
    private ArrayList GetSubscribers(string condition)
            {
               ArrayList subscribers = new ArrayList();
               ArrayList lst =  new user_category_notification().Factory.GetItems(condition, "user_category_notification.id_user");
                ArrayList distinc_lst = new ArrayList();
                ArrayList distinc_lst_ids = new ArrayList();
                ArrayList lst_ids = new ArrayList();
                for (int i = 0; i < lst.Count; i++)
                {
                    lst_ids.Add(((user_category_notification) lst[i]).id_user);
                }
                for (int i = 0; i < lst_ids.Count;i++ )
                {
                    if (distinc_lst_ids.Contains(lst_ids[i])) continue;
                    else
                    {
                        distinc_lst.Add(lst[i]);
                        distinc_lst_ids.Add(lst_ids[i]);
                    }
                }
                foreach (user_category_notification _un in distinc_lst)
                {
                    user _current = (user)new user().Factory.GetByID(_un.id_user);
                    subscribers.Add(_current);
                }
                
                return subscribers;
            }

    Филтрация :)

    bugotrep, 02 Октября 2009

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