Re:IBM says Swift is ready for the enterprise
by mikeash on Monday September 26, 2016 @10:22AM
(#12582009)
You can essentially write C in Swift by using UnsafePointer and such. If you avoid using reference types then you won't get any automatic memory management. I don't think it's quite ready to replace C as a kernel or driver language, but it's not that far off.
Re:IBM says Swift is ready for the enterprise
by themihai on Monday September 26, 2016 @02:42PM
(#12584457)
Is there any open source library that does that? I know in theory many things are possible but it would be great to actually test it/see it in action. I never thought of Swift as a language with zero cost abstractions and deterministic performance. If it works I think it really gives it a leg up.
Re:IBM says Swift is ready for the enterprise
by mikeash on Monday September 26, 2016 @02:49PM
(#12584520)
It's pretty uncommon, so I'm not sure. If I may toot my own horn a bit, you may find the code to my memory dumper interesting:
https://github.com/mikeash/memorydumper2
I also gave a talk on this subject a couple of years ago. It's out of date by now, but the basics are still more or less intact:
Or peruse the standard library documentation for UnsafePointer, UnsafeRawPointer, UnsafeMutablePointer, and UnsafeRawMutablePointer. These are built-in types that the compiler knows about, and code that uses them should compile down to essentially the same stuff as C pointer code would.
Re:IBM says Swift is ready for the enterprise
by aaronbrager on Monday September 26, 2016 @10:31AM
(#12582101)
This is especially true in Swift 3, which has many improvements around this type of programming.
Re:IBM says Swift is ready for the enterprise
by pjmlp on Monday September 26, 2016 @10:32AM
(#12582118)
> Swift can't do realtime. It has automatic memory management. How do you replace C or C++ with Swift for that?
Of course it can, it is just a matter of OS vendors caring to push it down developers throats.
There are ways to manually manage memory if required to do so, but then you suffer the consequences of dealing with Unsafe*.
It's almost like saying javascript will replace C/C++. I want a nice language like Swift (or Go) to replace C but there is none. Rust was the best/latest failed attempt.