Lesson 14 (2019) discussion and wiki

This in particular makes me uncomfortable too. I’m not sure if you just eventually get comfortable with it, or if it’s likely to actually cause problems.

4 Likes

Protocols (like interfaces and typeclasses in other languages) focus on functionality, and are not based on class inheritance.

Protocol-oriented programming is different from object-oriented programming. This comparison of protocol- and object-oriented programming provides some examples.

8 Likes

awesome article, thank you

Here is the introductory book Chris mentioned: A Swift Tour

4 Likes

Hearing Jeremy say “I just randomly press buttons until things start working or copy and paste other people’s code” is the most relatable thing I have heard all year.

14 Likes

Perhaps this is already addressed but I feel that Scala is also a very nicely designed language that, to my knowledge, doesn’t lack in terms of features I’ve seen so far in Swift. Is that true and if so is the choice of Swift more about JVM (as opposed to non-JVM runtimes) and compilers?

3 Likes

Naturally, it’s a very valid concern. Fortunately, because of the way protocols and extensions are defined, you can know without running the code exactly where a method is defined (be it in an extension, or a regular method, or otherwise). (Or at least the compiler can. And as a result, tools such as IDEs can tell you exactly where the implementation is, so you can figure out exactly what’s going on without running the code.)

2 Likes

I guess the Go language uses implicit conformance to interfaces. Not sure why they decided to adopt this approach. Explicit conformance seems to be more reasonable, I would say.

1 Like

FWIW, to back up what Jeremy just said, I started porting the nascent audio library to swift and was able to get it almost working in about 2 days. So it’s really quite approachable! My only warning is if it’s been a while since you learned a language besides python (or a while since you learned python) you tend to forget how frustrating it is to get error messages you’ve never seen before. That said swift’s are pretty good - once you can take a deep breath and read them instead of just panicking and feeling like an idiot!

11 Likes

Yeah, you’re exactly right. I came from Scala, and absolutely love the language. But the JVM (and garbage collection) are not appropriate for where we believe computing is going. (e.g. Our experience with GPUs, TPUs, and other hardware accelerators.)

1 Like

For those new to swift, @ste’s Tensors quick chart is really helpful.

11 Likes

Having seen him in the study group, he’s not just being humble - he really does exactly this (just like the rest of us!)

6 Likes

This page also has a short discussion and a link to a tutorial video (of mine) covering the topic of protocol-oriented programming compared to object-oriented programming: https://www.raywenderlich.com/1184-rwdevcon-2016-session-303-introduction-to-protocol-oriented-programming

10 Likes

Totally agree! Constrain yourself to be pure functional (aka DO NOT CHEAT), force your mind to think in a complete different way :wink:

To me that’s the value to learn a bit of the alien functional language named haskel

2 Likes

Named tuples are available starting python3, and are pretty useful for the reason Jeremy just mentioned (you don’t have to create a class every time).

Example (from the link):

EDIT: namedtuples have been a part of python since 2.7, thanks @mediocrates

This is a fantastic resource, @ste and @SHAR1! Thank you for sharing. :slightly_smiling_face:

Would love to help expand this into a cheatsheet (a la the #tidyverse cheatsheets: https://www.rstudio.com/resources/cheatsheets/).

4 Likes

FWIW, namedtuples exist in python 2.7 as well.

1 Like

Is the forthcoming book available in draft form for the community to read and provide comments?

I want to put this on a T-shirt. :heart:

13 Likes

What is that free book about Protocols that Chris mentioned in the slides?