Learning How to Program Episode 4

So, I decided to change things up a little bit. I actually went back and rerecorded the first parts of my second and third episode to make the learning process a little bit easier for those who may watch this in the future, that way people aren't spending hours actually learning how to learn this stuff.

I actually made these two videos a few weeks back, but didn't get around to posting them. That being the case, Episode 5 will probably be right around the corner. I'm hoping to finish it before school starts next week, but we'll see.

Thanks to those that are watching. I'm getting at least a couple views on everything, so I'm glad to see at least someone is paying attention, even if they aren't actually using these videos for their purpose.

5 Comments
5 Comments
Posted by DoctorWelch

So, I decided to change things up a little bit. I actually went back and rerecorded the first parts of my second and third episode to make the learning process a little bit easier for those who may watch this in the future, that way people aren't spending hours actually learning how to learn this stuff.

I actually made these two videos a few weeks back, but didn't get around to posting them. That being the case, Episode 5 will probably be right around the corner. I'm hoping to finish it before school starts next week, but we'll see.

Thanks to those that are watching. I'm getting at least a couple views on everything, so I'm glad to see at least someone is paying attention, even if they aren't actually using these videos for their purpose.

Posted by TyCobb

Here's a couple of tips:

Name your variables and avoid single letter variables for anything other than a for loop.

I saw in your fifteen.c file you have 4 single letter variable names are that are global level variables. That is bad. Variables should be named appropriately to describe what they are. It's almost as bad as having magic numbers everywhere.

For instance: you have d, r, c, s as dimensions. Why did you use these specific letters? That definitely does not tell someone looking at your code what they are. Is "d" for depth? No clue. I could make an educated guess, but that is something you shouldn't need to do. Code should be written so it can easily be read by others. This is why comments shouldn't say what you are doing since others should be able to read the code and know, but why you are doing it. Also as mentioned, you have them globally defined. At the most it should be at the class level. Now everything referencing fifteen.c has access to those variables and can very easily be unintentionally modified.

With all the said.... awesome videos. Keep it up! Also, once you learn about classes, you will then truly understand the point of the header file and see that you can create your own objects to hold your data (your dimension variables can be in a single struct to hold the data).

Posted by DoctorWelch

@TyCobb said:

Here's a couple of tips:

Name your variables and avoid single letter variables for anything other than a for loop.

I saw in your fifteen.c file you have 4 single letter variable names are that are global level variables. That is bad. Variables should be named appropriately to describe what they are. It's almost as bad as having magic numbers everywhere.

For instance: you have d, r, c, s as dimensions. Why did you use these specific letters? That definitely does not tell someone looking at your code what they are. Is "d" for depth? No clue. I could make an educated guess, but that is something you shouldn't need to do. Code should be written so it can easily be read by others. This is why comments shouldn't say what you are doing since others should be able to read the code and know, but why you are doing it. Also as mentioned, you have them globally defined. At the most it should be at the class level. Now everything referencing fifteen.c has access to those variables and can very easily be unintentionally modified.

With all the said.... awesome videos. Keep it up! Also, once you learn about classes, you will then truly understand the point of the header file and see that you can create your own objects to hold your data (your dimension variables can be in a single struct to hold the data).

I actually know that's the rule in regards to the whole words instead of letters thing, but so far in the course they haven't really emphasized that. It'd probably be a good habit to get into using words instead of letters though. Also I'm not sure about the whole class vs globally defined thing, I'm guessing I just haven't learned that yet. I mean, I know that I'm putting the variables outside main to make them global variables (in fact the program the course gives you to start with has those variables defined globally), but I'm not yet sure how to do what you are suggesting.

Also, the next episode/problem set just touches the surface of using a struct. I'm not yet at the level of completely understanding what exactly that is or does, but that's not too far off.

Thanks for the response :)

Posted by TyCobb

@DoctorWelch: That's fine. Everyone uses single letter variables when they first start. I also didn't realize the source material had them that way (I didn't look). I figured it was more of "I have this problem and need a program that can do X" and it just gave hints of what the steps were to solve.

Glad to hear the next episode is about structs. That means you are going to be learning a ton about Object Oriented Programming. I look forward to the next episode.

Posted by DoctorWelch

@TyCobb The next episode is actually about making a sudoku game. And yeah, for this one you just watched and the next one as well they start you out with some code already written and then you have to add to it to make the thing actually work. So for this one I actually didn't even write main, I just wrote the functions that main calls.