Live data from Hacker News

Go vs. Swift [pdf]

github.com

91–100 of 128 posts

Re: Go vs. Swift [pdf]

#91
post #74

I don't see any "strength" in the classical object oriented programming model as found in C++ or Java. Actually, in modern programming composition is considered superior to inheritance. The interface concept of Go makes programming with composition much more flexible and powerful than with the class model. The author skips this Go specific and original interface typing. This provides a multiple inheritance equivalent…

OOP is primarily about polymorphism (subtyping) and encapsulation, code reuse by means of inheritance is just a nice to have, so that comparison doesn't make sense. You can compare OOP with parametric polymorphism, you can compare it with type-classes. Heck, OOP isn't necessarily about subtyping and we could be talking about row polymorphism (e.g. OCaml) which has some really nice properties. > This provides a multip…

> Except that it doesn't solve the fundamental problems with OOP, because it's still essentially OOP with subtyping

I'm not sure what fundamental problems you're speaking of, but what's nice about Go viz-a-vis C++ is that classes are fundamentally open. Personally, I think it's a win. By the way, I'm a C++ dev and I love C++ too. I just think Go has really interesting ideas.

Re: Go vs. Swift [pdf]

#92
post #69

Earlier quoted context omitted.

I never understand the praise for XCode. I love the iOS specific features like GUI creator out property explorer. But the text editor part is just awful compared to anything else I've used (primarily JetBrains IDEs, but also vim, sublime and some atom). On top of that it also has comparatively poor git integration. Edit: one thing I forgot is the very slow feedback at least when editing Swift. For syntax error notifi…

I'm not sure it should be Apples job to build a best-in-class text editor. I haven't used XCode in a long while, but last time I did it worked pretty well with external text editors, and you could configure the UI in a way that really facilitated using it just for just compiling/debugging. Every single IDE I've used, I've always used another text editor for doing actual programming. It's nice to have a half-decent te…

Have you used any of the JetBrains IDEs?

Re: Go vs. Swift [pdf]

#93

Earlier quoted context omitted.

Maybe I'm wrong about how it works, but I feel that Optionals in Java are a bolt-on solution that only solves half the problem that the same concept solves in Swift (or Haskell, or Rust, etc.) An Optional in Java is just another value, and nothing in practice stops that from being null. I.e. a method that returns an Optional can still return an actual null if poorly implemented. So the major benefit Optionals give yo…

I completely agree with your point -- you can't compare the power of compile-time checking to Java's Optionals, for the most part. However I tend to think that what's important about Optionals is the spreading of the notion of thinking critically about failure modes around improper input/output. "Defensive" coding is often considered a mid-range skill (at least I think), and IMO it's because a lot of junior programme…

> Also, Optionals are a light introduction to functors which is nice.

Optional is not a functor, in fact it violates the functor laws quite blatantly.

Re: Go vs. Swift [pdf]

#94
post #53
post #34

Earlier quoted context omitted.

I'm going to answer but I should preface by saying I'm not going to try to proselytize you to Swift. If it doesn't work for you and you're happy with Objective-C, then by all means do what makes you happy and keeps you productive. I have a couple of apps that have about 50k lines of Swift, one also with 60k lines of Objective-C and another with 40k lines of Objective-C. We use MVVM as well as a fairly involved mechan…

Aha! You haven't hit the LOC barrier that starts to make swift & xcode/source kit act like bsaul described. At around 100kloc you will start to get that experience with swift. While an equivalent 100-200kloc line app written in objective c will work quite fine with xcode. You'll start noticing some degradation as you get to 60-70kloc. You also have a simple module structure, which makes things better. You can see it…

Then, it's not Swift that is not production ready, but XCode that is crap :)

Re: Go vs. Swift [pdf]

#95

Earlier quoted context omitted.

One of the things that makes Optional so pleasant in Swift is the syntax support. This includes optional-chaining, if-let and guard-let unwrapping, and some convenient operators. For example, in Haskell, by default you can't compare an Optional with the value it wraps: `5 == Just 5` fails. But in Swift this works like you would want. All that is to say that Options in Swift are a bit nicer than what you could get wit…

>in Haskell, by default you can't compare an Optional with the value it wraps: `5 == Just 5` fails. -- Probably nothing like in Swift instance (Num a , Integral a) => Num (Maybe a) where fromInteger x = Just (fromIntegral x) main = print $ 5 == (Just 5)

This only works because you're working with number literals here, which have the very liberal type "Num a => a". If I replace your main function by

  check :: Int -> Bool
  check x = x == (Just x)

  main = print (check 5)
I get a compile error:

  Main.hs:7:17: error:
      • Couldn't match expected type ‘Int’ with actual type ‘Maybe Int’
      • In the second argument of ‘(==)’, namely ‘(Just x)’
        In the expression: x == (Just x)
        In an equation for ‘check’: check x = x == (Just x)

Re: Go vs. Swift [pdf]

#96

Earlier quoted context omitted.

One of the things that makes Optional so pleasant in Swift is the syntax support. This includes optional-chaining, if-let and guard-let unwrapping, and some convenient operators. For example, in Haskell, by default you can't compare an Optional with the value it wraps: `5 == Just 5` fails. But in Swift this works like you would want. All that is to say that Options in Swift are a bit nicer than what you could get wit…

> `5 == Just 5` fails. But in Swift this works like you would want Why in the world would you want those two to be equal when they obviously don't represent the same thing? That doesn't make sense, not even if they have the exact same memory representation, in which case I'm pretty sure it has been a compromise, which would mean you're still dealing with `null` with some lipstick on it, making that type behave incons…

> Why in the world would you want those two to be equal when they obviously don't represent the same thing?

This is the difference between normal people and theoretical computer scientists, summarized in one sentence.

Re: Go vs. Swift [pdf]

#97
post #29

Earlier quoted context omitted.

Rust copied 'if let' from Swift (~2 years ago) despite having decent pattern matching; community consensus today is that it's highly worthwhile as a feature. There have also been proposals to add 'guard let'. So, while I don't have enough Swift experience to judge its ADT support overall, I wouldn't cite those features as evidence that it's wanting. They might not be as natural in traditional FP languages like Haskel…

? is bind for Either monad if you squint. `context(e?)` becomes `e >>= \x -> context(x)`

You mean `e >>= context` ? ;)

Re: Go vs. Swift [pdf]

#98
post #63

I found the study very shallow and superficial. For example, who cares how many people have starred a project on github? And why should I care how many lines "hello world" is in a language [1]? I would rather see a discussion about performance, platform support, maintainability, governance and do on. --- [1] someone please create a new programming language where the empty file means "print hello world". Since you can…

> And why should I care how many lines "hello world" is in a language?

Because it's a good proxy for how good the language is for writing short, (often) throwaway programs.

Re: Go vs. Swift [pdf]

#99

Earlier quoted context omitted.

I completely agree with your point -- you can't compare the power of compile-time checking to Java's Optionals, for the most part. However I tend to think that what's important about Optionals is the spreading of the notion of thinking critically about failure modes around improper input/output. "Defensive" coding is often considered a mid-range skill (at least I think), and IMO it's because a lot of junior programme…

Checked exceptions also forces thinking critically about failure modes, but they seem to be an unpopular language feature, and few new libraries seem to use them. No other popular language has adopted them. Why are optionals good and checked exceptions bad? (I'm certainly not implying that one replaces the other - i'm just saying that it they both have an origin of forcing programmers to think about errors)

The compiler should be helpful.

I love checked expressions, hate Optionals.

I'll be happy when the language pimps stop trying to make Java look and act like a scripting language.

Edit: I apologize if I've offended anyone with my opinions. I hope this helps. http://bit.ly/1S1943H

Re: Go vs. Swift [pdf]

#100

Earlier quoted context omitted.

I completely agree with your point -- you can't compare the power of compile-time checking to Java's Optionals, for the most part. However I tend to think that what's important about Optionals is the spreading of the notion of thinking critically about failure modes around improper input/output. "Defensive" coding is often considered a mid-range skill (at least I think), and IMO it's because a lot of junior programme…

> Also, Optionals are a light introduction to functors which is nice. Optional is not a functor, in fact it violates the functor laws quite blatantly.

I didn't assert they were functors. Just that seeing `map` on something that isn't a list should be somewhat eye-opening to someone who just casually uses it and isn't too familiar with functional programming, that was the point.

Also, when I wrote "functor" I was thinking of https://wiki.haskell.org/Functor, is that what you're thinking of? In that case, which of the rules does it break? if not, what definition of functor were you thinking of?

Optional.of(whatever).map(identityfunction) will definitely give you back an Optional... Am I missing something fundamental? Also Optional.of(whatever).map(f).map(y) is equivalent in return to Optional.of(whatever).map(f . y)... (of course that's not the java syntax for composing functions but I digress)

Post reply on HN