Yak Shaving – Swift Edition
tirania.org
tirania.org
If you like creating wrappers around C libraries, perhaps this is the most overlooked feature in Swift, called the 'ClangImporter'. Compared with Rust's bindgen, bindgen looks like a more complicated bindings generator even at the C level with you tweaking the options and other knobs to 'get it right' for your specific wrapper project.
This is before you even start to write a higher-level and more idiomatic wrapper and ClangInporter binds the C part to generate Swift functions for you by default. Similarly, Zig also has this too which is "@cImport" with the path to the header file as the input IIRC.
It also looks like Swift is getting C++ interop for this too. [0]
[0] https://forums.swift.org/t/manifesto-interoperability-betwee...
But aside of that, I think Migual appreciates good language design on high level languages. His original pitch for Mono for usage in GNOME was about productivity I guess not about .NET fandom. And Swift as a productivity language to replace Objective-C is surely an interest for him.
Event as a .NET fanboy (like me) you have to look what other languages are doing. So much good stuff out there.
> Yet, this prevents a bug where the base constructor can
> call a virtual method that you override, and might not
> be ready to handle. So eventually I just learned to
> embrace and love this capability.
But this merely means that sub-classes cannot call functions (virtual or not) of their base class, since the base class is not yet initialized. It's not clear it is a net benefit. I have called base-class non-virtual functions a few times in the past, so this is not purely theoretical.The correct solution would be for a language to have two-phase initialization. In the first phase you cannot call virtual functions, it would be a compile-time error. In the second phase, you can, as everything has been initialized already.
(You can have a poor-man version of this with static create() or make() functions and private constructors in C++ and similar languages.)
// This is valid swift:
class MyClass: MyBaseClass {
let someVar: Int
init() {
// initialize member vars
self.someVar = 99
// call base constructor
super.init()
// we are now completely initialized
self.anyFunction()
}
}Python's Urwid is fun to play with but I find it difficult to compose the interface I have in mind. Node's Blessed looks like a great improvement, and React-Blessed brings the declarative, state-driven model to the terminal. But I really prefer to not write system utilities in JavaScript.
Unfortunately Swift's cross-platform support leaves some to be desired, which probably leads me back to Urwid.
Very few terminal emulators go as far as attempting BiDi support. Egmont Koblinger has done some amazing work speccing this out and implementing it in VTE. More here: https://terminal-wg.pages.freedesktop.org/bidi/
Some day I'd like to support this in iTerm2, but it's a breathtakingly large amount of work.