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

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

    0

    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
    public class Main {
      public static void uh() {
        try {
          
        } catch (Exception e) {
          throw e;
        }
      }
    
      // <no errors>
    
      public static void oh() {
        try {
          throw new RuntimeException();
        } catch (Exception e) {
          throw e;
        }
      }
    
      // <no errors>
    
      public static void snap() {
        try {
          throw new Exception();
        } catch (Exception e) {
          throw e;
        }
      }
    
      // /tmp/Main.java:8: error: unreported exception Exception; must be caught or declared to be thrown
      //       throw e;
      //       ^
      // 1 error
    }

    Где-то посередке между хорошим inference и остутствием интуитивности

    Fike, 20 Марта 2020

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

    +59

    1. 1
    2. 2
    3. 3
    4. 4
    std::transform( keyframes.begin(), keyframes.end(), std::back_inserter( result ),
          boost::bind( & qMakePair< KeyframeType::first_type, KeyframeType::second_type >,
             boost::bind( & Prm::TType::view, _1 ),
             boost::bind( & Prm::Time::value, boost::bind( & Prm::TType::time, _1 ) ) ) );

    boost bind головного мозга

    QBatman, 24 Сентября 2014

    Комментарии (143)
  4. Куча / Говнокод #16549

    +128

    1. 1
    2. 2
    isParallel :: Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Integer -> Bool
    isParallel x1 y1 x2 y2 x3 y3 x4 y4 = if (((x1-x2)*(y3-y4)-(y1-y2)*(x3-x4)) == 0) then True else False

    лаба по хаски
    параллельны ли 2 прямые?

    kegdan, 16 Августа 2014

    Комментарии (143)
  5. Куча / Говнокод #16305

    +138

    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
    Викиучебник по хаскелю такой викиучебник
    
    Задание - написать frequency — функция, возвращающая список пар (символ, частота). Каждая пара определяет атом из заданного списка и частоту его вхождения в этот список.
    
    Решение 
    
    frequency :: [a] -> [(a : Integer)]
    frequency l = f [] l
    
    f :: [a] -> [a] -> [(a : Integer)]
    f l []    = l
    f l (h:t) = f (corrector h l) t
    
    corrector :: a -> [a] -> [(a : Integer)]
    corrector a []      = [(a : 1)]
    corrector a (a:n):t = (a : (n + 1)) : t
    corrector a h:t     = h : (corrector a t)
    
    Логика-то верна, но код тупо не скомпилится. И как тут быть нубцу? 
    
    
    
    Задание - Описать следующие классы типов. При необходимости воспользоваться механизмом наследования классов.
    Show — класс, объекты экземпляров которого могут быть выведены на экран.
    
    Думаю что-то мегасложное, сделать самому руками show
    
    Решение 
     
    class Show a where
      show :: a -> String
    
    /-*)

    Викиучебник по хаскелю такой викиучебник

    kegdan, 11 Июля 2014

    Комментарии (143)
  6. Kotlin / Говнокод #26591

    0

    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
    enum class Measures {
        B, KB, MB, GB;
    
        private val size = BigDecimal.valueOf(1024L).pow(ordinal)
    
        companion object {
            fun toHumanSize(value: Long): String {
                val decValue = value.toBigDecimal()
                val measure = values().reversed().find { it.size < decValue } ?: B
                return "${decValue.divide(measure.size, 3, RoundingMode.UP)} $measure"
    
            }
        }
    }

    MAKAKA, 20 Апреля 2020

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

    +78

    1. 1
    2. 2
    3. 3
    wb.getApplication().run(macro, null, null, null, null, null, null, null, null, null, null, null,
            null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
            null, null, null, null);

    Использование библиотеки для взаимодействия с мелкософтовскими COM-объектами

    evg_ever, 02 Апреля 2014

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

    +165

    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
    function register()
    {
        if (!empty($_POST)) {
            $msg = '';
            if ($_POST['user_name']) {
                if ($_POST['user_password_new']) {
                    if ($_POST['user_password_new'] === $_POST['user_password_repeat']) {
                        if (strlen($_POST['user_password_new']) > 5) {
                            if (strlen($_POST['user_name']) < 65 && strlen($_POST['user_name']) > 1) {
                                if (preg_match('/^[a-z\d]{2,64}$/i', $_POST['user_name'])) {
                                    $user = read_user($_POST['user_name']);
                                    if (!isset($user['user_name'])) {
                                        if ($_POST['user_email']) {
                                            if (strlen($_POST['user_email']) < 65) {
                                                if (filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
                                                    create_user();
                                                    $_SESSION['msg'] = 'You are now registered so please login';
                                                    header('Location: ' . $_SERVER['PHP_SELF']);
                                                    exit();
                                                } else $msg = 'You must provide a valid email address';
                                            } else $msg = 'Email must be less than 64 characters';
                                        } else $msg = 'Email cannot be empty';
                                    } else $msg = 'Username already exists';
                                } else $msg = 'Username must be only a-z, A-Z, 0-9';
                            } else $msg = 'Username must be between 2 and 64 characters';
                        } else $msg = 'Password must be at least 6 characters';
                    } else $msg = 'Passwords do not match';
                } else $msg = 'Empty Password';
            } else $msg = 'Empty Username';
            $_SESSION['msg'] = $msg;
        }
        return register_form();
    }

    Из рассылки PHPWeekly: "A Clean and Secure Open Source PHP Login Script"
    https://github.com/panique/php-login/blob/master/0-one-file/index.php#L98

    Что-то уж очень сильно "Clean".

    brevis, 29 Августа 2013

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

    −136

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    sub parse_http_date($)
    {
    	my ($date)=@_;
    	my %months=(Jan=>0,Feb=>1,Mar=>2,Apr=>3,May=>4,Jun=>5,Jul=>6,Aug=>7,Sep=>8,Oct=>9,Nov=>10,Dec=>11);
    
    	if($date=~/^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) (\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$/)
    	{ return eval { timegm($6,$5,$4,$1,$months{$2},$3-1900) } }
    
    	return undef;
    }

    Вакаба.

    7ion, 28 Июля 2012

    Комментарии (142)
  10. Си / Говнокод #3599

    +142

    1. 1
    enum {size = 10, timeout = 50};

    vovochka, 30 Июня 2010

    Комментарии (142)
  11. Си / Говнокод #29120

    0

    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
    #include <stdio.h>
    #include <stddef.h>
    #include <stdlib.h>
    #include <limits.h>
    
    int gcc_rtm_virt_test(int a, int(*f)(int, int(*)(), float*), float fa[static (-1,0,1)]) {
        short s = sizeof (short) + sizeof 0;
        char b[12] = "0123456789";
    
        for (long ll = sizeof b; ll -= 4;) {
            b[ll]   = '0';
            b[ll-1] = '1';
            b[ll-2] = '2';
            b[ll-3] = '3';
        }
    
        return s - ((1 << 2) - (b[0] - '2'));
    }
    
    int gcc_rtm_cf32(int(*f0)(), int(*f1)()) {
        ptrdiff_t d = f1 - f0;
        // guess you know what you're doing
        if (! (d >> sizeof (ptrdiff_t) * CHAR_BIT - 1)) { 
            while (d--) {
                switch(*(unsigned short*)(f0 + d)) {
                    case 0xc3c9:
                        return 0;
                    case 0xb8:
                        if (!*(unsigned int*)(f0 + d + 1)) {
                            return 1;
                        } 
                        break;
                    case 0xC031:
                        return 2;
                }
            }
            return -1;
        };
    
        return -2;
    }
    
    int main() {
    
        switch (gcc_rtm_cf32(gcc_rtm_virt_test, gcc_rtm_cf32)) {
            case -1:
                fprintf(stderr, "Hey, added smth. special? Maybe -Og? \n"), abort();
                break;
            case 0:
                fprintf(stderr, "Hey, -O0 smells like a dead rat.. check your flags!\n"), abort();
                break;
            case 1:
                fprintf(stderr, "Hey, -O1 is still not allowed.. Would you do better?\n"), abort();
                break;
            case 2:
                fprintf(stdout, "Hey, finally you've captured [-O2 || -O3 || -Ofast || -Os] flag!");
                break;
            default:
                fprintf(stderr, "Hey, looks like you've got impl. defined crap, check PTRDIFF_T stuff.. \n"), abort();
                break;
        };
    
    }

    И далее по тексту..gcc'шники опять обкурились в рантайме. Зачэм так делоть, это прикольно?

    BCHARa, 10 Апреля 2025

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