1. 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

    Комментарии (39)
  2. 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

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

    −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
    static func == (lhs: Card, rhs: Card) -> Bool {
           return (lhs.color == rhs.color &&
            lhs.number == rhs.number &&
            lhs.shading == rhs.shading &&
            lhs.symbol == rhs.symbol) ||
            (lhs.color == rhs.color &&
            lhs.number != rhs.number &&
            lhs.shading != rhs.shading &&
            lhs.symbol != rhs.symbol) ||
            (lhs.color != rhs.color &&
            lhs.number == rhs.number &&
            lhs.shading != rhs.shading &&
            lhs.symbol != rhs.symbol) ||
            (lhs.color != rhs.color &&
            lhs.number != rhs.number &&
            lhs.shading == rhs.shading &&
            lhs.symbol != rhs.symbol) ||
            (lhs.color != rhs.color &&
            lhs.number != rhs.number &&
            lhs.shading != rhs.shading &&
            lhs.symbol == rhs.symbol) ||
            (lhs.color != rhs.color &&
            lhs.number != rhs.number &&
            lhs.shading != rhs.shading &&
            lhs.symbol != rhs.symbol)
        }

    Пытаюсь реализовать правила игры в Set протоколом Equatable. Говнокод?

    govnokoder3948, 25 Мая 2018

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

    0

    1. 1
    2. 2
    3. 3
    4. 4
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
            let count = self.gameResults == nil ? 0 : self.gameResults?.count
            return count!
        }

    nil-coalescing operator? Не не слашали.

    astmus, 04 Апреля 2018

    Комментарии (20)
  5. Swift / Говнокод #24070

    0

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    if gameResults != nil && (gameResults?.count)! > 0 {
                
                for gameResult in self.gameResults! {
                    let newLine = "\(gameResult.gameSession!.gameTable!.tableNumber!) / \(gameResult.sessionHand!.endTime!) / \(Utils.getShortGameName(gameName: gameResult.gameSession!.game!.name!)),\(String(describing:gameResult.sessionHandResult!.score!.doubleValue)),\(String(describing:gameResult.sessionHandResult!.profitSum!.doubleValue)),\(String(describing:gameResult.sessionHandResult!.credits!.doubleValue))\n"
                    csvText.append(newLine)
                }
            }

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

    astmus, 04 Апреля 2018

    Комментарии (2)
  6. Swift / Говнокод #24066

    0

    1. 1
    2. 2
    3. 3
    if let viewControllers = self.navigationController?.viewControllers {
        self.navigationController?.popToViewController(viewControllers[viewControllers.count - 3], animated: true)
    }

    Попытка вернуться на рут контроллер.

    torip3ng, 03 Апреля 2018

    Комментарии (4)
  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

    Комментарии (47)
  8. Swift / Говнокод #23691

    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
    public class DialogBuilder: NSObject {
    
        private var style: UIAlertControllerStyle
        private var titleColor: UIColor?
    
        /**
         * initial DialogBuilder with UIAlertControllerStyle and  for title color
         */
        public init(style: UIAlertControllerStyle = .alert, titlecolor : UIColor?) {
            self.style = style
            if(titlecolor != nil)
            {self.titleColor = titlecolor}
        }
        /**
         * initial DialogBuilder with UIAlertControllerStyle
         */
        public init(style: UIAlertControllerStyle = .alert) {
            self.style = style
        }
    
        ...
    }

    wwweshka, 31 Января 2018

    Комментарии (6)
  9. Swift / Говнокод #23687

    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
    func stateDidChange(contorl: TitledTextField?, isEpmtyState: Bool) {
        
        let  userCodeisEpmtyState = (contorl == userCodeTextView) ? isEpmtyState : (userCodeTextView.textValue().isEmpty)
        let  authCodeisEpmtyState = (contorl == authCodeTextView) ? isEpmtyState : (authCodeTextView.textValue().isEmpty)
        changeEnterAvailabilityAccoardingToTextFieldsOccupancy (userCodeisEpmtyState, authCodeisEpmtyState)
    }
    /*
     * Метод устанавливает активность кнопки энтер взависимости от заполнения текстовых полей
     */
    private func changeEnterAvailabilityAccoardingToTextFieldsOccupancy(_ userCodeisEpmtyState: Bool, _ authCodeisEpmtyState: Bool) {
        enter.isEnabled = !userCodeisEpmtyState && !authCodeisEpmtyState
    }

    Кто-то очень спешил выпустить версию, что пустота стала чем-то непонятным.
    Да и вообще знание языков у человека на высшем уровне, вы ничего не понимаете!
    А пробелов у меня ограниченное количество, буду их тыкать вдвойне после let, зато не буду их ставить после метода и всё будет ОК.

    wwweshka, 30 Января 2018

    Комментарии (26)
  10. Swift / Говнокод #23686

    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
    func onlyCashLessEUR(_ rates : [CurrencyRateMto]) ->  CurrencyRateItem {
        var EUR : CurrencyRateItem? = nil
        let cashLessEUR = rates.filter({$0.type.enumValue == CurrencyRateTypeMtoEnum.CASHLESS && $0.currency.isEUR() == true})
        if(cashLessEUR.count > 0){
            EUR = CurrencyRateItem(
                cashLessEUR.first?.currency.getIcon(),
                (cashLessEUR.first?.currency.id)!,
                NumberFormatting.sum(cashLessEUR.first?.buyPrice?.price),
                NumberFormatting.sum(cashLessEUR.first?.sellPrice?.price))
        }
        if(EUR == nil){
            EUR = CurrencyRateItem(
                UIImage.init(named: "currency_eur"),
                "EUR",
                "-",
                "-")
        }
        return EUR!
    }

    "Я форматирую как далбаёб, и мне похер на то, что cashLessEUR.first опционален, я буду его юзать дальше".

    wwweshka, 30 Января 2018

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