Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
s0956678 opened this issue May 3, 2024 · 2 comments · May be fixed by #827
Open

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

s0956678 opened this issue May 3, 2024 · 2 comments · May be fixed by #827

Comments

@s0956678
Copy link

s0956678 commented May 3, 2024

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
Copy link

+1

@meatball133 meatball133 linked a pull request Jan 26, 2025 that will close this issue
@mvanec
Copy link

mvanec commented Mar 16, 2025

Using a closure did not even occur to me. I wouldn't have thought of it in my wildest dreams; it's not something I use in daily programming. It's not mentioned anywhere in the instructions. I just added 2 inits--one empty and one with all mutable members. It satisfied the test of getting a mainWindow variable instantiated. shrug The instructions on a lot of these exercises are poorly written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants