Ябло (Свежее) / Говнокод #19936 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
if enabled {
            billingNameTextField.textColor = UIColor.blackColor()
            billingLasNameTextField.textColor = UIColor.blackColor()
            billingCompanyNameTextField.textColor = UIColor.blackColor()
            billingPhoneNumberTextField.textColor = UIColor.blackColor()
            billingAddressTextField.textColor = UIColor.blackColor()
            billingAddressTwoTextField.textColor = UIColor.blackColor()
            billingCityTextField.textColor = UIColor.blackColor()
            billingStateTextField.textColor = UIColor.blackColor()
            billingStateTextField.textColor = UIColor.blackColor()
            billingPostalCodeTextField.textColor = UIColor.blackColor()
            billingCountryTextField.textColor = UIColor.blackColor()
        } else {
            billingNameTextField.textColor = UIColor.lightGrayColor()
            billingLasNameTextField.textColor = UIColor.lightGrayColor()
            billingCompanyNameTextField.textColor = UIColor.lightGrayColor()
            billingPhoneNumberTextField.textColor = UIColor.lightGrayColor()
            billingAddressTextField.textColor = UIColor.lightGrayColor()
            billingAddressTwoTextField.textColor = UIColor.lightGrayColor()
            billingCityTextField.textColor = UIColor.lightGrayColor()
            billingStateTextField.textColor = UIColor.lightGrayColor()
            billingStateTextField.textColor = UIColor.lightGrayColor()
            billingPostalCodeTextField.textColor = UIColor.lightGrayColor()
            billingCountryTextField.textColor = UIColor.lightGrayColor()
        }

Зачем использовать промежуточные переменные, когда можно написать такой большой if

gorsash gorsash, (Updated )

Комментарии (22, +22)

Ябло (Свежее) / Говнокод #19472 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
let serviceKeys = Array(Set(listOfRestrictions.map {$0.service!})).map{ $0 }
serviceKeys.map { key in
        self.restriction[key] = listOfRestrictions.filter{ $0.service! == key }.map { $0.sample! }
}

По-моему, количество wtf на три строчки кода зашкаливает

tapoton tapoton, (Updated )

Комментарии (1, +1)

Ябло (Свежее) / Говнокод #19414 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
public var messageStatus = MessageStatus.IncomingMessage {
    didSet {
        self.messageStatusChanged(messageStatus)
        switch messageStatus {
        case .IncomingMessage:
            haloView.alpha = 0.0
            whiteCircleView.fillColor = .clearColor()
            whiteCircleView.borderColor = .clearColor()
            colorCircleView.fillColor = .clearColor()
            colorCircleView.borderColor = .clearColor()
            haloView.color = .clearColor()
        default:
            whiteCircleView.fillColor = collectionViewBackgroundColor
            haloView.alpha = 1.0
        }
        
        switch messageStatus {
        case .ReadedMessage:
            colorCircleView.fillColor = bubbleColor
            colorCircleView.borderColor = bubbleColor
            haloView.color = bubbleColor
        case .DeliveredMessage:
            colorCircleView.fillColor = .whiteColor()
            colorCircleView.borderColor = bubbleColor
            haloView.color = bubbleColor
        case .NonDeliveredMessage:
            colorCircleView.fillColor = .clearColor()
            colorCircleView.borderColor = bubbleColor
            haloView.color = .clearColor()
        default: break
        }
    }
}

Когда одного switch мало...
PS: язык Swift

TeknoMatik TeknoMatik, (Updated )

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

Ябло (Свежее) / Говнокод #19104 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  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
//
//  How ARC causes memory leaks and leads to crashes out of the blue
//

import Foundation

let noLeak = 131030          // Empirically found constant
let withLeak  = noLeak*10

// Single-linked list
class R {
    var _a : R?
    init(a : R?) {
        _a = a
    }

//    One have to resort to a manual C-like code to fix it
//
//    deinit {
//        var i = self._a;
//        while let i2 = i {
//            let t = i2._a
//            i2._a = nil
//            i = t
//        }
//    }
}

func test(n:Int, leak:Bool) {
    let p0 = R(a : nil)
    var p = R(a : p0)
    for _ in 1...n {
        p = R(a : p)
    }
    if leak {
        // When the list is not cyclic it will be deleted by ARC just fine...
        p0._a = p
    }
} // Oh wait, the destructor isn't tail-recursive...

test(withLeak, leak: true)
print("Bad leaking function")
test(noLeak, leak: false)
print("Good function")

гц -- сила, ARC -- могила
(язык -- Swift, если что)

CHayT CHayT, (Updated )

Комментарии (29, +29)

Ябло (Свежее) / Говнокод #18746 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
struct Family: Enumerable {
  var name = "Smith"
  var father = "Bob"
  var mother = "Alice"
  var child = "Carol"

  func each(block: (String) -> Void) {
    for i in 0...2 {
      switch i {
        case 0: block("\(father) \(name)")
        case 1: block("\(mother) \(name)")
        case 2: block("\(child) \(name)")
        default: break
      }
    }
  }

}

http://matthijshollemans.com/2015/07/22/mixins-and-traits-in-swift-2/

Pattern matching головного мозга. Верно говорят, что тот, кто не умеет делать, идет учить других как надо делать.

gumbert gumbert, (Updated )

Комментарии (11, +11)

Ябло (Свежее) / Говнокод #16101 Ссылка на оригинал

0

  1. 1
Ждем нового раздела под язык Swift. Ожидается наплыв.

https://developer.apple.com/swift/
http://habrastorage.org/getpro/habr/comment_images/f80/9bd/f07/f809bdf079e06818109355db44e9430b.png
http://habrastorage.org/getpro/habr/comment_images/45a/feb/cfe/45afebcfe01065e7bdb2b618ea045f18.png
http://habrastorage.org/getpro/habr/comment_images/32e/c47/ae5/32ec47ae5be2bb4f540e318764c8f2ab.png
http://habrastorage.org/getpro/habr/comment_images/d21/480/e59/d21480e59827fc1c6b93150c91fdcf90.png
http://habrastorage.org/getpro/habr/comment_images/b30/513/b4f/b30513b4f3345b51b18565a235b6ab6a.png

LispGovno LispGovno, (Updated )

Комментарии (174, +174)