1. C++ / Говнокод #8415

    +1011

    1. 1
    #define RETURN_OR_THROW_EXCEPTION_IF_ERROR(Expression, Exception) if(!Expression) throw Exception; return Expression

    AnimeGovno-_-, 03 Ноября 2011

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

    +75

    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
    // Gets the starting position for the endtag of the first element in text.
        private int getEndTagPosition(String element, String text) {
            String startTag = "<" + element;
            String endTag = "</" + element;
            int nestingLevel = 1;
            int end = 0;
            int startPos = 1;
    
            while (nestingLevel > 0) { // loop until matching endtag is found
                int start = text.indexOf(startTag, startPos);
                end = text.indexOf(endTag, startPos);
    
                if ((start == -1) || (start > end)) {   // next tag is an endtag
                    nestingLevel--;
                    startPos = end + 1;
                } else {    // next tag is a starttag
                    nestingLevel++;
                    startPos = start + 1;
                }
            }
    
            return end;
        }

    euee, 03 Ноября 2011

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

    +127

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if (ddlSex.SelectedValue.Contains("мужской"))
           cbPregnant.Visible = false;
    if (employer.Pregnant.StartsWith("1"))
          cbProject.Checked = true;
    if (employer.Pregnant.StartsWith("2"))
          cbPregnant.Checked = true;

    TasmX, 03 Ноября 2011

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

    +163

    1. 1
    2. 2
    while($row = mysql_fetch_array($r))
    	echo $row[0] . '|' . $row[1] . '|' . $row[2] . '|' . $row[3] . '|' . $row[4] . '|' . $row[5] . "\n";

    implode? не, не слышал

    1101_debian, 03 Ноября 2011

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

    +165

    1. 1
    2. 2
    mysql_query("DELETE FROM tblTokens WHERE intRestaurantID = $id AND cToken = '$token';");
    mysql_query("INSERT INTO tblTokens (intRestaurantID, cToken) VALUES ($id, '$token');");

    Увеличиваем id, наверное.

    1101_debian, 03 Ноября 2011

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

    +71

    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
    /**
     * @see ru.dwin.inbox.gtk.videotypes.IVideo#startPlay(int)
     */
    @Override public void startPlay(int delay)
    {
        try
        {
            Thread.sleep(delay * 1000);
        }
        catch (InterruptedException e1)
        {
            RestartAllThreads();     
        }
        if (theTimer == null)
        {
            theTimer = new Timer(ASECOND, new ActionListener()
            {
                @Override public void actionPerformed(ActionEvent e)
                {
    	if (elapsedTime >= getDuration())
    	{
    	    theTimer.stop();
    	    resetPlay();
    	    Toolkit.getDefaultToolkit().beep();
    	}
    	else
    	{
    	    elapsedTime += (int) ASECOND / 1000;
    	    notifyAddedRenderers(USwingWorker.ALL);
                    }
                }
            });
        }
        else
        {
            theTimer.start();
        }
    }

    Играть через ХЗ сколько секунд...

    dwinner, 03 Ноября 2011

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

    +161

    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
    class Super_Loader extends Zend_Loader {
        public static function loadClass($class, $dirs = null)
        {
            parent::loadClass($class, $dirs);
        }
    
        private function moduleIsExist($name) {
            if(is_dir(APPLICATION_PATH . "/modules/" . $name . "/")) {
                return true;
            }
    
            return false;
        }
    
        public static function autoload($class)
        {
            $classArray = explode("_", $class);
            $firstPart = array_shift($classArray);
    
            if(self::moduleIsExist($firstPart)) {
    
                $moduleDir = APPLICATION_PATH . "/modules/";
                $typePart = array_shift($classArray);
                switch($typePart) {
                    case "Lib":
                        $file_name = $moduleDir . $firstPart . "/lib/" . implode("/", $classArray) . ".php";
                        break;
                    case "Model":
                        $file_name = $moduleDir . $firstPart . "/models/" . implode("/", $classArray) . ".php";
                        break;
                    default:
    
                        break;
                }
    
                if($file_name) {
                    try {
                        self::loadFile($file_name);
                        return $class;
                    } catch (Exception $e) {
                        return false;
                    }
                }
            } else {
                try {
                    self::loadClass($class);
                    return $class;
                } catch (Exception $e) {
                    return false;
                }
            }
        }
    }

    Свой супер-автолоадер для ZF

    asfalanaft, 03 Ноября 2011

    Комментарии (12)
  8. Objective C / Говнокод #8408

    −107

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    - (void)applicationWillTerminate:(UIApplication *)application
    {
        exit(0);
        /*
         Called when the application is about to terminate.
         Save data if appropriate.
         See also applicationDidEnterBackground:.
         */
    }

    На всякий пожарный, а то вдруг не завершиться апп.

    lime, 03 Ноября 2011

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

    +167

    1. 1
    2. 2
    3. 3
    $query1234 = "select ....";
    $result1234 = mysql_query($query1234);
    $rs1234 = mysql_fetch_assoc($result1234);

    Это до такой степени не было фантазии придумать осмысленное название переменным. И бедные боялись, что перепишет где-то другие $query, $result, $rs. Не говоря уже о том, что никакой модели, сплошные фетчи, вместо того, чтобы вытянуть всё сразу

    Sash, 03 Ноября 2011

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

    +75

    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
    private Connection getConnection() throws SQLException {
    		Connection conn = null;
    		try{
    			conn = DriverManager.getConnection(OnlineUsers.db,OnlineUsers.user,OnlineUsers.pass);
    		} catch (Exception e) {
    			log.severe(name + ": " + e.getMessage());
    		}
    		checkConnection(conn);
    		return conn;
    	}
    	
    	private boolean checkConnection (Connection conn) throws SQLException {
    		if (conn == null) {
    				log.severe("Could not connect to the database. Check your credentials in online-users.settings");
    			throw new SQLException();
    		}
    		if (!conn.isValid(5)) {
            	log.severe("Could not connect to the database.");
            	throw new SQLException();
            }
    		return true;
    	}
    	
    	private boolean execute(String sql) {
    		return execute(sql, null);
    	}
    	
    	private boolean execute(String sql, String player) {
    		Connection conn = null;
            PreparedStatement ps = null;
            try {
            	conn = getConnection();
            	ps = conn.prepareStatement(sql);
            	if (player != null && !player.equalsIgnoreCase("")) {
            		ps.setString(1, player);
            	}
            	
            	if (ps.execute()) {
            		return true;
            	}
            } catch (SQLException ex) {
            	log.severe(name + ": " + ex.getMessage());
            	String msg = name + ": could not execute the sql \"" + sql + "\"";
            	if (player != null ) {
            		msg += "    ?=" +player;
            	}
            	log.severe(msg);
            } finally {
                try {
                    if (ps != null) {
                        ps.close();
                    }
                    if (conn != null) {
                        conn.close();
                    }
                } catch (SQLException ex) {
                	log.severe(name + ": " + ex.getMessage());
                }
            }
            return false;
    	}

    Мартин, 02 Ноября 2011

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