1. PHP / Говнокод #17035

    +156

    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
    <?php
    class ACL  
    {  
        var $perms = array();     // Массив : Содержит привилегия текущего пользователя
        var $userID = 0;          // Целое число : Содержит ID текущего пользователя
        var $userRoles = array(); // Массив : Содержат роли текущего пользователя
      
        function __constructor($userID = '')  
        {  
            if ($userID != '')  
            {  
                $this->userID = floatval($userID);  
            } else {  
                $this->userID = floatval($_SESSION['userID']);  
            }  
            $this->userRoles = $this->getUserRoles('ids');  
            $this->buildACL();  
        }  
        function ACL($userID='')  
        {  
            $this->__constructor($userID);  
        } 
    ?>

    Конструктор
    __constructor() предназначен для того, чтобы инициализировать объект при создании экземпляра класса ACL. Он вызывается автоматически после вот этой записи: new ACL();

    Не сразу понял, что логика тут есть, но какая-то кривая

    DmitryDick, 02 Ноября 2014

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

    +140

    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
    type func = function (x : real) : real;
    const
    	eps = 0.0000003;
    	pi = 3.14159265358979;
    function Integral (f : func; a, b : real) : real;
    var center : real;
    begin
    	center := (a + b) / 2;
    	if abs(b - a) < eps then
    		Integral := f(center) * (b - a)
    	else Integral := Integral(f, a, center) + 
    		Integral(f, center, b);
    end;
    function myFunc(x : real) : real;
    begin
    	myFunc := cos(x) / x;
    end;
    begin
    	writeln(Integral(myFunc, pi/2, pi));
    	readln;
    end.

    Толи я дурачек, толи автор кода - школьник....

    ShadowXX, 02 Ноября 2014

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

    +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
    protected boolean valid_move(int from, int to, int aBoard[], int colorfor) {
      if(plainType(colorfor) == userColor) {
        return (to>=0 && to<=35 && from >=0 && from<=35 && plainType(aBoard[from])==colorfor && aBoard[to]==emptyType 
                && ((from-to == 4 || from-to==5) 
                    || ((from-to == 10 && plainType(aBoard[from-5])==oppositeType(colorfor)) 
                        || (from-to == 8 && plainType(aBoard[from-4])==oppositeType(colorfor))) 
                    || (aBoard[from]==kingType(colorfor) 
                        && ((to-from == 4 || to-from==5) 
                            || ((to-from == 10 && plainType(aBoard[from+5])==oppositeType(colorfor)) 
                                || (to-from == 8 && plainType(aBoard[from+4])==oppositeType(colorfor)))))));
      }
      else {
        return (to>=0 && to<=35 && from >=0 && from<=35 && plainType(aBoard[from])==colorfor && aBoard[to]==emptyType 
                && ((to-from == 4 || to-from==5) 
                    || ((to-from == 10 && plainType(aBoard[from+5])==oppositeType(colorfor)) 
                        || (to-from == 8 && plainType(aBoard[from+4])==oppositeType(colorfor))) 
                    || (aBoard[from]==kingType(colorfor) 
                        && ((from-to == 4 || from-to==5) 
                            || ((from-to == 10 && plainType(aBoard[from-5])==oppositeType(colorfor)) 
                                || (from-to == 8 && plainType(aBoard[from-4])==oppositeType(colorfor))))))); // =)))))
      }
    }

    https://github.com/haiming020/BBS-AKB48/blob/master/src/Checkers.java

    zadrot, 01 Ноября 2014

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

    +139

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    struct Counter{
    	static int k;
    	Counter(){ k++; }
    	~Counter() { k--; }
    };
    int Counter::k = 0;
    #define LOL(x) {string s = #x; Counter c##x; cout<<s.substr(0,1+s.find('['))<<Counter::k<<"]="<<x<<'\n'; }

    Abbath, 01 Ноября 2014

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

    +145

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    function myscandir($dir){
    	if(!file_exists($dir)){
    		return false;
    	}
    
        $list = scandir($dir);
        unset($list[0],$list[1]);
        return array_values($list);
    }

    taras_shs, 31 Октября 2014

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

    +155

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    function generateSession()
    {
        $chars = "qazxswedcvfrtgbnhyujmkiolp1234567890QAZXSWEDCVFRTGBNHYUJMKIOLP";
        $max = rand(20, 32);
        $size = StrLen($chars) - 1;
        $sessionID = null;
        while ($max--)
            $sessionID .= $chars[rand(0, $size)];
        return $sessionID;
    }

    taras_shs, 31 Октября 2014

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    while (1) { // Не все знают логические значения
        ...
    }
    
    for (;;) // Ещё хуже
    { ... }

    nns2009, 31 Октября 2014

    Комментарии (28)
  8. C++ / Говнокод #17001

    +135

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    void SoundService::stop(){
        if (mOutputMixObj != NULL) {
            (*mOutputMixObj)->Destroy(mOutputMixObj);
            mOutputMixObj = NULL;
        }
        if(mEngineObj != NULL){
            (*mEngineObj)->Destroy(mEngineObj);
             mEngineObj = NULL; mEngine = NULL;
        }
    }

    Случайно нашёл в книге по Android NDK, открытой на случайной странице.

    tehned, 30 Октября 2014

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

    −106

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    qdev_id, iops = _update_device_iops(instance, device_for_change)
    try:
    	qemu.volumes.set_io_throttle(controller.qemu(), qdev_id, iops)
    except Exception as e:
    	# Check if we turn off this instance? just a moment ago.
    	if "'NoneType' object has no attribute 'connected'" in e:
    		LOG.warning("kemu process seems to be killed")
    	else:
    		raise

    Метод set_io_throttle не бросает exception.
    Мы так проверяем,есть ли connection к qemu или нет.

    gmmephisto, 30 Октября 2014

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

    +133

    1. 1
    2. 2
    3. 3
    TopPassGridBox.ItemsSource = CollectionViewSource.GetDefaultView((from t in Edit_Curent_Pass.PassFieldList
    	where Edit_Curent_Pass.PassFieldList.IndexOf(t) == 0 || Edit_Curent_Pass.PassFieldList.IndexOf(t) == 1 || Edit_Curent_Pass.PassFieldList.IndexOf(t) == 2
    	select t).ToList());

    Я так и не понял, что хотели этим сказать...

    SantePaulinum, 30 Октября 2014

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