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

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

    +69

    1. 1
    foos.removeAll(Collections.singleton(null));

    foos.remove(null)?не, не наш метод.

    Lure Of Chaos, 02 Августа 2013

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

    +109

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    static void Main()
    {
      int i = 0;
      Console.WriteLine(String.Format("{0} {1} {2}", i, i, i));
    }

    Я долго не видел там немного гoвна, но оказалось оно там есть

    taburetka, 02 Августа 2013

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

    −120

    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
    - (NSManagedObject *)entityForName:(NSString *)entityName withServerID:(NSString *)serverID inContext:(NSManagedObjectContext *)context
    {
        if ((entityName==nil) || ([entityName isEqualToString:@""]) || (serverID==nil) || ([serverID isEqualToString:@""]))
        {
            return nil;
        };
    
        NSFetchRequest *fr=[[NSFetchRequest alloc] init];
        [fr setEntity:[NSEntityDescription entityForName:entityName inManagedObjectContext:context]];
        [fr setPredicate:[NSPredicate predicateWithFormat:@"server_id == %@", serverID]];
        [fr setIncludesPropertyValues:YES];
        NSError *err;
        NSArray *res=[context executeFetchRequest:fr error:&err];
        if (err!=nil)
        {
            NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: an error occured while gathering objects. %@ | %@ | %@", err.localizedDescription, err.localizedFailureReason, err.localizedRecoverySuggestion);
            return nil;
        }
        else
        {
            if ([res count]<=0)
            {
                NSLog(@"[res count]<=0");
                //NSLog(@"PTDataFetchHelper: findEntity:%@ withServerID:%@ inContext: not found", entityName, serverID);
                return nil;
            }
            else if([res count]>1)
            {
                NSLog(@"PANIC: PTDataFetchHelper: entityWithName:serverID:inContext: unable to fetch single object. server_id uniqueness error");
                return nil;
            }
            else //[res count] == 1
            {
                return [res objectAtIndex:0];
            };
        };
    }

    Фетч

    stanislaw, 21 Июля 2013

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

    +148

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    $type = isset($config['type']) ? $config['type'] : 'default';
    switch($type) {
        default:
            $blockClass = 'adminhtml/widget_grid_massaction_item_additional_default';
            break;
    }

    Magento core

    crook, 18 Июля 2013

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

    +130

    1. 1
    2. 2
    3. 3
    Прокси-граббер
    
    http://rghost.ru/47337858

    Товарищи, попробуйте мой новый прокси-граббер! Это только эскиз, так что прошу строго не судить. Однопоточный. Парсит с 2 сайтов.

    Stertor, 10 Июля 2013

    Комментарии (20)
  7. Python / Говнокод #13209

    −102

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    a=[1,2,3,1,2,1,4]
     
    for i in a:
        if i is 1:
            zzz=222
        else:
            print zzz

    http://ideone.com/nhqqRU
    Сегодня весь день чинил странный баг, смысл которого сводится вот к такой синтетки.
    Притом если условие не выполниться на первой итерации http://ideone.com/G3Uf7V , то будет эксепшен.

    хуита, 21 Июня 2013

    Комментарии (20)
  8. PHP / Говнокод #13163

    +159

    1. 1
    <?php if( (!isset($post_id) ) || ( isset($post_id))  ) {	?>

    Одна платная Wordpress тема

    antongorodezkiy, 13 Июня 2013

    Комментарии (20)
  9. Perl / Говнокод #13127

    −172

    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
    sub company_stuff_add_array_elems
    {
            my $list = shift;
    
            my $count = 0;
    
            foreach ( @$list )
            {
                    $count += $_;
            }
    
            return $count;
    }

    List::Util::sum
    http://perldoc.perl.org/List/Util.html

    kainwinterheart, 07 Июня 2013

    Комментарии (20)
  10. Ruby / Говнокод #13027

    −89

    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
    def set_path
          if name && (!path || path == "/")
            self.path = self.parent.present? ? "#{self.parent.path}/#{name}" : "/#{name}"
          elsif !new_record? && name && path && name_was != name
            parts = path.split("/")
            parts.pop
            self.path = [parts.join("/"), name].join("/")
          elsif !new_record? && name && self.parent_id_changed?
            self.path = self.parent.present? ? "#{self.parent.path}/#{name}" : "/#{name}"
          elsif new_record? && name && path
            self.path = [path, name].join("/")
          end
    
          if path && self.parent.blank?
            parts = path.split("/")
    
            self.name = parts.pop
    
            parent_path = parts.join("/")
            if parent_path.blank? || parent_path == "/"
              self.parent = nil
            else
              possible_parent = site.asset_folders.find_by_path(parent_path)
              self.parent = possible_parent.present? ? possible_parent : self.class.create(path: parent_path, site: site)
            end
          end
          true
         end

    Как не нужно работать с путями в Rails-приложении. Это и еще примерно 500 строк было заменено на 11 строк кода, включая пустые.

    whitequark, 20 Мая 2013

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

    +10

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    static int
          _S_compare(size_type __n1, size_type __n2)
          {
      const difference_type __d = difference_type(__n1 - __n2);
    
      if (__d > __gnu_cxx::__numeric_traits<int>::__max)
        return __gnu_cxx::__numeric_traits<int>::__max;
      else if (__d < __gnu_cxx::__numeric_traits<int>::__min)
        return __gnu_cxx::__numeric_traits<int>::__min;
      else
        return int(__d);
          }

    LispGovno, 01 Мая 2013

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