exercism / swift

Exercism exercises in Swift.
https://exercism.org/tracks/swift
MIT License
113 stars 158 forks source link

Explain use of closures to overcome disallowed expressions at top level in Windowing System #746

Open s0956678 opened 5 months ago

s0956678 commented 5 months ago

In exercise "Windowing System", sub exercise 7, user is asked to create a Window and adjust its properties by using methods.

As Swift disallows expressions at the top level except for in the main file, the user cannot simply adjust the window properties at top level. The apparent solution is to use a closure that is immediately executed. While I was familiar with this concept from JS, it was not immediately obvious to me as a solution here. The possibility to immediately execute a closure is mentioned in passing in the Syllabus for "Closures" but it is not practiced in the corresponding learning exercise ("Double-Null0111: Closures Are Forever"). I think it is not immediately obvious for especially beginning Users that the sub-exercise in "Windowing System" can be resolved this way.

I would propose that this way of applying closures is explicitly practiced as such in "Double-Null0111: Closures Are Forever" and/or the Syllabus is adapted to make this application (the usages of closures to enable top-level execution code) explicit.

gyenabubakar commented 1 month ago

+1