Object literals are weird to get your head around. At first, they seem so simple. You have the object itself, which is basically a container. Then you have the properties, which are made of a name and value pair. But! The properties can be objects themselves, or the name value pair could have a function in it. It gets pretty complicated fast.
As part of the JavaScript Kata, there was a challenge around object manipulation, and assigning new properties, new values, making functions to do these, etc. Instead of taking my time and reading through carefully, I charged headlong into it, and quickly became stuck. Not to be dissuaded however, I trucked on, modified the objects as requested (I thought), and got to a point where only a couple tests were failing.
I managed to work around this by declaring the 'adam' value at the top of the page, and it passed the test! But it didn't feel right, like I had cheated somehow. So I finished most of the other exercises (had similar issues with the 'Gradebook' exercise, and you guessed it, it was objects again), but then on review, realised I had misread the instructions. So I looked through the exercises again, then reread everything I had about objects, looked through some other exercises, and tackled it again, with Google as my trusty companion. This is how I learned that just because the test is being passed, does not mean you are right, and that reviewing your code after a break to see if it still makes sense is very, very important.
The above example fairly neatly lines up with a problem I think I solved well, which was the stretch question on the 'Gradebook' exercise, involving writing a function to create an empty 'gradebook' object from scratch, a daunting exercise. From extensive Googling and reading documentation, the [ ] square bracket notation is how you pass in a value that is changing, maybe being iterated through as an array (like object[arrayValue[i]] ), and dot notation means you have to hard code the value. With this 'ah-ha' moment in hand (one of the best feeling ones I have had this whole course), I then went through and refactored a lot of code that I could see might be made more succinct this way. From this I learned that it WILL click, and suddenly make sense, as long as you keep going.
Technique | Rating | Reflections |
---|---|---|
Pseudocode | 10 / 10 | The most useful first step to a hard problem. Write it down, what should it do? What steps would it go through to do this? This also works with real life problems, recommended. |
Trying something. | 8 / 10 | Starting SOMEWHERE is starting, and once you start, just try and stop. |
Rubber ducky method | 10 / 10 | My favourite way to review code that now is presenting bugs. Explain it to yourself, and if you can't, find out why. What is that sneaky value up to? |
Reading error messages | 7 / 10 | The great thing about error messages, is that you can Google them! Give me a bug that results in an error message and not 'undefined' any day. |
console.log | 10 / 10 | How are you supposed to know what that sneaky value is up to without logging it to console? Have a console.log on every step, do it. |
Googling | 8 / 10 | Someone else has solved your problem already, you just have to find where they posted about it. |
Asking your peers for help | 8 / 10 | I have fortunately not gotten stuck enough yet that the above processes didn't work, but I'm sure I will. When I do, I will happily ask people to help. |
Asking coaches for help | 8 / 10 | See above. |
Improving your process with reflection | 7 / 10 | I have been going through old code I have written to see if I can explain how it works hours, days, weeks later, to try and cram it in my brain permanently, and I recommend it. |
In my last job, the 'culture' was pretty awful. I had a lot of responsibilities, and probably took on too much. I severely disliked the idea of failure, and what that meant about me. Still though, I did ask for help when I needed it, when I had to. Being seen as weak by my boss was the main reason I found it hard to ask for help, he was very hard to work for. It is why I quit, and resolved to never put myself in a position like that again.
20 April 2023