5 ms·
What got me over the line was optionals and protocols + generics, the safety and expressiveness combined will eventually (hopefully!) win you over!
by aplummer 8y ago
What got me over the line was optionals and protocols + generics, the safety and expressiveness combined will eventually (hopefully!) win you over!
- LeoNatan25 8y agoI prefer to keep the dynamism over unreadable fp "expressiveness" or safety that was not needed in the first place.
- aplummer 8y agoI’m surprised you downvoted this, we should be able to discuss pros / cons without downvoting people.
- saagarjha 8y agoThere's nothing stopping you from writing dynamic Swift code or functional programming in Objective-C.
- LeoNatan25 8y agoYes, but it’s not officially “condoned”, so it feels “out of place”. This is very individual, of course, but I don’t like bending the system to get patterns that are not “natively” supported. In Swift, you cannot currently create classes in code, enhance and swizzle, implement proper proxies. You couldn’t even load a nib without the ObjC runtime. Not even reflection. It’s telling what their priorities were with that language. What good is the language when you cannot implement most of the system frameworks (Cocoa, Core Data, etc.) without nasty hacks?
- aplummer 8y agoYou’ve made some good points though I’ve found the reflection in swift since v2 to be sufficient for my day to day. I think the nib thing is a problem but in reverse, nibs needs to be swift so we can instantiate them with generics, this would be a game changer!
- LeoNatan25 8y agoWithout reflection, you cannot create a nib system (or any general purpose archiving solution). For Encodable, they used hacks that were tantamount to macros in C, but that requires compile-time knowledge of the class/struct structure. That's not how nibs work.
- aplummer 8y agoAlso I agree you can tell safety was the number one priority. However the positive is basically never getting runtime errors, except when interfacing with IB or obj-c even when people are programming in a hurry, which is nice for me.
- saagarjha 8y ago> However the positive is basically never getting runtime errors I don't quite think this is the "safety" that Swift aims for: rather, it prefers safety in the sense of failing fast and failing reliably if something goes wrong. Unwrapping nil and out of bounds array subscripting fall into this category of behavior.
- mpweiher 8y agoHmm...like making every arithmetic operation a potential crash site?
- LeoNatan25 8y ago"Never getting runtime errors" is as far fetched as it can be. Consider Xcode suggesting developers use force unwrap ("!"), that leads to many more crashes with unexperienced developers than the ObjC message to nil paradigm. Subjectively, I have seen much more crashes in third-party software written in Swift than in ObjC (usually unwrapping or casting incorrectly), including in Apple's software. I cannot say if this is down to more inexperienced developers, less time allotted to experienced developers or a worse development model. I'd say a combination of the three.
- saagarjha 8y ago> In Swift, you cannot currently create classes in code, enhance and swizzle, implement proper proxies In pure Swift, that is. These are all possible if you reach into the Objective-C runtime, as I'm sure you know well. Overall, though, I do agree with you: I'm unsatisfied with the current reflection API in Swift and I really think that this is something that the core team should focus on some time.
- coldtea 8y agoOr building a house with toothpaste. But this was more about what's more common/supported by the language/approved by the community rather than what's possible.
- tzahola 8y agoYea, but you lose C++ interop, your binary will be inflated with those Swift proxy libs and your compilation times will increase 2-3-fold.
- LeoNatan25 8y agoThose are actually temporary problems. Once ABI stability is implemented, those DLLs will not be needed. The compiler is obviously a WIP and will take years to become more mature and optimized. Likewise for C++ interop. There are fundamental issues with Swift, but those are not them.
- saagarjha 8y agoI'm much more hopeful for ABI stability than C++ interoperatability. I think will take a long time before we'll be able to seamlessly work with C++ code as we do currently with say Objective-C or C.
- LeoNatan25 8y agoWeren’t some steps taken to start working on preliminary support, or at least building blocks? I might be mistaken.
- saagarjha 8y agoI've been mostly away from the Swift Forums for the last couple weeks, so if they've done something recently I probably missed it. Otherwise, though, AFAIK there's very few user-facing features that we can take advantage of right now. I do know that this is something that is on the roadmap, but so far the only changes related to this feature would be confined to the internals of the compiler, if at all. Here's a relatively recent thread by Doug Gregor where he outlines some of the challenges necessary to surmount if this feature is to ever land: https://forums.swift.org/t/c-objective-c-interop/9989 https://forums.swift.org/t/c-objective-c-interop/9989
- 8y ago
- apple4ever 8y agoThat in fact is all the things I don't like about Swift. I actually fine its way less expressive than Objective-C.