Starting to dig into Swift... it sucks.

Discussion in 'iOS Programming' started by 1458279, Nov 2, 2015.

  1. SmalltalkFan macrumors newbie

    Joined:
    Feb 10, 2017
    #176
    The best syntax I have ever used is plain old Smalltalk.

    Objective C borrows Smalltalk's beautiful message sending syntax and abuses its block syntax to separate message sends from C.

    At some point you have to ask yourself what the language is for. I like languages that let me focus on stating the solution to my problem and don't distract me with implementation detail. I like small numbers of constructs that can be combined in a large number of flexible ways.

    Swift takes the opposite approach - it has a large number of constructs that can be combined in only a few ways and whenever a higher level facility is desired they turn to enhancing the compiler rather than the runtime (makes sense - its "designer" is a compiler guy - that's his hammer).

    Swift drives me nuts because my code ends up being festooned with vast numbers of annotations that are all about implementation detail rather than my solution space. Also, they could have kept the message send syntax closer to Smalltalk's rather than create the really ugly hack they have now.

    I'm doing a lot of iOS development for companies lately that ship iPhone apps that are used to configure smart appliances. I'm not touching Swift because there isn't going to be significant budget to update to Swift 4, 5, 6, etc and Swift has been a treadmill. Sticking with Objective C. Plus doing a lot of interfacing with low level C++ libs.
     
  2. GoldenJoe macrumors 6502

    Joined:
    Apr 26, 2011
    #177
    Been using Swift for about 18mo. I find it really gross...optionals and forcing you to initialize everything in a constructor is ugly, verbose, and insulting. Closure and generics syntax needs a lot of work too, but what's done is done. I'm only really using it because clients expect me to know it. The only real advantage I see over Obj-C is that you don't need a separate header, which is a great advantage. Xcode isn't quite there to support it either. Autocomplete falls apart so easily, and it takes forever to debug in console.
     
  3. rafark macrumors 6502a

    rafark

    Joined:
    Sep 1, 2017
    #178
    Every language has its perks. But I get you, I can't stand JavaScript (crap-script).
     
  4. AxoNeuron macrumors 65816

    AxoNeuron

    Joined:
    Apr 22, 2012
    Location:
    The Left Coast
    #179
    Fortunately, in Xcode 9, autocorrect for Swift seems a heck of a lot more stable.

    I noticed in previous versions of Xcode, Swift Autocomplete would break down all the time if you were editing both a Swift source file and were showing a storyboard/xib in the assistant editor or visa versa.
     
  5. dantastic macrumors 6502a

    dantastic

    Joined:
    Jan 21, 2011
    #180
    I've been working in Swift almost exclusively for about a year now. Some 98% of my time is spent in Swift.
    I absolutely hate it. To the point where I'm half considering a career change. I find no enjoyment in swift what so ever.

    The shorthand syntax the community seems to be using I find really rubish and just doesn't read well. It's often difficult finding the "right" function in a large app as really shorthand function names are often duplicated.

    Xcode is crashing or hanging several times per day.

    Breakpoints don't really work.

    Crash reports are largely useless.

    I miss macros - for things like logging etc.

    The documentation is hard to get to, clicking through to go to the method implementation only works some of the time. Half the time it can't be found and half the time it takes you to the protocol definition.

    Having to deal with optionals is a waste of time and the code is fugly. I far prefer being able to safely message nil.

    Not being able to multiply an int with a float is just making me angry. It is just anal and the type of people who think this is "right" are just the kind of people I don't have any time for i my life.

    We've been working on a new version of our app for about a year now. Some management decision that because Swift is new and better we have to rewrite everything in Swift. We still haven't reached feature parity. The Swit app is much slower on a device. There are far more crashes in the Swift app, in many cases we don't know why - the crash reports are useless. Developing in Swift is significantly slower.

    Raising these issuees Swift heads are often very quick to offer workarounds or tell you that you are wrong. I don't really want either. I just want to go through my work day writing code in an environment that isn't crashing for stupid reasons. Like... like I did a year ago!

    So after a year of writing Swift there are very few things I like about it. Overall I think Objective C is vastly superior.
     
  6. mildocjr, Nov 5, 2017
    Last edited: Nov 5, 2017

    mildocjr macrumors 65816

    #181
    Ok so when it comes to optionals they make your code safe. Really it’s so you can handle the possibility of missing data without having a do-catch everywhere in your code. While it may seem cumbersome it can prevent a lot of runtime errors. Having optional is best used with setting non-optional variables from optionals using a guard statement at the beginning of your function.

    As an example, you write a function that pulls data from a web service which may or may not be up. From there you can pass ‘data?’ to another function that would parse it into something useable. The first thing you do is say ‘guard let data - data else { return “Could not get data from remote service” }. Then you have an early exit from your method without wasting cycles.

    While I get your point of having it in an if != nil statement, this keeps it clean by not having to nest your processing of data in an if statement, and it creates a non-optional data variable for you to use and pass around further in your application as needed so you don’t have to keep checking if data is nil. You also aren’t declaring a global or static variable in memory that may never be used. +1 for memory management.

    Keep in mind you aren’t writing in C, you are writing in Swift, you may need to bend a little. I personally hate Java for the fact that I have to use System.out.println instead of just println, println is comparable to printf or print and should only be used to reference printing to the console. The fact I have to write System.out bugs me, I shouldn’t have to use two dot operators to get to a print function, but I do. Swift was designed for mobile, which means handling a lot of non-guaranteed data, bad connections, and so forth, the use of optionals was to ease the pain a little and was necessary to make the language clear.

    Since you said it just muddies up the readability, perhaps take a look at your code and see how you can make it more readable, I suggest guard statements whenever possible and if let statements for variables that are not used that often in your code.
     
  7. iOsDevMann macrumors newbie

    iOsDevMann

    Joined:
    Nov 16, 2017
    #182
    I started learning swift 4 months ago coming from a Java/Android background. I hated the language at first but now I quite enjoy it. For me Xcode is the problem, it's so frickin' buggy and crashes all the time, if there was an alternative like Swift + Other IDE I'd definitely give it a try.
     
  8. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #183
    I work in Xcode daily with a large complicated and mixed Swift & Objective-C code base and rarely see it crashing. In fact the other two coders next to me have the same luck. :)

    There are other bugs that can drive me a little crazy. Mostly the control clicking to Jump to Definition, and the tap for docs on the right when the docs don’t show up.

    An alternative may be AppCode.
     
  9. sundialsoft macrumors newbie

    sundialsoft

    Joined:
    Sep 2, 2010
    Location:
    Scotland
    #184
    I had a look at Swift not very long after it came out, tried a few little examples but decided it was not ready yet as it was still developing and changing.

    I'm starting a new app soon so I'm wondering whether to try Swift again instead of or mixed with Objective-C.

    Can anyone say that they have successfully moved from Objective-C to Swift full time for app development ?
     
  10. idelovski macrumors regular

    Joined:
    Sep 11, 2008
    #185
    It's till developing and changing and I still use C/ObjC in my day to day work. On the other hand, most younger developers I know are using swift for everything, even server side programming.

    Recently I bought this book: iOS and macOS Performance Tuning: Cocoa, Cocoa Touch, Objective-C, and Swift. The author has this at the end of one chapter: Swift, don't use it. Link to google books.

    I don't see myself switching any time soon.
     
  11. PhoneyDeveloper macrumors 68040

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #186
    Just about every iOS developer I know is using swift full-time. Every project I've started in the past 2-3 years is swift-only. swift is certainly mature enough now to be used for any new iOS project. I can't think of any reason that I'd start a new project using Objective-C. If you look at the tiobe.com list of programming language popularity you'll see that swift is more popular than Objective-C today.

    Knowledge of Objective-C is still a useful skill in iOS development and I wouldn't necessarily convert existing projects to swift but new projects in almost all development shops will be in swift.
     
  12. sundialsoft macrumors newbie

    sundialsoft

    Joined:
    Sep 2, 2010
    Location:
    Scotland
    #187
    Thanks for your reply.
    I have started a test app with Swift. I'm also converting from using XIB's at the same time so lots of fun. I'm just working up a simple core data app to learn what I need. So far I seem to be writing less code to get the same results as Objective-C and while I am getting on fine there are still plenty of things in the category of 'I know I must do this for it to work, but I'm not certain why I am required to do this'. I had to learn Objective-C having used C++ for a while so changing again is a pain but probably worth it.
     
  13. grandM macrumors 65816

    grandM

    Joined:
    Oct 14, 2013
    #188
    Isn't server side swift faster than node.js?
     
  14. sundialsoft macrumors newbie

    sundialsoft

    Joined:
    Sep 2, 2010
    Location:
    Scotland
    #189
    several months on. My biggest issue now is that so much of the help resource out there is out of date swift and in many cases there are no worked examples of some more complicated things. I'm assuming that Objective -C is not going to be taken forward by Apple so sticking with swift but it's hard going. It's nowhere near complete and it's yet another re-learning exercise having gone from C++ to Obj-C and all the way back it was COBOL then BASIC
     

Share This Page