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

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

    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
    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
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    // channel.h
    
    #pragma once
    
    namespace AMQP {
    
    class Channel
    {
    private:
        std::shared_ptr<ChannelImpl> _implementation;
    
    public:
        Channel(Connection *connection) : _implementation(new ChannelImpl()) 
        {
            // attach the connection to the channel
            _implementation->attach(connection);
        }
        
        Channel(const Channel &channel) = delete;
    
        virtual ~Channel() 
        {
            // close the channel (this will eventually destruct the channel)
            _implementation->close();
        }
    
        //...
    };
    
    // ---------------------------------------------------------
    // amqpcpp.h
    
    /**
     *  AMQP.h
     *
     *  Starting point for all includes of the Copernica AMQP library
     *
     *  @documentation public
     */
    
    #pragma once
    
    // base C++ include files
    #include <vector>
    #include <string>
    #include <memory>
    #include <map>
    //...
    
    // base C include files
    #include <stdint.h>
    #include <math.h>
    
    // forward declarations
    #include <amqpcpp/classes.h>
    
    // utility classes
    #include <amqpcpp/endian.h>
    #include <amqpcpp/buffer.h>
    #include <amqpcpp/bytebuffer.h>
    //...
    
    // amqp types
    #include <amqpcpp/field.h>
    #include <amqpcpp/numericfield.h>
    #include <amqpcpp/decimalfield.h>
    #include <amqpcpp/stringfield.h>
    //...
    
    // envelope for publishing and consuming
    #include <amqpcpp/metadata.h>
    #include <amqpcpp/envelope.h>
    #include <amqpcpp/message.h>
    
    // mid level includes
    #include <amqpcpp/exchangetype.h>
    #include <amqpcpp/flags.h>
    #include <amqpcpp/callbacks.h>
    #include <amqpcpp/deferred.h>
    #include <amqpcpp/deferredconsumer.h>
    #include <amqpcpp/deferredqueue.h>
    #include <amqpcpp/deferreddelete.h>
    #include <amqpcpp/deferredcancel.h>
    #include <amqpcpp/deferredget.h>
    #include <amqpcpp/channelimpl.h>
    #include <amqpcpp/channel.h>
    //...

    https://github.com/CopernicaMarketingSoftware/AMQP-CPP

    scp, 23 Декабря 2015

    Комментарии (18)
  3. PHP / Говнокод #18727

    +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
    class Order_OrderProcessorBuilder
    {
        /**
         * @param $processorName
         * @return Order_Abstract_OrderAbstract
         */
        private static function createOrderProcessor($processorName)
        {
            $processorClassName = 'Order_Types_'.ucfirst($processorName);
            return new $processorClassName;
        }
    
        /**
         * @param $builderName
         * @param Order_Abstract_OrderAbstract $orderProcessor
         * @return Order_Abstract_BuilderAbstract
         */
        private static function createOrderBuilder($builderName, Order_Abstract_OrderAbstract $orderProcessor)
        {
            $builderClassName = 'Order_Builders_'.ucfirst($builderName);
            return new $builderClassName($orderProcessor);
        }
    
        /**
         * @param Order_Abstract_BuilderAbstract $orderBuilder
         * @return Order_Director
         */
        private static function createDirectorClass(Order_Abstract_BuilderAbstract $orderBuilder)
        {
            return new Order_Director($orderBuilder);
        }
    
        /**
         * @param $orderTypeName
         * @return Order_Abstract_OrderAbstract
         */
        public static function build($orderTypeName)
        {
            /** @var Order_Abstract_OrderAbstract $orderProcessor */
            $orderProcessor = self::createOrderProcessor($orderTypeName);
            /** @var Order_Abstract_BuilderAbstract $orderBuilder */
            $orderBuilder = self::createOrderBuilder($orderTypeName, $orderProcessor);
            $director = self::createDirectorClass($orderBuilder);
    
            $director->construct();
            return $orderBuilder->getResult();
        }
    }

    Вот такая у нас есть прослойка, которая работает с паттероном "строитель", честно говоря недавно понял зачем она нужна, не знаю.. Как вам решение? Код не мой

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

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

    +6

    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
    #include <bits/stdc++.h>
    #define MP make_pair
    #define PB push_back
    #define int long long
    #define st first
    #define nd second
    #define rd third
    #define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
    #define RE(i, n) FOR(i, 1, n)
    #define FORD(i, a, b) for(int i = (a); i >= (b); --i)
    #define REP(i, n) for(int i = 0;i <(n); ++i)
    #define VAR(v, i) __typeof(i) v=(i)
    #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
    #define ALL(x) (x).begin(), (x).end()
    #define SZ(x) ((int)(x).size())
    #ifdef LOCAL
    #define debug(x) {cerr <<#x<<" = " <<x<<"\n"; }
    #define debug2(x, y) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<"\n";}
    #define debug3(x, y, z) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<"\n";}
    #define debug4(x, y, z, t) {cerr <<#x<<" = " <<x<<", "<<#y <<" = " <<y <<", "<<#z<<" = "<<z<<", "<<#t <<" = " <<t<<"\n";}
    #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
    #else
    #define debug(x)
    #define debug2(x, y)
    #define debug3(x, y, z)
    #define debug4(x,y,z,t)
    #define debugv(x)
    #define cerr if(0)cout
    #endif
    #define make(type, x) type x; cin>>x;
    #define make2(type, x, y) type x, y; cin>>x>>y;
    #define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
    #define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;
    #define next ____next
    #define prev ____prev
    #define left ____left
    #define hash ____hash
    using namespace std;
    typedef long long ll;
    typedef long double LD;
    typedef pair<int, int> PII;
    typedef pair<ll, ll> PLL;
    typedef vector<int> VI;
    typedef vector<VI> VVI;
    typedef vector<ll> VLL;
    typedef vector<pair<int, int> > VPII;
    typedef vector<pair<ll, ll> > VPLL;

    Даже #define int long long есть
    http://codeforces.com/contest/575/submission/12867420

    3_dar, 15 Сентября 2015

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

    +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
    <?php
    
    $self=$_SERVER['PHP_SELF'];
    
    if (isset($_GET['page'])) { $page=$_GET['page'];} else {$page=1;}
    
    $pages=25;
    $page_offset=5;
    $unique_links=9;
    
    if ($page != 1) { // Don't show back link if current page is first page.
    $back_page = $page-1;
    echo("<a href=\"$self?page=$back_page\">prev</a>    \n");}
    
    for ($i=1; $i <= $pages; $i++)  {
    
    if ($i == $page) {
     echo("<b>$i</b>\n");// If current page don't give link, just text.
     }  else {
    
    if (($i>$page-$page_offset) && ($i<$page+$page_offset)  && ($page>$page_offset)) {	
    echo("<a href=\"$self?page=$i\">$i</a> \n");
    } 
    elseif (($i<=$unique_links) && ($page<=$page_offset)) {
    	echo("<a href=\"$self?page=$i\">$i</a> \n");
    }
    elseif (($i>$pages-$unique_links) && ($page>$pages-$page_offset)) {
    echo("<a href=\"$self?page=$i\">$i</a> \n");	
    }
    
    }
    
    }
    
    if (!($page >= $pages) && $pages != 1) { // If last page don't give next link.
    $next_page = $page + 1;
    echo("<a href=\"$self?page=$next_page\">next</a>");}
    
    
    ?>

    Адовый аромат (хоть и рабочий), понимаю, но помогите упростить, пожалуйста. Условия внутри цикла скорее всего избыточны.
    Вкратце: "плавающий" пагинатор, 9 уникальных ссылок.

    nurfed362, 30 Июня 2015

    Комментарии (18)
  6. C++ / Говнокод #17928

    +56

    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
    std::map<int, int> aSummator; //Массив частичных сумм
    std::vector<int> v; //Исходный массив
    
    void InitSummator()
    {
        aSummator[0] = v[0];
        aSummator[-1] = 0;
    
        for(int i = 1; i < int(v.size()); i++)
        {
            aSummator[i] = aSummator[i - 1] + v[i];
        }
    }
    
    int GetSum(int l, int r)
    {
        return aSummator[r] - aSummator[l - 1]; 
    }

    Как я писал сумматор 0.1 года назад. Вместо того, чтобы написать один if, я использовал std::map, что увеличило ассимптотику алгоритма на запрос с O(1) до O(log(n)). Но задачу при тех ограничениях (в массиве до 100000 элементов, запросов не более 100000) алгоритм решил. Преподу, естественно, показывать забоялся.

    Janycz, 03 Апреля 2015

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

    +67

    1. 1
    2. 2
    3. 3
    public boolean isUsing(AttributeType type) {
            return (this.attributeTypes.indexOf(type) >= 0);
    }

    низкоуровневое программирование

    dmli, 24 Марта 2015

    Комментарии (18)
  8. Java / Говнокод #17813

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public void setSkyboxName(String skyboxName) {
        if (skyboxName != null && skyboxName.length() > 2) {
          this.setSkybox(new SkyBox(skyboxName));
        } else {
          this.setSkybox(null);
        }
      }

    если имя неба длинна > 2 значит создать новое небо,
    а иначе неба не будет вообще

    dmli, 18 Марта 2015

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

    +145

    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;

    П О Ч И Н Е Н О

    Elvenfighter, 11 Марта 2015

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

    +103

    1. 1
    if (openFileDialog1.ShowDialog().ToString() == "OK")

    не хватает еще

    if(1.ToString() == "1")

    Lokich, 13 Февраля 2015

    Комментарии (18)
  11. C++ / Говнокод #17580

    +56

    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
    void split_int(int num)
    {
        int i1,i2,i3,i4,i5,i6,i7,i8,i9,MAX = 10;
        for(i1 = 1; i1 < MAX; i1++)
        {
            if(i1 == num)
                    printf("%d = %d\r\n",i1,num);
            for(i2 = 1; i2 < MAX; i2++)
            {
                if(i1 + i2 == num)
                    printf
                    (
                        "%d + %d = %d\r\n",
                        i1,i2,num
                    );
                for(i3 = 1; i3 < MAX; i3++)
                {
                    if(i1 + i2 + i3 == num)
                        printf
                        (
                            "%d + %d + %d = %d\r\n",
                            i1,i2,i3,num
                        );
                    for(i4 = 1; i4 < MAX; i4++)
                    {
                        if(i1 + i2 + i3 + i4 == num)
                            printf
                            (
                                "%d + %d + %d + %d = %d\r\n",
                                i1,i2,i3,i4,num
                            );
                        for(i5 = 1; i5 < MAX; i5++)
                        {
                            if(i1 + i2 + i3 + i4 + i5 == num)
                                printf
                                (
                                    "%d + %d + %d + %d + %d= %d\r\n",
                                    i1,i2,i3,i4,i5,num
                                );
                            for(i6 = 1; i6 < MAX; i6++)
                            {
                                if(i1 + i2 + i3 + i4 + i5 + i6 == num)
                                    printf
                                    (
                                        "%d + %d + %d + %d + %d + %d = %d\r\n",
                                        i1,i2,i3,i4,i5,i6,num
                                    );
                                for(i7 = 1; i7 < MAX; i7++)
                                {
                                    if(i1 + i2 + i3 + i4 + i5 + i6 + i7 == num)
                                        printf
                                        (
                                            "%d + %d + %d +%d + %d + %d + %d = %d\r\n",
                                            i1,i2,i3,i4,i5,i6,i7,num
                                        );
                                    for(i8 = 1; i8 < MAX; i8++)
                                    {
                                        if(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 == num)
                                            printf
                                            (
                                                "%d + %d + %d + %d + %d + %d + %d + %d = %d\r\n",
                                                i1,i2,i3,i4,i5,i6,i7,i8,num
                                            );
                                        for(i9 = 1; i9 < MAX; i9++)
                                            if(i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9 == num)
                                                printf
                                                (
                                                    "%d + %d + %d + %d + %d + %d + %d + %d + %d = %d\r\n",
                                                    i1,i2,i3,i4,i5,i6,i7,i8,i9,num
                                                );
                                    }
     
                                }
                            }
                        }
                    }
                }
            }
        }
        printf("\r\n");
    }

    С одного известного форума.

    DesmondHume, 04 Февраля 2015

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