Smarter maxHits logic

I have placed the instruction i.e.
int maxHits=hitSprites.Length+1;
in the Start() function which I feel is more appropriate as it would not unwantedly update on every collision. Are my changes logically correct ?

Hi Ronnie,

Welcome to our community! :slight_smile:

Yes, your reasoning makes sense. However, when it comes to programming, we usually do not rely on opinions, we test our code. And if it works, it’s a solution, no matter what other people think.

Keep it up and Happy Coding!

See also:

1 Like

Hi Ronnie,

There isn’t anything wrong with your way. While GameDevTV is pretty great there are some Computer Science 101 mistakes they make. None of their mistakes will cause errors with the programs we’re learning to make. However, they are considered no-nos.

A big example is Rick initializing variables in functions. This works. You can do this. However, for readability it is wise to keep variables all initialized in one spot. Usually at the top of the code under “public class Block : MonoBehaviour”.

Also when it comes to larger scale projects this is actually a giant way to waste resources too. As each time you call a function it initializes it. This is something I’ve seen in web development and console development a lot. I’ve seen SQL databases initialize on every search before. It brought the server down to its knees.

While these lessons are great at teaching fundamentals and logic it is worth looking into programming 101 practices. To make sure you’re writing clean, easy to read, and efficient code.

With all that said, this is still one of the best intro to game dev courses I’ve seen on the market.

Hi @Elvenmonk,

Welcome to our community! :slight_smile:

You are right. We do not focus that much on performance optimisation in this course. This course caters to beginners, and the majority of our students struggle with the most important thing: logic. Ben and Rick decided to keep things simple to make coding more accessible. If they taught all the rules to write “good code”, coding would become much more complex because the goal would not be anymore to make things work in Unity but to also follow “Computer Science 101”. People get discouraged quickly if they feel that they’ll never be able to meet the “requirements”.

Our games are so small and our devices so powerful, that the “mistakes” usually do not matter. Improving the code usually does not have any significant positive impact on the performance. If we initialise a variable of type float, that’s 4 bytes. We certainly do not worry about a couple of bytes if we have 4+ GiB of RAM.

Executing code on a server where you expect thousands of accesses or fetching data from the internet is a another story than our computers and laptops where we run our game locally. And the WebGL games are usually restricted to a few MiB.

As soon as students learnt the fundamentals of game development and start working on their own projects, especially larger projects, they’ll very likely encounter issues with the performance which require them to optimise their code. Andthen, they will hopefully be self-confident and experienced enough to do research themselves and to learn all these good techniques to improve their code. They will improve their skills by experiencing issues and by fixing them, not by copying some instructor.

If you want, please feel free to share good (free) resources on “Computer Science 101” with our community. :slight_smile:

Hi Nina,

However, it’s not just 4 bytes. Every time this instruction would be called you have:
int timesHit = timesHit++;
Vector2 velocityTweak = velocityTweak;
float bounceAdjust = .02f; (I’ve edited this from the name random)
AudioSource myAudioSource =…;
vector2 paddlePos =paddlePos; (because it is called every frame)
if you destroy a block then there’s also:
GameSession gameStatusRef = gameStatusRef;

Then it is possible to hit 3 blocks at once which would cause all of these, except for the paddlePos, to be called 3 times.

Also the argument of “It’s okay we have 4+ GB” is a bad one. Especially when the average person is using Chrome and Chrome doesn’t flush memory usage like it is supposed to with HTML 5. Then unless you know to RegEdit your Windows the new News and Weather section added to Windows 10, and 11, can eat up over 3GB of RAM usage. If you have notifications enabled with it people were reporting over 10 GB. We do not know the hardware, or OS, people are using it. I know people who have computers with less than 2GB of RAM.

Lastly, there was a basics of C# section in the course. That is when you would explain some basic programming standards of “make sure you put your variables here. So we keep it nice and tidy and prevent using too much memory.”

Like I said. The course is great. It encourages way more logical thinking and critical thinking than other CS courses out there. However, syntax issues like these do need to be stomped out early as if people get used to coding like this too early they make very wasteful code. Which is a big problem these days. Especially because everyone goes “you have enough RAM.” Do I? Between Windows hogging it up and daily software I need running getting worse and worse it doesn’t feel like it. I’ll cold boot and kill all services before I play a game these days because of RAM issues with software.

Overall the code written is very clean and readable with the exception of variables. Which when learned how to do wrong early on can be a pain to fix, and even stop you from getting future jobs. I’ve seen studios hiring mock programmers doing such. Also, if you post code like that to StackOverflow the people would be pretty ruthless. Which is a thing I hate about that site.

I must say Rick’s advice of making more functions to keep code clean and readable is excellent advice too. One I’d never seen other courses suggest. Which is why I actually suggest y’alls courses to people looking to learn. However, some people want me to do a detailed review.

I, personally, agree with you regarding starting with the “good practice”. When I learn something new, I usually recreate my projects multiple times from scratch because there is always something I could improve. I love spending time refactoring code and optimising stuff. That’s just me, though, and I’m well aware that most people are not like I.

In the past few years, we got a lot of feedback for our courses. One topic I remember well is TDD in our ancient Unity 2D course (2016-2017, I think). You might think a simple game project (it was in section 8 or something like that) is perfect for learning TDD, and it probably is, but the majority of students ignored those videos, and a few wrote angry messages because they didn’t see any point in “wasting their time” with writing tests when they could simply write the actual code.

Ben and Rick have been gaining lots of experience as instructors during the past years. And they learnt that most of our students are not interested in an academic approach. The majority want to have fun and make a few nice games within a couple of hours. It’s a nice and productive hobby for them, they don’t want to worry about anything, and that’s what our courses are trying to provide: learning something new while having fun.

Since this is Ben’s, Rick’s and Gary’s concept, I, as a teaching assistent, are expected to support that. If a student shares their solutions or alternative approaches, you rarely see me nitpicking unless the student explicitely asked for feedback regarding a specific aspect. I also won’t make people question if this course might be right for them or if they risk internalising bad practice.

Those who do want to become good programmers usually take this course as an introduction to learn the fundamentals, and they continue with our RPG courses or other resources. If somebody is interested in C#, I usually recommend Bob Tabor’s free C# course.

Well, that was a wall of text again. I just wanted to point out that our instructors’ decisions are based on their experience with teaching online and with our community of students.

We appreciate that you are sharing your knowledge and your honest opinion with our community. Please keep doing that. :slight_smile:

I liked the wall of text a lot.

It gave me a good insight. I can see why you unfortunately wouldn’t cover it.

I think Ben and Rick are doing a fantastic job, you as well. I was just very confused by this. Don’t worry, y’all are still my go to recommended introduction to programming course to people. It’s a shame that people fail to see the importance of TDD. I know when the original Kickstarter happened a lot of people I saw were trying to use it not for hobbyist game development but intending to make, for a lack of a better phrase, real games.

In all honesty I would love to see a TDD lesson plan by Ben and Rick. Even if they sold an optional “programming fundamentals” class I would gladly buy it. No matter how good you are studying your fundamentals is always a good idea. It’s why guitarist always practice scales.

I’m sorry if my posts came off negative. Writing early in the morning and before bed isn’t a smart thing to do. My nitpicks weren’t really meant to throw shade at the course but point out a part I thought was confusing for something pretty important that obviously Ben and Rick know. Especially when people later show work on a site like StackOverflow and if they said “I learned it from GameDevTV” the snobby people of StackOverflow would use it to tarnish your reputation. Stuff I’ve seen them do in the long long agos (like 2012) and is why I left the site entirely.