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

    +119

    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
    public static Tuple<t1, t2,="" t3,="" t4,="" t5,="" t6,="" t7,="" tuple=""><t8>> Create<t1, t2,="" t3,="" t4,="" t5,="" t6,="" t7,="" t8="">(T1 item1, T2 item2, T3 item3, T4 item4, T5 item5, T6 item6, T7 item7, T8 item8) {
                return new Tuple<t1, t2,="" t3,="" t4,="" t5,="" t6,="" t7,="" tuple=""><t8>>(item1, item2, item3, item4, item5, item6, item7, new Tuple<t8>(item8));
    
       Int32 IStructuralEquatable.GetHashCode(IEqualityComparer comparer) {
                // We want to have a limited hash in this case.  We'll use the last 8 elements of the tuple
                ITuple t = (ITuple) m_Rest;
                if(t.Size >= 8) { return t.GetHashCode(comparer); }
     
                // In this case, the rest memeber has less than 8 elements so we need to combine some our elements with the elements in rest
                int k = 8 - t.Size;
                switch(k) {
                    case 1:
                    return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
                    case 2:
                    return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
                    case 3:
                    return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
                    case 4:
                    return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
                    case 5:
                    return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
                    case 6:
                    return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
                    case 7:
                    return Tuple.CombineHashCodes(comparer.GetHashCode(m_Item1), comparer.GetHashCode(m_Item2), comparer.GetHashCode(m_Item3), comparer.GetHashCode(m_Item4), comparer.GetHashCode(m_Item5), comparer.GetHashCode(m_Item6), comparer.GetHashCode(m_Item7), t.GetHashCode(comparer));
                }
                Contract.Assert(false, "Missed all cases for computing Tuple hash code");
                return -1;
            }
     
            Int32 ITuple.GetHashCode(IEqualityComparer comparer) {
                return ((IStructuralEquatable) this).GetHashCode(comparer);
            }
            public override string ToString() {
                StringBuilder sb = new StringBuilder();
                sb.Append("(");
                return ((ITuple)this).ToString(sb);
            }
     
            string ITuple.ToString(StringBuilder sb) {
                sb.Append(m_Item1);
                sb.Append(", ");
                sb.Append(m_Item2);
                sb.Append(", ");
                sb.Append(m_Item3);
                sb.Append(", ");
                sb.Append(m_Item4);
                sb.Append(", ");
                sb.Append(m_Item5);
                sb.Append(", ");
                sb.Append(m_Item6);
                sb.Append(", ");
                sb.Append(m_Item7);
                sb.Append(", ");
                return ((ITuple)m_Rest).ToString(sb);
            }

    Давно заприметил в C# кортежи. За них отвечаёт чудесный класс System.Tuple
    http://msdn.microsoft.com/en-us/library/system.tuple.aspx
    Вот стало интересно - как они там это дело реализовали, ведь постоянно вводит новые плюшки в язык.
    Посмотрел и ужаснулся - решили "в лоб" и кортежи обошлись в 1000 строк.
    http://reflector.webtropy.com/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/clr/src/BCL/System/Tuple@cs/1305376/Tuple@cs

    Хотел запостить в #12129. Но он утонул.

    3.14159265, 19 Ноября 2012

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

    +9

    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
    class A
    {
    public:
            A () : p (new SomeType)
            {
                    assert ("It must be non-zero" && p);
            }
            ~A ()
            {
                    Box <SomeType> deleter (p);
                    p = 0;
            }
    private:
            SomeType *p;
    };

    А вот и применение класса Box

    Setry, 19 Ноября 2012

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

    +22

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    class ClassA 
    {
    };
    class ClassB : private ClassA
    {
    public:
    	ClassA& AsClassA()
    	{
    		return *this;
    	}
    };

    Setry, 19 Ноября 2012

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

    +22

    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
    template<class T>
    class Box
    {
    private:
    	explicit Box(const Box&);
    	Box& operator = (const Box&);
    public:
    	explicit Box()
    		: m_value(0)
    	{}
    	explicit Box(T* value)
    		: m_value(value)
    	{}
    	~Box()
    	{
    		std::auto_ptr <T> toDelete(m_value);
    	}
    	T* Release()
    	{
    		T* const result(m_value);
    		m_value = 0;
    		return result;
    	}
    	void Reset(T* value)
    	{
    		std::auto_ptr <T> toDelete(m_value);
    		m_value = value;
    	}
    private:
    	T* m_value;
    };

    Setry, 19 Ноября 2012

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

    −119

    1. 1
    2. 2
    3. 3
    1С::Функторы::АппликативныйФунктор::Монад 1С::Монада::НаЭкран -> 1С::Монада::Символ,1С::Монада::СимволСлед
    | Пустота = Отчёт.Откат()
    | 1С::Буква = 1С::МонадаМир::ВводВывод::Печать 1С::Буква

    Многие интересуются, существует ли в 1С метод вывода монады на экран? Оказывается, существует!
    Данный аппликативный функтор не требует теор.ката, хотя и не без улыбки, выводит квантовое состояние функциональной монады в виде стрелок и морфизмов.
    PS Автор не я, а мой коллега, который, ковыряясь в 1С, обнаружил в нём "Функциональный режим"

    serpinski, 18 Ноября 2012

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

    +139

    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
    <div class="slogan">
      <table>
        <tbody>
          <tr>
            <td>В</td>
            <td class="r"> </td>
            <td>с</td>
            <td class="r"> </td>
            <td>ё</td>
            <td> </td>
            <td class="r"> </td>
            <td>ч</td>
            <td class="r"> </td>
            <td>т</td>
            <td class="r"> </td>
            <td>о</td>
            <td> </td>
            <td class="r"> </td>
            <td>д</td>
            <td class="r"> </td>
            <td>в</td>
            <td class="r"> </td>
            <td>и</td>
            <td class="r"> </td>
            <td>ж</td>
            <td class="r"> </td>
            <td>е</td>
            <td class="r"> </td>
            <td>т</td>
            <td class="r"> </td>
            <td>с</td>
            <td class="r"> </td>
            <td>я</td>
          </tr>
        </tbody>
      </table>
    </div>

    Разрядка слогана "ВСЁ ЧТО ДВИЖЕТСЯ" на motor.ru

    Yurik, 18 Ноября 2012

    Комментарии (7)
  7. JavaScript / Говнокод #12147

    +157

    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
    <SCRIPT language=JavaScript>                     <!--#### Подпрограммы (скрипты) для вывода фотографий составных частей ПК #### -->
    	function picture1(){
    		window.open("P4P800.jpg", "newwindow01", config="width=460, height=515, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture2(){
    		window.open("CPU.jpg", "newwindow02", config="width=355, height=380, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture3(){
    		window.open("Video.jpg", "newwindow03", config="width=475, height=380, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture4(){
    		window.open("Syst.jpg", "newwindow04", config="width=220, height=220, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture5(){
    		window.open("audio.jpg", "newwindow05", config="width=315, height=200, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture6(){
    		window.open("Seti.jpg", "newwindow06", config="width=190, height=120, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture7(){
    		window.open("hdd.jpg", "newwindow07", config="width=725, height=425, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture8(){
    		window.open("dvd.jpg", "newwindow08", config="width=520, height=205, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture9(){
    		window.open("korpus.jpg", "newwindow09", config="width=820, height=435, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture10(){
    		window.open("monitor.jpg", "newwindow10", config="width=320, height=320, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture11(){
    		window.open("Klava.jpg", "newwindow11", config="width=510, height=250, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture12(){
    		window.open("Mouse.jpg", "newwindow12", config="width=340, height=285, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture13(){
    		window.open("print.jpg", "newwindow13", config="width=467, height=295, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    	function picture14(){
    		window.open("RAM.jpg", "newwindow14", config="width=530, height=135, toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0");
    }
    </script>                                    <!--#### Конец скриптов ####-->

    Stallman, 18 Ноября 2012

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

    −117

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Часто проскальзывают темы, что 1С часто отказывает в монадах.
    Я вот этого вообще не понимаю, как такое может выглядеть???
    Я со своей восьмёрочкой 2 года, в любой момент, когда я захочу монад, он будет.
    Если он скажет, нет, я не хочу, я показываю ему С++, показываю что я недоволен и говорю, почему ты не хочешь монаду?
    Ты любишь кресты? Когда монады встречаются в 1С, они должны преобразовываться по первому же желанию программиста.

    serpinski, 17 Ноября 2012

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

    +46

    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
    62. 62
    63. 63
    public function custom_result_object($class_name)
    	{
    		if (array_key_exists($class_name, $this->custom_result_object))
    		{
    			return $this->custom_result_object[$class_name];
    		}
    
    		if ($this->result_id === FALSE OR $this->num_rows() == 0)
    		{
    			return array();
    		}
    
    		// add the data to the object
    		$this->_data_seek(0);
    		$result_object = array();
    
    		while ($row = $this->_fetch_object())
    		{
    			$object = new $class_name();
    
    			foreach ($row as $key => $value)
    			{
    				$object->$key = $value;
    			}
    
    			$result_object[] = $object;
    		}
    
    		// return the array
    		return $this->custom_result_object[$class_name] = $result_object;
    	}
    
    	// --------------------------------------------------------------------
    
    	/**
    	 * Query result.  "object" version.
    	 *
    	 * @access	public
    	 * @return	object
    	 */
    	public function result_object()
    	{
    		if (count($this->result_object) > 0)
    		{
    			return $this->result_object;
    		}
    
    		// In the event that query caching is on the result_id variable
    		// will return FALSE since there isn't a valid SQL resource so
    		// we'll simply return an empty array.
    		if ($this->result_id === FALSE OR $this->num_rows() == 0)
    		{
    			return array();
    		}
    
    		$this->_data_seek(0);
    		while ($row = $this->_fetch_object())
    		{
    			$this->result_object[] = $row;
    		}
    
    		return $this->result_object;
    	}

    Govnisti_Diavol, 17 Ноября 2012

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

    −125

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    МояМонада :: МойПарсерТип МойПарсер -> (МойПарсерТип -> МойПарсер МойПарсерТип2) -> МойПарсер МойПарсерТип2
    
    МойСущность МойМонад [] Где
        Возврат МойТип = [МойТип]
        МойВозвратВозврат >>= МойФункция = МойСклейка (МойВсем МойФункция МойВозвратВозврат)

    Коллега выдал - закоммитил в локальный гитхаб 1С парсер хаскелля на 1С.

    serpinski, 17 Ноября 2012

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