3 ms·
I'd be curious to get a summary of what Swift has that is not a mix of traditional OO and ML-family features.
by mercurial 12y ago
I'd be curious to get a summary of what Swift has that is not a mix of traditional OO and ML-family features.
- tomp 12y agoWell, the problem with C++/Java and the ML language families is that they are quite incompatible, so it's not really trivial to mix them. Many languages have tried, most recent languages really. Rust is C with ADTs or ML without garbage collection (not yet sure how closures will turn out), Scala is Java with first-class functions and ADTs, Java and C# are absorbing more and more features from ML, ... Swift is just another attempt to mix the two, quite a successful one IMO. They kept some warts, probably to maintain binary compatibility with Obj-C, but otherwise I think it's a huge improvement over Java-style languages. One particular pain point between Java-style and ML-style languages are generics; Java and C# have a common object protocol and thus allow a top type, Object, and run-time type information. So, they must decide whether generics/type parameters are only relevant at compile-time (Java) or are kept at run-time (C#). ML avoids this issue by not having any runtime type information (and no type-testing construct). I haven't yet found where Swift stands, but it's a hard problem to solve.
- austinz 12y agoSwift doesn't have a designated base class like Java, C#, or Objective-C's NSObject. It seems, though, that there are a bunch of interop considerations which means that you might need your Swift classes to inherit from NSObject for them to work properly with Cocoa code. Swift also doesn't perform type erasure. You can do something like the following, as I believe is possible in C#: struct SquareMatrix<T> { let dimension: Int var backingArray: Array<T> init(dimension d: Int, initialValue: T) { dimension = d backingArray = T[](count:d*d, repeatedValue:initialValue) } subscript(row: Int, col: Int) -> T { get { return backingArray[row*dimension + col] } set { backingArray[row*dimension + col] = newValue } } }
- mercurial 12y agoI see. Not really such a big deal in practice, but nice to have.
- AlexanderDhoore 12y agoWhat other language families are there, apart from C and ML languages? Lisp, maybe? Maybe dataflow or logic programming?
- Dewie 12y agoPascal?
- nextos 12y agoThis is a very interesting and complex question. CTM provides some answers, summarized in http://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdf http://www.info.ucl.ac.be/~pvr/VanRoyChapter.pdf
- pjmlp 12y agoAlgol family, which C definitely isn't part of. It is composed by Mesa, Cedar, Modula-2, Modula-2+, Modula-3, Oberon, Oberon-2, Active Oberon, Oberon-07, Ada, Spark, ParaSail, ...
- Someone 12y agoIf you zoom out far enough, few (for example, from a few miles away with my eyes almost closed, I would put Algol and C in the same family: procedural and with block scoping). There are quite a few distinctly other languages, though. To name a few: APL, COBOL, Forth, sed, Snobol.
- jamra 12y agoYou have some nice functional stuff. You can define a function on a primitive type like an integer. This enables you to have code like 400.times(doX). doX is a function. Functions as first class citizens are nice. If you have a function as a final argument, you can change this: something(a, b, { }) to something(a, b) { }. Basically, you just put your anonymous function on the outside of the parenthesis. I think the book's example was something along the lines of sort(arr) { $1 > $2 }. I think that $1 is some kind of default specifier for the first param and $2 for the second, but I'm not sure.
- nextstep 12y agoYou're correct about the $1 syntax representing parameters, but the parameter indices start at 0: sort(arr) { $0 > $1 }