I received good advice to transition to my own project ideas once I got the basics of a language. Excellent idea. I remembered a friend of mine once - many years back - recommending that simple card games (like Uno) are a good practice problem.
Where I live, we have a game called Mau Mau, which is basically like Uno, just with normal cards. If you play a 7, the next person draws 2 cards, unless s/he has a 7 as well - then the following person draws 4 cards. A jack allows you to wish for a colour. Other than that, you have to say "Mau" when you're down to 1 card, and you need to follow colour or value when playing. Like Uno, as I said.
Boiled spaghettis taste good but are your enemy when on screen
I started, full of energy. Gave it a good 30 hours. And ended with boiled spaghettis. Code I could no longer maintain unless diving a full hour into it. Functions here and there, variables for what again? And then functions fixing functions fixing problems. Variables copied to another scope because that one function handling this important thing wouldn't have access to it - or so I thought. I had to dump it all.
Lasagne is better
I stepped back, admitted my failure and started to think properly (so I thought!). Laid out a solid structure, worked out a practice problem where I would experiment with my design in a simple environment (yes - it worked well, I now have a website that highlights single entries of a list when you click a corresponding button.) Then started to work on my game again. Surprisingly, in less than 4 hours I had achieved the same level of functionality as before, only with much cleaner code and a perspective to continue.
Set your ingredients aside before you cook
Well, I'd done my planning, but only halfway. undefined
this, undefined
that. I've been chasing these undefineds
until I realised that I had forgotten another planning step. Concerning one particular object (the card that is played), some functions would use the card itself, others a unique id as a parameter. This over-complicated matters and led to confusion - was this the function with the id or with the object? It also led me on the wrong path - I thought my problem was scope-related, when indeed it was just sloppyness on my part!
I stepped back again and thought about the inner communication between my classes. 30min later, my problems were gone.
What about you?
Have you been organised and well-structured from the beginning of your coding? Do you remember a moment of clarity? Do you have a good advice for me? Love to hear from you!
Photo by Paul Bergmeir on Unsplash
Top comments (0)