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

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

    +3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (!$('#enable-continious').is(':checked') && $('#enable-continious').is(':checked')) {
    	...
    } else {
    	...
    }

    Продолжаем находить великие письмена великих людей на проекте. К слову, человек на позиции Senior PHP Developer является автором.

    Un3Solka, 31 Августа 2015

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

    +4

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    with TfmVersionUpdate.Create(Application) do
    begin
      try
        Init;
      except
      end;
      Free;
    end;

    Такой код 100500% отработает без ошибок. Зачем вообще сообщения о них выводить...

    kiryl, 19 Августа 2015

    Комментарии (21)
  4. 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)
  5. 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)
  6. Python / Говнокод #18011

    −241

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

    3_14dar, 17 Апреля 2015

    Комментарии (21)
  7. 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)
  8. 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)
  9. 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)
  10. 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)
  11. 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)