3 ms·
Yeah but it can't replace C++. Swift was designed to make programming fun/nice not to replace C or C++.
by themihai 10y ago
Yeah but it can't replace C++. Swift was designed to make programming fun/nice not to replace C or C++.
- superJimmy64 10y agoAgreed. Certainly if the dev has any regard for things like performance and security
- pjmlp 10y ago"Swift is intended as a replacement for C-based languages (C, C++, and Objective-C). " Taken from https://swift.org/about/ https://swift.org/about/ "Swift is a successor to both the C and Objective-C languages." Taken from https://developer.apple.com/swift/ https://developer.apple.com/swift/
- themihai 10y agoSwift can't do realtime. It has automatic memory management. How do you replace C or C++ with Swift for that? What they mean is that Swift replaces Objective-C on user facing apps(on Apple devices) but I doubt you will see the critical parts of the OS (kernel, drivers, etc) written in Swift. 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.
- mikeash 10y agoYou 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.
- aaronbrager 10y agoThis is especially true in Swift 3, which has many improvements around this type of programming.
- aaronbrager 10y agoThis is especially true in Swift 3, which has many improvements around this type of programming.
- themihai 10y agoIs 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.
- mikeash 10y agoIt'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 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: https://vimeo.com/107707576 https://vimeo.com/107707576 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.
- pjmlp 10y ago> 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*.
- mpweiher 10y agoThose are the claims. The reality does not match those claims.
- pjmlp 10y agoNot, yet. That is how systems programming languages get adopted, when OS vendors do "my way or the highway".