Live data from Hacker News

Why Objective-C

inessential.com

121–130 of 160 posts

Re: Why Objective-C

#121
post #56

Earlier quoted context omitted.

Obj-C does have a "nonnull" annotation now (apparently added to assist Swift interop). One of the final jigsaw pieces turning it into a really pleasant language.

It is a really pleasant language, but I think the annotation is for initialization only - compiler checking against initializing an object ptr with a null value - and does not prevent crashing when addressing an already released object

> does not prevent crashing when addressing an already released object

I don’t know what behavior you’d expect here or in what situation you’d encounter this for a nonnull reference. You’d have to be really living dangerously I’d imagine. The footgun was that nonnull isn’t enforced. And anyway, leaks were more the issue.

Re: Why Objective-C

#122

Earlier quoted context omitted.

I hate how pendantic and useless some of the features of swift being pushed down by academics that don't write apps or services themselves. Simple example: Objective-C if myObject { } in swift if myObject != nil { } Also opitionals in swift could have totally be avoided if they adopted a prototype based langue (basically object are never nil). Lua did this, and it is very elegant But meanwhile, we got a half backed o…

> you still can crash an app doing myArray[1] the first thing i do when starting a new project: extension Array { subscript(safe: Int) -> Element? { ... } } there was talk in the swift forms about adding that as standard that but it seems to have died off... [0] https://forums.swift.org/t/draft-adding-safe-indexing-to-arr...

Even with that there is nothing from you accidentally using [i]. Also there are just a ton of Swift APIS and bridge API that take an index and then crash… for full coverage you would need hundreds of safe wrappers… (doing what you propose though at least gives you. Some peace of mind..

Also Swift has a lot of other areas where it just lacks any safeguards… Memory issues are still a thing. It’s using ARC under the hood after all.

Infinite recursion is still a thing (not sure if this would even detectable - probably not).

Misuse of APIs.

And it introduces new issues: which methods are being called depends on your imports.

In my experience Swift lulls you into a false sense of safety while adding more potential safety issues and “only” solving some of the less important ones. objc has null ability as well. Which can warn u if used appropriately. objc also has lightweight generics. In practice this is all you need.

Re: Why Objective-C

#123

Earlier quoted context omitted.

I go back and forth. I do miss the simplicity of objc at times though. I think in a short amount of time someone can become close to an expert in objc. Swift is already incredibly complicated and there's no end in sight.

I hate how pendantic and useless some of the features of swift being pushed down by academics that don't write apps or services themselves. Simple example: Objective-C if myObject { } in swift if myObject != nil { } Also opitionals in swift could have totally be avoided if they adopted a prototype based langue (basically object are never nil). Lua did this, and it is very elegant But meanwhile, we got a half backed o…

I love Obj-C, but the Swift version isn't as bad as you say:

    if let myObject {
        // myObject is non-nil in here
    }
The Swift version is also usingfirst-class optionals. In Obj-C there is very small chance you'll confuse `NULL` with `nil` or `0`. Or that you'll message `nil` resulting in `nil`.. and in well-built software you have to guard against that.

Aside: Obj-C is narrowly focused on adding objects (in the Smalltalk sense) to C whereas Swift is trying to deliver a compiler and language with memory safety _guarantees_... Turns out that means you need a lot more language. Not to mention the `async` syntax/feature explosion.

Obj-C is "hippie" and Swift is "corporate suit" + "we're doing serious work here!"

Finally I want to say: I believe Obj-C was a huge competitive advantage and secret weapon that let Apple deliver an OS with so much more built-in functionality than any competitor for years and years. (Obj-C is great for system APIs) That's under-appreciated.

Re: Why Objective-C

#124
post #52

Earlier quoted context omitted.

> Inside Swift is a slim language waiting to get out... and that slim language is just a safer Objective C. Rust? Rust is basically a simpler Swift. The objective-c bindings are really nice too, and when you're working with obj-c you don't have have worry about lifetimes too much, because you can lean on the objective-c runtime's reference counting. I think the way to think about it is that with Rust, it's as if all…

Except the entire design of swift is meant to make everything more automated. * automated exclusivity with value types and value witness tables, classes as arc types (ie Arc >) * automated interop with C/C++/Obj-C through the clang ast importer Maybe they could have started with rust and added on what they needed, but why not build a new language at that point where things so fundamental are involved? Source: I worke…

> Maybe they could have started with rust and added on what they needed

Unlikely, I think, because of timelines. Swift’s first public release was in June 2014. Rust is a few years older (first public release in January 2012), but that wasn’t the rust we have today. It still had garbage collection, for example (https://en.wikipedia.org/wiki/Rust_(programming_language)#20...)

Re: Why Objective-C

#125

Earlier quoted context omitted.

If you use Objective-C objects, operations on null pointers are just a no-op, so there is not such thing as chasing exceptions.

So you silently ignore something being null when you don't expect it to be? That sounds even worse.

It's just that

    pointer?.doSomething()
is the default. Le horreur!

Re: Why Objective-C

#126
post #121
post #56

Earlier quoted context omitted.

It is a really pleasant language, but I think the annotation is for initialization only - compiler checking against initializing an object ptr with a null value - and does not prevent crashing when addressing an already released object

> does not prevent crashing when addressing an already released object I don’t know what behavior you’d expect here or in what situation you’d encounter this for a nonnull reference. You’d have to be really living dangerously I’d imagine. The footgun was that nonnull isn’t enforced. And anyway, leaks were more the issue.

That was exactly my point.

GP mentioned ‘chasing null pointer exceptions’, then parent mentioned that the language ’now does have nonnull annotation’, prompting me to explain that that does not prevent null pointer exceptions.

So, not living a dangerously. All that can be held against me is being “dangerously” imprecise on HN - definitely not good either

Re: Why Objective-C

#127

Earlier quoted context omitted.

C++ is trying to make C easier to use for 40 years, and it's still not there. So I wouldn't call that easier.

how would you write something like #include #include #include int main(int argc, char** argv) { using namespace std::literals; std::string foo = "foo:"; foo += argv[0]; std::map m{ {foo, 123} , {"count: "s + std::to_string(argc), 456} }; std::println("{}", m); } in C

[deleted]

Re: Why Objective-C

#128

I really miss Objective-C, and in the world of Swift craziness [1] I'm reminded often of this blog post [2] wondering what would have happened if Apple hadn't encountered Second System Syndrome for its recommended language. (There's a decent argument it encountered it in iOS and macOS too.) [1] https://github.com/swiftlang/swift-evolution/blob/main/propo... -- apologies to the authors, but even as a previous C++ guy,…

I don't miss @ and [] all over the place, even if Objective-C has some cool ideas into it.

I do agree Swift's design has gone a bit overbord, we wanted Delphi and got Haskell instead.

However note the same phenomen happening with other languages, as soon as you have a team being paid to develop a language, their job depends on adding features in every single release.

Programming languages are products, even those that praise C's simplicity have certainly not read compiler manuals about language extensions, or the mailings from WG14 proposals.

Re: Why Objective-C

#129

Earlier quoted context omitted.

One of my recurring language design hot takes is that it's easier to design for speed and then make it easy to use than it is to make it easy to use and then try to speed it up.

C++ is trying to make C easier to use for 40 years, and it's still not there. So I wouldn't call that easier.

It has been there for me since 1993, in every single scenario as alternative to C, when the choice boils down to either of them.

Since 1993, I only have used C when required to do for various reasons out of my control, or catching up with WG14 standards.

Re: Why Objective-C

#130

Earlier quoted context omitted.

C++ is trying to make C easier to use for 40 years, and it's still not there. So I wouldn't call that easier.

how would you write something like #include #include #include int main(int argc, char** argv) { using namespace std::literals; std::string foo = "foo:"; foo += argv[0]; std::map m{ {foo, 123} , {"count: "s + std::to_string(argc), 456} }; std::println("{}", m); } in C

Even better example,

    import std;

    int main(int argc, char** argv)
    {
        using namespace std::literals;

        auto foo = "foo:"s;
        foo += argv[0];

        std::map m{
          {foo, 123}
        , {"count: "s + std::to_string(argc), 456}
        };

        std::println("{}", m);
    }
Post reply on HN