News for hackers. Stuff that matters.
Re:On Apple's Love Affair with Swift by coldcode on Saturday August 11, 2018 @09:12AM (#17739541)
I have used Objective-C since 1997 when I worked with WebObjects back then and I don't miss it for a second. When I have to touch our one codebase with Objective-C I have to groan. It was amazing for its day and I did enjoy it despite its shortcomings. But I can write way more highly functional code faster in Swift than I ever could in Objective-C due to real type safety and other modern features. I also spent years doing regular C and C++ and Java (not at the same time) and all 3 languages seem clunky to me now. Preferring Objective-C over Swift is wishing for the golden oldie days kind of thinking and I'm one with almost 4 decades of programming experience. Swift is still young and growing and sometimes thats a bit challenging to adapt, but its the one language I truly enjoy now.
Re:On Apple's Love Affair with Swift by apple4ever on Saturday August 11, 2018 @03:52PM (#17741232)
I’m the opposite. When I see Swift I just groan. It’s so much hard and slower to write more highly functional code (not to mention going back to ready it) than Objective-C. Part of that is lots of things about Swift are backwards (variable definition) or overly expressive (var/let/func).

I just cannot enjoy Swift at all. When I go back to Objective-C its just such a joy to write.

Re:On Apple's Love Affair with Swift by valuearb on Saturday August 11, 2018 @06:36PM (#17741922)
Developer productivity is far less determined by how fast you can write code, than by how many bugs you create, and how hard it is to fix them. The vast majority of time is spent debugging and maintaining code.

And I feel like I can write in Swift nearly as fast as Objective C. Objective C was always so baroque, when I define a method or variable and declare the exact same thing in a header file? Properties syntax?

I actually switched when Swift 1.0 came out (just after writing a twenty thousand line simulation engine in Objective C). It was so lightly baked I was starting to regret my decision for a couple months until version 1.2 released, only then could I ship my app commercially. Since then every release has only gotten better, and the rough edges are entirely gone. The only thing I miss from Objective C is compile time, and now just barely given how much faster the compiles have gotten.

Re:On Apple's Love Affair with Swift by gurkendoktor on Sunday August 12, 2018 @06:38AM (#17743820)
> The vast majority of time is spent debugging and maintaining code.

Not all programming is the same. I've seen a lot more code churn in frontend projects than in the backend, where the actual logic and persistence happens. That makes the speed of (re)writing code relatively more important (at least for the iOS apps I've worked on, YMMV).

But even when I had to clean up legacy code, I spent most of my debugging time on on incorrect threading (typically using UIKit or Core Data from the wrong thread), AutoLayout errors, Apple framework bugs, storyboards/NIBs out of sync with code, performance degradations, or anything else where Swift doesn't help much.

In my experience, Objective-C programmers aren't allergic to safety or brevity. We love ARC! It's just that Swift has taken away too much productivity, mostly through terrible tooling and by dividing the community, for very little gain.

> Objective C was always so baroque, when I define a method or variable and declare the exact same thing in a header file

When I helped out on a Java project, I noticed that my coworkers religiously created interfaces for every single class they wrote. They couldn't really explain it beyond it being a "best practice", but I suspect they enjoyed being able to look at a short file that only contained the interface plus JavaDoc, instead of opening the full implementation every time. They basically re-invented header files :P

I don't think people would mind headers as much if Xcode was a better IDE, and we didn't have to copy declarations around manually.

Re:On Apple's Love Affair with Swift by pjmlp on Sunday August 12, 2018 @12:43PM (#17745162)
> They couldn't really explain it beyond it being a "best practice", but I suspect they enjoyed being able to look at a short file that only contained the interface plus JavaDoc, instead of opening the full implementation every time. They basically re-invented header files :P

Then they should have known better.

That makes sense for unit testing, in cases where mock classes would be required.

All Java IDEs have object browsers no need for header files.

Re:On Apple's Love Affair with Swift by gurkendoktor on Monday August 13, 2018 @05:12AM (#17748869)
Mockability was the official reason until we started using Mockito 2. I hope everyone on the team was aware of the object browser. And yet they felt better with interfaces everywhere. It might have been a simple case of cargo-culting, though.
Re:On Apple's Love Affair with Swift by baby on Saturday August 11, 2018 @05:02PM (#17741525)
I'm surprised that anyone could find Objective-C a better language than Swift. I'm just waiting for iOS to move completely to Swift to start developing on that platform. It's a much better language.
Re:On Apple's Love Affair with Swift by vbezhenar on Saturday August 11, 2018 @05:35PM (#17741686)
Not everyone wants features. Go is an extremely simple language, it doesn't even have generics. People use it widely anyway.
Re:On Apple's Love Affair with Swift by Redoubts on Sunday August 12, 2018 @01:15AM (#17743042)
> Part of that is lots of things about Swift are backwards (variable definition) or overly expressive (var/let/func).

Is this a joke? This sounds like "the language is wrong because it didn't completely ape C"

Re:On Apple's Love Affair with Swift by 0x0 on Saturday August 11, 2018 @09:27AM (#17739588)
Objective-C in 1997 and in 2017 are almost two different languages. Between ARC and generics, auto-synthesized ivars, and blocks, there's not much missing from being a modern C#/Java-like language.
Re:On Apple's Love Affair with Swift by zoul on Saturday August 11, 2018 @09:58AM (#17739677)
I love Objective-C, but calling it (close to) a modern language is a long stretch. The “generics” are a joke, for example. The whole type system is miles from what can be expressed (and guaranteed!) by a modern language. We got an immense amount of fun out of it considering its age, but it’s time to move on.
Re:On Apple's Love Affair with Swift by tsycho on Saturday August 11, 2018 @12:01PM (#17740187)
Totally agree that generics in objective c are very bare. And that's what frustrates me the most. Apple/Lattner could have improved them, but chose not to, by focusing all their energy on Swift.

"Simple" things I want from generics:

1. Carry over generic information from header files to .m files, and not force us to drop all type information by having to use "id".

2. A compiler flag to enforce that the generic type must be specified at usage.

3. Where clauses in generics: Foo <T where T : NSCopying, MyProtocol>>

4. Generics on protocols, ideally with all the other features.

I know some of these are not trivial to implement, but they are mostly new syntax and hence don't have backward compatibility issues (except #2 which is why I asked for a compiler flag).

Re:On Apple's Love Affair with Swift by mariodiana on Saturday August 11, 2018 @06:11PM (#17741833)
I wan't to ask in all seriousness, or in all ignorance—I don't mind, so please take your pick—why generics are so important. Let's say, in the first case, you have an NSArray in Objective-C. The object in the array is of type id. Now, in the second case, you have an NSArray, but you've declared that it will only hold types of NSString. Why is the second any better?

I ask, because the only way I could see it being better is if you're taking that array—that data structure—and passing it all over the program and using it everywhere. (Note to the literal-minded: this is hyperbole.) If that's what you're doing, that's not Object-Oriented Programming.

If you're instead doing real OOP, you're designing an object that will perform a clearly circumscribed bit of work for you by responding to a set of messages. The NSArray may live inside that object—in other words, the object is composed in part by using an NSArray—but that array is hidden from the rest of the program.

Generics are no big whoop-di-do in that case, because there is no client-programmer that has to worry about them; or, to put it another way, you—the original programmer—only have to worry about that NSArray with respect to the programming of that one object. In that case, the data type the array holds is not a big deal to keep track of.

So, again—seriously—what is so great about generics? The whole point of Objective-C, originally, was that it was late-binding—which, if you ask Alan Kay, was the point of OOP in the first place. If you're worrying about types all over the place, you're doing something wrong, no?

Re:On Apple's Love Affair with Swift by valuearb on Saturday August 11, 2018 @06:43PM (#17741943)
Your array of NSString example has little to do with generics. Instead think of a class that contains an NSArray, and has methods to do specific things to the array items, for example a sort() method. Using generics you can define the array values to match the type given when the class is created. So the same class could contain NSStrings, UImages, UIControls, etc, etc, and sort accordingly.
Re:On Apple's Love Affair with Swift by slavapestov on Saturday August 11, 2018 @09:09PM (#17742399)
Alan Kay’s ideas are very interesting and Smalltalk introduced many groundbreaking ideas that still inspire programmers today. But there’s no fundamental law of nature that says dynamic message passing OOP is the “right” way to approach OOP, or even that OOP is the best paradigm for many coding problems developers face today.
Re:On Apple's Love Affair with Swift by mariodiana on Sunday August 12, 2018 @02:26PM (#17745650)
Okay, the context of the reply to which I was initially replying to was about how the implementation of generics in Objective-C was "very bare." I'm beginning with this point, because though I agree with your second point about OOP perhaps not being necessarily "the best paradigm for coding problems developers face today," I don't quite see where that point fits in. We're talking about Objective-C, which means we're talking about OOP. If you want to explore some other kind of programming paradigm and insist that generics are needed there, I have no quarrel with you. My point was that I didn't see why generics were needed in OOP.

But that brings us to your first point: namely, what is the "right" way to approach OOP.

When I bring up Alan Kay, I'm bringing up a guy who was there at the start, and who set his stamp on OOP. Granted, "OOP" has been done in different ways. You'll note, however, my use of scare quotes. Allow me to explain.

When OOP had the misfortune to become a managerial buzz, somewhere back in the 1990's, and thus became a "must-have," what happened was a lot of procedural programmers simply took their procedural programming, wrapped in in C++, compiled it with a C++ compiler, nodded to the boss and assured him that they were doing OOP—and went along on their happy way.

Likewise, when college professors—set in their ways, as is their want—were told that they had to start teaching OOP, they largely did the same thing.

The result is that we have lots and lots of people out in the world "doing OOP"—who actually aren't. They're writing procedural programs, with the trappings of classes and sub-classing and what not. But all over in their programs, they are digging into the internals of their classes—and, sometimes, you see them digging in many layers deep.

And they're "doing OOP."

As I understand him, Kay is saying that you send a message to an object, on the understanding that the object will handle the message, the sender not having to worry about the ultimate who or how. If there's another kind of OOP other than that—or other than the travesty I described above—what is it?

But, that's another question, entirely. My original question was: why are generics such a big deal in OOP? I don't believe that's been answered.

Re:On Apple's Love Affair with Swift by pjmlp on Sunday August 12, 2018 @12:44PM (#17745170)
And even Smalltalk had many ideas from FP, like blocks (closures) and the collection messages similar to what modern developers know as LINQ.
Re:On Apple's Love Affair with Swift by zoul on Sunday August 12, 2018 @02:05AM (#17743149)
For me, the big deal about generics is that they allow the type system to cover a much bigger part of my design. Without generics, any parametrized API will erase your types and then the compiler is blind. With generics the type information is preserved and when I specify a parameter type, somewhere several API layers away a type is suddenly fixed, too. That gives me a warm feeling (and code completion, too). And since expressive static type systems seem to be the right way to go, allowing the type system better insight into your code is a big win.
Re:On Apple's Love Affair with Swift by saagarjha on Saturday August 11, 2018 @01:26PM (#17740618)
I don’t understand how you think this should be implemented. Many classes informally conform to protocols or in some cases the conformance can only be checked at runtime with a respondsToSelector: check. So any generics at compile time stricter than what we currently have will just not work or be useful.
Re:On Apple's Love Affair with Swift by valuearb on Saturday August 11, 2018 @06:46PM (#17741951)
Not useful as I’d rather find that mistake when a customer reports the crash, instead of having the compiler tell me?
Re:On Apple's Love Affair with Swift by saagarjha on Saturday August 11, 2018 @09:10PM (#17742411)
The point I'm making is that the compiler can't tell you this, since conventional Objective-C code does generics checking at runtime. There's just not enough information available for this to be reliably diagnosed.
Re:On Apple's Love Affair with Swift by slavapestov on Saturday August 11, 2018 @09:06PM (#17742392)
A fundamental problem with Objective-C generics that cannot be addressed in an additive manner is that generic parameters just desugar to ‘id’; you cannot use Objective-C generics with C types and you still pay the performance and memory use cost of trafficking exclusively in class instances. This of course was the right trade off, since it allowed generics to be layered on top of existing types like NSArray without either changing their implementation or breaking existing client code. However, when designing a new language with generics built in from the start you can make much better design decisions.
Re:On Apple's Love Affair with Swift by kitsunesoba on Saturday August 11, 2018 @05:01PM (#17741514)
That’s a real stretch. As someone who previously wrote Obj-C and currently writes Swift full time, whenever I revisit and work on old Obj-C code I constantly have “oh right, Obj-C doesn’t have that” moments and either have to pull in some third-party library that does what I need or settle for a less than satisfactory (and usually dramatically longer) solution.

I do have times when writing Swift where I miss some bit of Obj-C, but those are rare and are becoming fewer as the language develops.

Re:On Apple's Love Affair with Swift by pjmlp on Saturday August 11, 2018 @10:16AM (#17739754)
Other than safety, that is.
Re:On Apple's Love Affair with Swift by apple4ever on Saturday August 11, 2018 @03:53PM (#17741239)
Meh, I think that is overrated.
Re:On Apple's Love Affair with Swift by kitsunesoba on Saturday August 11, 2018 @05:10PM (#17741554)
It boils down to the self discipline of individual developers. If you’re meticulous in making sure you’ve dotted your I’s and crossed your T’s and haven’t let too many of those insidious cast statements slip in, you can write reasonably safe Obj-C, but during my career as an iOS dev I have yet to encounter an Obj-C codebase that was fully written by such developers. They’ve all been riddled with gratuitous casting, erroneous type assumptions, and other bad practices (that aren’t possible in Swift) to the point that it’s a wonder that they ever functioned as intended.

Personally though, I’ve found that even when I’m keeping a close guard on things when writing Obj-C and am sure to avoid all the obvious pitfalls, bugs slip through in the most unexpected places, so I’m quite happy to have the Swift compiler double checking everything for me.

Re:On Apple's Love Affair with Swift by valuearb on Saturday August 11, 2018 @06:49PM (#17741962)
I’ve never understood this opinion, and always wonder if it’s a professional developer espousing it. Because most of your time as a commercial developer is spent debugging, and Swift makes it far easier to write correct code, and to find bugs when you write incorrect code.
Re:On Apple's Love Affair with Swift by blub on Sunday August 12, 2018 @04:10AM (#17743468)
On a positive note, at least you're just writing buggy programs and not killing your patients somewhere or causing industrial accidents.

Unfortunately, as software continues disrupting various industries, it's less and leas certain that even buggy programs written by someone who thinks that safety is overrated will remain harmless.

Re:On Apple's Love Affair with Swift by pjmlp on Sunday August 12, 2018 @12:45PM (#17745172)
Only because software is a special snowflake where companies aren't held responsible for shitty software.
Re:On Apple's Love Affair with Swift by jmpt on Saturday August 11, 2018 @09:52AM (#17739655)
I'm glad for you, but everything you said is completely subjective.
Re:On Apple's Love Affair with Swift by IowaBoyInMN on Saturday August 11, 2018 @10:16AM (#17739753)
I believe the parent was subjective as well. I am curious as to why you appear to label just this comment. HN is for opinions as well as facts and I deeply value all of them. Particularly the opinions that politely challenge me.