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

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

    −92

    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
    def get_next_line(max_level, current_level, current_line_items)
            next_line_items = []
            result_string = ''
    
            if current_level == 1
                    next_line_items.push(1)
                    result_string = "1\n"
            else
                    current_line_number = false
                    current_line_number_count = 0
                    current_index = 0
    
                    current_line_items.each do |line_number|
                            if current_index == 0
                                    current_line_number = line_number
                                    current_line_number_count = 1
                            else
                                    if line_number == current_line_number
                                            current_line_number_count = current_line_number_count + 1
                                    else
                                            next_line_items.push(current_line_number_count)
                                            next_line_items.push(current_line_number)
    
                                            current_line_number_count = 1
                                            current_line_number = line_number
                                    end
                            end
    
                            if current_index >= current_line_items.length - 1
                                    next_line_items.push(current_line_number_count)
                                    next_line_items.push(current_line_number)
                            end
    
                            current_index = current_index + 1
                    end
    
                    result_string = next_line_items.join(' ') + "\n"
            end
    
            if current_level < max_level
                    result_string = result_string + get_next_line(max_level, current_level + 1, next_line_items).to_s
            end
    
            # return result
            result_string
    end
    
    puts 'Input max level:'
    level = gets
    
    puts ''
    puts get_next_line(level.to_i, 1, [])

    реальное тестовое задание кандитата.
    задача - вывести несколько членов последовательности
    1
    11
    21
    1211
    ....

    malleus, 04 Июня 2010

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    string buf;
    ...
    char c_buf[MAX_LEN];
    strncpy(c_buf, buf.c_str(), MAX_LEN);

    в чём ошибка?

    skor4ik, 10 Мая 2010

    Комментарии (63)
  4. SQL / Говнокод #22

    −1094

    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
    SELECT A.Id AS AppraiserId, 
    	(SELECT A2.FieldValueInt AS SubcontractorId
    	FROM sm_forms_FieldValues A2
    	WHERE 
    		A2.InstanceId = (
    			SELECT 	FormInstanceId
    			FROM	sm_genericdatabase_Instances
    			WHERE	ModuleId=1736 AND Title='Appraisers'
    			)
    		AND 
    		A2.FieldId = (
    			SELECT Id FROM sm_forms_Fields 
    			WHERE InstanceId= A2.InstanceId 
    			AND Title = 'Subcontractor'	
    			)
    		AND
    		A2.ValueId=A.Id
    	) AS SubcontractorId,
    	
    	(SELECT A3.FieldValueInt
    	FROM sm_forms_FieldValues A3
    	WHERE 
    		InstanceId = (
    			SELECT 	FormInstanceId
    			FROM	sm_genericdatabase_Instances
    			WHERE	ModuleId=1736 AND Title='Appraisers'
    			)
    		AND 
    		FieldId = (
    			SELECT Id FROM sm_forms_Fields 
    			WHERE InstanceId= A3.InstanceId 
    			AND Title = 'Heavy Equipment'	
    			)
    		AND
    		A3.ValueId= A.Id
    	) AS HeavyEquipment,
    	
    	(SELECT A3.FieldValueInt
    	FROM sm_forms_FieldValues A3
    	WHERE 
    		InstanceId = (
    			SELECT 	FormInstanceId
    			FROM	sm_genericdatabase_Instances
    			WHERE	ModuleId=1736 AND Title='Appraisers'
    			)
    		AND 
    		FieldId = (
    			SELECT Id FROM sm_forms_Fields 
    			WHERE InstanceId= A3.InstanceId 
    			AND Title = 'Name'	
    			)
    		AND
    		A3.ValueId= A.Id
    	) AS Name
    	
    	
    	FROM sm_forms_Values A
    	where InstanceId = (
    			SELECT 	FormInstanceId
    			FROM	sm_genericdatabase_Instances
    			WHERE	ModuleId=1736 AND Title='Appraisers'
    			)
    	ORDER BY 2

    выборка из большой базы... И нихрена не понятной.

    guest, 27 Ноября 2008

    Комментарии (63)
  5. Go / Говнокод #28342

    +1

    1. 1
    Конструктор по умолчанию?

    Не, не слышали.
    Рефлексией итерируемся по свойствам и вызываем функцию инициализации полей ))))))))))))))

    3_dar, 22 Августа 2022

    Комментарии (62)
  6. JavaScript / Говнокод #27863

    0

    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
    type NetworkLoadingState = {
      state: "loading";
    };
    
    type NetworkFailedState = {
      state: "failed";
      code: number;
    };
    
    type NetworkSuccessState = {
      state: "success";
      response: {
        title: string;
        duration: number;
        summary: string;
      };
    };
    
    type NetworkState =
      | NetworkLoadingState
      | NetworkFailedState
      | NetworkSuccessState;
    
    
    function logger(state: NetworkState): string {
      switch (state.state) {
        case "loading":
          return "Downloading...";
        case "failed":
          // The type must be NetworkFailedState here,
          // so accessing the `code` field is safe
          return `Error ${state.code} downloading`;
        case "success":
          return `Downloaded ${state.response.title} - ${state.response.summary}`;
        default:
          return "<error>";
      }
    }
    
    function main() {
        print(logger({ state: "loading" }));
        print(logger({ state: "failed", code: 1.0 }));
        print(logger({ state: "success", response: { title: "title", duration: 10.0, summary: "summary" } }));
        print(logger({ state: "???" }));
        print("done.");
    }

    Ура... радуйтесь.... я вам еще говнокодца поднадкинул... ну и перекопал же говна в коде что бы это сделать. Дампик тут.. https://pastebin.com/u7XZ00LV Прикольно получается если скомпилить с оптимизацией то нихрена от кода не остается. и результат работы

    C:\temp\MLIR_to_exe>1.exe
    Downloading...
    Error 1 downloading
    Downloaded title - summary
    <error>
    done.

    ASD_77, 10 Декабря 2021

    Комментарии (62)
  7. Куча / Говнокод #27281

    +5

    1. 1
    2. 2
    3. 3
    inkanus-gray
    gost
    syoma

    Вернитесь.

    OCETuHCKuu_nemyx, 03 Марта 2021

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

    +2

    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
    Function/method calling convention. Here’s a simple example:
    
    struct Foo { a: i32 }
    impl Foo { fn bar(&mut self, val: i32) { self.a = val + 42; } }
    fn main() {
      let mut foo = Foo { a: 0 };
      foo.bar(foo.a);
    }
    
    For now this won’t compile because of the borrowing but shouldn’t the compiler be smart enough to create a copy of foo.a before call?
    I’m not sure but IIRC current implementation first mutably borrows object for the call and only then tries to borrow the arguments.
    Is it really so and if yes, why?
    Update: I’m told that newer versions of the compiler handle it just fine but the question still stands (was it just a compiler problem or the call definition has been changed?).
    
    The other thing is the old C caveat of function arguments evaluation. Here’s a simple example:
    
    let mut iter = “abc”.chars();
    foo(iter.next().unwrap(), iter.next().unwrap(), iter.next().unwrap());
    
    So would it be foo('a','b','c') or foo('c','b','a') call. In C it’s undefined because it depends on how arguments are passed on the current platform 
    (consider yourself lucky if you don’t remember __pascal or __stdcall). 
    
    In Rust it’s undefined because there’s no formal specification to tell you even that much. 
    And it would be even worse if you consider that you may use the same source for indexing the caller object like 
    handler[iter.next().unwrap() as usize].process(iter.next().unwrap()); in some theoretical bytecode handler 
    (of course it’s a horrible way to write code and you should use named temporary variables but it should illustrate the problem).

    https://codecs.multimedia.cx/2020/09/why-rust-is-not-a-mature-programming-language/

    3.14159265, 27 Сентября 2020

    Комментарии (62)
  9. Куча / Говнокод #26632

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    Срочно нужна помощь с засылкой на хабр!
    
    Желательно перед этим почитать от того, что не пропустит анальная модерация и сектанты.
    
    Предложения так же жду в комментах. По тексту и в целом.

    https://tsar1997.blogspot.com/2020/05/blog-post_54.html

    Исходник пасты - просьба кидать патчи. Позже зашлю на хабр.

    https://pastebin.com/raw/haeHPx89

    3.14159265, 03 Мая 2020

    Комментарии (62)
  10. Java / Говнокод #26297

    −6

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    // определяем приоритет операций
         private int getPriority(char currentCharacter){
         if (Character.isLetter(currentCharacter))            return 4;
    else if (currentCharacter =='*'|| currentCharacter=='/')  return 3;
    else if (currentCharacter == '+'|| currentCharacter=='-') return 2;
    else if (currentCharacter == '(')                         return 1;
    else if (currentCharacter ==')')                          return -1;
    else                                                      return 0;
    }

    Калькулятор стажера

    kekar2, 31 Декабря 2019

    Комментарии (62)
  11. Python / Говнокод #25872

    0

    1. 1
    2. 2
    3. 3
    4. 4
    def __repr__(self):
        return 'environ({{{}}})'.format(', '.join(
            ('{!r}: {!r}'.format(self.decodekey(key), self.decodevalue(value))
            for key, value in self._data.items())))

    {{впечатляйте{с{GNU/Python}}}}

    Stallman, 26 Сентября 2019

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