DEV Community

CodeCara
CodeCara

Posted on

Tic-tac-stubbed-my-toe!

(Should have been posted yesterday, 13/10/24)

If I went into all the issues I have had this week, I would not have time for anything else(!). However, I will try to give a summary below and not make it too long…

Things I've worked on/completed since my last post…

  • I worked on the Tic-tac-toe project this week

Things that went well...

  • I got all my code working fairly quickly…or so I thought (see below for more detail)
  • I finally figured out (to some extent and after some pain), the Object Oriented Programming aspect of this project (more detail in section below ‘things that didn’t go well’).
  • Figured out that I could ‘get around’ not being able to access certain variables within functions by returning them (I had probably read this, but ‘saw it in action’ and so understood it better)
  • I found myself using booleans as ‘triggers’ more automatically without thinking about it, something I know I didn’t do before because I had a problem in a previous project that I needed help with which was solved by this, so it looks like I have retained that
  • I thought I did an ‘okay job’ of figuring out a way to figure out a ‘no-win’ situation
  • I initially assigned numerical values to my gameboard array and so the check I implemented for a ‘no-win situation’ was to filter out arrary items whose typeof was not a number (as numbered were replaced by Xs/0s during gameplay).
  • My check was then that if the length of the filtered array was ‘0’, then the game did not have a winner (the situations for actual wins were covered using other logic)

Things that didn't go quite so well...

Wow, I really did not start this project off well!

I had a fair bit of my code working, then got completely confused by the idea of objects. For some reason, I thought my factory function had to look like a list of object properties and values, because they had to be objects (sigh)

I went off on a tangent and seemingly managed to create my own programming language, intelligible only to me. Not quite the stroke of genius I would be proud of!

In any case, someone confirmed to me that factory functions are just normal functions, but that they return objects (I was trying to create objects within the function for some reason). Some further questions to my fellow Odinites helped to clear up some doubts I had.

So why did this project start off on the wrong foot? Well, I’ve thought about it and it’s a combination of the following…

  • Not referring back to the theory enough (which in this project was required in my opinion, more so that I remember from previous projects). I had clearly not understood factory functions enough, nor the place of IIFEs (immediately invoked function expressions) and modular patterns (which I need to read more on)
  • There was quite a jump from the theory to the project - for me at least. Perhaps I thought everything would become immediately obvious once I started it, but I had missed the point a bit (my initial code was actually working perfectly - I just had not created any factory functions with returned objects!). In hindsight, I don’t see why I found it so confusing, but I did and at least now I have a better understanding.
  • It was in the middle of the project that I realised ‘this must be Object Oriented Programming’ and I had not wrapped my head around the idea of being able to call/use a function stored in an object for example. It just did not click immediately, even though it seems obvious now that I understand it a bit better
  • In my head, I was planning to finish this project during the week, so maybe in haste, I just carried on with something similar to what I thought I should be doing, assuming it would all come together, instead of taking the time to understand the requirements better

Things I've learnt/need to improve on...

  • If I am struggling to approach a project in the future, I will refer back to the documentation and examples more to try to tie it in with what I am supposed to be doing
  • For this particular project, I personally found that a couple of You Tube videos on the principles of OOP really helped me also. I might supplement future projects with explanatory videos if I experience similar problems again, which I most certainly will
  • ‘Playing around’ in the console with objects and functions really helped me. Although I think I understand most of the theory as I read it, I think it really doesn’t stick in my brain until/unless I physically see/do it myself, which I know is the experience of a lot of people learning to code. In my case, this is certainly true. I liken it to trying to learn Algebra by reading without actually doing any calculations yourself. ** The practical part helped to solidify the theoretical in my brain and I found this hugely beneficial**

Plan for the forthcoming week...

I want to say that I will finish Tic-tac-toe. However, since I lost a lot of time and have only just started on the UI aspect of the project, this may be wishful thinking…

In any case, I hope to make some good progress and to move a lot closer to finishing it…

Top comments (0)