1. Perl / Говнокод #1693

    −55.2

    1. 1
    return ('3');

    Возвращаем код ошибки.

    propanoid, 26 Августа 2009

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

    +161.9

    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
    function checkAllRemarks()
    { // ЧТО ЭТО!?!?!?!?17СЕМНАДЦАТЬ!!!!1111
       for (i = 0; i < document.getElementsByTagName("input").length; i++)
       {
            if (document.getElementsByTagName("input")[i].name.split("|").length>=2)
            {
                if (document.getElementsByTagName("input")[i].name.split("|")[0]=="CBR")
                {
                    if (document.getElementsByTagName("input")[i].name.split("|")[1].length==36)
                    {
                        if (document.getElementsByName("allRemarks")[0].checked == true)
                            document.getElementsByTagName("input")[i].checked = true;
                        else
                            document.getElementsByTagName("input")[i].checked = false;            
                    }
                }
            }
        } 
    }

    Много кривого кода я видел на работе, но глядя на эту функцию я не мог не поразиться.

    iley, 26 Августа 2009

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

    +133.9

    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 (aDataType.FullName)
    			{
    				case "System.SByte":	
    				case "System.Int16":	
    				case "System.Int32":	
    				case "System.Int64":	
    				case "System.Single":	
    				case "System.Double":	
    				case "System.Decimal":	
    				case "System.DateTime":	
    					_IsNumeric = true;
    					break;
    				case "System.String":   
    					_IsNumeric = false;
    					break;	
    				default:
    					throw new ArgumentException("Not supported field data type: " + 
    						aDataType.FullName, "aDataType");
    			}

    Не надо хардкодить названия типов

    sanya_fs, 26 Августа 2009

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

    +142

    1. 1
    2. 2
    echo $search;        
    $result = mysql_query ("SELECT id,title,description,date,author,view,mini_img FROM data WHERE MATCH(text) AGAINST('".$search."')");

    st0rk, 26 Августа 2009

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

    +48

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    while( !InputFileStream.atEnd() )
    {
    	QString Qstrtmp;
    	InputFileStream >> Qstrtmp;
    	ReadButton.bTag =  QString(QObject::tr( (Qstrtmp.toStdString()).c_str() ));
    	InputFileStream >> Qstrtmp;
    	ReadButton.iTag =  QString(QObject::tr( (Qstrtmp.toStdString()).c_str() ));
    	InputFileStream >> Qstrtmp;
    	ReadButton.Popup =  QString(QObject::tr( (Qstrtmp.toStdString()).c_str() ));
    	ReadButton.PartitionId = *iVar;
    	this->Buttons.push_back( ReadButton );
    }

    Код взят из совместного проекта 5-ти студентов.
    Это был начальный период нашего изучения Qt.

    k06a, 26 Августа 2009

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

    +70.9

    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
    import javax.microedition.lcdui.*;
    import java.lang.*;
    import java.io.*;
    
    public class LNRES
    {
    	public InputStream is=null;
    	public String lines[]=null;
    	
    	LNRES(String name,int size) 
    	{
    		int x=0;
    		is=getClass().getResourceAsStream(name);
    		byte mb[]=new byte[size];
    		try { x=is.read(mb); } catch (Exception ex) { }
    		char mc[]=new char[x];
    		for (int i=0; i<x; i++) mc[i]=(char)mb[i];
    		
    		int n=0,a=0,l=0;
    		String mas2[]=null;
    		for (int i=0; i<mc.length; i++) {
    			if ((mb[i]==13)||(i==mc.length-1)) {
    				mas2=new String[n+1];
    				for (int j=0; j<n; j++) mas2[j]=new String(lines[j]);
    				mas2[n]=new String(mc,a,l+((i==mc.length-1)?1:0)); n++; lines=new String[n];
    				for (int k=0; k<n; k++) lines[k]=new String(mas2[k]);
    				a=i+2; l=0; i++;
    			} else l++;
    		}
    		lines=new String[n];
    		for (int i=0; i<n; i++) lines[i]=new String(mas2[i]);		
    	}	
    }

    Писалось под j2me. Класс считывает весь файл и превращает его в массив строк.

    k06a, 26 Августа 2009

    Комментарии (6)
  7. Ruby / Говнокод #1687

    −95.4

    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
    @ids.each_index do |di|
            if @ids[di] then
              @ids[di].each_index do |li|
                @employ[di][li] = Hash.new
                @employ[di][li][:subject] = Subject.find(:first, :conditions => "id = #{
                  Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:subject_id]
                 }")[:title] if @ids[di][li]
                @employ[di][li][:class] = SchoolClass.find(:first, :conditions => "id = #{
                  Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:school_class_id]
                 }")[:number].to_s +
                  SchoolClass.find(:first, :conditions => "id = #{
                  Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:school_class_id]
                 }")[:letter] if @ids[di][li]
                @employ[di][li][:teacher] = Teacher.find(:first, :conditions => "id = #{
                  Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:teacher_id]
                 }")[:name] + ' ' +
                  @employ[di][li][:teacher] = Teacher.find(:first, :conditions => "id = #{
                  Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:teacher_id]
                 }")[:surname] + ' ' +
                  @employ[di][li][:teacher] = Teacher.find(:first, :conditions => "id = #{
                  Lesson.find(:first, :conditions => "id = #{@ids[di][li]}")[:teacher_id]
                 }")[:patronymic] if @ids[di][li]
              end
            end
          end

    Небольшая утренняя ревизия кода раскрыла заговор по свержению власти и захвату мозга остальных кодеров проекта.

    Сидим, рефакторим.

    eveel, 26 Августа 2009

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

    +62.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class UglyColumnsRedefine < ActiveRecord::Migration
      def self.up
        change_column :variable_sets, :active, :boolean
        VariableSet.all.each{|v| v.update_attribute :active, !!v.active}
      end
    
      def self.down
      end
    end

    Миграция с весёлым названием 20090601130619_ugly_columns_redefine.rb, для рельсового приложения, аля "так делать низя".

    NoName, 26 Августа 2009

    Комментарии (1)
  9. Python / Говнокод #1685

    −105.1

    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
    def init_images():
        rect  = [[0,0],[0,0],[0,0],[0,0],[0,0]]
        image = [[0,0],[0,0],[0,0],[0,0],[0,0]]
        
        rect[0][0], image[0][0]=load_image('box.png')
        rect[0][1], image[0][1]=load_image('box.png')
        
        rect[1][0], image[1][0]=load_image('fpoint.png')
        rect[1][1], image[1][1]=load_image('freefpoint.png')
        
        rect[2][0], image[2][0]=load_image('spoint.png')    
        rect[2][1], image[2][1]=load_image('freespoint.png')
        
        rect[3][0], image[3][0]=load_image('fbox.png')
        rect[3][0], image[3][0]=load_image('fbox.png')
        
        rect[4][0], image[4][0]=load_image('sbox.png')
        rect[4][1], image[4][1]=load_image('sbox.png')
        
        return image, rect

    Процедура загрузки изображений. Т.к. программа писалась через силу (мозги не работали), получались вот такие жуткие куски кода...

    algor_1, 25 Августа 2009

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

    +158.8

    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
    function h_circle_1_view() {
    	document.getElementById("circle_1").style.display = "block";
    	document.getElementById("circle_2").style.display = "none";
    	document.getElementById("circle_3").style.display = "none";
    	document.getElementById("circle_4").style.display = "none";
    	document.getElementById("circle_5").style.display = "none";
    	}
    	function h_circle_1_none() {
    	document.getElementById("circle_1").style.display = "none";
    	}
    	
    	function h_circle_2_view() {
    	document.getElementById("circle_1").style.display = "none";
    	document.getElementById("circle_2").style.display = "block";
    	document.getElementById("circle_3").style.display = "none";
    	document.getElementById("circle_4").style.display = "none";
    	document.getElementById("circle_5").style.display = "none";
    	}
    	function h_circle_2_none() {
    	document.getElementById("circle_2").style.display = "none";
    	}
    	
    	function h_circle_3_view() {
    	document.getElementById("circle_1").style.display = "none"; 
    	document.getElementById("circle_2").style.display = "none"; // прячем 1, 2
    	document.getElementById("circle_3").style.display = "block";	// показываем 3
    	document.getElementById("circle_4").style.display = "none";
    	document.getElementById("circle_5").style.display = "none";
    	}
    	function h_circle_3_none() {
    	document.getElementById("circle_3").style.display = "none";
    	}
    	
    	function h_circle_4_view() {
    	document.getElementById("circle_1").style.display = "none"; 
    	document.getElementById("circle_2").style.display = "none"; 
    	document.getElementById("circle_3").style.display = "none"; // прячем 1, 2
    	document.getElementById("circle_4").style.display = "block";	// показываем 3
    	document.getElementById("circle_5").style.display = "none";
    	}
    	function h_circle_4_none() {
    	document.getElementById("circle_4").style.display = "none";
    	}
    	
    	function h_circle_5_view() {
    	document.getElementById("circle_1").style.display = "none"; 
    	document.getElementById("circle_2").style.display = "none"; 
    	document.getElementById("circle_3").style.display = "none"; // прячем 1, 2
    	document.getElementById("circle_4").style.display = "none";	// показываем 3
    	document.getElementById("circle_5").style.display = "block";
    	}
    	function h_circle_5_none() {
    	document.getElementById("circle_5").style.display = "none";
    	}

    Натолкнулся вот при тестировании одного проекта

    Abductio, 25 Августа 2009

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