1. Java / Говнокод #6658

    +147

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (nn.isleaf) {
          this.traverse_ssector((BSPLeaf) nn);
          return;
        }
        final BSPBranch n = (BSPBranch) nn;

    правильное наследование:
    в родительском классе BSPNode определено поле isleaf
    в конструкторе класса BSPLeaf оно выставляется true и никогда не меняется
    в конструкторе класса BSPBranch соответственно false

    а ведь так просто сделать проверку instanceof

    Lure Of Chaos, 14 Мая 2011

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

    +147

    1. 1
    2. 2
    3. 3
    static int getSign(final int num) {
        return (num < 0) ? -1 : (num > 0) ? 1 : 0;
      }

    лисапед, бо есть Math.signum()

    Lure Of Chaos, 14 Мая 2011

    Комментарии (8)
  3. Java / Говнокод #6656

    +147

    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
    try {
              final int dx = MazeBuilder.dirsx[n];
              final int dy = MazeBuilder.dirsy[n];
              final int dn = this.mazedists[this.px + dx][this.py + dy];
              if (dn < d) {
                break;
              }
            } catch (final Exception e) {
            }
    // потом, чуть дальше:
          if (n == 4) {
            this.dbg("HELP!");
          }

    заедаем исключения NullPointerException и ArrayIndexOutOfBoundsException, а заодно и если вдруг еще какое вылетит.
    неудивительно, что потом бывают сюрпризы

    Lure Of Chaos, 14 Мая 2011

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

    +147

    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
    // ...
    if ((dot1 > 0) || ((dot1 == 0) && (se.GetDir() == pe.GetDir()))) {
            rcount++;
          } else if ((dot1 < 0) || ((dot1 == 0) && (se.GetDir() == -pe.GetDir()))) {
            lcount++;
          } else {
            this.dbg("grade_partition problem: dot1 = " + dot1 + ", dot2 = " + dot2);
          }
    // ...
    
    // где GetDir определена так:
    int GetDir() {
      if (this.dx != 0) {
        return (this.dx < 0) ? 1 : -1;
      }
      return (this.dy < 0) ? 2 : -2;
    }

    вот мусор встретился.
    Pattern id: NOISE_OPERATION, type: NOISE, category: NOISE

    Lure Of Chaos, 14 Мая 2011

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

    +168

    1. 1
    2. 2
    3. 3
    $new_array=array();
    foreach ($old_array as $k => $v)
        $new_array[$k] = $v;

    Таким образом чел создаёт копию массива...

    uni, 14 Мая 2011

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

    −180

    1. 1
    2. 2
    3. 3
    auto = False
    if self.options.has_key('auto') and self.options['auto']:
        auto = True

    frol, 13 Мая 2011

    Комментарии (13)
  7. Java / Говнокод #6652

    +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
    import java.util.Calendar;
    public class CalendarTime {
    	public static void main(String args[]) {
    	Calendar now = Calendar.getInstance();
    	now.setTimeInMillis(System.currentTimeMillis());
    	System.out.println("Now : "+(((now.get(Calendar.YEAR))))+" year.");
    	System.out.println("Now : "+(((now.get(Calendar.MONTH))))+" month.");
    	System.out.println("Now : "+(((now.get(Calendar.DATE))))+" day.");
    	System.out.println("Now : "+(((now.get(Calendar.HOUR_OF_DAY))))+" hour.");
    	System.out.println("Now : "+(((now.get(Calendar.MINUTE))))+" minute.");
    	System.out.println("Now : "+(((now.get(Calendar.SECOND))))+" second.");
    	}
    }

    System.out.println("Now : "+(((now.get(Calendar.MONTH))))+" month.");
    Обратите внимание на эту строку. Отображение идёт некорректно , странно почему??
    С наилучшими пожеланиями, Sun Microsystems ^_^).

    Akira, 13 Мая 2011

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

    +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
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    function colorQuote($message) {
        global $tinyib, $mysql_posts_table, $mysql_database, $mysql_password, $mysql_username, $mysql_host;
        $message=str_replace("<", "<", $message);
        $message=str_replace("'", "'", $message);
        $message=str_replace("\n", "<br>\n", $message);
        $cd = getcwd();
        $lastSlash = 0;
        if (($lastSlash = strrpos($cd, '/')) === false)
        {
            if (($lastSlash = strrpos($cd, '\\')) === false)
            {
                $lastSlash = 0;
            }
        }
        $message_lines=explode("\n", $message);
        for($i=0; $i<count($message_lines); $i++) {
            if(preg_match("#^(\*|\+|-) .*#si", $message_lines[$i])) {
                if(!preg_match("#^(\*|\+|-) .*#si", $message_lines[$i-1]) && substr($message_lines[$i-1], 0, 4)!="<ul>" && substr($message_lines[$i-1], 0, 4)!="<li>"){
                    $message_lines[$i]="<ul>".preg_replace("#^(\*|\+|-) (.*)#si", "<li>\\2</li>", $message_lines[$i]);
                }
                $message_lines[$i]=preg_replace("#^(\*|\+|-) (.*)#si", "<li>\\2</li>", $message_lines[$i]);
                if(!preg_match("#^(\*|\+|-) .*#si", $message_lines[$i+1]) && substr($message_lines[$i+1], 0, 5)!="</ul>" && substr($message_lines[$i+1], 0, 4)!="<li>"){
                    $message_lines[$i].="</ul>";
                }
            }
            if(preg_match("|^[0-9]+\..*|si", $message_lines[$i])) {
                if(!preg_match("|^[0-9]+\..*|si", $message_lines[$i-1]) && substr($message_lines[$i-1], 0, 4)!="<ol>" && substr($message_lines[$i-1], 0, 4)!="<li>"){
                    $message_lines[$i]="<ol>".$message_lines[$i];
                }
                $message_lines[$i]=preg_replace("|[0-9]+\.(.*)|si", "<li>\\1</li>", $message_lines[$i]);
                if(!preg_match("|^[0-9]+\..*|si", $message_lines[$i+1]) && substr($message_lines[$i+1], 0, 5)!="</ol>" && substr($message_lines[$i+1], 0, 4)!="<li>"){
                    $message_lines[$i].="</ol>";
                }
            }
            $message_lines[$i]=preg_replace("|^>(.*)|is", "<span class=\"unkfunc\">>\\1</span>", $message_lines[$i]);
            if(preg_match("|^[\s]{4}.+$|si", $message_lines[$i])){
                $message_lines[$i]=preg_replace("|^[\s]{4}(.+)$|si", "<pre>\\1</pre>", $message_lines[$i]);
            }
        }
        $message=implode("\n", $message_lines);
        $message=preg_replace("|\*\*([^\*\*]+)\*\*|si", "<strong>\\1</strong>", $message);
        $message=preg_replace("|\*([^\*]+)\*|si", "<em>\\1</em>", $message);
        $message=preg_replace("|__([^__]+)__|si", "<span style='text-decoration: underline;'>\\1</span>", $message);
        $message=preg_replace("#(http://|ftp://|mailto:|irc:|news:)([^\s]+[^\s\.,?(!):;])#si", "<a href='\\1\\2'>\\1\\2</a>", $message);
        $message=preg_replace("|%%([^%%]+)%%|si", "<span class='spoiler'>\\1</span>", $message);
        $message=preg_replace("|`([^`]+)`|si", "<pre>\\1</pre>", $message);
        return $message;
    }

    Вставил почти целиком, только кусочек вырезал. PHP делает просто лютый пиздец!
    Откуда - сами догадаетесь.

    Skelet0n, 13 Мая 2011

    Комментарии (28)
  9. SQL / Говнокод #6650

    −119

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    $query = "SELECT * FROM ns_preces".
    			 	" inner join ns_group on".
    				" ns_group.groupid=ns_preces.groupid".
     				" WHERE (assortiment=1) ".$group_case." and (proizvod like '%".$_POST["find"]."%' or model like '%".$_POST["find"]."%')";
    			$view_type=4;

    Если значение поля FIND избавляем от пробелов с помощью JavaScrip, разбивается слово в t убираются пробелы, как несколько значений скормить такому запросу ?

    lan-dao, 13 Мая 2011

    Комментарии (16)
  10. PHP / Говнокод #6649

    +159

    1. 1
    2. 2
    3. 3
    while ($row = @mysql_fetch_array($this->_sqlResult, $result_type)):
    	$return[] = $row;
    endwhile;

    1_and_0, 13 Мая 2011

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