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

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

    +75.3

    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
    public static ru.project.subpackage.PersonDTO convertOshPersonDtoToPersonDto(OshPersonDTO person){
            ru.project.subpackage.PersonDTO dto = new ru.project.subpackage.PersonDTO();
            dto.setPersonid(person.getPersonid().longValue());
            dto.setNamelast(person.getNamelast());
            dto.setNamefirst            (person.getNamefirst            ());
            dto.setNamesec              (person.getNamesec              ());
            dto.setInitials             (person.getInitials             ());
            dto.setSex                  (convertSkVocValue(person.getSex()));
            dto.setReason               (person.getReason               ());
            dto.setWorkphone            (person.getWorkphone            ());
            dto.setWorkphonedigit       (person.getWorkphonedigit       ());
            dto.setLocalphone           (person.getLocalphone           ());
            dto.setLocalphonedigit      (person.getLocalphonedigit      ());
            dto.setHomephone            (person.getHomephone            ());
            dto.setHomephonedigit       (person.getHomephonedigit       ());
            dto.setMobilephone          (person.getMobilephone          ());
            dto.setMobilephonedigit     (person.getMobilephonedigit     ());
            dto.setFax                  (person.getFax                  ());
            dto.setFaxdigit             (person.getFaxdigit             ());
            dto.setPager                (person.getPager                ());
            dto.setEmail                (person.getEmail                ());
            dto.setWeb                  (person.getWeb                  ());
            dto.setNamelastdative       (person.getNamelastdative       ());
            dto.setNamefirstdative      (person.getNamefirstdative      ());
            dto.setNamesecdative        (person.getNamesecdative        ());
            dto.setNamelastaccusative   (person.getNamelastaccusative   ());
            dto.setNamefirstaccusative  (person.getNamefirstaccusative  ());
            dto.setNamesecaccusative    (person.getNamesecaccusative    ());
            dto.setNamelastgenitive     (person.getNamelastgenitive     ());
            dto.setNamefirstgenitive    (person.getNamefirstgenitive    ());
            dto.setNamesecgenitive      (person.getNamesecgenitive      ());
            dto.setNamelastinstrumental (person.getNamelastinstrumental ());
            dto.setNamefirstinstrumental(person.getNamefirstinstrumental());
            dto.setNamesecinstrumental  (person.getNamesecinstrumental  ());
            dto.setNamelastprepositional(person.getNamelastprepositional());
            dto.setNamefirstprepositional(person.getNamefirstprepositional());
            dto.setNamesecprepositional (person.getNamesecprepositional ());
            return dto;
        }

    И так далее еще несколько сотен строк. А главное переупаковка из одних объектов в другие и обратно бессмысленна, т.к. можно использовать исходные (они доступны в приложении)

    johnsoft, 07 Сентября 2009

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

    +127

    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
    /// <summary>
        ///  Retrieve currency rates from an external site to be sure they are up to date.
        /// In this case just checking the one currency (Australian Dollar) so no need to dynamically parse the site.
        /// </summary>
        /// <returns>currency rates or msg indicating an error</returns>
        private String getCurrencyRates()
        {
            string strURL = @"http://www.x-rates.com/d/JPY/table.html";
            HttpWebRequest txtRequest = (HttpWebRequest)WebRequest.Create(strURL);
    
            txtRequest.Method = "GET";
            txtRequest.ContentType = "application/x-www-form-urlencoded";
            string response;
            using (StreamReader streamReader = new StreamReader(txtRequest.GetResponse().GetResponseStream()))
            {
                response = streamReader.ReadToEnd();
                if (response.IndexOf("Australian Dollar") > 0)
                {
                    //parse the returned page for the two values of the currency rate based on the existing design
                    int ind_jpy = (response.IndexOf("/d/AUD/JPY/graph120.html") + 39);
                    int ind_aud = (response.IndexOf("/d/JPY/AUD/graph120.html") + 39);
                    String jpy_aud = response.Substring(ind_jpy, (response.IndexOf("</a>",ind_jpy) - ind_jpy) );
                    String aud_jpy = response.Substring(ind_aud, (response.IndexOf("</a>", ind_aud) - ind_aud));
                    Session["curr_rate"] = "set";
                    Session["JPY"] = jpy_aud;
                    Session["AUD"] = aud_jpy;
                    return aud_jpy + " / " + jpy_aud;
                }
                //else present msg to user that unable to obtain currency rates
            }
            return "";
        }

    Еще один кандидат

    OlgaWolga, 07 Сентября 2009

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

    +154.3

    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
    There is a little problem with iconv in such using:
    
    $mytext = iconv('windows-1251', 'utf-8', $mytext);
    echo $mytext;
    
    This code isn't work correctly. Solution is:
    
    $mytext_utf = iconv('windows-1251', 'utf-8', $mytext);
    echo $mytext_utf;
    //or just
    echo iconv('windows-1251', 'utf-8', $mytext);
    
    ссылка: http://www.php.net/manual/en/function.iconv.php#83511

    смотрел ман, наткнулся на вот такой комментарий
    Если я еще не ослеп, то чувак одну один и тот же код три раза переписал
    и он якобы у него заработал :D

    getme, 03 Сентября 2009

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

    +50.1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    ...
    double total, free;
    GetCensoredServer()->GetCensoredMemory(total, free);
    if (free<0.) // <-- чудесная проверка
    {
    	MessageBox(AfxGetMainWnd()->m_hWnd, censored("Please check censored for enough memory!")), _T(""), MB_OK|MB_ICONWARNING);
    	return false;
    }
    ...

    Найдено в рабочем коде. Некоторые идентификаторы изменены.

    Xentrax, 01 Сентября 2009

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

    +158.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
    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
    Нашел в одном индусском скрипте мега аплоадер хендлер
    
    if($_FILES["attach1e"]["name"]){
    	//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
    	$file_details=pathinfo($_FILES["attach1e"]["name"]);
    	copy ($_FILES['attach1e']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$_POST[pid].'-attach1e.'.$file_details['extension']);
    }
    
    if($_FILES["attach2"]["name"]){
    	//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
    	$file_details=pathinfo($_FILES["attach2"]["name"]);
    	copy ($_FILES['attach2']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach2.'.$file_details['extension']);
    }
    
    if($_FILES["attach3"]["name"]){
    	//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
    	$file_details=pathinfo($_FILES["attach3"]["name"]);
    	copy ($_FILES['attach3']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach3.'.$file_details['extension']);
    }
    
    if($_FILES["attach4"]["name"]){
    	//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
    	$file_details=pathinfo($_FILES["attach4"]["name"]);
    	copy ($_FILES['attach4']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach4.'.$file_details['extension']);
    }
    
    if($_FILES["attach5"]["name"]){
    	//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
    	$file_details=pathinfo($_FILES["attach5"]["name"]);
    	copy ($_FILES['attach5']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach5.'.$file_details['extension']);
    }
    
    if($_FILES["attach6"]["name"]){
    	//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
    	$file_details=pathinfo($_FILES["attach6"]["name"]);
    	copy ($_FILES['attach6']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach6.'.$file_details['extension']);
    }
    
    if($_FILES["attach7"]["name"]){
    	//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
    	$file_details=pathinfo($_FILES["attach7"]["name"]);
    	copy ($_FILES['attach7']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'-attach7.'.$file_details['extension']);
    }
    
    if($_FILES["attach8b"]["name"]){
    	//@unlink(glob($_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$pid.'.*'));
    	$file_details=pathinfo($_FILES["attach8b"]["name"]);
    	copy ($_FILES['attach8b']["tmp_name"], $_SERVER['DOCUMENT_ROOT'].'/hdb/upload_file/new_files/'.$_POST[pid].'-attach8b.'.$file_details['extension']);
    }

    sergee, 30 Августа 2009

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

    −866.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
    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
    CREATE TABLE [Battles] (
    	[name] [varchar] (20) NOT NULL ,
    	[date] [datetime] NOT NULL 
    ) ON [PRIMARY]
    GO
    CREATE TABLE [Classes] (
    	[class] [varchar] (50) NOT NULL ,
    	[type] [varchar] (2) NOT NULL ,
    	[country] [varchar] (20) NOT NULL ,
    	[numGuns] [tinyint] NULL ,
    	[bore] [real] NULL ,
    	[displacement] [int] NULL 
    ) ON [PRIMARY]
    GO
    CREATE TABLE [dbo].[Ships] (
    	[name] [varchar] (50) NOT NULL ,
    	[class] [varchar] (50) NOT NULL ,
    	[launched] [smallint] NULL 
    ) ON [PRIMARY]
    GO
    CREATE TABLE [dbo].[Outcomes] (
    	[ship] [varchar] (50) NOT NULL ,
    	[battle] [varchar] (20) NOT NULL ,
    	[result] [varchar] (10) NOT NULL 
    ) ON [PRIMARY]
    GO
    ALTER TABLE [dbo].[Battles] ADD 
    	CONSTRAINT [PK_Battles] PRIMARY KEY  CLUSTERED 
    	(
    		[name]
    	)  ON [PRIMARY] 
    GO
    ALTER TABLE [dbo].[Classes] ADD 
    	CONSTRAINT [PK_Classes] PRIMARY KEY  CLUSTERED 
    	(
    		[class]
    	)  ON [PRIMARY] 
    GO
    ALTER TABLE [dbo].[Ships] ADD 
    	CONSTRAINT [PK_Ships] PRIMARY KEY  CLUSTERED 
    	(
    		[name]
    	)  ON [PRIMARY] 
    GO
    ALTER TABLE [dbo].[Outcomes] ADD 
    	CONSTRAINT [PK_Outcomes] PRIMARY KEY  CLUSTERED 
    	(
    		[ship],
    		[battle]
    	)  ON [PRIMARY] 
    GO
    ALTER TABLE [dbo].[Ships] ADD 
    	CONSTRAINT [FK_Ships_Classes] FOREIGN KEY 
    	(
    		[class]
    	) REFERENCES [dbo].[Classes] (
    		[class]
    	) NOT FOR REPLICATION 
    GO
    ALTER TABLE [dbo].[Outcomes] ADD 
    	CONSTRAINT [FK_Outcomes_Battles] FOREIGN KEY 
    	(
    		[battle]
    	) REFERENCES [dbo].[Battles] (
    		[name]
    	)
    GO

    Это с sql-ex.ru , база "корабли"
    Может, упражнения там интересные,
    но сама база истинный говнокод. Почему?
    Строчка
    "В отношение Outcomes могут входить корабли, отсутствующие в отношении Ships."
    делает её говнокодом.

    lexx, 27 Августа 2009

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

    +80.3

    1. 1
    // here must be english equivalent for simple russian 'nahuya?'

    Bobby, 27 Августа 2009

    Комментарии (6)
  9. 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)
  10. 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)
  11. PHP / Говнокод #1682

    +156

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class DbSimple_Generic_Database extends DbSimple_Generic_LastError
    {
    ...
        /**
         * Virtual protected methods
         */
        function ____________PROTECTED() {} // for phpEclipse outline
    ...
    }

    ой какая красотень у нас будет в аутлайне теперь...

    Smoke, 25 Августа 2009

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