1. Java / Говнокод #27574

    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
    package test.sandbox
    
    object Main {
      def foo(implicit a: Int): Int = a * 2
    
      def main(args: Array[String]): Unit = {
        {
          import Test._
          val result = foo
    
          println(s"Result1 = $result") // Result1 = 42
        }
        {
          implicit val x = 16
          println(s"Result2 = $foo")  // Result2 = 32
        }
      }
    }
    
    object Test {
      implicit val x: Int = 21
    }

    "Scala" — сахарная. (*^‿^*)

    PolinaAksenova, 16 Августа 2021

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

    +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
    type int = 1;
    
    function makeRangeIterator(start = 0, end = 10000, step = 1) {
        print("makeRangeIterator.");
    
        let nextIndex = start;
        let iterationCount = 0;
    
        const rangeIterator = {
    	next() {
                let result: [value: int, done: boolean];
                if (nextIndex < end) {
                    result = [nextIndex, false];
                    nextIndex += step;
                    iterationCount++;
                    return result;
                } else {
                    result = [iterationCount, true];
                }
    
                return result;
            },
        };
    
        return rangeIterator;
    }
    
    function main() {
        let it = makeRangeIterator(1, 10, 2);
    
        let result = it.next();
        while (!result.done) {
            print(result.value); // 1 3 5 7 9
            result = it.next();
        }
    
        print("done.");
    }

    Ну вот и все... позвольте мне представить самый сложный кусок когда либо компилированный моей программой. но ввиду того что "трамплины" хрен знает как работают то придется этот код "забанить" до лучших времен. Но он рабочий

    ASD_77, 16 Августа 2021

    Комментарии (140)
  3. Куча / Говнокод #27571

    0

    1. 1
    2. 2
    3. 3
    Автомобиль-русофоб
    
    https://habr.com/ru/post/572984/

    Я нашел статью про Насру (formerly Gologub).

    JloJle4Ka, 15 Августа 2021

    Комментарии (1)
  4. Куча / Говнокод #27570

    +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
    16. 16
    C	5.2s 	gcc test.c
    C++	1m 25s 	g++ test.cpp
    Zig	10.1s 	zig build-exe test.zig
    Nim	45s 	nim c test.nim
    Rust	Stopped after 30 minutes	rustc test.rs
    Swift	Stopped after 30 minutes 	swiftc test.swift
    D	Segfault after 6 minutes 	dmd test.d
    
    Rust and Swift took too long to compile 400k lines, so I tried smaller numbers: 
    
    # lines	Rust	Swift 	D
    2k	3.4s 	0.8s
    4k	9.0s 	1.0s
    8k	30.8s 	2.3s
    20k	3m 52s 	11.8s 	4.7s
    100k	- 	5m 57s 	segfault

    https://vlang.io/compilation_speed

    3.14159265, 15 Августа 2021

    Комментарии (40)
  5. JavaScript / Говнокод #27569

    +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
    class S
    {
    	print()
    	{
    		print("Hello World");
    	}
    }
    
    interface IPrn
    {
    	print();
    }
    
    function run(iface:IPrn)
    {
    	iface.print();
    }
    
    function main() {
    	const s = new S();
    	let iface = <IPrn>s;
    	iface.print();	
    	run(s);
    }

    короче новый говнокод подоспел. Т.к. вы все тут самые умные я не раскажу в чем фича. Сами догадаетесь

    ASD_77, 15 Августа 2021

    Комментарии (42)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. Си / Говнокод #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)