25 ms·
There are ten different pointer types, all with different and not easily memorized APIs.
by hhas01 7y ago
There are ten different pointer types, all with different and not easily memorized APIs.
- coldtea 7y agoWell, it's all in the name, no? And the use is rather obvious, mutable vs not, typed vs not, and buffer types (contiguous memory with count of items) or not. If only C had those how safer it would be!
- hhas01 7y ago“If only C had those how safer it would be!” Indeed it would be, because then no-one would want to use C. All languages are abstractions, but there are good abstractions and there are bad abstractions, and a truly depressing number of Swift abstractions fall firmly in the “not good” camp. A well-designed type system abstraction would support and encourage free and open-ended composition of clearly-defined individual orthogonal concerns. Thus mutability would be a composable trait, `Mutable<Pointer<…>>`, untyped would just be `Pointer` without a constaint (Void being the default), and buffers would likewise be expressed via constraint, `Pointer<Buffer<TYPE,COUNT>>`. But Swift’s type system was designed by amateurs; its inconsistencies and lack of expressivity resulting in a stdlib that’s a bloated convoluted mess as it struggles around those limitations. (Makes even Ruby’s stdlib APIs look clean, consistent, and concise!)
- SamReidHughes 7y ago> But Swift’s type system was designed by amateurs LOL. The amateurish type system design is the one you've described. Mutable<Pointer<...>> either makes the wrong thing mutable, or makes too much stuff mutable. Pointer<Buffer<Type, Count>> would make the whole language more complicated, and it doesn't solve any of the problems Swift's pointers solve. The Swift devs in fact are not amateurs, and it shows in how they managed to keep things simple, instead of convoluting the problem with total I-am-a-very-smart-Haskell-programmer complexity. > Thus mutability would be a composable trait I mean, this is a major tell. You don't just hand-wave mutability being a composable trait.
- hhas01 7y ago“Mutable<Pointer<...>> either makes the wrong thing mutable, or makes too much stuff mutable.” You may be reading `Mutable<>` overly literally. I just used generic notation for familiarity; that doesn’t mean it’d map directly to a struct. Have it be a `mut[able]` keyword if you prefer. The point is, it can be applied to any type, and eliminates the need for let and var definitions. “Pointer<Buffer<Type, Count>> would make the whole language more complicated” Why? We’ve gone from ten single-purpose types to three general-purpose ones: Mutable<>, Pointer<>, and Buffer<>. (And, in practice, Buffer would merge with Data, so really it’s two.) “The Swift devs in fact are not amateurs, and it shows in how they managed to keep things simple” Oh really. There is nothing simple about Swift, a language designed by C++ programmers to be a “better C++”. Just the fact it implements every collection type (String, Array, Dictionary, Set) twice—once as a class and then again as a struct—puts the lie to that. And then, of course, adopted by Apple and bodged into a “better ObjC++”. Which has even more hair on. See also: https://www.quora.com/Which-features-overcomplicate-Swift-What-should-be-removed/answer/Rob-Rix https://www.quora.com/Which-features-overcomplicate-Swift-Wh... “You don't just hand-wave mutability being a composable trait.” And yet, C’s `const` is composable. (Albeit not as a trait of the type itself, but I can’t think of a reason it couldn’t be.) Plus, with [im]mutability disentangled from collection implementation and a general purpose “pointer” for referring specifically to variables, the class+struct duplication can be eliminated. Let the user describe the behavioral constraints for their code, and leave the machine to decide when to allocate on heap vs stack and when to reference-count, single-owner/borrow, or pass-by-value. I may not know much about compiler engineering, but I do have a bit of experience in (Lisp-y) language design. Whereas the Swift team are compiler engineering wizards (no contest), but compiler engineers do not necessarily make good language designers (since they’re liable to design it to suit the language’s compiler engineers rather than its end users).
- SamReidHughes 7y agoYour idea of complexity is totally backwards. Swift has some types that do different things. Maybe you could add features, thought out to a vague level, that infect every part of the type system, and require redesigning major parts of how the language works, so you can define a few less types! C/C++ have const [which doesn't work well], so surely you can just throw such a notion into Swift's type system! Well that's not gonna make the language simpler. Go make a statically typed language with Mutable<>, in some form. Then talk.