I've read some articles online that say, as a beginner, learning to code in the command line is better to get aquatinted with programming and writing code. I want to learn Swift and have been following the chapter 'A Swift Tour' in Apple's 'The Swift Programming Language' iBook but have been doing so in Playgrounds (as suggested in the chapter). Is there any benefit of me starting to write Swift in the Terminal instead of Xcode Playgrounds or is it purely a personal preference thing?

2

Best Answer


A little research reveals e.g. REPL vs Playground, where you can read, that in REPL, you cannot use let. Also, IMO, playgrounds can rather fast grow into some more mature prototypical implementation, while REPL is rather for seeing what some statement does.

In the command line environment, Cocoa and UIKit are not available. So you cannot do visual prototyping of your UI. Further, Playgrounds has lots of fancy features like letting you explore the history of a variable's value, and graphing numeric values over time. The downside is that as your Playground grows, it pre-emptively re-renders all the calculations, loops, and UI prototypes you've created after every statement you add. This makes it very slow, and prone to crashing. Or, it will fail silently on a syntax error somewhere in the file.

On the other hand, a command line REPL is only concerned with evaluating the current expression, so it's very fast and gives you instant feedback on errors. It's for focusing on the language proper, like syntax, basic data types, for loops, function syntax, and closures.