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

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

    −395

    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
    + (NSArray *)orderDBFilePaths:(NSArray *)paths {
        NSMutableDictionary *dictionary = [NSMutableDictionary new];
        
        for (NSString *path in paths) {
            if ([path hasSuffix:@"-shm"]) {
                [dictionary setObject:path forKey:@2];
            } else if ([path hasSuffix:@"-wal"]) {
                [dictionary setObject:path forKey:@1];
            } else {
                [dictionary setObject:path forKey:@0];
            }
        }
        
        return @[dictionary[@0], dictionary[@1], dictionary[@2]];
    }

    Сортировка фалов *.sqlite* в порядке *.sqlite, *.sqlite-wal, *.sqlite-shm для бэкапа правильного рестора бэкапа в коде 4х летней давности.

    Drenwtc, 18 Июня 2015

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

    +143

    1. 1
    2. 2
    3. 3
    4. 4
    public static bool IsEmpty(this string input)
            {
                return String.IsNullOrEmpty(input);
            }

    А почему бы и да?

    alexCoder2007, 17 Июня 2015

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

    −89

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public class Klass_vzaimosvyazey
    {
          static public var panel_sloyev:*;                        //Ссылка на объект содержащий: "Панель Слоев".
          static public var kontyeiner_vizualizatsii:*;     //Ссылка на объект содержащий: "Контейнер Визуализации"
          ...
          static public var ispolzovaniye_kombinatsii_reguliruyushchego_klapana_i_regulyatora_perepada_davleniya:Object = { znacheniye: "Не использовать" };
          static public var ispolzovaniye_elektroprivoda_s_vozvratnoy_pruzhinoy_GVS:Object = { znacheniye: "Нет" };
          static public var ispolzovaniye_elektroprivoda_s_vozvratnoy_pruzhinoy_SO_SV:Object = { znacheniye: "Нет" };

    В программе есть класс, который хранит вот такие вот штуки. Видимые отовсюду в коде. Их сотни. Вот с такими названиями. Хранят вот такое. Есть нетипизированные.

    Инкапсуляция? Не, не слышал. Строгая типизация? Да ладно - зачем?

    teoadal, 11 Июня 2015

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

    +165

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $claimAboutBlackout = false;
    foreach ($blackouts as $blackout) {
        if ($claimAboutBlackout = $claim->getType() === $blackout->getType() ? true : false) {
            break;
        }
    }
    return $claimAboutBlackout;

    Нашли в одном из проектов.

    bit0rez, 08 Июня 2015

    Комментарии (5)
  6. Си / Говнокод #18238

    +140

    1. 1
    2. 2
    3. 3
    4. 4
    /*
     * To the unenlightened: This sets the X (where X is variable between calls) LSB's of mask to 1.
     */
    mask = ~(~0 << X);

    Байтопроблемушки. Me gusta.

    codemonkey, 27 Мая 2015

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

    +143

    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
    /* Example libCello Program */
    
    #include "Cello.h"
    
    int main(int argc, char** argv) {
    
      /* Stack objects are created using "$" */
      var int_item = $(Int, 5);
      var float_item = $(Real, 2.4);
      var string_item = $(String, "Hello");
    
      /* Heap objects are created using "new" */
      var items = new(List, int_item, float_item, string_item);
    
      /* Collections can be looped over */
      foreach (item in items) {
        /* Types are also objects */
        var type = type_of(item);
        print("Object %$ has type %$\n", item, type);
      }
    
      /* Heap objects destroyed with "delete" */
      delete(items); 
    }

    http://libcello.org/

    dxd, 22 Мая 2015

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

    +145

    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
    this.serializeParams = function(params) {                                                                 
            var serialize = [];                                                                                   
            var buildParameters = function (parameters) {                                                         
                var result = {};                                                                                  
                if(typeof parameters == "object") {                                                               
                    for(var param in parameters) {                                                                
                        if(!parameters.hasOwnProperty(param)) {                                                   
                            continue;                                                                             
                        }                                                                                         
                        result[param] = buildParameters(parameters[param]);                                       
                    }                                                                                             
                }                                                                                                 
                if(typeof parameters == "string") {                                                               
                    return parameters;                                                                            
                }                                                                                                 
                return result;                                                                                    
            };                                                                                                    
            console.log(buildParameters(params));                                                                 
            for (var param in params) {                                                                           
                if(!params.hasOwnProperty(param)) {                                                               
                    continue;                                                                                     
                }                                                                                                 
                buildParameters(params[param]);                                                                   
                serialize.push(param + '=' + params[param]);                                                      
            }                                                                                                     
            if (serialize.length === 0) {                                                                         
                return '';                                                                                        
            }                                                                                                     
            return (this.options.method === "GET" ? "?" : "") + serialize.join('&');                              
        };

    В голове выглядело все идеально а получилось что то типа
    for(var i = 0; i < 1e10; i++) { continue; } // бесполезная работа

    LarexSetch, 22 Мая 2015

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

    +146

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    if((pDir = opendir(pchPath)) != NULL)
    {
        strcpy(chBuffer, pchPath);
        strcat(chBuffer, "/");
        while((pTemp == NULL) && ((pDirent = readdir(pDir)) != NULL))
        {
            if(((pChar = strstr(pDirent->d_name, Info.pchFilePrefix)) == pDirent->d_name) &&
               ((pChar = strstr(pDirent->d_name, Info.pchFileExtension)) != NULL)  &&
               (pChar[strlen(Info.pchFileExtension)] == '\0'))
            {
                sprintf(strrchr(chBuffer, '/') + 1, "%s", pDirent->d_name);

    лаконичные программисты лаконично ходят по каталогам.

    Dummy00001, 21 Мая 2015

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

    +142

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    $act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';
    	
    	if ($act == 'details') {
    		orders_details();
    	} elseif ($act == 'details_xls') {
    		orders_details_xls();
    	} elseif ($act == 'set_status') {
    		orders_set_status();
    	// ... ещё строчек 30
    	} else {
    		orders_list();
    	}

    Так мы реализуем роутер

    Tairesh, 20 Мая 2015

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

    +142

    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
    foreach ($id as $k) {
    		//Помним, что меньший id всегда пишется первым
    		if ($firm_id < $k)
    			{ $a = 1; $b = 2; }
    		else
    			{ $a = 2; $b = 1; }
    			if ($_REQUEST['submit'] == 1) {
                                    //  ...
    			}
    			if ($_REQUEST['submit'] > 1) {
    				sql_query("UPDATE partners SET ".$type.$a.$b." = 1, firm{$a}_date = {$NOW} WHERE firm{$a} = $firm_id AND firm{$b} = $k");
                                    //  ...
    			}
    	}
    }

    А Вы знаете что будет если -1 отправить?)

    dimka3210, 19 Мая 2015

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