1. Список говнокодов пользователя Desktop

    Всего: 12

  2. Куча / Говнокод #24511

    −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
    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
    #lang racket
    (require (for-syntax racket/syntax syntax/to-string))
    (require ffi/unsafe)
    
    (define-for-syntax *method-names*
      ; Given I have hello, one and two methods in my shared lib
      (list "hello"
            "one"
            "two"
            ))
    
    (define-syntax (load-ffi-functions stx)
      (syntax-case stx ()
        [(_ name lib ffi-func)
        (let ([elem->fn-id 
                (λ (elem-str)
                  (display elem-str)
                  (format-id 
                   stx "~a" 
                   (datum->syntax stx (string->symbol elem-str))))]
                )
          (with-syntax ([(_) 
            (elem->fn-id "one")])
            #`(begin
              (define (name)
                  (printf (string->symbol name))
                  (ffi-func name lib (_fun -> _int))
                  )
                )
            )
        )]))
    
    (define rustlib (ffi-lib "./libffitest.dylib"))
    
    (define-syntax (define-ffi-func stx)
      (syntax-case stx ()
        [(_ lib ffi-func)
         (let ([elem->fn-id 
                (λ (elem-str)
                  (format-id 
                   stx "~a" 
                   (datum->syntax stx (string->symbol elem-str))))]
                )
           (with-syntax 
             ([((method name) ...)
               (map 
                (λ (elem)
                  (list (elem->fn-id elem) elem)
                )
                *method-names*)])
             #`(begin
                 (define method
                    (ffi-func name lib (_fun -> _int))
                  )
                 ...)))]))
    
    (define-ffi-func rustlib get-ffi-obj)
    (+ (one) (two) (one))

    Когда мне показали, как это правильно сделать, я немного ох#ел.

    Desktop, 17 Июля 2018

    Комментарии (4)
  3. Swift / Говнокод #24489

    0

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    type file;
    
    app (file o) simulation ()
    {
      simulate stdout=filename(o);
    }
    
    foreach i in [0:9] {
      file f <single_file_mapper; file=strcat("output/sim_",i,".out")>;
      f = simulation();
    }

    Более другой swift

    Desktop, 13 Июля 2018

    Комментарии (38)
  4. Swift / Говнокод #24431

    +1

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    @dynamicMemberLookup
    struct Uppercaser {
        subscript(dynamicMember input: String) -> String {
            return input.uppercased()
        }
    }
    
    Uppercaser().hello // → "HELLO"
    // You can type anything, as long as Swift accepts it as an identifier.
    Uppercaser().käsesoße // → "KÄSESOSSE"

    https://oleb.net/blog/2018/06/dynamic-member-lookup

    The proposal and implementation of dynamic member lookup was largely driven by the Swift for TensorFlow team at Google. Their main motivation is to facilitate interoperability between Swift and dynamic languages, specifically (though not exclusively) Python. Their goal is to make it possible to call Python code from Swift with a pretty and familiar syntax.

    We need MOAR syntax sugar

    Desktop, 30 Июня 2018

    Комментарии (18)
  5. Objective C / Говнокод #24124

    −6

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    + (NSString*)enumToString:(SomeEnum)someEnumValue
    {
    	NSDictionary *strings =
    	@{
    		@(SomeEnumUndefined) : @"Undefined",
    		@(SomeEnumValue1) : @"Value1",
    		@(SomeEnumValue2) : @"Value2",
    		// Ещё 100500 пар
    	};
    
    	return strings[@(someEnumValue)];
    }

    Имена изменены, но смысл понятен. Точнее, непонятен.

    Desktop, 14 Апреля 2018

    Комментарии (82)
  6. Objective C / Говнокод #23987

    −3

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    NSString* bodyParams = [NSString stringWithFormat:@"username=%@&password=%@&client_secret=very_secret", username, password];
    
    // Ниже по коду
    
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[bodyParams dataUsingEncoding:NSUTF8StringEncoding]];

    И ведь имя переменной не врёт

    Desktop, 23 Марта 2018

    Комментарии (92)
  7. Swift / Говнокод #23907

    +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
    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
    protocol Multi {
        associatedtype T
        associatedtype U
    
        func printSelf()
    }
    
    extension Multi where T == Int, U == Float {
        func printSelf() {
            print("Int & Float!")
        }
    }
    
    extension Multi where T == String, U == Int {
        func printSelf() {
            print("String & Int!")
        }
    }
    
    extension Multi {
        func printSelf() {
            print("Unknown")
        }
    }
    
    class MultiImplementationIntFloat: Multi {
        typealias T = Int
        typealias U = Float
    }
    
    class MultiImplementationStringInt: Multi {
        typealias T = String
        typealias U = Int
    }
    
    class MultiImplementationInvalid: Multi {
        typealias T = Float
        typealias U = String
    }
    
    let m1 = MultiImplementationIntFloat()
    m1.printSelf()
    
    let m2 = MultiImplementationStringInt()
    m2.printSelf()
    
    let m3 = MultiImplementationInvalid()
    m3.printSelf()

    Multimethods в Swift с проверкой в compile-time

    Desktop, 10 Марта 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    Whether or not you check in your Pods folder is up to you, as workflows vary from project to project. We recommend that you keep the Pods directory under source control, and don't add it to your .gitignore
    
    Benefits of checking in the Pods directory
    
        After cloning the repo, the project can immediately build and run, even without having CocoaPods installed on the machine. There is no need to run pod install, and no Internet connection is necessary.
        The Pod artifacts (code/libraries) are always available, even if the source of a Pod (e.g. GitHub) were to go down.
        The Pod artifacts are guaranteed to be identical to those in the original installation after cloning the repo.

    https://guides.cocoapods.org/using/using-cocoapods.html

    Desktop, 25 Февраля 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    -(id)copyWithZone:(NSZone *)zone
    {
        NSString* str = [self toJSONString];
        
        return [[MyBeautifulClass alloc] initWithJSON:str :NO];
    }

    Desktop, 05 Февраля 2018

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

    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
    mixin template IConvertible(Args...)
    {
        interface IConvertible
        {
            mixin template IConvertiblePrivate(T)
            {
            	T Convert();
            }
        
            mixin template IConvertiblePrivate(TFirst, Args...) 
            {
    	TFirst Convert();
    	mixin IConvertiblePrivate!(Args);
            }
            
            mixin IConvertiblePrivate!(Args);
        };
    }
    
    void main()
    {
       mixin IConvertible!(int, float);
       
       class Number : IConvertible 
       {
       	int Convert() { return 0; }
       	float Convert() { return 0.0; }
       };
    }

    #dlang

    В продолжение темы дженериков и шаблонов

    P.S. Проверочный код: hate

    Desktop, 06 Января 2018

    Комментарии (4)
  11. Swift / Говнокод #23638

    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
    open class Converter {
        init() { }
        func convert<T, U>(from: T) -> U {
            return self.convert(from: T.self)
        }
        
        private func convert(from: MyClass1) -> MyClass2 {
            return MyClass2(value: from.value)
        }
        
        private func convert(from: MyClass2) -> MyClass1 {
            return MyClass1(value: from.value)
        }
    }
    
    let converter = Converter()
    let mC1 = MyClass1(value: 10)
    let mC2 = MyClass2(value: 30)
    
    let mc2_1: MyClass2 = converter.convert(from: mC1)
    let mc1_1: MyClass1 = converter.convert(from: mC2)

    So deep, too recursion

    Desktop, 04 Января 2018

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