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

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

    −1

    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
    template <typename T> 
    void doSomething(const T& i_field, unsigned int i_offset)
    {
       ...
    }
    
    template <> 
    void doSomething<Boo>(const Boo& i_field, unsigned int i_offset)
    {
       doSomething(i_field.aaa, i_offset + offsetof(Boo, aaa));
       doSomething(i_field.bbb, i_offset + offsetof(Boo, bbb));
       doSomething(i_field.ccc, i_offset + offsetof(Boo, ccc));
    }
    
    ...
    
    template <class T, typename S>
    void addSomething(S T::* i_pField)
    {
       const T* pR = 0;
       const unsigned int offset = (unsigned int)&(pR->*i_pField);
       doSomething(pR->*i_pField, offset);
    }

    Увидел вот такой код (рабочий!) в одном довольно крупном проекте.

    -Eugene-, 25 Декабря 2015

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

    +5

    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
    namespace ConsoleApplication
    {
        public static class Program
        {
            private static void Main( string[] args )
            {
                new Random().Next( -100, 100 )
                    .Execute( x => Console.Write( $"{x} это " ) )
                    .IfElse( x => x % 2 == 0, () => Console.Write( "четное " ), () => Console.Write( "нечетное " ) )
                    .Execute( () => Console.Write( "число " ) )
                    .IfElse( x => x > 0, () => Console.Write( "больше " ), () => Console.Write( "меньше " ) )
                    .Execute( () => Console.Write( "нуля" ) )
                    .Execute( () => Console.WriteLine() );
            }
        }
    }

    вывод в консоли (прим.): "-88 это четное число меньше нуля"

    Адские экстеншены

    anweledig, 14 Декабря 2015

    Комментарии (12)
  4. JavaScript / Говнокод #18962

    +2

    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
    var data = [];
    if(!Ext.isEmpty(val[i][Object.keys(value[i])[0]])) {
     data['duration'] = val[i][Object.keys(value[i])[0]]['duration'];
     data['count'] = val[i][Object.keys(value[i])[0]]['count'];
     data['acd'] = val[i][Object.keys(value[i])[0]]['acd'];
     data['asr'] = val[i][Object.keys(value[i])[0]]['asr'];
    } else {
     data['duration'] = '';
     data['count'] = '';
     data['acd'] = '';
     data['asr'] = '';
    }
    i++;
    if(i>=val.length) {
     i = 0;
    }
    return tpl.apply(data);

    user-dob, 03 Ноября 2015

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

    −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
    #include <stdio.h>
    #include <string.h>
    
    static struct foo {
    
    } fooo;
    
    int main(void)
    {
        int peace_of_shit = 0xFF;
        memcpy(&fooo, &dream, sizeof(peace_of_shit));
        **/Хочу увидеть говно**/
        return 0;
    }

    Как я могу увидеть говно, что лежит в fooo?)

    MiD, 09 Октября 2015

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

    +11

    1. 1
    2. 2
    3. 3
    4. 4
    for ($i = 0; $i < 11; $i++) {
        if ($i < 5) continue;
        //остальной код
    }

    первые 5 не нужны

    kropotor, 16 Сентября 2015

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

    +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
    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
    public function isMobile()
    {
        // ...
    
        if (in_array (strtolower (substr ($user_agent, 0, 4)), array (
            '1207' => '1207', '3gso' => '3gso', '4thp' => '4thp', '501i' => '501i', '502i' => '502i', '503i' => '503i', '504i' => '504i',
            '505i' => '505i', '506i' => '506i', '6310' => '6310', '6590' => '6590', '770s' => '770s', '802s' => '802s', 'a wa' => 'a wa',
            'acer' => 'acer', 'acs-' => 'acs-', 'airn' => 'airn', 'alav' => 'alav', 'asus' => 'asus', 'attw' => 'attw', 'au-m' => 'au-m',
            'aur ' => 'aur ', 'aus ' => 'aus ', 'abac' => 'abac', 'acoo' => 'acoo', 'aiko' => 'aiko', 'alco' => 'alco', 'alca' => 'alca',
            'amoi' => 'amoi', 'anex' => 'anex', 'anny' => 'anny', 'anyw' => 'anyw', 'aptu' => 'aptu', 'arch' => 'arch', 'argo' => 'argo',
            'bell' => 'bell', 'bird' => 'bird', 'bw-n' => 'bw-n', 'bw-u' => 'bw-u', 'beck' => 'beck', 'benq' => 'benq', 'bilb' => 'bilb',
            'blac' => 'blac', 'c55/' => 'c55/', 'cdm-' => 'cdm-', 'chtm' => 'chtm', 'capi' => 'capi', 'cond' => 'cond', 'craw' => 'craw',
            'dall' => 'dall', 'dbte' => 'dbte', 'dc-s' => 'dc-s', 'dica' => 'dica', 'ds-d' => 'ds-d', 'ds12' => 'ds12', 'dait' => 'dait',
            'devi' => 'devi', 'dmob' => 'dmob', 'doco' => 'doco', 'dopo' => 'dopo', 'el49' => 'el49', 'erk0' => 'erk0', 'esl8' => 'esl8',
            'ez40' => 'ez40', 'ez60' => 'ez60', 'ez70' => 'ez70', 'ezos' => 'ezos', 'ezze' => 'ezze', 'elai' => 'elai', 'emul' => 'emul',
            'eric' => 'eric', 'ezwa' => 'ezwa', 'fake' => 'fake', 'fly-' => 'fly-', 'fly_' => 'fly_', 'g-mo' => 'g-mo', 'g1 u' => 'g1 u',
            'g560' => 'g560', 'gf-5' => 'gf-5', 'grun' => 'grun', 'gene' => 'gene', 'go.w' => 'go.w', 'good' => 'good', 'grad' => 'grad',
            'hcit' => 'hcit', 'hd-m' => 'hd-m', 'hd-p' => 'hd-p', 'hd-t' => 'hd-t', 'hei-' => 'hei-', 'hp i' => 'hp i', 'hpip' => 'hpip',
            'hs-c' => 'hs-c', 'htc ' => 'htc ', 'htc-' => 'htc-', 'htca' => 'htca', 'htcg' => 'htcg', 'htcp' => 'htcp', 'htcs' => 'htcs',
            'htct' => 'htct', 'htc_' => 'htc_', 'haie' => 'haie', 'hita' => 'hita', 'huaw' => 'huaw', 'hutc' => 'hutc', 'i-20' => 'i-20',
            'i-go' => 'i-go', 'i-ma' => 'i-ma', 'i230' => 'i230', 'iac' => 'iac', 'iac-' => 'iac-', 'iac/' => 'iac/', 'ig01' => 'ig01',
            'im1k' => 'im1k', 'inno' => 'inno', 'iris' => 'iris', 'jata' => 'jata', 'java' => 'java', 'kddi' => 'kddi', 'kgt' => 'kgt',
            'kgt/' => 'kgt/', 'kpt ' => 'kpt ', 'kwc-' => 'kwc-', 'klon' => 'klon', 'lexi' => 'lexi', 'lg g' => 'lg g', 'lg-a' => 'lg-a',
            'lg-b' => 'lg-b', 'lg-c' => 'lg-c', 'lg-d' => 'lg-d', 'lg-f' => 'lg-f', 'lg-g' => 'lg-g', 'lg-k' => 'lg-k', 'lg-l' => 'lg-l',
            'lg-m' => 'lg-m', 'lg-o' => 'lg-o', 'lg-p' => 'lg-p', 'lg-s' => 'lg-s', 'lg-t' => 'lg-t', 'lg-u' => 'lg-u', 'lg-w' => 'lg-w',
            'lg/k' => 'lg/k', 'lg/l' => 'lg/l', 'lg/u' => 'lg/u', 'lg50' => 'lg50', 'lg54' => 'lg54', 'lge-' => 'lge-', 'lge/' => 'lge/',
            'lynx' => 'lynx', 'leno' => 'leno', 'm1-w' => 'm1-w', 'm3ga' => 'm3ga', 'm50/' => 'm50/', 'maui' => 'maui', 'mc01' => 'mc01',
            'mc21' => 'mc21', 'mcca' => 'mcca', 'medi' => 'medi', 'meri' => 'meri', 'mio8' => 'mio8', 'mioa' => 'mioa', 'mo01' => 'mo01',
            'mo02' => 'mo02', 'mode' => 'mode', 'modo' => 'modo', 'mot ' => 'mot ', 'mot-' => 'mot-', 'mt50' => 'mt50', 'mtp1' => 'mtp1',
            'mtv ' => 'mtv ', 'mate' => 'mate', 'maxo' => 'maxo', 'merc' => 'merc', 'mits' => 'mits', 'mobi' => 'mobi', 'motv' => 'motv',
            'mozz' => 'mozz', 'n100' => 'n100', 'n101' => 'n101', 'n102' => 'n102', 'n202' => 'n202', 'n203' => 'n203', 'n300' => 'n300',
            'n302' => 'n302', 'n500' => 'n500', 'n502' => 'n502', 'n505' => 'n505', 'n700' => 'n700', 'n701' => 'n701', 'n710' => 'n710',
            'nec-' => 'nec-', 'nem-' => 'nem-', 'newg' => 'newg', 'neon' => 'neon', 'netf' => 'netf', 'noki' => 'noki', 'nzph' => 'nzph',
            'webc' => 'webc', 'whit' => 'whit', 'winw' => 'winw', 'wmlb' => 'wmlb', 'xda-' => 'xda-'
        ))) {
            return true;
        }
        return false;
    }

    Я правда не знаю что это ваще и зачем.

    creaturemyst, 03 Сентября 2015

    Комментарии (12)
  8. Си / Говнокод #18535

    +973

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    /* */
            int fooBar() {
                /* do something */
    
    /* - */     return NULL;
    /* + */     return 0ULL;
            }

    > src/foobar.c:42:3: warning: return makes integer from pointer without a cast
    > return NULL;

    П О Ч И Н Е Н О

    #17766

    Elvenfighter, 26 Июля 2015

    Комментарии (12)
  9. PHP / Говнокод #18348

    +144

    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
    // Класс валидации в PrestaShop
    class ValidateCore
    {
    ...
    	public static function isIp2Long($ip)
    	{
    		return preg_match('#^-?[0-9]+$#', (string)$ip);
    	}
    
    	public static function isAnything()
    	{
    		return true;
    	}
    ...

    invision70, 16 Июня 2015

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

    +142

    1. 1
    2. 2
    #define ns 7
    #define nfio 15

    Клевый стиль определения глобальных констант

    KGOH, 17 Мая 2015

    Комментарии (12)
  11. JavaScript / Говнокод #18109

    +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
    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
    function num_to_sxg($n) {
     $s = "";
     $m = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz";
     if ($n===undefined || $n===0) { return 0; }
     while ($n>0) {
       $d = $n % 60;
       $s = strcat($m[$d],$s);
       $n = ($n-$d)/60;
     }
     return $s;
    }
    
    function num_to_sxgf($n, $f) {
     $s = num_to_sxg($n);
     if ($f===undefined) { 
       $f=1; 
     }
     $f -= strlen($s);
     while ($f > 0) { 
       $s = strcat("0",$s); 
       --$f; 
     }
     return $s;
    }
    
    function sxg_to_num($s) {
     $n = 0;
     $j = strlen($s);
     for ($i=0;$i<$j;$i++) { // iterate from first to last char of $s
       $c = ord($s[$i]); //  put current ASCII of char into $c  
       if ($c>=48 && $c<=57) { $c=$c-48; }
       else if ($c>=65 && $c<=72) { $c-=55; }
       else if ($c==73 || $c==108) { $c=1; } // typo capital I, lowercase l to 1
       else if ($c>=74 && $c<=78) { $c-=56; }
       else if ($c==79) { $c=0; } // error correct typo capital O to 0
       else if ($c>=80 && $c<=90) { $c-=57; }
       else if ($c==95) { $c=34; } // underscore
       else if ($c>=97 && $c<=107) { $c-=62; }
       else if ($c>=109 && $c<=122) { $c-=63; }
       else { $c = 0; } // treat all other noise as 0
       $n = 60*$n + $c;
     }
     return $n;
    }

    Угадайте, какой это язык и что пил автор.

    http://ideone.com/87cVrr

    http://ideone.com/Z8j7ve

    solnze_dar, 02 Мая 2015

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