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

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

    +147.7

    1. 1
    $this->view->isAdmin = ($auth->getIdentity()->role_id == 1) ? true : false;

    Называется: "заработался".
    Написал и только потом дошло.

    oldfornit, 16 Сентября 2009

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

    +157.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
    ....
    $str = str_replace(',', ' ', $this->searchString);
    $str = str_replace(';', ' ', $str);
    $str = str_replace('.', ' ', $str);
    $str = str_replace(':', ' ', $str);
    $str = str_replace('+', ' ', $str);
    $str = str_replace('-', ' ', $str);
    $str = str_replace('"', ' ', $str);
    $str = str_replace("'", ' ', $str);
    		
    $str = trim(preg_replace('!\s{2,}!', ' ', $str));
    .....

    вот что я наклал как-то

    paranoid, 11 Сентября 2009

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

    +154.8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    function get_($what)
    	{
    		global $parser;
    		$lang = $parser->lang;
    		$lang = $this->$lang;
    		return $lang[$what];
    	}

    random2, 09 Сентября 2009

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

    +166.8

    1. 1
    unset($keys[count($keys)-1][count($keys[count($keys)-1])-1]);

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

    Комментарии (6)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)
  11. 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)