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

    +163

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if($errors == 0){
                $filename = 'films.txt';
                if(!file_exists($filename)){
                    flose(fopen($filename,'w'));
                }
    }

    denis90, 12 Апреля 2012

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

    +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
    14. 14
    15. 15
    16. 16
    17. 17
    function reverseStack()
    {
    $this->stackNotation = array_reverse($this->stackNotation);
    $this->lenght = count($this->stackNotation);
    return $this->lenght;
    }
    
    function calculateNotation()
    {
    $this->result = $this->stackNotation[0];
    for($this->i = 1; $this->i < $this->lenght; $this->i++) {
    $this->j = $this->i — 1;
    switch($this->arifmeticSign[$this->j] ) {
    case ’*’:
    $this->result = $this->result * $this->stackNotation[$this->i];
    
    ...

    новое слово в пэхэпэ-оопэ.

    http://dou.ua/forums/topic/5548/

    huitka, 11 Апреля 2012

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

    +154

    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
    #include "stdafx.h"
    #include "expression.h"
    #include <vector>
    
    int _tmain(int argc, _TCHAR* argv[]) {
    //Инициализация
    	std::vector<expression> arrayOfExpressions;
    	std::string inputString;
    //Ввод количества выражений
    	printf( "Enter expressions count: " );
    	int countOfExpressions = 0;
    	scanf( "%d", &countOfExpressions );
    //Ввод самих выражений
    	for ( int i = 1; i <= countOfExpressions; i++ ) {
    		printf( "Enter expression: " );
    		scanf( "%s", inputString );
    		arrayOfExpressions.push_back( expression( inputString ) );
    	}
    //Подсчёт операторов
    	int total = 0;
    	for (int i = 0; i < arrayOfExpressions.size(); i++)
    		total += arrayOfExpressions.at(i).operatorsCount();
    	printf( "Total operators = %d", total );
    //Освобождение памяти
    	arrayOfExpressions.erase(arrayOfExpressions.begin(),arrayOfExpressions.end());
    	return 0;
    }

    Один из уже известных вам студентов написал вот это. Вроде получше.

    Fai, 11 Апреля 2012

    Комментарии (9)
  4. Java / Говнокод #9926

    +77

    1. 1
    2. 2
    Superclass s = new Subclass();
    ((Subclass)s).useSubclassMethod();

    Чудеса полиморфизма.

    thePooh, 11 Апреля 2012

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

    +110

    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
    public abstract class AbstractSegment<P extends Number, V extends IOffsettable<P, V>,
    		U extends AbstractSegment<P, V, U>> implements IOffsettable<P, U>, Iterable<V>, Serializable {
    	...
    	
    	protected final List<V> offsetHelper(final P dx, final P dy) {
    		return Lists.transform(points, new Function<V, V>() {
    			@Override
    			public V apply(final V input) {
    				return input.offset(dx, dy);
    			}
    		});
    	}
    
    
    
    public final class FloatSegment extends AbstractSegment<Float, FloatPoint, FloatSegment> {
    	...
    	@Override
    	public FloatSegment offset(final Float dx, final Float dy) {
    		return new FloatSegment(offsetHelper(dx, dy));
    	}
    }

    someone, 11 Апреля 2012

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

    +114

    1. 1
    EventTypeId = (int)Enum.Parse(typeof(AmazonMailingLogEventType), Enum.GetName(typeof(AmazonMailingLogEventType), AmazonMailingLogEventType.SendEmailError))

    вместо
    EventTypeId = (int)AmazonMailingLogEventType.SendEmail Error

    mozg_raka, 11 Апреля 2012

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

    +108

    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
    string result = Encoding.GetEncoding(CharSet).GetString(resultData);
                //       сам паттерн    \[\[\[\"([^"]*)
    
    
                String commonString = "";
                commonString += @"\";
                commonString += @"[";
                commonString += @"\";
                commonString += @"[";
                commonString += @"\";
                commonString += @"[";
                commonString += @"\";
                commonString += "\"";
                commonString += @"(";
                commonString += "[";
                commonString += "^";
                commonString += "\"";
                commonString += @"]";
                commonString += @"*";
                commonString += @")";
                String pattern = commonString;
    
                Regex reg = new Regex(pattern);
                var mathces = reg.Match(result);
                String stringResult = mathces.ToString().Replace("[[[\"", "");

    Сборка паттерна регулярки, скажите как можно такое покороче собрать

    AndrKn, 11 Апреля 2012

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

    +159

    1. 1
    2. 2
    3. 3
    4. 4
    bool THotKeysRepository::TKeyCombination::operator<( const TKeyCombination& y ) const
    {
    	return this->_AltKeyState<y._AltKeyState && this->_ScanCode<y._ScanCode;
    }

    Говногость, 11 Апреля 2012

    Комментарии (10)
  9. Си / Говнокод #9920

    +140

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    long long int temp;
    		temp=a-b;
    		if (temp<0) temp=temp*(-1);
    .....
    r = b*(2^g);

    Из работ студентов.
    Первый фрагмент - взятие по модулю.
    Второй - вызвал вопрос "почему неправильно работает возведение в степень?".

    startrack, 11 Апреля 2012

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

    +150

    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
    <tr class="cursor-over">
            <td><i class="fs12">Сегодня</i></td>
            <td><?= isset($today_stat['Отправлен']) ? $today_stat['Отправлен'] : 0 ?> <?=
    HTML::image('media/img/private/good.png',
            array('class' => 'png_bg', 'alt' => ''))
    ?></td>
            <td><?= isset($today_stat['В обработке']) ? $today_stat['В обработке'] : 0 ?></td>
            <td><?= isset($today_stat['Возврат']) ? $today_stat['Возврат'] : 0 ?></td>
            <td><?= isset($today_stat['Отказ']) ? $today_stat['Отказ'] : 0 ?> <?=
                HTML::image('media/img/private/error.png',
                        array('class' => 'png_bg', 'alt' => ''))
    ?></td>
        </tr>
        <tr class="cursor-over">
            <td><i class="fs12">Вчера</i></td>
            <td><?= isset($yesterday_stat['Отправлен']) ? $yesterday_stat['Отправлен'] : 0 ?> <?=
                HTML::image('media/img/private/good.png',
                        array('class' => 'png_bg', 'alt' => ''))
    ?></td>
            <td><?= isset($yesterday_stat['В обработке']) ? $yesterday_stat['В обработке'] : 0 ?></td>
            <td><?= isset($yesterday_stat['Возврат']) ? $yesterday_stat['Возврат'] : 0 ?></td>
            <td><?= isset($yesterday_stat['Отказ']) ? $yesterday_stat['Отказ'] : 0 ?> <?=
                HTML::image('media/img/private/error.png',
                        array('class' => 'png_bg', 'alt' => ''))
    ?></td>
        </tr>

    это кусок шаблона, в котором, "опытный" программист выводит некую статистику за некий период

    login, 11 Апреля 2012

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