1. C++ / Говнокод #27568

    +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
    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
    // https://github.com/seanbaxter/circle/blob/master/examples/README.md#tldr
    // ...
    // Circle's primary syntactic element is the @meta keyword, which runs the prefixed statement
    // during source translation (or during template instantiation in dependent contexts).
    
    // https://github.com/seanbaxter/circle/blob/master/examples/README.md#same-language-reflection
    // duff1.cxx
    
    void duff_copy1(char* dest, const char* source, size_t count) {
      const char* end = source + count;
      while(size_t count = end - source) {
        switch(count % 8) {
          case 0: *dest++ = *source++; // Fall-through to case 7
          case 7: *dest++ = *source++; // Fall-through to case 6...
          case 6: *dest++ = *source++;
          case 5: *dest++ = *source++;
          case 4: *dest++ = *source++;
          case 3: *dest++ = *source++;
          case 2: *dest++ = *source++;
          case 1: *dest++ = *source++;
          break;
        }
      }
    }
    
    // Reproduced above is a simplified version of Duff's device, an infamous memcpy function designed
    // to reduce the amount of branching in the operation. (The loop is optimally interleaved with the switch,
    // but I'm trying to illustrate some other points and don't want to add to the confusion.) Once we enter the
    // switch, perform an assignment and unconditionally progress to the next case statement. This algorithm
    // cries out for automation. The case statements have indices that run from 8 down to 1, modulo 8. Can we give it the Circle treatment?
    
    // duff2.cxx
    
    void duff_copy2(char* dest, const char* source, size_t count) {
      const char* end = source + count;
      while(size_t count = end - source) {
        switch(count % 8) {
          @meta for(int i = 8; i > 0; --i)
            case i % 8: *dest++ = *source++;
          break;
        }
      }

    Но гомоиконности таким подкостыливанием вы естественно не добавите!

    j123123, 14 Августа 2021

    Комментарии (21)
  2. JavaScript / Говнокод #27562

    +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
    type int = 1;
    
    function main() {
        let result: [value: int, done: boolean];
    
        let v: int | undefined;
        v = 1;
    
        result = [v, false];
    
        print(result[0], result[1]);
    
        assert(result[0] == 1);
        assert(result[1] == false);
    }

    опа. новый говнокодец подоспел. а кто знает какая проблема решалась в данном коде?

    ASD_77, 14 Августа 2021

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

    +1

    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
    QSqlQuery& SQLConnect::get()
    {
        if ( makeConnection() ) {
            query = QSqlQuery(mDb);
            return query;
        }
        QSqlQuery empty;
        return empty;
    }
    
    bool SQLConnect::makeConnection()
    {
       mDb = SQLConnectPool::Instance().get();
       return true;
    }

    Раньше компилилось и не замечал, а тут на новом компиляторе начал кидать ошибки и решил посмотреть, что же там напроектировали

    avk17, 14 Августа 2021

    Комментарии (12)
  4. bash / Говнокод #27560

    +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
    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
    #!/bin/bash
    set -euo pipefail
    
    host() {
        echo "n${1}.local"
    }
    
    node() {
        echo "erl@$(host $1)"
    }
    
    build() {
        [ "${1}" -eq "1" ] && echo "build: ."
    }
    
    container() {
        cat <<EOF
      worker${1}:
        $(build $1)
        image: worker
        hostname: $(host $1)
        networks:
          backplane:
            aliases:
              - $(host $1)
    
        environment:
        - "NODE_NAME=$(node $1)"
        - ... прочая питушня
    EOF
    }
    
    main() {
        cat <<EOF
    version: '3.3'
    
    networks:
      backplane:
    
    services:
    $(node 1)
    
    $(node 2)
    
    ...
    EOF
    }
    
    main > docker-compose.yml
    docker-compose $@

    Как тебе такое, Helm?

    CHayT, 13 Августа 2021

    Комментарии (35)
  5. Си / Говнокод #27559

    +3

    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
    #include <stdlib.h>
    #include <stdio.h>
    #include <inttypes.h>
    
    #define STRING 0
    #define INTEGER 1
    
    
    #define CAT(x,y) x ## _ ## y
    #define J(x,y)  CAT(x,y)
    
    
    typedef union
    {
      char *J(v, STRING);
      int J(v,INTEGER);
    } Un;
    
    typedef struct
    {
      uint8_t Obj_t;
      Un u;
    } Object;
    
    #define IF_INSTOF(var, t, newvar) \
    if(var.Obj_t == t) \
    { \
      typeof(var.u.J(v,t)) *newvar = &var.u.J(v,t);
    
    int main(void)
    {
      Object obj1 = {STRING, {.J(v,STRING) = "1"}};
      
      IF_INSTOF(obj1,STRING,str)
        printf("String: %s\n", *str);
      }
      else
      {
        printf("Not a string\n");
      }
    
      Object obj2 = {INTEGER, {.J(v,INTEGER) = 1}};
      IF_INSTOF(obj2,INTEGER,i)
        printf("Integer: %d\n", *i);
      }
      else
      {
        printf("Not an Integer\n");
      }
    
      return EXIT_SUCCESS;
    }

    Вот такие смарткасты через препроцессор.

    https://govnokod.ru/27556#comment655527

    j123123, 13 Августа 2021

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

    +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
    function foo(arg: any) {
        if (typeof arg === "string") {
            // We know this is a string now.
            print(arg);
        }
    }
    
    function main() {
        foo("Hello");
        foo(1);    
    
        print("done.");
    }

    наговнокодил

    ASD_77, 13 Августа 2021

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

    +1

    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
    function foo(arg: any) {
        if (typeof arg === "string") {
            // We know this is a string now.
            print(<string>arg);
        }
    }
    
    function main() {
        foo("Hello");
        foo(1);    
    
        print("done.");
    }

    я вам новый говнокодец притарабанил.... вот будете как настоящие жабаскриптеры в нативе

    ASD_77, 11 Августа 2021

    Комментарии (162)
  8. JavaScript / Говнокод #27555

    +5

    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
    function call_func_1(
        f: () => void
    ) {
        f();
    }
    
    function call_func(
        f: (o: object) => void,
        user: { firstName: string }
    ) {
        f(user);
    }
    
    function main() {
        const user = {
            firstName: "World",
            sayHi() {
                print(`Hello ${this.firstName}`);
            },
        };
    
        user.sayHi();
    
        const hi = user.sayHi;
        hi();
    
        let hi2 = user.sayHi;
        hi2();
    
        call_func_1(() => {
            hi2();
        });
    
        call_func(user.sayHi, user);
    
        print("done.");
    }

    как тебе такой говно-пиздец Илон Маск?

    ASD_77, 10 Августа 2021

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

    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
    47. 47
    48. 48
    static public (int, int) FirstPosition(int figure, int rotate)
            {
                int x = 0;
                int y = 0;
                if ((figure == 1) && (rotate == 1)) { x = 6; y = 2; }
                if ((figure == 1) && (rotate == 2)) { x = 6; y = 3; }
                if ((figure == 2) && (rotate == 1)) { x = 6; y = 2; }
                if ((figure == 2) && (rotate == 2)) { x = 6; y = 3; }
                if ((figure == 3) && (rotate == 1)) { x = 6; y = 2; }
                if ((figure == 3) && (rotate == 2)) { x = 6; y = 3; }
                if ((figure == 4) && (rotate == 1)) { x = 6; y = 2; }
                if ((figure == 4) && (rotate == 2)) { x = 6; y = 2; }
                if ((figure == 4) && (rotate == 3)) { x = 6; y = 2; }
                if ((figure == 4) && (rotate == 4)) { x = 6; y = 3; }
                if ((figure == 5) && (rotate == 1)) { x = 6; y = 2; }
                if ((figure == 5) && (rotate == 2)) { x = 6; y = 3; }
                if ((figure == 5) && (rotate == 3)) { x = 6; y = 2; }
                if ((figure == 5) && (rotate == 4)) { x = 6; y = 2; }
                if ((figure == 6) && (rotate == 1)) { x = 6; y = 3; }
                if ((figure == 6) && (rotate == 2)) { x = 6; y = 2; }
                if ((figure == 6) && (rotate == 3)) { x = 6; y = 2; }
                if ((figure == 6) && (rotate == 4)) { x = 6; y = 2; }
                if ((figure == 7) && (rotate == 1)) { x = 6; y = 3; }
                return (x, y);
            }                           //НАЧАЛЬНАЯ ПОЗИЦИЯ ЦЕНТРА ФИГУРЫ
            static public int[,] Position(int figure, int rotate, int[,] a, int x, int y)
            {
                if ((figure == 1) && (rotate == 1)) { a[x, y - 2] = 1; a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
                if ((figure == 1) && (rotate == 2)) { a[x - 1, y] = 1; a[x, y] = 1; a[x + 1, y] = 1; a[x + 2, y] = 1; }
                if ((figure == 2) && (rotate == 1)) { a[x - 1, y - 1] = 1; a[x - 1, y] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
                if ((figure == 2) && (rotate == 2)) { a[x - 1, y] = 1; a[x, y] = 1; a[x, y - 1] = 1; a[x + 1, y - 1] = 1; }
                if ((figure == 3) && (rotate == 1)) { a[x + 1, y - 1] = 1; a[x + 1, y] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
                if ((figure == 3) && (rotate == 2)) { a[x - 1, y - 1] = 1; a[x, y - 1] = 1; a[x, y] = 1; a[x + 1, y] = 1; }
                if ((figure == 4) && (rotate == 1)) { a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; a[x + 1, y + 1] = 1; }
                if ((figure == 4) && (rotate == 2)) { a[x + 1, y] = 1; a[x, y] = 1; a[x - 1, y] = 1; a[x - 1, y + 1] = 1; }
                if ((figure == 4) && (rotate == 3)) { a[x - 1, y - 1] = 1; a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
                if ((figure == 4) && (rotate == 4)) { a[x - 1, y] = 1; a[x, y] = 1; a[x + 1, y] = 1; a[x + 1, y - 1] = 1; }
                if ((figure == 5) && (rotate == 1)) { a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; a[x - 1, y + 1] = 1; }
                if ((figure == 5) && (rotate == 2)) { a[x - 1, y - 1] = 1; a[x - 1, y] = 1; a[x, y] = 1; a[x + 1, y] = 1; }
                if ((figure == 5) && (rotate == 3)) { a[x + 1, y - 1] = 1; a[x, y - 1] = 1; a[x, y] = 1; a[x, y + 1] = 1; }
                if ((figure == 5) && (rotate == 4)) { a[x - 1, y] = 1; a[x, y] = 1; a[x + 1, y] = 1; a[x + 1, y + 1] = 1; }
                if ((figure == 6) && (rotate == 1)) { a[x, y] = 1; a[x, y - 1] = 1; a[x - 1, y] = 1; a[x + 1, y] = 1; }
                if ((figure == 6) && (rotate == 2)) { a[x, y - 1] = 1; a[x + 1, y] = 1; a[x, y + 1] = 1; a[x, y] = 1; }
                if ((figure == 6) && (rotate == 3)) { a[x - 1, y] = 1; a[x, y + 1] = 1; a[x + 1, y] = 1; a[x, y] = 1; }
                if ((figure == 6) && (rotate == 4)) { a[x, y - 1] = 1; a[x - 1, y] = 1; a[x, y + 1] = 1; a[x, y] = 1; }
                if ((figure == 7) && (rotate == 1)) { a[x, y] = 1; a[x + 1, y] = 1; a[x + 1, y - 1] = 1; a[x, y - 1] = 1; }
                return (a);
            }             //ПОСТРОЕНИЕ ФИГУРЫ ОТНОСИТЕЛЬНО ЕЁ ЦЕНТРА

    Поворот тетрисных фигур

    VladimirM4K, 08 Августа 2021

    Комментарии (52)
  10. Куча / Говнокод #27551

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    10 лет назад читала самоучитель по Паскалю, где были задания: "написать алгоритм для нахождения простых чисел до n", 
    "написать 2D-пушку (на CRT модуле)". 
    Сейчас хочется найти его, вспомнить свое детство (задолго до того, как пошла формошлепить хех). 
    Ничего похожего пока не нашла.

    JaneBurt, 06 Августа 2021

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