Hacker News new | ask | show | jobs
by meoz 4406 days ago
It's again the same boilerplate-code to create something simple as a tableview. I don't understand why they had to 'invent' a new programming language for that.
4 comments

That's not why they built Swift.

Objective-C is a difficult language to work with and has decades of cruft. Swift is a start-over, but with Objective-C interop so you still have full access to the full existing APIs for OSX and iOS. Thus, the same boiler plate.

The thing is, understanding Obj-C was never the hard part. For example, understanding ARC, weak vs. strong (and now unowned [1]), and the various libraries is what took time and experience. Swift doesn't solve that at all and in fact offers its own oddities like the below:

“You indicate type methods for classes by writing the keyword class before the method’s func keyword, and type methods for structures and enumerations by writing the keyword static before the method’s func keyword.”

Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l

I do think the new language is neat and will be fun to work in, but it doesn't solve the parts that tripped up many people when working in Objc.

[1]

    @lazy var asHTML: () -> String = {
        [unowned self] in
        if let text = self.text {
            return "<\(self.name)>\(text)</\(self.name)>"
        } else {
            return "<\(self.name) />"
        }
    }
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l
Is there ever a time when you don't want a weak/unowned self in a block? Perhaps this should be made the default in Swift? (I understand that the Blocks spec requires all captured variables to be strong unless otherwise specified.)
>>understanding Obj-C was never the hard part.

It seems important for traction to make the beginning learning curve non-steep. See PHP, Python, etc.

>>Swift is a start-over

For me, Lua+LuaJIT+C/C++ as a cross-platform solution to everything is a start-over, and it gives me all kinds of things I don't get from Swift, one of them is the ability to make decisions for myself about how the basic structures of the application are going to be managed and under what conditions, either in the VM as needed or out of it, and with whatever current frameworks you want to interface with (e.g. everything). Plus, LuaJIT for the win. Plus put it, simply everywhere. (On:iOS,Linux,OSX,Win,Web,&etc.)

Swift is interesting, but I will not again be swayed to the darkside of using platform-provider-provided-platforms to achieve platform nirvana, for that harness contains nails upon which to be pinned.

Planks can be assembled of many kinds, but mine is shiny enough without another dastardly developer-mindset-grab by a very, very serious cult.

(<<--MacbookPro'er)

Feel free to do 10x the amount of work everyone else does.
Lua does seem to attract a number of prolifically productive people.
You are free to use one of the many tableview helper libraries if you aren't happy with the tradeoff between flexibility and convenience that the built-in API makes.

You could argue that the frameworks should ship with such a wrapper, but I'd personally rather that they spent their time making difficult things easier than making easy things easier.

I think the problem is with the boilerplate of objective-c. I tried to make something last night and I'll be honest, I felt like I was in Go or Scala (functional) more than I was in a C-ish style language. I'm not gonna lie, I was looking at some of the docs with a "WTF" look, but I'm a big proponent of functional programming. In the few instances that I've used it, my code has been very concise, but not always easily readable.
What features of Swift do you find functional? What kind of functional features are you using? I'm asking out of genuine curiosity, not to put you on the spot. Thanks!
Not to speak for the OP, but two features bear resemblance to functional programming languages:

1) Function Types ( = higher order functions)

This allows functions to be passed around as function parameters or return values.

2) Immutable variables via let

let a = 1 // a is always bound to the constant 1

a = 2 // error

I couldn't find any built in list/map/set comprehension. Did they leave it out or did I just miss it?
A big one is sum types (which it calls enum, a la rust), which come from ML.
Agree. While Obj-C is one of the ugliest language, the main problem was/is API/SDK.
Wat? Cocoa is pretty great.