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

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

    +2

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    /* ../COBYLA2/cobyla2.f -- translated by f2c (version 20100827) */
    ...
    /* Subroutine */ int cobyla_(integer *n, integer *m, doublereal *x, 
    	doublereal *rhobeg, doublereal *rhoend, integer *iprint, integer *
    	maxfun, doublereal *w, integer *iact)
    {
        static integer ia, idx, mpp, icon, isim, isigb, idatm, iveta, isimi, 
    	    ivsig, iwork;
        extern /* Subroutine */ int cobylb_(integer *, integer *, integer *, 
    	    doublereal *, doublereal *, doublereal *, integer *, integer *, 
    	    doublereal *, doublereal *, doublereal *, doublereal *, 
    	    doublereal *, doublereal *, doublereal *, doublereal *, 
    	    doublereal *, doublereal *, integer *);
        /* Parameter adjustments */
        --iact;
        --w;
        --x;
    
        /* Function Body */
        mpp = *m + 2;
        icon = 1;
        isim = icon + mpp;
        isimi = isim + *n * *n + *n;
        idatm = isimi + *n * *n;
        ia = idatm + *n * mpp + mpp;
        ivsig = ia + *m * *n + *n;
        iveta = ivsig + *n;
        isigb = iveta + *n;
        idx = isigb + *n;
        iwork = idx + *n;
        cobylb_(n, m, &mpp, &x[1], rhobeg, rhoend, iprint, maxfun, &w[icon], &w[
    	    isim], &w[isimi], &w[idatm], &w[ia], &w[ivsig], &w[iveta], &w[
    	    isigb], &w[idx], &w[iwork], &iact[1]);
        return 0;
    } /* cobyla_ */
    ...
    /* Subroutine */ int cobylb_(integer *n, integer *m, integer *mpp, doublereal 
    	*x, doublereal *rhobeg, doublereal *rhoend, integer *iprint, integer *
    	maxfun, doublereal *con, doublereal *sim, doublereal *simi, 
    	doublereal *datmat, doublereal *a, doublereal *vsig, doublereal *veta,
    	 doublereal *sigbar, doublereal *dx, doublereal *w, integer *iact)
    {
        /* Format strings */
        static char fmt_10[] = "(/3x,\002The initial value of RHO is\002,1pe13.6"
    	    ",2x,\002and PARMU is set to zero.\002)";
        static char fmt_50[] = "(/3x,\002Return from subroutine COBYLA because t"
    	    "he \002,\002MAXFUN limit has been reached.\002)";
        static char fmt_70[] = "(/3x,\002NFVALS =\002,i5,3x,\002F =\002,1pe13.6,"
    	    "4x,\002MAXCV =\002,1pe13.6/3x,\002X =\002,1pe13.6,1p4e15.6)";
        static char fmt_80[] = "(1pe19.6,1p4e15.6)";
        static char fmt_210[] = "(/3x,\002Return from subroutine COBYLA because"
    	    " \002,\002rounding errors are becoming damaging.\002)";
        static char fmt_410[] = "(/3x,\002Increase in PARMU to\002,1pe13.6)";
        static char fmt_580[] = "(/3x,\002Reduction in RHO to\002,1pe13.6,\002  "
    	    "and PARMU =\002,1pe13.6)";
        static char fmt_590[] = "(/3x,\002Normal return from subroutine COBYL"
    	    "A\002)";
    
        /* System generated locals */
        integer sim_dim1, sim_offset, simi_dim1, simi_offset, datmat_dim1, 
    	    datmat_offset, a_dim1, a_offset, i__1, i__2, i__3;
        doublereal d__1, d__2;
    
        /* Builtin functions */
        integer s_wsfe(cilist *), do_fio(integer *, char *, ftnlen), e_wsfe(void);
        double sqrt(doublereal);
    
        /* Local variables */
        static doublereal f;
        static integer i__, j, k, l, mp, np, iz;
        static doublereal phi, rho, sum, beta, cmin, cmax;
        static integer ivmc;
        static doublereal weta;
        static integer ivmd;
        static doublereal temp, wsig, gamma;
        static integer iflag;
        static doublereal alpha, delta, denom, tempa, barmu;
        static integer nbest, ifull, iptem, jdrop;
        static doublereal ratio, vmold, parmu, error, vmnew;
        extern /* Subroutine */ int calcfc_(integer *, integer *, doublereal *, 
    	    doublereal *, doublereal *);
        static integer ibrnch;
        static doublereal edgmax, pareta, prerec, phimin, parsig;
        static integer isdirn, nfvals, izdota;
        static doublereal cvmaxm, dxsign, prerem;
        static integer iptemp;
        static doublereal resmax, cvmaxp;
        static integer idxnew;
        static doublereal resnew, trured;
        extern /* Subroutine */ int trstlp_(integer *, integer *, doublereal *, 
    	    doublereal *, doublereal *, doublereal *, integer *, integer *, 
    	    doublereal *, doublereal *, doublereal *, doublereal *, 
    	    doublereal *, doublereal *);
    
        /* Fortran I/O blocks */
        static cilist io___22 = { 0, 6, 0, fmt_10, 0 };
        static cilist io___29 = { 0, 6, 0, fmt_50, 0 };
        static cilist io___33 = { 0, 6, 0, fmt_70, 0 };
        static cilist io___34 = { 0, 6, 0, fmt_80, 0 };
        static cilist io___39 = { 0, 6, 0, fmt_210, 0 };

    Найдено в зависимостях «SlangTNG». Библиотека «COBYLA», автоматически переведённая с «Фортрана».

    /* This subroutine minimizes an objective function F(X) subject to M */
    /* inequality constraints on X, where X is a vector of variables that has */
    /* N components. The algorithm employs linear approximations to the */
    /* objective and constraint functions, the approximations being formed by */
    /* linear interpolation at N+1 points in the space of the variables. */

    https://tng.tuxfamily.org/index.php?title=Main_Page

    XYPO3BO3, 05 Декабря 2019

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

    +2

    1. 1
    2. 2
    3. 3
    https://tjournal.ru/analysis/128216-moshenniki-3-0-kak-ne-popastsya-na-udochku-novogo-pokoleniya-prestupnikov-v-sfere-it
    
    https://leonardo.osnova.io/0234cd39-a2ef-c6d8-d8df-87df562f9997/-/scale_crop/600x398/center/

    booratihno, 30 Ноября 2019

    Комментарии (96)
  4. Python / Говнокод #26046

    +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
    >>> from heapq import heappush, heappop
    >>> heap = []
    >>> data = [1, 3, 5, 7, 9, 2, 4, 6, 8, 0]
    >>> for item in data:
    ...     heappush(heap, item)
    ...
    >>> ordered = []
    >>> while heap:
    ...     ordered.append(heappop(heap))
    ...
    >>> ordered
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>> data.sort()
    >>> data == ordered
    True

    В «Python» есть стандартный модуль «heapq» с процедурками, которые делают из обычного листа очередь с приоритетом: https://docs.python.org/3.8/library/heapq.html. Всё просто, понятно, удобно и без этих ваших «классов» с «наследованиями». Именно поэтому я за «Python».

    gost, 26 Ноября 2019

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

    +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
    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
    case Type::Instruction:
            {
              if (o == "movzwl") return OpCode::movzwl;
              if (o == "movzbl") return OpCode::movzbl;
              if (o == "shrb") return OpCode::shrb;
              if (o == "shrl") return OpCode::shrl;
              if (o == "xorl") return OpCode::xorl;
              if (o == "andl") return OpCode::andl;
              if (o == "ret") return OpCode::ret;
              if (o == "movb") return OpCode::movb;
              if (o == "cmpb") return OpCode::cmpb;
              if (o == "movl") return OpCode::movl;
              if (o == "jmp") return OpCode::jmp;
              if (o == "testb") return OpCode::testb;
              if (o == "incl") return OpCode::incl;
              if (o == "sarl") return OpCode::sarl;
              if (o == "decl") return OpCode::decl;
              if (o == "jne") return OpCode::jne;
              if (o == "je") return OpCode::je;
              if (o == "js") return OpCode::js;
              if (o == "subl") return OpCode::subl;
              if (o == "subb") return OpCode::subb;
              if (o == "addl") return OpCode::addl;
              if (o == "addb") return OpCode::addb;
              if (o == "sall") return OpCode::sall;
              if (o == "orl") return OpCode::orl;
              if (o == "andb") return OpCode::andb;
              if (o == "orb") return OpCode::orb;
              if (o == "decb") return OpCode::decb;
              if (o == "incb") return OpCode::incb;
              if (o == "rep") return OpCode::rep;
              if (o == "notb") return OpCode::notb;
              if (o == "negb") return OpCode::negb;
              if (o == "sbbb") return OpCode::sbbb;
              if (o == "pushl") return OpCode::pushl;
              if (o == "retl") return OpCode::retl;
            }

    Фрагмент транслятора из ассемблера в ассемблер.

    https://github.com/lefticus/x86-to-6502

    XYPO3BO3, 24 Ноября 2019

    Комментарии (59)
  6. Java / Говнокод #26035

    +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
    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
    public class AdvancedBoolean {
        private boolean result;
        private DefenitionDictionary.RESULT_CODE code;
        
        
        
    //------------------------------------------------------------------------------  
    //constructors
    //------------------------------------------------------------------------------       
        public AdvancedBoolean() {
            result = true;
        }
            
        public AdvancedBoolean(boolean _result) {
            result = _result;
        }
     
         
        public AdvancedBoolean(boolean _result, DefenitionDictionary.RESULT_CODE _code) {
            result = _result;
            code = _code;
        }
    
        
        
    //------------------------------------------------------------------------------
    //get methods
    //------------------------------------------------------------------------------     
        public boolean isResult() {
            return result;
        }
    
        public DefenitionDictionary.RESULT_CODE getCode() {
            return code;
        }
    
    
            
    //------------------------------------------------------------------------------
    //set methods
    //------------------------------------------------------------------------------ 
        public void setResult(boolean _result) {
            result = _result;
        }
        
        public void setCode(DefenitionDictionary.RESULT_CODE _code) {
            code = _code;
        }
        
        
        
    //------------------------------------------------------------------------------
    //other methods
    //------------------------------------------------------------------------------     
        public String getLabel() {
            return code.getResultLabel();
        }
    }

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

    Veers, 19 Ноября 2019

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

    +2

    1. 1
    2. 2
    Comparing structs with, let's say, memcmp, does not work,
     as you end up comparing the "unspecified" padding bytes as well — you must compare member-by-member.

    While writing this post, the author observed that some verions of GCC (experimentally, >= 4.7, < 8.0) do not zero padding if an empty intializer list is passed, under certain a certain code pattern; if an entire struct (i.e. sizeof(STRUCTNAME)) is subsequently memcpy'd after assigment of its members, and this intermediate buffer is what is used by the code going forward. This appears to be based on how optimization passes interact with GCC's built-in memcpy, since passing -fno-builtin-memcpy returns the behavior to the expected.
    https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2019/october/padding-the-struct-how-a-compiler-optimization-can-disclose-stack-memory/

    3.14159265, 18 Ноября 2019

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

    +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
    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
    #include <stdio.h>
    #include <inttypes.h>
    #include <string.h>
    
    // endian dependend
    #define PUT3(a,b,c) (((uint64_t)a<<8*0) | ((uint64_t)b<<8*1) | ((uint64_t)c<<8*2))
    
    void testswitch(uint64_t x)
    {
      switch (x) 
      { 
        case PUT3('a','b','c'): printf("abc\n"); 
          break; 
        case PUT3('d','e','f'): printf("def\n"); 
          break; 
        case PUT3('g','h','i'): printf("ghi\n"); 
          break; 
        default: printf("Choice other than abc, def and ghi\n"); 
          break;   
       }
    }
    
    int main() 
    { 
       uint64_t x = 0;
       char a[] = "abc";
       memcpy(&x, a, sizeof(a)-1);
       testswitch(x);
    
       char b[] = "def";
       memcpy(&x, b, sizeof(a)-1);
       testswitch(x);
    
       char c[] = "ghi";
       memcpy(&x, c, sizeof(a)-1);
       testswitch(x);
       return 0; 
    }

    switch для строк!

    Перечитывал несвежие говнокоды, где я выкладывал творчество вконтактоолимпиадников https://govnokod.ru/23170#comment388376

    j123123, 12 Ноября 2019

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

    +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
    18. 18
    Дали тестовое задание.
    Написать хеш таблицу с открытой адресацией. Главное качество, а не скорость, сказали.
    Реализовал на C++.
    Самая тягомотина - это тестирование многопоточности.
    Есть операции: 
    find, equalRange, operator [] - тот же equalRange, но возвращает все найденные вхождения, insert, remove, extend, size, capacity.
    
    И вот надо каждую относительно другой проверять.  
    Только это выходит (9 - 1)^2 тестов. Помимо остальных, уже реализованных.
    
    у меня проверка на значения только в операциях поиска относительно вставки, то бишь, нашелся ли в многопоточном исполнении элемент, или нет.
    относительно удаления проверять - это муторно, потому что после удаления на той же позиции встает соседняя пара, и это случайно, проверено 
    экспериментально.
    
    Сойдет ли просто проверять время блокировки (shared_lock, и lock_guard) 
    каждого параллельного текущему потоку относительно времени блокировки\старта\окончания блокировки текущего?
    кроме связки (access - insert)?
    Тем более, что операции записи\чтения проверяются в немногопоточном исполнении?

    OlegUP, 08 Ноября 2019

    Комментарии (31)
  10. Куча / Говнокод #25999

    +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
    https://habr.com/ru/post/472970/
    
    Критика протокола и оргподходов Telegram. Часть 1, техническая: опыт написания клиента с нуля
    
    в Full самая наркомания, с точки зрения сетевика: длина,
    sequence number, причем НЕ ТОТ, что в основном MTProto,
    тело, CRC32. Да, всё это поверх TCP. Который предоставляет
    нам надежный транспорт в виде последовательного потока байт,
    никакие последовательности не нужны, тем более контрольные
    суммы. Окей, мне сейчас возразят, что в TCP 16-битная
    контрольная сумма, так что искажение данных случается.
    Отлично, только у нас вообще-то криптографический протокол
    с хэшами длиннее 16 байт, все эти ошибки — и даже
    более — будут отловлены на несовпадении SHA уровнем выше.
    Никакого смысла в CRC32 поверх этого — НЕТ.

    Ебать дебилы

    j123123, 27 Октября 2019

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

    +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
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    // https://godbolt.org/z/dMT7v3
    
    unsigned div_eq(unsigned a, unsigned b)
    {
      ALWAYS_TRUE(a == b);
      return a/b;
    }
    
    unsigned div(unsigned a, unsigned b)
    {
      return a/b;
    }
    
    
    int test_array(unsigned char a[10])
    {
      for (int i = 1; i < 10; i++)
      {
        ALWAYS_TRUE(a[i-1] <= a[i]);
      }
      return a[0] <= a[2];
    }

    Refinement type
    Можно этой хуйней ассерты позаменять попробовать, и компилятор возможно что-то сможет за счет этого соптимизировать

    j123123, 26 Октября 2019

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