3 ms·
Swift certainly can be a scripting language. #!/usr/bin/env swift print("hello, world!")
by runjake 4y ago
Swift certainly can be a scripting language.
#!/usr/bin/env swift
print("hello, world!")
- meindnoch 4y agoOf course, but so can C++ and Java: https://stackoverflow.com/a/29709521 https://stackoverflow.com/a/29709521
- musicale 4y agoImplicit main in Swift means you don't need "public static void main..." or other boilerplate. No reason why Java and C++ couldn't do something similar though.
- astrange 4y agoTop level programming is actually a little too surprising in Swift. For instance, you can access variables before they're declared - so you're not just implicitly inside a main function.
- runjake 4y agoRight, but unlike C++ and Java, the scriptability of Swift was designed by spec. It's not a hack or convolution.
- teh64 4y agoJava being used as a script is now also built in (since Java 11 in 2018): https://nipafx.dev/scripting-java-shebang/ https://nipafx.dev/scripting-java-shebang/
- musicale 4y agoThat's kind of one of Swift's things - it is designed to be as accessible as a scripting language but scalable to full applications and system software. Ideally it gives you some of the convenience and accessibility of a language like Python, combined with runtime efficiency of a language like Objective-C. print("hello, world") is a cute example since it's a valid program in both Python and Swift. (Though I still haven't forgiven Python for removing the print statement, which dates back to BASIC antiquity.)