Live data from Hacker News

Swift as a C Language REPL

medium.com

21–24 of 24 posts

Re: Swift as a C Language REPL

#21
post #5

Would not be my first choice. A good REPL allows you to write code quickly and off the top of your head. As article notes, Swift’s C pointer/buffer semantics are absolutely horrendous, liable to melt the top of your head instead. If you understand C it just gets in your way. If you don’t understand C it gets in your way even worse. Working with ObjC classes is cleaner, but even that has bridging issues. Incidentally,…

On the subject of hair messes, I've always wondered what life would be like with a C+Lua-only style philosophy, stack, etc.

And then the obvious thought occurs, a Lua editor/IDE environment built on top of that stack would be a very nice project. Basically, make everything Lua - the system services, etc.

One of these days I'll sit down and play with the idea of using only LOAD81 [1], for example, to build an operating environment with a fat library of functionality ..

[1] - http://github.com/antirez/load81.git

Re: Swift as a C Language REPL

#22
post #18

Earlier quoted context omitted.

“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…

> But Swift’s type system was designed by amateurs LOL. The amateurish type system design is the one you've described. Mutable > either makes the wrong thing mutable, or makes too much stuff mutable. Pointer > 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,…

“Mutable> 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> 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-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).

Re: Swift as a C Language REPL

#23
post #9
post #7

Earlier quoted context omitted.

What would I have to do to use gdb as a C repl? I'm not very familiar with gdb other than using the backtrace to debug segmentation faults.

Compile your executable with debug info, and then make use of gdb expressions. https://sourceware.org/gdb/current/onlinedocs/gdb/Expression... It is not fully featured REPL, don't expect to use it to create stuff on the fly, it is more to query and call existing code. For a proper REPL, check one of the listed interpreters.

So what you are saying that it's not actually a C REPL. It's a GDB expression REPL which is very different. What was the original point of your comment?

Re: Swift as a C Language REPL

#24
post #22

Earlier quoted context omitted.

> But Swift’s type system was designed by amateurs LOL. The amateurish type system design is the one you've described. Mutable > either makes the wrong thing mutable, or makes too much stuff mutable. Pointer > 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,…

“Mutable > 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 > would make the whole language more co…

Your 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.

Post reply on HN