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

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

    +81

    1. 1
    2. 2
    3. 3
    4. 4
    try {
        // долго и упорно делаем что-то полезное
    } catch (Exception e) {
    }

    После увольнения говнопрограммиста разбираю его творчество.
    Выскочил непонятный Exception? Не беда! Пустой блок catch легко исправит ситуацию и избавит пользователя от неприятных эмоций :)

    farnsworth, 06 Февраля 2015

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

    +136

    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
    private static string RemoveInvalidChars(string source)
    {
        foreach (var c in invalidChars)
            source = source.Replace(c.ToString(), "");
    
        return source;
    }
    
    public static string Validate(string source)
    {
        source = RemoveInvalidChars(source);
    
        return source;
    }

    pushistayapodmyshka, 02 Февраля 2015

    Комментарии (19)
  4. C# / Говнокод #17510

    +95

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    static void Main(string[] args)
            {
                Func<int, int> m = delegate(int a)
                {
                    Func<int, int> c = x => x / 2;
                    return a * c(a);
                };
                Console.WriteLine(m(10));
                Console.ReadKey();
            }

    Нестандартный подход

    SharK1870, 24 Января 2015

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

    +76

    1. 1
    2. 2
    if ( !log.append(log_line) )
    	log.append("Can't append to log");

    Безумие, оно рядом.

    Anus, 20 Января 2015

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

    +76

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    @Override
    public void keyPressed(KeyEvent e)
    {
        if (e.getKeyCode() == KeyEvent.VK_LEFT)
            move(-deltaX, 0);
        else if (e.getKeyCode() == KeyEvent.VK_RIGHT)
            move(deltaX, 0);
        else if (e.getKeyCode() == KeyEvent.VK_UP)
            move(0, -deltaY);
        else if (e.getKeyCode() == KeyEvent.VK_DOWN)
            move(0, deltaY);
    }

    Случайно встретил вот это на одном из сайтов, посвященных обучению джаве

    orotti, 07 Декабря 2014

    Комментарии (19)
  7. Python / Говнокод #17131

    −113

    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
    def normalize_url(url, preserve_fragment=False):
            url = url.strip()
            if not re.search(r'^\w+:', url):
                url = 'http://' + url.lstrip('/')
    
            if not (url.startswith('http:') or url.startswith('https:')):
                return url
    
            url = list(urlparse.urlsplit(url))
            if url[0] not in ('http', 'https'):
                url[0] = 'http'
            url[1] = url[1].lower().encode('idna')
    
            if type(url[2]) == unicode:
                try:
                    url[2] = url[2].encode('ascii')
                except UnicodeEncodeError:
                    pass
            url[2] = urllib.unquote(url[2])
            if type(url[2]) == unicode:
                url[2] = url[2].encode('utf-8')
            url[2] = urllib.quote(url[2], '/')
    
            if type(url[3]) == unicode:
                try:
                    url[3] = url[3].encode('ascii')
                except UnicodeEncodeError:
                    pass
            cut_params = ('utm_source', 'utm_medium', 'utm_term',
                          'utm_content', 'utm_campaign',
                          'yclid', 'gclid', 'ref')
            new_qsl = []
            for tag in url[3].split('&'):
                if '=' in tag:
                    param, value = tag.split('=', 1)
                    param = urllib.unquote(param)
                    value = urllib.unquote(value)
                    if param in cut_params:
                        continue
                    if type(value) == unicode:
                        value = value.encode('utf-8')
                    new_tag = "%s=%s" % (urllib.quote(param), urllib.quote(value))
                else:
                    new_tag = urllib.unquote(tag)
                    if type(new_tag) == unicode:
                        new_tag = new_tag.encode('utf-8')
                    new_tag = urllib.quote_plus(new_tag)
                new_qsl.append(new_tag)
            url[3] = '&'.join(new_qsl)
            if not preserve_fragment:
                url[4] = ''
            return urlparse.urlunsplit(url)

    Еще немного магии и хватит на сегодня.

    kyzi007, 18 Ноября 2014

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

    +155

    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
    <?php
     
    // Default: http://<host>/<dir>/<filename>.php?iter1=64&width=600&height=400&coef=32
     
    function BN($n, $l, $r) {return $n>$l && $n<=$r;}
    function SQR($a) {return $a*$a;}
     
    define("COEF",	$_GET["coef"]);
    $iter1	=	$_GET["iter1"];
    $width	=	$_GET["width"];
    $height	=	$_GET["height"];
     
    header("Content-type: image/png");
     
    $img	=	imagecreatetruecolor($width, $height);
    $iter2	=	0.01/($width/300);
    $yy	=	-1;
     
    for ($y = -1; $y < 1; $y = $y + $iter2) {
    	$yy++; $xx=-1;
    	for($x = -2; $x < 1; $x = $x + $iter2) {
    		$xx++;
    		$Cx	=	$x;
    		$Cy	=	$y;
    		$X	=	$x;
    		$Y	=	$y;
    		$ix	=	0;
    		$iy	=	0;
    		$n	=	0;
    		while ((SQR($ix) + SQR($iy) < 4) and ($n < $iter1)) {
    			$ix 	=	SQR($X) - SQR($Y) + $Cx;
    			$iy 	=	2*$X*$Y + $Cy;
    			$X	=	$ix;
    			$Y	=	$iy;
    			$n++;
    		}
    		if(BN($n,0,7)) $col = imagecolorallocate($img,COEF*$n,0,0);
    		elseif(BN($n,7,14)) $col = imagecolorallocate($img,COEF*$n,COEF*$n,0);
    		elseif(BN($n,14,21))$col = imagecolorallocate($img,COEF*$n,0,COEF*$n);
    		elseif(BN($n,21,28))$col = imagecolorallocate($img,0,COEF*$n,0);
    		elseif(BN($n,28,35))$col = imagecolorallocate($img,COEF*$n,COEF*$n,0);
    		elseif(BN($n,35,42))$col = imagecolorallocate($img,0,COEF*$n,COEF*$n);
    		elseif(BN($n,42,49))$col = imagecolorallocate($img,0,0,COEF*$n);
    		elseif(BN($n,49,56))$col = imagecolorallocate($img,COEF*$n,0,COEF*$n);
    		elseif(BN($n,56,64))$col = imagecolorallocate($img,0,COEF*$n,COEF*$n);
    		imagesetpixel($img, $xx, $yy, $col);
    	}
    }
    imagepng($img);
    imagedestroy($img);
    ?>

    https://ru.wikipedia.org/wiki/%D0%9C%D0%BD%D0%BE%D0%B6%D0%B5%D1%81%D1% 82%D0%B2%D0%BE_%D0%9C%D0%B0%D0%BD%D0%B4% D0%B5%D0%BB%D1%8C%D0%B1%D1%80%D0%BE%D1%8 2%D0%B0

    gost, 17 Ноября 2014

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

    +159

    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
    <?php
    $action = $_REQUEST["action"];
    $subaction = $_REQUEST["subaction"];
    $id = intval($_REQUEST["id"]);
    
    if ($action == "" or $subaction == ""  or $id =="") {
        die("Go fuck yourself!");
    } elseif ($action == 'add' or $action == 'edit' or $action == 'delete') {
        if ($action == 'add') {
            if ($subaction == "character") {
    
            } elseif ($subaction == "seiyu") {
    
            } else {
                die("Go fuck yourself!");
            }
        } elseif ($action == 'edit') {
            if ($subaction == "character") {
    
            } elseif ($subaction == "seiyu") {
    
            } else {
                die("Go fuck yourself!");
            }
        } elseif ($action == 'delete') {
            if ($subaction == "character") {
    
            } elseif ($subaction == "seiyu") {
    
            } else {
                die("Go fuck yourself!");
            }
        }
    } else {
        die("Go fuck yourself!");
    }

    Вырезка из модуля DLE

    Lothbrok, 23 Сентября 2014

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

    +57

    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
    void NestMathematica::DATABS(){
      int ks1 = 0;
      int ns1=0;
      int ns=0;
      ia=-1;
      ia=ia+1;
      b[ia]=-ak[0];
      ia=ia+1;
      b[ia]=alfa;
      mud=1;
      mld=1;
      if(ks!=1){
        ia=ia+1;
        b[ia]=0.;
        ks1=ks-1;
        for(int i=0; i<ks1; i++){
          ns1=ns;
          ns=ns+1;
          if(ns!=1){
            ia=ia+1;
            b[ia]=0.;
          }
          ia=ia+1;
          b[ia]=ak[ns1];
          ia=ia+1;
          b[ia]=0.;
          ia=ia+1;
          b[ia]=-ak[ns];
          ia=ia+1;
          b[ia]=0.;
          ia=ia+1;
          b[ia]=h[ns1];
          ia=ia+1;
          b[ia]=1.;
          ia=ia+1;
          b[ia]=0.;
          ia=ia+1;
          b[ia]=-1.;
          if(ns!=ks){
            ia=ia+1;
            b[ia]=0.;
          }
        }
        mud=2;
        mld=2;
        ia=ia+1;
        b[ia]=0.;
      }	//10
      if(beta<0){
        ia=ia+1;
        b[ia]=h[ks-1];
        ia=ia+1;
        b[ia]=1.;
      }else{
        ia=ia+1;
        b[ia]=ak[ks]+beta*h[ks];
        ia=ia+1;
        b[ia]=beta;
      }
      return;
    }

    Программист на фортране может программировать на любом языке... как на фортране.

    Abbath, 16 Сентября 2014

    Комментарии (19)
  11. SQL / Говнокод #16675

    −118

    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
    CREATE FUNCTION get_date RETURN DATE
    IS
    BEGIN
        RETURN SYSDATE;
    END;
    
    DECLARE
        v_date  DATE;
        v_dummy VARCHAR2(2);
    BEGIN
    
    v_date := SYSDATE+4/24/60/60;
    
    SELECT MAX(dummy)
      INTO v_dummy
      FROM dual
    connect BY v_date > get_date;
    
    END;

    "А есть ли какой-то еще способ, когда нет прав на DBMS_LOCK? "

    http://www.sql.ru/forum/1115120/pauza-v-pl-sql-kak

    n1919, 10 Сентября 2014

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