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

    +2

    1. 1
    wrapOnException(() -> file.writeTo(env.getFiler()));

    https://www.youtube.com/watch?v=nCkpzqqog4k

    3_dar, 17 Августа 2021

    Комментарии (5)
  2. Куча / Говнокод #27576

    +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
    // And then I replaced the idiomatic Rust code for working with block like
    
        for (dline, (sline0, sline1)) in dst.chunks_mut(dstride).zip(tmp.chunks(TMP_BUF_STRIDE).zip(tmp2.chunks(TMP_BUF_STRIDE))).take(h) {
            for (pix, (&a, &b)) in dline.iter_mut().zip(sline0.iter().zip(sline1.iter())).take(w) {
                *pix = ((u16::from(a) + u16::from(b) + 1) >> 1) as u8;
            }
        }
    
    // with raw pointers:
    
        unsafe {
            let mut src1 = tmp.as_ptr();
            let mut src2 = tmp2.as_ptr();
            let mut dst = dst.as_mut_ptr();
            for _ in 0..h {
                for x in 0..w {
                    let a = *src1.add(x);
                    let b = *src2.add(x);
                    *dst.add(x) = ((u16::from(a) + u16::from(b) + 1) >> 1) as u8;
                }
                dst = dst.add(dstride);
                src1 = src1.add(TMP_BUF_STRIDE);
                src2 = src2.add(TMP_BUF_STRIDE);
            }
        }

    What do you know, the total decoding time for the test clip I used shrank from 6.6 seconds to 4.9 seconds. That’s just three quarters of the original time!

    And here is the problem. In theory if Rust compiler knew that the input satisfies certain parameters i.e. that there’s always enough data
    to perform full block operation in this case, it would be able to optimise code as good as the one I wrote using pointers or even better.
    But unfortunately there is no way to tell the compiler that input slices are large enough to perform the operation required amount of times.
    Even if I added mathematically correct check in the beginning it would not eliminate most of the checks.

    https://codecs.multimedia.cx/2021/05/missing-optimisation-opportunity-in-rust/

    3.14159265, 17 Августа 2021

    Комментарии (125)
  3. JavaScript / Говнокод #27575

    +7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    console.log(parseInt(0.5)); // 0
    console.log(parseInt(0.05)); // 0
    console.log(parseInt(0.005)); // 0
    console.log(parseInt(0.0005)); // 0
    console.log(parseInt(0.00005)); // 0
    console.log(parseInt(0.000005)); // 0
    console.log(parseInt(0.0000005)); // 5

    https://ideone.com/YMWUGq

    Возможно баян, спижжено с https://vk.com/wall-72495085_1267978

    3_dar, 17 Августа 2021

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

    0

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

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

    JloJle4Ka, 15 Августа 2021

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