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

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

    +5

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    <?
    if($login=='')
    {
       global $APPLICATION;
       $APPLICATION->ThrowException('Имя входа должно быть заполнено.'); 
       return false;
    }
    
    // Получить последнее исключение можно методом 
    $APPLICATION->GetException()
    ?>

    Bitrix. Лучшие стандарты веб-разработки и новое ядро! Создатели логики try-catch-throw наверное перевернулись бы 100500 раз в гробу увидев такую "реализацию". Пруф как "нужно делать": https://dev.1c-bitrix.ru/api_help/main/reference/cmain/throwexception.php

    zenn1989, 08 Июня 2016

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

    +1

    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
    #include <iostream>
    #include <map>
    
    template <typename T1, typename T2, typename F>
    void operator ^= (std::map<T1,T2> &m, F func) {
        for (typename std::map<T1,T2>::iterator i = m.begin();  i != m.end(); ) {
            if (func(i))
                i = m.erase(i);
            else
                ++i;
        }
    }
    
    template <typename T1, typename T2>
    void operator ^= (std::map<T1,T2> &m, T2 value) {
        for (typename std::map<T1,T2>::iterator i = m.begin();  i != m.end(); ) {
            if (value == i->second)
                i = m.erase(i);
            else
                ++i;
        }
    }
    
    int main() {
        std::map<int,bool> m = {
            {0,false},
            {1,true},
            {2,false},
            {3,true},
            {4,false},
            {5,true},
            {6,false},
            {7,true},
            {8,false},
            {9,true},
            {10,false}
        };
    
        for (auto i = m.begin(); i != m.end(); ++i)
            std::cout << "{" << i->first << "," << i->second << "} ";
        std::cout << std::endl;
    
        m ^= false;
        m ^= [](auto &i) { return i->first == 5; };
    
        for (auto i = m.begin(); i != m.end(); ++i)
            std::cout << "{" << i->first << "," << i->second << "} ";
        std::cout << std::endl;
    }

    Для std::vector'a запись не особо-то кошерная:

    std::vector<int> v = {1,2,3,4,5};
    v.erase(std::remove_if(v.begin(),v.end(),[](int &i){ return i <= 3;}), v.end());
    А для std::map даже такого не придумали. Пора исправлять

    Antervis, 10 Мая 2016

    Комментарии (17)
  4. JavaScript / Говнокод #19856

    +7

    1. 1
    2. 2
    3. 3
    4. 4
    function checkPermission(user, post) {
      return equals(post.author, user) ||
             user.role = 'admin';
    }

    when you see it, you'll shit bricks

    thepotato, 21 Апреля 2016

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

    −3

    1. 1
    2. 2
    $this->strQueryText = $strQuery = trim($arParams["QUERY"]);
    $this->strTags = $strTags  = $arParams["TAGS"];

    Из ядра.
    Многобуков не любят.

    braun3812, 07 Апреля 2016

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

    +4

    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
    <div class="col-sm-3">
    	<select class="form-control" id="year">
    		<option <?php if($explode[0] == 2002) Echo "selected"; ?> value="2002">2002</option>
    		<option <?php if($explode[0] == 2001) Echo "selected"; ?> value="2001">2001</option>
    		<option <?php if($explode[0] == 2000) Echo "selected"; ?> value="2000">2000</option>
    		<option <?php if($explode[0] == 1999) Echo "selected"; ?> value="1999">1999</option>
    		<option <?php if($explode[0] == 1998) Echo "selected"; ?> value="1998">1998</option>
    		<option <?php if($explode[0] == 1997) Echo "selected"; ?> value="1997">1997</option>
    		<option <?php if($explode[0] == 1996) Echo "selected"; ?> value="1996">1996</option>
    		<option <?php if($explode[0] == 1995) Echo "selected"; ?> value="1995">1995</option>
    		<option <?php if($explode[0] == 1994) Echo "selected"; ?> value="1994">1994</option>
    		<option <?php if($explode[0] == 1993) Echo "selected"; ?> value="1993">1993</option>
    		<option <?php if($explode[0] == 1992) Echo "selected"; ?> value="1992">1992</option>
    		<option <?php if($explode[0] == 1991) Echo "selected"; ?> value="1991">1991</option>
    		<option <?php if($explode[0] == 1990) Echo "selected"; ?> value="1990">1990</option>
    		<option <?php if($explode[0] == 1989) Echo "selected"; ?> value="1989">1989</option>
    		<option <?php if($explode[0] == 1988) Echo "selected"; ?> value="1988">1988</option>
    		<option <?php if($explode[0] == 1987) Echo "selected"; ?> value="1987">1987</option>
    		<option <?php if($explode[0] == 1986) Echo "selected"; ?> value="1986">1986</option>
    		<option <?php if($explode[0] == 1985) Echo "selected"; ?> value="1985">1985</option>
    		<option <?php if($explode[0] == 1984) Echo "selected"; ?> value="1984">1984</option>
    		<option <?php if($explode[0] == 1983) Echo "selected"; ?> value="1983">1983</option>
    		<option <?php if($explode[0] == 1982) Echo "selected"; ?> value="1982">1982</option>
    		<option <?php if($explode[0] == 1981) Echo "selected"; ?> value="1981">1981</option>
    		<option <?php if($explode[0] == 1980) Echo "selected"; ?> value="1980">1980</option>
    		<option <?php if($explode[0] == 1979) Echo "selected"; ?> value="1979">1979</option>
    		<option <?php if($explode[0] == 1978) Echo "selected"; ?> value="1978">1978</option>
    		<option <?php if($explode[0] == 1977) Echo "selected"; ?> value="1977">1977</option>
    		<option <?php if($explode[0] == 1976) Echo "selected"; ?> value="1976">1976</option>
    		<option <?php if($explode[0] == 1975) Echo "selected"; ?> value="1975">1975</option>
    	</select>
    </div>

    Суровые челябинские программисты продолжают кодить :)

    by133312, 13 Марта 2016

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

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    void MultMatrix(const GLfloat m1[16], const GLfloat m2[16], GLfloat result[16])
    {
      glLoadMatrixf(m1);
      glMultMatrixf(m2);
      glGetFloatv(GL_MODELVIEW_MATRIX, result);
    }

    LispGovno, 12 Марта 2016

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

    +5

    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
    catch(...)
    {
    	static int i = 0;                     
    	//if we enter this catch clause more than 1 time
    	//it is very likely that the RestartSystem() command
    	//did not succeed. If this is the case we just exit.
    	if(i>0)
    		exit(0);
    	else
    		MonitorT::GetInstance()->RestartSystem();
    	i++;
    	throw;
    }

    Навеяло...

    blackhearted, 11 Марта 2016

    Комментарии (17)
  9. C++ / Говнокод #19606

    +6

    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
    //		implicit_cast< >
    // I believe this was originally going to be in the C++ standard but 
    // was left out by accident. It's even milder than static_cast.
    // I use it instead of static_cast<> to emphasize that I'm not doing
    // anything nasty. 
    // Usage is identical to static_cast<>
    template <class OutputClass, class InputClass>
    inline OutputClass implicit_cast(InputClass input){
    	return input;
    }
    
    //		horrible_cast< >
    // This is truly evil. It completely subverts C++'s type system, allowing you 
    // to cast from any class to any other class. Technically, using a union 
    // to perform the cast is undefined behaviour (even in C). But we can see if
    // it is OK by checking that the union is the same size as each of its members.
    // horrible_cast<> should only be used for compiler-specific workarounds. 
    // Usage is identical to reinterpret_cast<>.
    
    // This union is declared outside the horrible_cast because BCC 5.5.1
    // can't inline a function with a nested class, and gives a warning.
    template <class OutputClass, class InputClass>
    union horrible_union{
    	OutputClass out;
    	InputClass in;
    };
    
    template <class OutputClass, class InputClass>
    inline OutputClass horrible_cast(const InputClass input){
    	horrible_union<OutputClass, InputClass> u;
    	// Cause a compile-time error if in, out and u are not the same size.
    	// If the compile fails here, it means the compiler has peculiar
    	// unions which would prevent the cast from working.
    	typedef int ERROR_CantUseHorrible_cast[sizeof(InputClass)==sizeof(u) 
    		&& sizeof(InputClass)==sizeof(OutputClass) ? 1 : -1];
    	u.in = input;
    	return u.out;
    }

    Боль и страдание шаблонного программирования на С++98. Комменты и названия доставляют.

    gorthauer87, 11 Марта 2016

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

    −1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    <?if (strlen($prod['img'])>0):?>						
    	<img src="<?=URL::site()?>resize/resizer.php?type=photos&width=260&height=210&method=crop&image=<?=$prod['img']?>"/></a>						
    <?else:?>
    	<img src="<?=URL::site()?>resize/resizer.php?type=catalog&width=260&height=210&method=crop&image=nophoto.jpg"/></a>
    <?endif?>

    Вы ещё не знаете, как использовать ООП для генерации URL? Тогда мы идём к вам!

    UncaughtException, 07 Октября 2015

    Комментарии (17)
  11. Assembler / Говнокод #18603

    +74

    1. 1
    2. 2
    3. 3
    4. 4
    foobar:
        stmdb sp!, {r4-r11, lr}
        ...
        ldmia sp!, {r4-r11, pc}

    Ассемблер для ARM'а, оказывается, очень даже няшный.

    bormand, 15 Августа 2015

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