1. C# / Говнокод #17421

    +134

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    using System;
    class ololo
    {
        static void Main()
        {
            int ru, en;
            for (ru = 7700; ru < 8025; ru += 25)
                for (en = 3220; en < 4050; en += 50)
                    Console.WriteLine("Ру " + ru + " и En " + en);
        }
    }

    Нужно было посчитать одновременно от 7700 до 8025 и от 3220 до 4050, в итоге получилось так.

    EVjGeNiX, 08 Января 2015

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

    +73

    1. 1
    2. 2
    3. 3
    4. 4
    @Override public int hashCode()
        {
            return id.hashCode(); // id - Integer !!!
        }

    Хэшкод интегера

    sarvigalava, 08 Января 2015

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

    +51

    1. 1
    auto a = []{return 1;}();

    http://rextester.com/NQVDP75721

    LispGovno, 08 Января 2015

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

    +46

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    extern QString code2text(unsigned long code)
    {
        if (code == 0) return QString::fromUtf8("Операция успешно завершена");
        if (code == 1) return QString::fromUtf8("Неверная функция");
        //over 3400 строк
        return QString("%1").arg(code);
    }

    как это сделать по человечески?
    полная версия https://github.com/kin63camapa/softodrom/blob/master/softodrom/errcodes.cpp

    kin63camapa, 07 Января 2015

    Комментарии (31)
  5. JavaScript / Говнокод #17417

    +155

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (!self.options.cat_main) {
        counter = self.renderSingleGame(game_id, cat, cat.name, counter);
    } else if (cat_id === self.options.cat_main) {
        counter = self.renderSingleGame(game_id, cat, cat.name, counter);
    }

    гениально!

    beatmasta, 07 Января 2015

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

    +46

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    In file included from ./boost/bind/bind.hpp:29:0,
                     from ./boost/bind.hpp:22,
                     from ./boost/multi_index/sequenced_index.hpp:50,
                     from ./boost/property_tree/ptree.hpp:23,
                     from ./boost/log/utility/setup/settings.hpp:26,
                     from ./boost/log/utility/setup/from_settings.hpp:25,
                     from libs/log/src/init_from_stream.cpp:19:
    ./boost/bind/arg.hpp: In constructor ‘boost::arg<I>::arg(const T&)’:
    ./boost/bind/arg.hpp:37:22: warning: typedef ‘T_must_be_placeholder’ locally defined but not used [-Wunused-local-typedefs]
             typedef char T_must_be_placeholder[ I == is_placeholder<T>::value? 1: -1 ];

    Выхлоп при компиляции зломерзкого (из-за громоздкости разумеется) boost. Шаблоны такие шаблоны. А всё из-за того, что надо поставить на ix2 deluge т.к встроенная качалка торрентов не умеет качать торренты (там можно только указать ограничение скорости и порты, но добавить torrent или magnet некуда).

    mittorn, 07 Января 2015

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

    +162

    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
    class StupidClass
    {
    	public function __toString()
    	{
    		return 'this';
    	}
    	public function hax()
    	{
    		return $this === $$$$$$this;
    	}
    }
    
    var_dump((new StupidClass)->hax()); // true

    Уииии

    Fike, 06 Января 2015

    Комментарии (6)
  8. Куча / Говнокод #17414

    +129

    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
    <macrodef name="foreach">
      <attribute name="target"/>
      <attribute name="file-property"/>
      <element name="files"/>
      <element name="args"/>
      <sequential>
        <local name="foreach.files"/>
        <local name="foreach.target"/>
        <local name="foreach.file-property"/>
        <local name="foreach.args"/>
        <property name="foreach.target" value="@{target}"/>
        <property name="foreach.file-property" value="@{file-property}"/>
        <pathconvert property="foreach.files">
          <files/>
        </pathconvert>
        <propertyset id="foreach.args">
          <args/>
        </propertyset>
        <property name="foreach.args" refid="foreach.args"/>
        <property name="foreach.target" value="@{target}"/>
        <!-- there is no better way to do this at the moment
             property names and values should not contain comma-space and equals signs
        -->
        <script language="javascript"><![CDATA[
           var files = project.getProperty("foreach.files").split(":"),
           args = project.getProperty("foreach.args").split(", "),
           task = project.createTask("antcall"), arg;
    
           task.target = project.getProperty("foreach.target");
           for (var a in args) {
             arg = task.createParam();
             arg.setName(a.split("=")[0]);
             arg.setValue(String(a.split("=")[1]));
           }
    
           for (var f in files) {
             arg = task.createParam();
             arg.setName(project.getProperty("foreach.file-property"));
             arg.setValue(String(files[f]));
             task.perform();
           }
         ]]></script>
      </sequential>
    </macrodef>
    <!-- пример использования: -->
    
    <target name="transcode-font-helper">
      <property name="font.face.local" value="${font.face}"/>
      <foreach target="transcode-font" file-property="font.raw.source">
        <files>
          <fileset dir="${basedir}/fonts">
            <include name="*/${font.face.local}/*.otf"/>
            <include name="*/${font.face.local}/*.ttf"/>
          </fileset>
        </files>
        <args>
          <propertyref name="font.face.local"/>
        </args>
      </foreach>
    </target>

    А ведь если подумать: собрали все самое лучше, что есть в современном программировании - Ява, ХМЛ и ж.скрипт. Потом выбросили условные операторы, итерацию и операции со строкам - потому что не нужны. И получилась замечательная система для сборки проектов.

    wvxvw, 06 Января 2015

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

    +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
    <?php
    
    function load ($file) {
    	static $files = null;
    	$files or $files = [];
    	
    	if (!isset($files[$file])) {
    		require($file);
    		$files[$file] = true;
    	}
    }
    
    $times = 1000000;
    $time1 = microtime(true);
    
    for ($i = 0; $i < $times; $i ++) {
    	require_once('inc.php');
    }
    
    $end1 = microtime(true) - $time1;
    
    $time2 = microtime(true);
    
    for ($i = 0; $i < $times; $i ++) {
    	load('inc.php');
    }
    
    $end2 = microtime(true) - $time2;
    
    echo "require_once = $end1 vs \nload = $end2";

    Вот это да... require_once работает в ~8 раз медленнее чем функция load. Вывод:
    require_once = 16.962311029434 vs
    load = 2.6861710548401

    Содежания файла inc.php:

    <?php echo 'Hello, world!';

    volter9, 06 Января 2015

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

    +151

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    $friends = mysql_query("(SELECT * FROM  `friends` WHERE `from` LIKE  '{$act}' AND  `to` LIKE  '{$act}' AND  `isaccepted` =  '1') UNION (SELECT  `id` ,  `name` ,  `surname` FROM  `users_info`);");
    		$friend = array();$loop=0;
    		while($fetch = mysql_fetch_assoc($friends)) {
    			if ($fetch['from'] == $act) $search=$fetch['to']; else $search=$fetch['from'];
    			$friend[$loop]=mysql_fetch_assoc(mysql_query("SELECT `id`,`name`,`surname` FROM `users_info` where `id`='{$search}'"));
    			$loop++;
    		}

    Почему не работает?

    yanislavb, 05 Января 2015

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