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

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (['text'].indexOf(data[a]['input']) === 'date') {
         data[a]['value'][f].subscribe(function (nv) {
             self.pollChanges();
        })
    }

    lord_rb, 24 Июня 2015

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    catch (Exception ex)
                {
                    status = ex.Message;
                    throw ex;
                }

    zhilinskyegor, 07 Мая 2015

    Комментарии (21)
  4. Python / Говнокод #18011

    −241

    1. 1
    2. 2
    3. 3
    def __repr__(self):
            # почему здесь бесконечная рекурсия?
            return repr(self.__repr__)

    3_14dar, 17 Апреля 2015

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

    +57

    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
    #include <iostream>
    #include <stdexcept>
    
    template<std::size_t N>
    static int constexpr date_component(const char (&s)[N], int i, bool last, int max) {
      return 
        (i + 2 + (last ? 0 : 1) >= N) 
            ? throw std::logic_error("Too short date string") :
        (!last && s[i + 2] != ':') 
            ? throw std::logic_error("Cannot find delimiter") :
        (s[i] < '0' || s[i] > '9' ||  s[i + 1] < '0' || s[i + 1] > '9') 
            ? throw std::logic_error("Not a number") :
        ((s[i] - '0') * 10 + (s[i + 1] - '0') > max) 
            ? throw std::logic_error("Too large number") :
                (s[i] - '0') * 10 + (s[i + 1] - '0');
    }
    
    struct time { 
        int hour; int minute; int second; 
        
        template<std::size_t N>
        constexpr time(const char (&datestr)[N]) :
            hour(date_component(datestr, 0, false, 24)), 
            minute(date_component(datestr, 3, false, 60)),
            second(date_component(datestr, 6, true, 60)) 
        {}
    };
    
    struct time constexpr midnight("00:00:00");
    struct time constexpr afternoon("12:00:00");
    
    int main(int argc, char* argv[]) {
        std::cout << "Midnight hour is " << midnight.hour << std::endl;
        std::cout << "Afternoon hour is " << afternoon.hour << std::endl;
    }

    C++ и даты времени компиляции

    myaut, 03 Апреля 2015

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

    +164

    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
    function addnews($str1="", $str2="", $str3="", $str4="", $str5=""){
      $num = 0;
      $done = 0;
      while ($done == 0){
        $num++;
        $s = "";
        if ($num<10000000) {$s="0".$s;}
        if ($num<1000000)  {$s="0".$s;}
        if ($num<100000)   {$s="0".$s;}
        if ($num<10000)    {$s="0".$s;}
        if ($num<1000)     {$s="0".$s;}
        if ($num<100)      {$s="0".$s;}
        if ($num<10)       {$s="0".$s;}
    	$done = 1;
    	if (file_exists("news/".$s.$num.".txt")){$done=0;}
      }
      $fh1 =fopen("news/".$s.$num.".txt","w");
      fwrite($fh1, $str1."\r\n");
      fwrite($fh1, $str2."\r\n");
      fwrite($fh1, $str3."\r\n");
      fwrite($fh1, $str4."\r\n");
      fwrite($fh1, $str5);
      fclose($fh1);
    }

    Предложили доработать корпоративную тикет-систему. Движок абсолютно всё хранит в txt-файлах. Да, и пароли пользователей тоже - в открытом виде. БД? Нет, не слышали :(
    Но это еще не так страшно...

    Arris, 26 Марта 2015

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

    +54

    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
    void Game::initialize()
    {
        if (SDL_Init(SDL_INIT_VIDEO))
            exit(1);
        
        window = new Window("Game", 640, 480);
        try
        {
            window->create();
        }
        catch (const Exception& exception)
        {
            std::cout << exception.getError() << '\n';
            delete window;
            exit(1);
        }
        
        canvas = new Canvas();
        try
        {
            canvas->initialize(window->getWindow());
        }
        catch (const Exception& exception)
        {
            std::cout << exception.getError() << '\n';
            delete canvas;
            exit(1);
        }
    }

    jangolare, 09 Марта 2015

    Комментарии (21)
  8. PHP / Говнокод #17667

    +157

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    function getMinQueueOrdering()
      {
        $sql="SELECT MAX(ordering)
              FROM priceloaddata_queue";
      .........
      }

    нет слов.

    Vasiliy, 19 Февраля 2015

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

    +64

    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
    import java.util.HashMap;
    import java.util.Map;
    import java.util.StringTokenizer;
    
    public class PolynomialParser {
    	
    	public Polynomial parse(String rawPolynomial) {
    		String source = normalizeSourceString(rawPolynomial);
    		Map<Integer, Integer> result = new HashMap<>();
    		
    		StringTokenizer tokenizer = new StringTokenizer(source, "[+-]", true);
    		boolean isCurrentNegative = false;
    		int currentDegree;
    		int currentCoefficient;
    		while (tokenizer.hasMoreTokens()) {
    			String currentToken = tokenizer.nextToken();
    			if ("-".equals(currentToken)) {
    				isCurrentNegative = true;
    			} else if ("+".equals(currentToken)) {
    				isCurrentNegative = false;
    			} else {
    				if (currentToken.contains("x")) {
    					if (currentToken.contains("^")) {
    						String[] tmp = currentToken.split("x\\^");
    						currentDegree = Integer.parseInt(tmp[1]);
    						int draftCoefficient = Integer.parseInt(tmp[0]);
    						currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
    					} else {
    						currentDegree = 1;
    						String[] tmp = currentToken.split("x");
    						int draftCoefficient = (tmp.length == 0) ? 1 : Integer.parseInt(tmp[0]);
    						currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
    					}
    				} else {
    					currentDegree = 0;
    					int draftCoefficient = Integer.parseInt(currentToken);
    					currentCoefficient = (isCurrentNegative) ? - draftCoefficient : draftCoefficient;
    				}
    				result.put(currentDegree, currentCoefficient);
    			}
    		}
    		return new Polynomial(result);
    	}
    	
    	private String normalizeSourceString(String source) {
    		String result = source.replaceAll("\\s+","");
    		return result.toLowerCase();
    	}
    }

    Из сегодняшнего. Парсинг многочленов.

    itrofan-ebufsehjidov, 01 Февраля 2015

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

    +158

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    // classes.php
    return [
      'yii\base\Action' => YII2_PATH . '/base/Action.php',
      'yii\base\ActionEvent' => YII2_PATH . '/base/ActionEvent.php',
      'yii\base\ActionFilter' => YII2_PATH . '/base/ActionFilter.php',
      // еще порядка трех сотен классов
    ];

    https://github.com/yiisoft/yii2/blob/d2b864da84a68d56a96709479af78d203f050451/framework/classes.php

    осень 2014, использующий composer модный фреймворк, "requires PHP 5.4 and embraces the best practices and protocols found in modern Web application development", и, конечно, ебаный стыд.

    Fike, 18 Января 2015

    Комментарии (21)
  11. Java / Говнокод #17259

    +84

    1. 1
    List selection = new ArrayList((s != null) ? s : new ArrayList());

    Больше мусора для бога сборщика мусора!

    someone, 05 Декабря 2014

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