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

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

    +132

    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
    private double readDouble(string name, string wholeFile)
    {
    	try
    	{
    		int ind = -1;
    		if ((ind = wholeFile.IndexOf(name)) != -1)
    		{
    			var restofstr = wholeFile.Substring(ind + name.Length);
    			int lineendind = -1;
    			lineendind = restofstr.IndexOfAny(new char[] { '\n', '\r', (char)13, (char)10 });
    			if (lineendind == -1 && restofstr.Length > 1)
    			{
    				lineendind = restofstr.Length;
    			}
    			if (lineendind != -1)
    			{
    				int eqind = -1;
    				string valueString = restofstr.Substring(0, lineendind);
    				if ((eqind = valueString.IndexOf("=")) != -1)
    				{
    					double res = 0.0;
    					if (Double.TryParse(valueString.Substring(eqind + 1).Trim(), out res))
    					{
    						return res;
    					}
    				}
    			}
    		}
    	}
    	catch (Exception) { }
    
    	return 0.0;
    }

    А как бы вы написали это?

    tbolk, 03 Февраля 2015

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

    +137

    1. 1
    2. 2
    3. 3
    try { UserInfoProvider.DeleteUser(u.ID); }
                            catch { }
                            return "Ваш аккаунт успешно активирован";

    alexscrat, 27 Января 2015

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

    +74

    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
    private static File getTmpOutputFile(VirtualFile file) {
            String origPath = file.getRealFile().getAbsolutePath();
            File tmp = new File(origPath + ".tmp");
    
            // If the temp file already exists
            if (tmp.exists()) {
                long tmpLastModified = tmp.lastModified();
                long now = System.currentTimeMillis();
    
                // If the temp file is older than the destination file, or if it is
                // older than the allowed compression time, it must be a remnant of
                // a previous server crash so we can overwrite it
                if (tmpLastModified < file.lastModified()) {
                    return tmp;
                }
                if (now - tmpLastModified > PluginConfig.maxCompressionTimeMillis) {
                    return tmp;
                }
    
                // Otherwise it must be currently being written by another thread,
                // so wait for it to finish
                while (tmp.exists()) {
                    if (System.currentTimeMillis() - now > PluginConfig.maxCompressionTimeMillis) {
                        throw new PressException("Timeout waiting for compressed file to be generated");
                    }
    
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                }
    
                // Return null to indicate that the file was already generated by
                // another thread
                return null;
            }
    
            return tmp;
        }

    Самый вредный говнокод, который я встречал за последний год.
    При определённых условиях может так случиться, что он ждёт (до 60 секунд!), пока предыдущий временный файл не исчезнет. Он не пытается его удалить, не пытается создать новый файл, ничего не логирует - он просто ждёт, пока файл сам исчезнет.

    И у меня как раз так и случилось - из-за совпадения разных событий файл не удалялся, метод ждал 60 секунд, но за это время валились совсем другие вещи по таймауту, и ушло много времени на то, чтобы понять, где же настоящая проблема.

    И весь этот геморрой можно было бы благополучно заменить всего-навсего одной сточкой:
    return File.createTempFile(origPath, "tmp");

    Исходник - плагин play-press:
    https://github.com/dirkmc/press/blob/master/app/press/io/OnDiskCompressedFile.java

    asolntsev, 21 Января 2015

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

    +157

    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
    if ( diffYear < 5 ) {
            document.getElementById('yearsText').innerHTML = "года |";
        } else if ( diffYear > 1 ){
            document.getElementById('yearsText').innerHTML = "лет |";
        } else {
            document.getElementById('yearsText').innerHTML = "год |";
        }
        
        if ( diffMonth > 4 ) {
            document.getElementById('monthText').innerHTML = "месяцев |";
        } else if ( diffMonth > 1 ){
            document.getElementById('monthText').innerHTML = "месяца |";
        } else {
            document.getElementById('monthText').innerHTML = "месяц |";
        }
        
        if ( diffDay > 5 ) {
            document.getElementById('monthText').innerHTML = "дней |";
        } else if ( diffDay > 1 ){
            document.getElementById('monthText').innerHTML = "дня |";
        } else {
            document.getElementById('monthText').innerHTML = "день |";
        }
    }

    очередная кака с датой

    artembegood, 21 Января 2015

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

    +158

    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
    $i = 0;
            for ($k = 0; $k<=5; $k++){
                if ($i==5)
                    break;
                foreach (getContent($id) as $content_row) {
                    $i++;
                    $htmlshowcase = $content_row->getShowcase(1, $k);
                    if ($htmlshowcase == '')
                        $i--;
                    else
                        $html .= $htmlshowcase;
                    if ($i==5)
                        break;
                }
            }

    Лучший способ прохода по циклу.

    arkham_vm, 20 Января 2015

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

    +53

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    int s = 0;
    string N;
    getline(cin, N);
    // Прости господи
    for (int i = 0; i < N.length(); i++)
        if (N[i] != 0)
            s += N[i] - 48;

    Глянул свой недавний код

    DesmondHume, 17 Января 2015

    Комментарии (2)
  8. Си / Говнокод #17446

    +138

    1. 1
    if (!GL_TRUE == linkStatus)

    пример из vuforia sdk
    вроде подобного булшита еще не было

    chtulhu, 15 Января 2015

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

    +161

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public function change_password() {
    		if (!oauth_verify_client($this->client_id, $this->client_secret, 'user/password')) {
    			echo json_encode(array('status' => 403, 'error' => array('code' => 5, 'description' => 'accessError')));
    		}
    		$email = $this->input->post('email');
    		$new_password= $this->input->post('new_password');
    		//...

    "Тебе сюды нельзя, но так уж и быть, поменяю..."

    Lowezar, 14 Января 2015

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

    +162

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    function loadScript(varStr, codeStr) {
    					var $script = $('<script>').attr('type', 'text/javascript');
    					$script.html('var ' + varStr + ' = ' + codeStr);
    					document.getElementsByTagName("head")[0].appendChild($script[0]);
    			   }

    Как инициализировать переменную, используя любимый поисковик и jQuery

    dan, 12 Января 2015

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

    +136

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    int num10 = Convert.ToInt16(this.label13.Text);
        int num11 = Convert.ToInt16(this.label11.Text);
        int num12 = Convert.ToInt16(this.LH2.Text);
        int num13 = Convert.ToInt16(this.dmserver.Text);
        int num14 = Convert.ToInt16(this.vipserver.Text);
        int num15 = Convert.ToInt16(this.NAMALSK_FREE_server.Text);
        int num16 = Convert.ToInt16(this.Igromafia_serevr.Text);
        int num18 = Convert.ToInt16(this.LH3_total_on_off.Text);
        int num17 = ((((((num10 + num11) + num13) + num14) + num15) + num12) + num16) + num18;
        this.servers.Text = Convert.ToString(num17);

    Часть метода статистики одного из лаунчеров для пиратского клиента игры.

    kingmonstr, 03 Января 2015

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