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

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    // Я не знаю, на чём до c# писал человек, который пишет вот такой код...
    // sum типа decimal. Видимо, надо умножить её на 100 и передать округленной до целого куда-то в текстовом виде. 
    
    UInt32 summ_st = Convert.ToUInt32((Math.Round(sum * 100)).ToString("G"));
    string cmd = "" + summ_st.ToString() + "";

    И такое приходит от аутсорсеров

    babasya, 16 Июля 2015

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

    +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
    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
    /// <summary>
            /// Обновление данных о объекте
            /// </summary>
            /// <param name="theObject">ссылка на объект</param>
            public void Update(IPersistentObject theObject)
            {
                IDbCommand updateCommand = null;
                try
                {
                    using (updateCommand = CreateUpdateCommand(theObject))
                    {
                        updateCommand.Connection.Open();
                        updateCommand.ExecuteNonQuery();
                    }
                }
                catch (DbException ex)
                {
                    int code = 0;
                    if (ex is SqlException)
                    {
                        code = ((SqlException) ex).Number;
                    }
                    if (code == 229)
                    {
                        ex.Data.Add("Name", theObject.ClassInfo.Name);
                        ex.Data.Add("Description", theObject.ClassInfo.Description);
                        ex.Data.Add("Action", "UPDATE");
                        throw new InvalidOperationException(
                            String.Format("Ошибка обновления объекта [{0}] - {1} (ID = '{2}')",
                                          theObject.ClassInfo.Name,
                                          theObject.ClassInfo.Description,
                                          theObject.ID), ex);
                    }
                    if (code == 207 || code == 208)
                    {
                        throw new InvalidColumnException(theObject.ClassInfo, ex);
                    }
                    //theObject заменен на theObject.ID. Нечитабельно, но ... Т. к. при вычислении ToString()
                    //для показа объекта иногда задействуются методы загрузки данных
                    //названия объекта. Таким образом при высоком уровне изоляции транзакции
                    //мы получим зависание если будет попытка загрузить данные заблокированные транзакцией.
                    TraceLogger.Log(String.Format("Update {0}({1}){4} - {2}\n{3}", theObject.ID, theObject.ClassInfo,
                                                  ex.Message, ex.InnerException, theObject.GetInfoToTraceMessage()),
                                    TraceTypeEnum.UpdateStatement);
                    throw;
                }
                finally
                {
                    if (updateCommand != null)
                    {
                        updateCommand.Connection.Close();
                    }
                }
            }

    смертельный прием using
    и добьем соперника используя finally как фаталити

    перехват исключения тоже хорош, авторский комментарий добавляет изюминку

    vldalx, 10 Июля 2015

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

    +140

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    int __STRNCMP__(const char s1, const char s2, size_t n)
    {
     for (; n > 0; s1++, s2++, --n)
     if (s1 != s2)
      return (((unsigned char )s1 < (unsigned char )s2) ? -1 : +1);
     else if (*s1 == '\0')
      return 0;
     return 0;
    }

    Зачем нужен такой велосипед?

    Cynicrus, 07 Июля 2015

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

    +145

    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
    <?
    include "mode.php";
    #session_start();
    ?>
    <?		$carttext .='<div class="text">';
    		$carttext .= "<form action=\"?confirm\"  method=\"post\"><table border=\"0\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\">";
    		$carttext .="<tr>";
    
    		
    		$split = explode(",",$list);
    
    		foreach ($split as $item) {
    			$check = explode("+",$item);
    			$query = mysql_query("SELECT p.id, p.urlname, p.name, p.group_join_category,  p.price, c.name, p.photo_foto, c.urlname FROM catalog_prod as p left join catalog_category as c  ON  p.group_join_category=c.id WHERE p.id=$check[0]");					
    			$row = mysql_fetch_row($query);
    			$row[10]="руб.";			
    			$add_item="";
    			
    
    			
    			$add_item.=$row[1]."/";
    			
    			$carttext .= "</tr><tr>";
    
    			
    			
    		if (!empty($row[6])) {
    
    		if(file_exists($_SERVER['DOCUMENT_ROOT'].$row[6])) {
    				$fo1 = '<img style="border:3px solid #f1f1f1;" src="/image.php/image-name.jpg?width=100&amp;cropratio=1:1&amp;image='.$row[6].'" alt="'.$row[2].'" width="100" height="100" align="left" />';}
    				else {$fo1 = '<img style="border:3px solid #f1f1f1;" src="/images/nofoto.png" alt="'.$row[2].'" width="100" height="100" align="left" />';}
    		} else {
    			$fo1 = '<img style="border:3px solid #f1f1f1;" src="/images/nofoto.png" alt="'.$row[2].'" width="100" height="100" align="left" />';
    		}	
    			
    			$carttext .= "<td valign=\"top\" width=\"100\">
    			<a href=\"/catalog/$row[7]/$add_item\">$fo1</a></td><td class=\"catlist\" valign=\"top\" width=\"100%\"><a href=\"/catalog/$row[7]/$add_item\">$row[2]</a></td>";
    			
    			
    			$carttext .= "<td valign=\"top\" class=\"catlist\" nowrap=\"nowrap\">$row[4] $row[10]</td>";
    			
    			$carttext .= '<td valign=\"top\" class="catlist"><input type="hidden" value="'.$row[4].'" name="curprice" id="'.$check[0].'_curprice" /><input type="text" maxlength="5" size="3" style="width:20px" name="'.$check[0].'_amount" value="'.$check[1].'" id="'.$check[0].'_amount" class="basketinput1" onKeypress="onlyDigit(event);" onkeyup="updateBasket('.$check[0].');" /></td>';
    
    		
    			$price = $row[4] * $check[1];
    			$price = sprintf("%0.2f", $price);
    
    			
    			$carttext .= "<td valign=\"top\" class=\"catlist\" nowrap>$price $row[10]</td>";
    			$carttext .= '<td valign=\"top\" class="catlist"><input type="button" onclick="xajax_DelFromCart('.$check[0].');" value="Удалить" class="cartsubmit1" /></td>';
    
    			if (!IsSet($total1)) {
    				$total1 = 0;
    			}
    			if (!IsSet($totalcheck1)) {
    				$totalcheck1 = 0;
    			}
    
    			$total1 = $total1+ $price;
    			
    			$totalcheck1 = $totalcheck1 + $check[1];
    			
    			$total1 = sprintf("%0.2f", $total1);
    		}	
    		
    		$carttext .= "</tr><tr>";
    		
    		
    		
    		$carttext .= "</tr><tr>";
    		
    		$carttext .= "<td colspan=\"6\"><div style=\"border-bottom: solid 1px #3e1f16; padding: 5px 0 0 0; font-size:1px;\">&nbsp;</div></td>";
    		$carttext .= "</tr><tr>";
    		
    		$carttext .= "<td width=\"100%\" colspan=\"3\" class=\"catlist1\"><b>Итого:</b></td>";
    		$carttext .= "<td class=\"catlist1\">$totalcheck1</td>";
    		$carttext .= "<td class=\"catlist1\" colspan=\"2\" nowrap><b>$total1 $value</b></td>";
    	
    		$carttext .= "</tr><tr>";
    	
    		$carttext .= '';
    		$carttext .= "<td colspan=\"6\"><div style=\"border-bottom: solid 1px #3e1f16; padding: 1px 0 0 0; font-size:1px;\">&nbsp;</div><br><input type=\"submit\" value=\"Оформить заказ\" class=\"inputsubmit1\" /></td>";
    		$carttext .= "</tr></table></form></div>";
    ?>

    Специалист формирует корзину товаров. ЗП 1500$

    mordrag, 07 Июля 2015

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

    +141

    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
    void perestanovka(int a[13][13], int n, int m){
    	 int maxim, minim, temp,i;
    	
    	 for (i=0; i<n; i++){
             minim=0;
    	 	 for (int j=1; j<m; j++){
     	  	if(a[i][j]<a[i][minim]) minim=j;
       	  }
    	 temp=a[i][0];
         a[i][0]=a[i][minim];
         a[i][minim]=temp;}
    			 
     	  for (int j=0; i<n; i++){
    	  	  maxim=0;
    	 	 for (int j=1; j<m; j++){
    		 	 if(a[i][j]>a[i][maxim]) maxim=j;
    		 }
    		 temp=a[i][m-1];
             a[i][m-1]=a[i][maxim];
    	     a[i][maxim]=temp; }
     }

    lanior, 04 Июля 2015

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    var::var (double initial) {
        (*this) = initial;
    }
    var::var (char *initial) {
        (*this) = initial;
    }

    С воландесайта.http://habrahabr.ru/post/261351

    roman-kashitsyn, 29 Июня 2015

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

    +142

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    foreach($_REQUEST as $key => &$val) {
    	$val = htmlspecialchars(stripslashes(trim($val)));
    }
    $officeId = intval($_REQUEST["office-id"]);
    $date = $_REQUEST["date"];
    // [...]

    Эпик вин, однозначно

    creamy, 22 Июня 2015

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

    +145

    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
    #define pb push_back
    #define ll long long#define forit(it, r) for (auto it = r.begin(); it != r.end(); it++)
    #define forn(i, n) for (int i = 0; i < n; ++i)
    #define forn1(i, n) for (int i = 1; i < n; ++i)
    #define FOR(i, m, n) for (int i = m; i < n; ++i)
    #define ROF(i, m, n) for (int i = m; i >= n; --i)
    #define fori(n) for (int i = 0; i < n; ++i)
    #define forj(n) for (int j = 0; j < n; ++j)
    
    
    // ...
    
        string s;
        int k;
        while (i >= base)
            k = i % base,
            s.pb(k > 9 ? k + 'A' - 10 : k + 48),
            i /= base;
        k = i % base;
        s.pb(k > 9 ? k + 'A' - 10 : k + 48);
    
    // ...
    
        fori(s.size())
            if (i < s.size() - 1 && s[i] == '\\' && (s[i + 1] == 'n' || s[i + 1] == -47))
            {
                ret.append("%0A");
                i += 1 + (s[i + 1] == -47);//-47 -- russian t, because has the same place with n (\n == \t_russian)
            }
            else
                ret.append("%" + itoa((s[i] + 256) % 256, 16));

    Олимпиадники... Олимпиадники повсюду...

    Little-Horny, 21 Июня 2015

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

    +145

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    protected virtual void OnDisconnected()
    {
    		DispatcherHelper.CheckBeginInvokeOnUI(() =>
    		{
    			...
    			Cameras.ToList().Clear();
    			Meltings.ToList().Clear();
    			Spans.ToList().Clear();
    			...
    		});
    }

    Очищаем коллекции с данными, привязанные на списковые контролы UI. Доступ к свойствам Cameras, Meltings, Spans только через IEnumerable<>. Как же их очистить?

    elmanav, 18 Июня 2015

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

    +144

    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
    public String tommorowCalendarCountry(String date, String country){
    		String tommorowCountry = null;
    		if(date.equals(getTommorow())){
    			tommorowCountry =  country;
    		}
    		return tommorowCountry;
    	}
    	
    	public String tommorowCalendarIndicator(String date, String indicator){
    		String tommorowIndicator = null;
    		if(date.equals(getTommorow())){
    			tommorowIndicator =  indicator;
    		}
    		return tommorowIndicator;
    	}
    	
    	public String tommorowCalendarImportance(String date, String importance){
    		String tommorowImportance = null;
    		if(date.equals(getTommorow())){
    			tommorowImportance =  importance;
    		}
    		return tommorowImportance;
    	}
    	
    	public String tommorowCalendarForecast(String date, String forecast){
    		String tommorowForecast = null;
    		if(date.equals(getTommorow())){
    			tommorowForecast =  forecast;
    		}
    		return tommorowForecast;
    	}
    	
    	public String tommorowCalendarPrevious(String date, String previous){
    		String tommorowPrevious = null;
    		if(date.equals(getTommorow())){
    			tommorowPrevious =  previous;
    		}
    		return tommorowPrevious;
    	}
    	
    	public String tommorowCalendarActual(String date, String actual){
    		String tommorowActual = null;
    		if(date.equals(getTommorow())){
    			tommorowActual =  actual;
    		}
    		return tommorowActual;
    	}
    	
    	public String tommorowCalendarDescription(String date, String description){
    		String tommorowDescription = null;
    		if(date.equals(getTommorow())){
    			tommorowDescription =  description;
    		}
    		return tommorowDescription;
    	}
    	
    	public String tommorowCalendarPeriod(String date, String period){
    		String tommorowPeriod = null;
    		if(date.equals(getTommorow())){
    			tommorowPeriod =  period;
    		}
    		return tommorowPeriod;
    	}
    	
    	public String tommorowCalendarLocation(String date, String location){
    		String tommorowLocation = null;
    		if(date.equals(getTommorow())){
    			tommorowLocation =  location;
    		}
    		return tommorowLocation;
    	}

    пришло с аутсорса. Такого в проекте очень много)

    slavik, 15 Июня 2015

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