DEV Community

Medea
Medea

Posted on

Keep code short and tidy

So I've been working on Swift for a while now.
I started off with the basics, but then started writing lots of lines of code

By the time I was one week into my EduCity project, I ended up writing tons of lines of code in one struct and that created a major problem for me.

My code took about 3 minutes to run altogether and my laptop literally started overheating. On top of that, it showed the error: The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions.

After that, I started splitting my code into different structs, so it would hopefully take less time to run the code and the error wouldn't show up.

By doing that, I did reduce the speed by a minute (now it's on 2 minutes), but it did create a few errors like: Type '()' cannot conform to 'View'.

But the code still shows up with the error it previously showed, and is still not working :(

MORAL OF THE STORY: DON'T REWRITE ANY CODE AND PUT THEM INTO FUNCTIONS INSTEAD, AND KEEP YOUR CODE READABLE SO IF YOU NEED TO COME BACK TO IT IN THE FUTURE YOU CAN UNDERSTAND WHAT IT'S DOING

Top comments (0)