
Swift Changes Considered Harmful - tambourine_man
http://furbo.org/2017/02/17/swift-changes-considered-harmful/
======
coldcode
I work in Swift 7 days a week (sadly 7) but I am quite happy despite the
changes, it's an open source language built entirely in the open by
contributions from people who care. What the hell is there to complain about,
would you rather work in 50+ year old cobol? I've used ObjC since the NeXT
days and despite much of our codebase (not our part) is still in that language
I am always glad to be working on our part in a nice modern language. It's
only 3 years old. Go is almost 5 (announced like 8 years ago and started 10),
Ruby and Java are antiques in comparison at 20+, ObjC itself is 30 years old,
C is 40, C++ is around 25. Rust is about the only comparable aged language,
and it isn't used in any single environment as large as iOS and OSX. Swift is
3. Yet it's fun and productive to work in (other than compile times which
suck, and debugging which is painful sometimes, and Xcode is ugh). Sure often
I have to look up what the current syntax is, but it's still lightyears easier
than remembering C++ details (another language I spent a fair amount of time
in in the past) which also change from year to year. Debugging STL still gives
me nightmares.

Cyanide is considered harmful. Opinions are just opinions, but calling
something harmful when you just don't like it should be considered silly.

~~~
fiedzia
> What the hell is there to complain about, would you rather work in 50+ year
> old cobol?

I'd rather work on modern AND stable language (I actually do, its not Swift,
buy that's not my point). Broken code samples is a good reason to complain.
Swift is a moving target, it will be for a while, and this is real pain... but
its not a secret. If it bothers someone, why would they choose to use it?

~~~
lordnaikon
> I'd rather work on modern AND stable language (I actually do, its not Swift,
> buy that's not my point)

Greetings fellow Rust user ;)

------
tubehouse
I don't agree with this. Presumably this is going to be a long lived language.
They should fix the problems as early as possible so that generations of
developers don't have to keep reliving the same pain.

~~~
mrpippy
I think his main complaint is that Apple should stop publishing sample code
(which they update sporadically at best) in Swift when the language is
changing so much. At WWDC this year I believe virtually all code shown on
screen was Swift, but ObjC would have been fine for almost everything.

More broadly, I think Apple should have marketed Swift as "beta" until at
least v3, to really make clear (especially to managers) what it means to have
a language with constant source-breaking changes.

~~~
edblarney
" should stop publishing sample code (which they update sporadically at best)"

Ah? No. 'Sample code' is essential, often more valuable than the docs.

They are a $700 Billion dollar company.

You know what they can afford to do?

Have _more_ sample code, _better_ documentation - and update all of the goddam
samples, moreover, to make it clear in each sample, which version applies.

~~~
mrpippy
You cut the quote off too early, I think they should have sample code in ObjC
rather than Swift

------
drewcrawford
This is already being done.

Swift 4 (unreleased) has source compatibility with Swift 3 [0], so all Swift
code working today should work in the next version, no migrator necessary.

Additionally, _the_ goal of Swift 4 is to finalize the ABI. Once that is done,
you can mix and match different Swift versions in the same project.

The real "problem" here is that Swift wants to be a "big" language, in the
vein of C++ or Rust, as opposed to a "small" language like C or JS where you
can read one book. (Swift does have a book, it's 1200 pages.) There's a lot of
"stuff": a complex typesystem, many basetypes, generics, extensions, both
static and dynamic dispatch, programmer-assisted memory management, closures,
visibility, ephemerals, optionals, a mutability-based memory model, etc. etc.

Inevitably some of that stuff won't be quite right and so you have churn. But
ideally you only need 10% of those (it's just that everybody needs a different
10%) and so the amount of churn you personally have to deal with should be
low, and can be lower with the appropriate tooling.

[0] [https://swift.org/blog/swift-4-0-release-
process/](https://swift.org/blog/swift-4-0-release-process/)

[1] [https://github.com/apple/swift-evolution](https://github.com/apple/swift-
evolution)

~~~
edblarney
"Swift wants to be a "big" language"

My guess is that it is not ideological. Swift feels like it wants to be
'everything'.

Because of this, it's almost too much.

I want to like Swift, but I run into a lot of trouble with it.

The decision to be compatible with ObjC was one of the big issues: obviously,
pragmatically, they felt that they just had to do it. In hindsight, I wonder
if it would have been better to just have a clean break.

~~~
fiedzia
> In hindsight, I wonder if it would have been better to just have a clean
> break.

Language-wise - sure, it adds a lot of complexity. Platform-wise, they would
risk people staying on what they had and ignoring Swift entirely, and that
would mean Apple would need to support objective-c a lot longer than they want
to.

~~~
edblarney
Yes, that is the rationale.

But I wonder. They are a $700B company. What if they just 'did it right' \-
i.e. made sure all of the APIs and documentation were available in 'new Swift'
which had no relation to ObjC.

Because the 'fallback on ObjC' has more problems than integration.

A lot of people want to make apps for iPhone and ObjC is not in their vocab.
Me, for example.

Swift could have been an easy-to-approach language.

But because of 1) lack of docs and 2) dependency on a lot of ObjC residue ...
guess what? To make app in 'Swift' \- you still had better know a lot of ObjC!

So - to really make use of 'the new' \- you still have to know 'the old' \-
which totally defeats the purpose!

I wish they had made a clean break - great docs, examples that are _clear_ and
_well marked_ in terms of versions, all new APIs for Swift, left in beta for
longer, and made mostly backwards compatible changes. And left a few things
out.

~~~
fiedzia
> They are a $700B company.

But many of their customers aren't. Lot of them have no budget (or will) for
complete rewrite. And if you force them (or just make them believe you may do
it) they will complain and it means bad press, in a very competitive market.
It may not be something Apple can afford.

> What if they just 'did it right'

You can't "did it right" without support of large amount of users, regardless
of the money. The definition of "right" in programming languages is "works for
users". And to get users onboard, you have make sacrifices.

> A lot of people want to make apps for iPhone and ObjC is not in their vocab.

And even more has existing apps to maintain. Tradeoffs have to be made.

> great docs, examples that are clear and well marked in terms of versions,
> all new APIs for Swift, left in beta for longer, and made mostly backwards
> compatible changes

All those things will come. If you want them, wait for them. Being early
adopter has its cons.

~~~
edblarney
"Lot of them have no budget (or will) for complete rewrite. "

I don't mean they should force people onto Swift. I mean that Swift, should be
totally independent of ObjC, so that customers, if they choose to use it are
not dependent on it.

Also - Apple could feasibly provide a 'lib/bridge' \- just as Android can use
C++ code as well, if you want to use it.

I think Apple could surely commit to keeping ObjC around for quite some time -
maybe 4 years official support, and then maybe 8 years on the devices, but
with no more documentation/support.

"All those things will come. If you want them, wait for them."

I don't agree - this is 'doing it wrong'. It's been out for _years_. This is
way past 'early adoption'.

'Doing it right' means that it is _easy_ for new and old developers. Right now
- it's hard.

Doing Swift 'right':

1) Make Swift a clean break, get rid of some of the more obscure things that
make it difficult. Get rid of relationship to ObjC.

2) Detailed docs, tons of examples. Examples for every single class, every
single attribute. 100% of functionality should be 'explainable by example'.

3) Beta for 1 year, then production.

4) No backwards-incompatible changes after out of beta. (Easier said than
done).

5) Docs, examples etc that clearly demarcate versioning.

6) Tons of support on Stack Exchange: dedicated staff to simply monitoring,
answering, clarifying issues just on Stack Exchange.

7) 'Free Support and Training' for anyone who wants it and who can make it to
a major city, i.e. NYC Jan 1-5 or 'weekend course' for anyone who registers.
Free. Once every few months. At least 100 Engineers just doing training, and
going into dev/studios companies to help them with stuff.

8) Free online courses, for newbs, and those coming from other languages, and
Objc.

They made Swift a little too complicated, and left devs hanging in the dark on
so many issues.

~~~
fiedzia
> I don't mean they should force people onto Swift. I mean that Swift, should
> be totally independent of ObjC

If you will not provide seamless integration, you will seriously limit amount
of people who migrate. There are other problems here too: what should library
authors do? Write two versions?

> It's been out for years. This is way past 'early adoption'.

Looking at all programming languages I've ever used, getting out of this
childhood period always took years. Sure, Apple could do better job perhaps in
many aspects, but it really takes a very long time to get a language and
stdlib to usable shape.

>Make Swift a clean break, get rid of some of the more obscure things that
make it difficult.

If you make a clean break, you limit amount of your users. Without users, you
can't tell what obscure things are difficult for those who didn't opt in.

I agree with all those beta periods, stability guarantees, docs and training.
I am now appreciating more how well those things work in Rust.

~~~
edblarney
"If you will not provide seamless integration, you will seriously limit amount
of people who migrate. "

I don't agree at all.

Tons of people are 'starting out' on Swift - moreover - if Swift were done a
little better - it would actually be used on other platforms, etc. - as
opposed to an 'iPhone only' type thing.

New projects start all the time.

Major re-factors and re-writes happen all the time.

Second - I do not believe that the premise of: "well I can switch _some_ of my
code to Swift, but keep most of my libs on ObjC" \- is reasonable. This is a
minority case.

And of course - as I said - they could have provided access to ObjC libraries
through an interface exactly as Android does.

You want to use 'legacy C++ code' on Android? You can do it. It's just not so
clean, but you can do it. The same should have been provided for Swift-ObjC

So - companies who don't want to migrate - can stick to ObjC for a few more
years.

The rest can switch over.

"If you make a clean break, you limit amount of your users."

Again I don't agree at all. Node.js has more developers than Swift. With Apple
backing it (i.e. 'making it good' \- but also making it 'the basis for iPhone)
- they could have had an incredible number of users.

There's no reason that Swift couldn't have been used in internal-alpha for a
while, then external beta for a while - then then have a 'solid v1'.

AS you say - many languages were 'around for a long time' \- but they have
also been _stable_ for a long time!

Java for example, did not do anything at the .lang level that was not
backwards compatible. The only non-backwards compatible bit was java AWT,
which they replaced with Swing. But even AWT is still supported!

So, there's no excuse for rapid rollout of versions that are incompatible with
one another, no excuses for huge gaps in documentation etc..

------
kenshi
Swift changes _are_ harmful if you are building a product with a budget.

I don't have any problem with the fact Swift is churning. I think its healthy
for the language to be improved. I think it's great that there is so much open
source activity and enthusiasm around it.

But I also think Apple have been premature about pushing it for sample code
and WWDC talks. And some companies have adopted it too early given their
resources, constraints and objectives.

Yes it's a lot of fun from an engineering perspective to be on that bleeding
edge. It's not so much fun when your boss/client/own business has a tight
deadline to ship something, but then you have the extra work to migrate your
code to the latest Swift changes.

edits: fixed a couple of typos.

------
routelastresort
"Considered Harmful" Essays Considered Harmful:
[http://meyerweb.com/eric/comment/chech.html](http://meyerweb.com/eric/comment/chech.html)

~~~
quicksnap
Every time I see a "considered harmful" title, I groan and think of this. It's
a meme at this point, and really detracts from the value of the article for
me.

~~~
sverige
Is There An Alternative to “Considered Harmful” Essays?

Absolutely. The most basic alternative is not to write them at all, but to
instead engage in reasoned debate without resorting to dogmatic assertions or
distractive tactics (e.g., ad hominem attacks and straw man arguments). In
those cases where some sort of document is needed outside of the debate, there
are a number of superior alternatives.

* A description of the strong and weak aspects of one’s own point of view; we might call it a “benefits and weaknesses of” essay. This is a positive contribution to the debate, and allows the debating parties to take the best parts of each view and more readily find a compromise solution. Knowing both the benefits and weaknesses of all views makes it easier to cover the weaknesses in one view with the strengths in another.

* A description of the strong and weak aspects of another point of view; we might call it a “perceived benefits and weaknesses of” essay. This allows the author to evaluate what he believes to be good and bad about another point of view. Authors must be careful to avoid slanting the piece too far toward the weaknesses, lest they end up writing a “considered harmful” essay by another name.

* An essay that compares different viewpoints in the same piece; in other words, a “compare and contrast” essay. These essays attempt to objectively evaluate multiple views and point out how they are both alike and dissimilar, thus highlighting both common ground and areas that need work. The benefits of such essays are fairly self-evident.

~~~
ktRolster
The purpose of the "Considered Harmful" headline was, and always has been, to
draw attention. And it's frequently been successful, both in the original
attempt and here as well.

~~~
mcbuilder
My grief with this sort of "considered harmful" essay or blog post is that it
is being applied to such concrete subjects as Swift code migration, not the
almost philosophical objects as the original GOTO. "Considered harmful" essays
should be timeless to do service to the concept.

------
ktRolster
If Apple can't keep its own sample, example code up-to-date on its website,
maybe they are breaking things a little too quickly.

At a minimum, they should make sure their migration tool works on their own
examples, that seems like a basic regression test.

~~~
plorkyeran
Apple has always been very bad about keeping its sample code up to do. They
seem to only update it when they specifically get a radar about something
being broken.

------
vosper
> Take a look at the Stack Overflow page again. There’s some good information
> there, but it’s completely hidden by Swift code that’s no longer relevant.

I recently experienced this first-hand with Python, chasing an issue with SSL
certificates - my problem (SSL doesn't work on Python 3.6 on OSX unless you
follow a post-install step to install certificates) was completely masked by
problems some people experienced in a recent previous version of Python, where
they had switched on certificate validation by default [0]. There were a
number of similar-but-different SO questions, that all linked to each other. I
wasted hours before I discovered that none of the results on Google for my
exception were relevant.

It's hard with SO sometimes - information ends up being stale, and the
accepted answer might no longer be the best. Sometimes you find a helpful
comment or a new answer that has the right info, but other times it's just out
of date or completely irrelevant. Worst, it leads you to mis-diagnose the
problem, which is especially easy when it's something you're not familiar
with: I know very little about SSL, I just want my API requests to work.

[0] Yes, I was astonished to discover that all this time certificates weren't
being checked

------
dep_b
I had a bad time going from 2 to 3. The renamification was pretty smooth but
took a few hours of work for a big project. However there were more subtle
differences.

Example code:

    
    
        var rowID: Int! // Set elsewhere, keeping it short. Also would never declare anything in this way but legacy
    
        func someFunc() {
            let updateUrl = "things/\(rowID).json"
            print("updateUrl")
        }
    
    

The result in Swift 2:

    
    
        things/123.json
    

The result in Swift 3:

    
    
        things/Optional(123).json
    

A ton of subtle bugs not detected by the compiler. Apparently Swift 4 will
throw a warning for parsing an optional in a string but this was pretty bad.
However I trust the change between 3 and 4 will be less breaking and will
bring true or almost ABI stability. Between the 1.x versions and the migration
to 2 was already more difficult than the 2 to 3 migration if it wasn't for the
renamification and I still consider that a great thing.

I would still happily start a project in Objective-C(++) if I would need to
integrate a lot of libraries that rely on O-C, C or C++. But Swift is the
default for me.

------
refulgentis
After 3 years in Swift, the only clear drawback outside compile times, is
exactly this.

It's a real shock coming from Objective-C. Ad hoc name-spacing by prefixing
classes, and a language/core framework that's been stable for 30 years, made
it extremely easy to Google and get an accurate answer immediately.

Moving to a language that adds major features twice a year, and invalidated
large swaths of code by mass-renaming Cocoa in Swift 3, has made it much
harder to find correct material

~~~
pvg
_core framework that 's been stable for 30 years_

That's perhaps a little overstated.

------
pmarreck
Are we at a point yet where people have realized that mutability is basically
an optimization fraught with danger, and that immutability and functional data
structures (coupled with some decent GC scheme) are the way to go for the most
secure, bug-free code out of the gate?

Wake me up when we are, because "UnsafeMutableRawPointer" in _sample code_
makes me nauseous. Meantime, I'm gonna hang out here over in Elixir-land.

------
drk4
Its always a tough decision, either you make no changes but then have to live
with a less than ideal situation, or make changes but forces everyone to
update their code.

Personally I think its ok to make incompatible changes once and then, as long
as its not too many changes in one go (like python3), its preferable than
later on ending up with inconsistent or overly complex languages.

------
ebbv
This seems like an issue with out of date examples.

This same criticism could be leveled against any language that evolves and
invalidates past syntax.

PHP7 invalidates tons of old examples on the web. Does that mean those changes
were bad or harmful? No. Just because we happen to be at a transition window
with Swift such that recent examples are now invalid doesn't change that.

------
Entangled
I love Swift and I don't care if they break it everyday. I'll patch everything
that needs to be patched while having fun building apps for all devices in the
world, desktop, mobile, server, watch, tv, IoT, embedded, etc. Naysayers will
naysay, just stay away and let us code.

Swift is a beautiful language and it gets better by the day.

------
wilde
It's always a tradeoff. The io.js mess showed what happens when you try to be
too stable.

------
mirekrusin
I don't understand... if those are the problems, write code in objc - it will
be good for many years to come. Have some respect. You're looking at open
source project, you can get involved yourself if you wish, you can follow
design process - you have been given free access to "look into the future" in
this area, the future that's being crystallised in front of your eyes -
complaining from that position doesn't make sense.

------
Animats
Hey, it's "continuous integration". It's moving fast and breaking things. Keep
up or be roadkill.

