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

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

    +164

    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
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    template < int Order, typename T >
    struct PrefixSum {
      static inline void update ( T* a ) throw () { *a += *(a-1); PrefixSum < Order-1, T > :: update( a+1 ); }
    };
    
    template < typename T >
    struct PrefixSum < 1,T > {
      static inline void update ( T* a ) throw () { *a += *(a-1); }
    };
    
    template < int P, int N, int Condition = 0 > 
    struct Bpn {
      enum { value = N * ( Bpn < P-1, N-1, (N > P) > :: value - Bpn < P-1, N, (N > P-1) > :: value ) };
    };
    
    template < int P, int N > struct Bpn < P, N, !0 > { enum { value = 0 }; };
    template < int P >        struct Bpn < P, 0,  0 > { enum { value = P ? 0 : 1 }; };
    template < int P >        struct Bpn < P, 1,  0 > { enum { value = P & 1 ? 1 : -1 }; };
    
    template < typename Ta, typename Tb, bool C > struct IfThenElse;
    template < typename Ta, typename Tb > struct IfThenElse < Ta, Tb, true  > { typedef Ta TRes; };
    template < typename Ta, typename Tb > struct IfThenElse < Ta, Tb, false > { typedef Tb TRes; };
    
    template < int K, int I = 1 >
    struct MomentSeries {
      typedef typename IfThenElse < MomentSeries<K,I+1>, MomentSeries<K,K>, (I<K) >::TRes SubT;
      static inline double accumulate ( double const* psum ) throw () {
        return Bpn < K, I > :: value * psum [ I + 1 ] + SubT :: accumulate ( psum );
      }
    };
    
    template < int K >
    struct MomentSeries < K, K > {
      static inline double accumulate ( double const* psum ) throw () {
        return Bpn < K, K > :: value * psum [ K + 1 ];
      }
    };
    
    template < int Order >
    struct MomentLoop {
      static inline void assign ( double *moments, size_t momentStride, double const* psum ) throw() {
        *(moments - momentStride) = MomentSeries < Order-1 > :: accumulate ( psum );
        MomentLoopAssign < Order-1 > :: assign ( moments - momentStride, momentStride, psum ); 
      }
    };
    
    template <>
    struct MomentLoop < 1 > {
      static inline void assign ( double *moments, size_t momentStride, double const* psum ) throw() {
        moments [ 0 ] = MomentSeries < 1, 1 > :: accumulate ( psum );
        *(moments - momentStride) = psum [ 1 ];
      }
    };
    
    /**
     * Function computes a series of geometric moments by prefix summation method:
     * Zhou F., Kornerup P. Computing Moments by Prefix Sums. // VLSI Signal Proc. - 2000. - 25. - P. 5 - 17.
     * @param data is first data elemet address.
     * @param ndataItems is number of data items.
     * @param dataStride is the number of elements between two neighbor data items, 
     *        in case of simple array dataStride is equal to 1.
     * @param moments is address of 0-order moment.
     * @param momentStride is number of elements between two neigbor moment items,
     *        in case of consequtive moments placement, momentStride is equal to 1.
     */
    
    template < int Order, class OutPolicy >
    inline void psmoment ( double const* data, 
                           size_t const  ndataItems,
                           size_t const  dataStride,
                           double*       moments,
                           size_t const  momentStride ) throw() { 
      double psum [ Order+1 ] = { 0 };
      // Initialize prefix sum
      for ( size_t i = ndataItems, j = ndataItems * dataStride; i; ) {
        --i; j -= dataStride; psum [ 0 ] = data [ j ];
        PrefixSum < Order, double > :: update ( psum+1 );
      }
      // convert psum to moment values 
      OutPolicy :: assign ( moments + Order * momentStride, momentStride, psum );
    }

    Вы - тестовая площадка, перед написанием статьи в пфп ;)

    ngry, 12 Мая 2011

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

    +122

    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
    switch (item.Value.ModuleConfiguration.SystemModule) // у свойства SystemModule тип bool, а не bool?
    {
           case true:
           {
                CreateModuleDomain<ISystemModuleProxy>(moduleContainer);
                (moduleContainer.ModuleProxy as ISystemModuleProxy).Init(moduleContainer.ModuleConfiguration, this as ISystemCoreProvider);
                   
                 break;
           }
           case false:
           {
                CreateModuleDomain<IBusinessModuleProxy>(moduleContainer);
                (moduleContainer.ModuleProxy as IBusinessModuleProxy).Init(moduleContainer.ModuleConfiguration, this as ICoreProvider);
    
                break;
           }
           default:
                break;
    }

    Фрагмент кода официального Senior Developer. Пример абсолютно надежного кода, который умеет обрабатывать даже будущие состояния булевого типа (default: break;) Будет надежен даже, если Microsoft неожиданно расширит тип состояниями, например MayBeTrue, OfCourseFalse, DontUnderstand и т.п. :)

    anzu, 05 Мая 2011

    Комментарии (35)
  4. C++ / Говнокод #6495

    +166

    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
    class r{
    	r(const r&);
    	r& operator=(const r&);
    public:
    	r(){}
    	template<class t>
    	r& operator,(t *v){
    		return this->operator<<(*v);
    	}
    	template<class t>
    	r& operator<<(t &o){
    		crash_if_fail(dynamic_cast<const void*>(&o));
    		int l = 0;
    		int n = 0, n_ = sizeof(o) / sizeof(void*);
    		while (n < n_){
    			void **a = *((void***)&o + n++);
    			if (IsBadReadPtr(a, sizeof(void*)) || is_stack(a)){
    				continue;
    			}
    			int c = 0;
    			void *d = a[c];
    			while (is_code_segment__(d)){
    				print_info(&l, o, n, d, c, a);
    				d = a[++c];
    			}
    		}
    		return *this;
    	}
    	template<class t>
    	void print_info(int *l, const t &o, int n, void *d, int c, void **a){
    		if (!*l){
    			puts("///////////////////////////////////////////////////");
    			printf("object address %p\n", &o);
    			*l = 1;
    		}
    		if (!c){
    			puts("-=-=-=-=-=-=-=-=-=-");
    			printf("%15.1s%p:__vfptr %p\n", "+", ((char*)((void***)&o + n - 1)) - (char*)&o, a);
    		}
    		printf("%32.p\n", d);
    	}
    };

    34930fb4455e40f4, 28 Апреля 2011

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

    +162

    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
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    <?php
    if(isset($_GET['pid'])){
    $pid = $_GET['pid'];
    echo $pid;
    $szi=iconv_strlen($pid);
    if(file_exists("./$pid.txt")){
    $fc=fopen("$pid.txt","r");
    if($fc<0)exit(0);
    fseek($fc,0,0);
    $url = fread($fc,filesize("./$pid.txt"));
    fclose($fc);
      header('Location: '.$url);
    } else {
      echo "File not exist<br>";
    };
    
    };
    $idx=0;
    $fc=fopen("index.txt","r");
    if($fc<0)exit(0);
    $idx = fread($fc,filesize("index.txt"));
    fclose($fc);
    $fc=fopen("./$idx.txt","r");
    if($fc<0)exit(0);
    $url = fread($fc,filesize("./$idx.txt"));
    fclose($fc);
    echo "<a href=\"http://netelis.hmsite.net/index.php?pid=$idx\">$url</a>";
    
    if(isset($_POST['url'])){
    $url=$_POST['url'];
    if (parse_url($url)) {
        echo "Your url is ok.";
      for($i=0;$i<=$idx;$i+=2){
        $fc=fopen("$i.txt","r");
      if($fc<0)exit(0);
        $urla = fread($fc,filesize("$i.txt"));
        fclose($fc);
       // echo "$urla<br>";
        if(strcmp($url,$urla)==0){
            echo "<a href=\"http://netelis.hmsite.net/index.php?pid=$i\">http://netelis.hmsite.net/index.php?pid=$i</a>";
            exit(0);
        };
        };
    } else {
        echo "Wrong url.$url";
        exit(0);
    }
    $sz=iconv_strlen($idx);
    $idx+=2;
      $fn=$idx.".txt";
      $fd=fopen($fn,"a+");
      if($fd<0)exit(0);
      fwrite($fd,$url);
      fclose($fd);
    unlink("./index.txt");
      $fd2=fopen("index.txt","a+");
      if($fd2<0)exit(0);
      fwrite($fd2,$idx);
      fclose($fd2);
    echo "<a href=\"http://netelis.hmsite.net/index.php?pid=$idx\">http://netelis.hmsite.net/index.php?pid=$idx</a>";
    };
    
    
    ?>
    <H1> Short URL generator</H1>
    <form action="" method="POST" name="ifr">
    Enter URL:
    <input type=text name="url" value="http://">
    <br>
    <input type=submit name="sbm" value="OK">
    </form>

    Скрипт с сайта

    AliceGoth, 20 Апреля 2011

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

    +159

    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
    //Aios (17:12:13 3/04/2011)
    //Не то что ты накалякал никуда не годицца! Переделывай
    
    //bukvi (17:13:00 3/04/2011)
    //может тогда так?
    
    function timing($time)
    {
    $_TIME = $time;
    //тут код по умнее потому и опущу его
    }
    $time = time();
    timing($time);
    
    //Aios (17:14:22 3/04/2011)
    //*ROFL* - пиздец....

    Передача показателя суперглобальной функции как параметра!

    Aios, 03 Апреля 2011

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

    +164

    1. 1
    $update = !empty($id) and $id > 0;

    Вопреки ожиданиям автора, выражение $id > 0 вообще никогда не принимается во внимание.
    /* Ознакомьтесь с приоритетом операций */
    Сначала отработает $update = !empty($id)
    потом значение из $update будет сравниваться с $id > 0 и результат сравнения никуда не попадёт.

    Рекомендация: используйте && вместо оператора "and".

    zabuhailo, 09 Февраля 2011

    Комментарии (35)
  8. C# / Говнокод #5347

    +133

    1. 1
    2. 2
    3. 3
    4. 4
    int type = int.Parse(r.Cells[3].Value.ToString());
    if (type == 1 || type == 3 || type == 5 || type == 6 || type == 7) type--;
    else if (type == 4) type = 2;
    else if (type == 666) type = 3;

    Парсим данные из XLS-файла.

    Kirinyale, 21 Января 2011

    Комментарии (35)
  9. JavaScript / Говнокод #5316

    +169

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    function paramEncode(str){
    	var text = escape(str);
    	while(text.indexOf("%u") !=-1)
    		text = text.replace("%u","!u");
    	while(text.indexOf("%") !=-1)
    		text = text.replace("%","!u00");
            while(text.indexOf(".") !=-1)                                                                                        
                    text = text.replace(".","!u002E");   
            while(text.indexOf("/") !=-1)                                                                                        
                    text = text.replace("/","!u002F");   
    	return text;
    }

    альтернатива if:)

    moonie, 18 Января 2011

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

    +122

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public ActionResult View(string id)
    {
    	// some stupid code
    	return View("Picture");
    }

    Потратил больше часа, пытаясь разобраться, почему глючат роуты.

    andrewpey, 10 Декабря 2010

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

    +173

    1. 1
    2. 2
    3. 3
    $S=preg_replace('/(\')|(\")|(\,)|(\()|(\))|(\.)|(\‹)|(\:)|(\;)|(\$)|(\#)|(\/)|(\{)|(\})|(\*)|(\ )|(\|)|(\>)|(\<)|(\=)|(\-)|(\[)|(\])|(\!)|(\+)|(\☺)|(\☻)'
                                 .'|(\♥)|(\♦)...................../', '', $S);
    $S=trim($S);

    Регулярные выражения! Супер!

    Yakud, 16 Ноября 2010

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