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

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    ...
    $tlang->description = "Русский";
    $tlang->filename = "russian.php";
    $tlang->template_path = 'newtpl'; // Какой идиот придумал хранить настройки шаблонов в языках???
    ...

    Кусок из шоп скрипт... ивправду какого хрена так делать - загадка...

    dobs2005, 15 Марта 2011

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

    +169

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function isTheSame(string1, string2) {
    	var firstResult =new RegExp(string1).test(string2); 
    	var secondResult =new RegExp(string2).test(string1);
    	var commonResult = firstResult && secondResult;
    	return commonResult;
    }

    tr00_gr1m_doomster, 15 Марта 2011

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

    +126

    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
    public class BasisTariffing : IFormattable
    {
    	public override bool Equals(object obj) {
    		BasisTariffing subject = obj as BasisTariffing;
    		if (subject == null) {
    			return false;
    		}
    		return ((Profession == null && subject.Profession == null) || (Profession != null && subject.Profession != null && Profession.Equals(subject.Profession))) &&
    			((BasisRateOf == null && subject.BasisRateOf == null) || (BasisRateOf != null && subject.BasisRateOf != null && BasisRateOf.Equals(subject.BasisRateOf))) &&
    			((BasisRating1Main == null && subject.BasisRating1Main == null) || (BasisRating1Main != null && subject.BasisRating1Main != null && BasisRating1Main.Equals(subject.BasisRating1Main))) &&
    			((BasisRating1Add == null && subject.BasisRating1Add == null) || (BasisRating1Add != null && subject.BasisRating1Add != null && BasisRating1Add.Equals(subject.BasisRating1Add))) &&
    			((BasisRating2Main == null && subject.BasisRating2Main == null) || (BasisRating2Main != null && subject.BasisRating2Main != null && BasisRating2Main.Equals(subject.BasisRating2Main))) &&
    			((BasisRating2Add == null && subject.BasisRating2Add == null) || (BasisRating2Add != null && subject.BasisRating2Add != null && BasisRating2Add.Equals(subject.BasisRating2Add))) &&
    			((BasisRating3Main == null && subject.BasisRating3Main == null) || (BasisRating3Main != null && subject.BasisRating3Main != null && BasisRating3Main.Equals(subject.BasisRating3Main))) &&
    			((BasisRating3Add == null && subject.BasisRating3Add == null) || (BasisRating3Add != null && subject.BasisRating3Add != null && BasisRating3Add.Equals(subject.BasisRating3Add))) &&
    			((BasisRating4Main == null && subject.BasisRating4Main == null) || (BasisRating4Main != null && subject.BasisRating4Main != null && BasisRating4Main.Equals(subject.BasisRating4Main))) &&
    			((BasisRating4Add == null && subject.BasisRating4Add == null) || (BasisRating4Add != null && subject.BasisRating4Add != null && BasisRating4Add.Equals(subject.BasisRating4Add))) &&
    			((BasisRating5Main == null && subject.BasisRating5Main == null) || (BasisRating5Main != null && subject.BasisRating5Main != null && BasisRating5Main.Equals(subject.BasisRating5Main))) &&
    			((BasisRating5Add == null && subject.BasisRating5Add == null) || (BasisRating5Add != null && subject.BasisRating5Add != null && BasisRating5Add.Equals(subject.BasisRating5Add))) &&
    			((BasisRating6Main == null && subject.BasisRating6Main == null) || (BasisRating6Main != null && subject.BasisRating6Main != null && BasisRating6Main.Equals(subject.BasisRating6Main))) &&
    			((BasisRating6Add == null && subject.BasisRating6Add == null) || (BasisRating6Add != null && subject.BasisRating6Add != null && BasisRating6Add.Equals(subject.BasisRating6Add))) &&
    			((BasisRating7Main == null && subject.BasisRating7Main == null) || (BasisRating7Main != null && subject.BasisRating7Main != null && BasisRating7Main.Equals(subject.BasisRating7Main))) &&
    			((BasisRating7Add == null && subject.BasisRating7Add == null) || (BasisRating7Add != null && subject.BasisRating7Add != null && BasisRating7Add.Equals(subject.BasisRating7Add))) &&
    			((BasisRating8Main == null && subject.BasisRating8Main == null) || (BasisRating8Main != null && subject.BasisRating8Main != null && BasisRating8Main.Equals(subject.BasisRating8Main))) &&
    			((BasisRating8Add == null && subject.BasisRating8Add == null) || (BasisRating8Add != null && subject.BasisRating8Add != null && BasisRating8Add.Equals(subject.BasisRating8Add)));
    	}
    
    	public override int GetHashCode() {
    		return ((Profession != null) ? Profession.GetHashCode() : 0) ^
    			((BasisRateOf != null) ? BasisRateOf.GetHashCode() : 0) ^
    			((BasisRating1Main != null) ? BasisRating1Main.GetHashCode() : 0) ^
    			((BasisRating1Add != null) ? BasisRating1Add.GetHashCode() : 0) ^
    			((BasisRating2Main != null) ? BasisRating2Main.GetHashCode() : 0) ^
    			....................................
    	}
    }

    Как вам перегрузочка? И это только часть кода *сущности*, больше просто не вместилось =)

    Guid, 15 Марта 2011

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

    +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
    function AuthorizeUser()
            {
                    global $USER;
                    if ( ( $USER->IsAuthorized() && $USER->GetID() == $this->GetUserID()) || $USER->IsAdmin())
                    {
                            return true;
                    }
                    else if ($this->AuthorizeByIP())
                    {
                            return true;
                    }
                    else if (1==2)
                    {
                            return true;
                    }
                    
                    return false;
            }

    А вдруг?

    elw00d, 14 Марта 2011

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

    +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
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    #include <iostream>
    #include <cstdlib>
    #include "filesdescrtable.h"
    
    int ___cntr = 0;
    #define _(X) if((X) == EXIT_SUCCESS) {___cntr++;} else {std::cerr << "error on operator: " << ___cntr << std::endl; return (EXIT_FAILURE);}
    
    int main (int argc, char *argv[]) {
    	FilesDescrTable a;
    
    	int d1,d2,d3;
    
    	_(a.setAutoReport(true));
    	_(a.openFile(argv[1], O_RDWR | O_CREAT, 0600, d1));
    	_(a.openFile(argv[2], O_RDWR | O_CREAT, 0600, d2));
    	_(a.openFile(argv[3], O_RDWR | O_CREAT, 0600, d3));
    	_(a.clearFile(argv[3]));
    	_(a.cpy(d3,d2));
    	_(a.closeFile(d1));
    	_(a.closeFile(d2));
    	_(a.closeFile(d3));
    
    	return(EXIT_SUCCESS);
    }

    хитрый макрос для отлова ошибок. такой хитрый

    cahekm, 13 Марта 2011

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

    +146

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    package t;import java.awt.*;import java.awt.event.*;import javax.swing.*;class M
    extends JFrame implements Runnable{int T=100,s,W=500,H=W,x=T,l=10,y,i,S,L;M(){
    setBounds(T,T,W,H);new Thread(this).start();}public void paint(Graphics g){super
    .paint(g);g.drawOval(x,y,l,l);g.drawRect(i,H-l,T,l);g.drawString("Sco "+s,l,T);}
    public void processKeyEvent(KeyEvent e){int k=e.getKeyCode();if(k==37)i-=l;if(k
    ==39)i+=l;super.processKeyEvent(e);}public static void main(String[]args){new M(
    ).setVisible(true);}public void run(){while(true){try{Thread.sleep(5);}catch
    (Exception e){}x+=S==0?1:-1;y+=L==0?1:-1;if(y>H-l){if(x>i&&x<i+T){s++;}else{S=0;
    L=0;x=T;y=0;}}if(x>W-l)S=1;if(x<l)S=0;if(y>H-l)L=1;if(y<l)L=0;repaint();}}}

    рабочий JSwing теннис :9 строчек

    Egor, 09 Марта 2011

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

    +146

    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
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    public class Boruvka
    {
        // private representations
        /**
         * Array of edges, which form the MST of the graph
         */
        private Edge[] mst;
        /**
         * Edges not yet discarded and not yet in the MST
         */
        private Edge[] wannabes;
        /**
         * Each component's nearest neighbor with find component numbers as indices
         */
        private Edge[] neighbors;
        /**
         * Graph representation on which we are searching for MST
         */
        private Graph g;
        /**
         *
         */
        private UnionFind uf;
        // constructors and methods
        /**
         * constructor
         * @param G Graph
         */
        public Boruvka(Graph G) {
            this.g = G;
        }
        /**
         * Boruvka's algorithm
         *
         *
         * @return minimal spanning tree - edges that form it
         */
    
        public Edge[] BoruvkaMSTalg()
        {
            Edge hlpEdge = new Edge(g.getMaxWeight(), 0, 0);
            this.uf = new UnionFind(g.getCountVerteces());
            this.wannabes = new Edge[this.g.getCountEdges()];
    
             /**
             * Get all edges from the graph G to the array edges
             */
            for (int i=0; i < g.getCountEdges(); i++)
                this.wannabes[i] = g.getEdgeAt(i);
    
    
            this.neighbors = new Edge[this.g.getCountVerteces()];
            this.mst = new Edge[this.g.getCountVerteces()+1];
    
            /**
             * index, used to store those edges being saved for the next phase
             */
            int nxtPhase;
            int k=1;
    
            for (int i=this.g.getCountEdges(); i!=0; i=nxtPhase)
            {
                int l, m, n;
    
                for (int o=0; o<this.g.getCountVerteces(); o++)
                    this.neighbors[o] = hlpEdge;
    
                for (n=0, nxtPhase=0; n<i; n++) {
                    Edge e = this.wannabes[n];
                    l = this.uf.find(e.getSVIndex()-1);
                    m = this.uf.find(e.getDVIndex()-1);
    
                    if ( l==m )
                        continue;
                    if ( e.getWeight() < this.neighbors[l].getWeight() )
                        this.neighbors[l] = e;
                    if ( e.getWeight() < this.neighbors[m].getWeight() )
                        this.neighbors[m] = e;
    
                    this.wannabes[nxtPhase++] = e;
                }
    
                for (n=0; n<this.g.getCountVerteces(); n++)
                    if ( this.neighbors[n] != hlpEdge ) {
                        l = this.neighbors[n].getSVIndex();
                        m = this.neighbors[n].getDVIndex();
    
                        if ( !this.uf.find(l,m) ) {
                            this.uf.unite(l,m);
                            this.mst[k++] = this.neighbors[n];
                        }
                    }
            }
            System.out.println("MST by Boruvka successful");
            return this.mst;
        }
    }

    Кто шарит в графах, помогите разобраться с алгоритмом Борувки для нахождения минимального остова графа. Код писал по коду Седжевика подстраивая под свой граф, но видимо наделал кучу глупостей, потому что алгоритм никогда не выходит из цикла. Подскажите где я ошибок наделал и как бы их исправить, буду очень благодарен.

    NightCrime, 03 Марта 2011

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

    +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
    /*!
     * \brief is Printable Character
     * \param c Character
     * \return true/false
     */
    static int isPrintableChar(char c)
    {
    	if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z')
    	    && (c < '0' || c > '9') && (c != ' ') && (c != '\'')
    	    && (c != '(') && (c != ')') && (c != '+') && (c != ',')
    	    && (c != '-') && (c != '.') && (c != '/') && (c != ':')
    	    && (c != '=') && (c != '?') && (c != '_') && (c != '\\')
    	    && (c != '@') && (c != '"') && (c != '%') && (c != '$')
    	    && (c != '&') && (c != '#') && (c != ';')
    	    //&& (c != 'В_')
    	    && (c != '<') && (c != '>') && (c != ']') && (c != '{')
    	    && (c != '}') && (c != '*') && (c != '^')) {
    		return 0;
    	} else {
    		return 1;
    	}
    }

    из открытого проекта chan_sccp
    даже не знаю почему не использовать стандартный макрос isprint
    #define isprint(c) ((c) >= ' ' && (c) <= '~')

    ddkprog, 03 Марта 2011

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

    +135

    1. 1
    <SCRIPT LANGUAGE=JavaScript src="../../../../../vstavka.txt"></script>

    http://www.helloworld.ru/texts/comp/lang/php/spravscript/stranica13.html что статьи говно что сайт.

    Vasiliy, 02 Марта 2011

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

    +115

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    RepaymentEvent e = DatabaseHelper.GetString("event_type", pReader) == "RBLE"
    	                ? new BadLoanRepaymentEvent {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}
    	                : (DatabaseHelper.GetString("event_type", pReader) == "RRLE"
    	                       ? new RescheduledLoanRepaymentEvent {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}
    	                       :(DatabaseHelper.GetString("event_type", pReader).StartsWith("P") 
                                    ? new PendingRepaymentEvent (DatabaseHelper.GetString("event_type", pReader)) {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}
                                    : new RepaymentEvent {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}));

    Вот такую "элегантную" строчку нашел сегодня коллега в коде нашего проекта :)
    Создаем событие пойди разбери какое :)

    _Ru55_, 02 Марта 2011

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