130

Swift, oh my god, why do you have to be like this?

I'm looking to write a simple for loop like this one in java

for(int i = 5; i > 0; i--) {
// do shit
}

Thats it, simple, go from 5 to 1 (inclusive), I saw that to iterate over a range in a for loop (increasing ordeR) I can do this

for i in 0...5 {
// do shit.
}

So I thought maybe I could do this to go in reverse (which seems logical when you think about it doesn't it?)

for i in 5..<0 {
// do shit
}

But no, this compiles FINE (THIS IS THE FUCKING KICKER IT COMPILES), alright, when you the code runs you get a fucking exception that crashes the mother fucking application, and you know what the problem is?? This dogshit, shitStain of a language doesn't like it when integer that the for loop starts with is larger than the integer that the for loop ends with MOTHERFUCKER ATLEAST TELL ME THAT AT COMPILE TIME AS A MOTHERFUCKING WARNING YOU PIECE OF SHIT!!

Alright *deep breathing*, now we can't just be stuck on this raging, we're developers need to move forward, so I google this, "Swift for loop in reverse" fair enough I get a straight forward answer that tells me to use the `stride` functionality. The relevant code for it

for i in stride(from:5 to:1 by:-1) {
// do shit
}

Wow looks fine and simple right?? (looks like god damn any other language if you ask me, no innovations here piece of shit apple!) WRONG BITCHES !!! In the latest version of Swift THE FUCKING DEVELOPERS DECIDED TO REMOVE STRIDE ALTOGETHER, WITHOUT ADDING IN A GOOD REPLACEMENT FOR THAT SHIT!

Alright NOW IM FUCKING MAD, I got rage on stackoverflow chat, a guy who's been working on ios for quite a while comes up n says and I quote
"I can sort of figure it out, but besides that, iterating in reverse is uncommon enough that it probably hasn't crossed anyone's mind."

Now hope you guys understand my frustration, and send me cookies to calm me down.

Thank you for listening to me !

Comments
  • 6
    I tried swift a while back and I definitely agree!
  • 22
    this is a RANT. you need a stress ball.
  • 2
    rant win!
  • 11
    You know what I did in order to get a for loop like this? This

    var arrayFrom5To0: [Int] = [5,4,3,2,1,0]()
    for i in arrayFrom5To0 {
    //do shit
    }
  • 2
    whats abt
    for i in range (0...5).reverse () {
    //do sometging
    }
  • 2
    I thought swift was the most beloved language by its users, saw a survey of developers.
  • 0
    @eternalfool Thats all just BS, trust me, if you look at devRants own stats, you'll see that swift devs rant the most
  • 5
    @bhargav-mogra no they dont because they are busy finding the bugs
  • 0
    @bhargav-mogra I read an article about the success of devrant and at the time of writing, SQL devs won that(most rants) title.
  • 2
    What about:

    elems = 0..5
    for fakei in elems {
    i = len(elems) - 1 - fakei
    }
  • 0
    @0xcaff if youre gonna use an array anyway why not just initialize the array in reverse order rather than do the complicated lenth-1-fakei?
  • 0
    @livecoder What if your input isn't reversed? What if your source is immutable and you don't want to copy your array just to reverse it?
  • 1
    I ran into a similar issue a while back and was as frustrated as you especially because I came from the lovely world of pointers 😉
    Since stride is no longer an option, then why not just do a reverse while loop instead?!

    var maxElement: Int = 5

    while maxElement > 0
    {
    // do shit
    maxElement -= 1
    }

    Hope it helps! Cheers mate!!!
  • 0
    @spunky yes or either do that lol which is probably the correct way, but a for loop is much more readable for these kind of things
  • 1
    @HTahboub How long ago? I tried Swift 1 when it was new and couldn't write a line of Swift 2 code without an error or a warning a few months ago (I decided to play with Xcode again). I hear Swift 3 even changes things Swift 2 changed...
  • 0
    @Cube189 haha, well I'm pretty much like you, tried swift 1 thought it was ok, sasw swift 2 in wwdc, got disappointed...
  • 5
    @HTahboub whats wwdc? World wide dick conference?
  • 3
    @liveCoder it actually developers, but I think that your misconception suits it better.
  • 0
    @rookiemaverick this guy needs several stress balls XD
  • 2
    Only if I could ++ this rant two times 😂
  • 1
    Seriously? Even Python with its weird for loops can do this easily
  • 0
    @TheInitializer that is why its a complete modern language
  • 0
    Ahaha, I just heard from my boss that IBM's core swift contributors will be coming to Bangalore next Jan, I'm going to fuck them up so bad!
  • 0
    How about subtracting i from 6 every time you use it?
  • 0
    @TheInitializer yes thats what I did finally using a while loop, its very easy to simulate a for loop with a while loop, downside being you have to write 2-3lines of extra code
  • 0
    Totally agree with your rant. Swift is over conceptualized ugly language. Joined devRant just for the Swift hate. And I (used to) love Apple. Swift killed my desire to code for iOS/macOS ever!
  • 0
    yes I was forced to use swift in some project and it looks like the worst crap programming language every created, shame and waste of time. non documented and buggy. for instance, I spent 5 hours to try to understand how to navigate with a button between "views". There is no way... everything is bad, badly designed, badly done and crappy.
Add Comment