How to study programming
Zsolt Kohári · 2019.10.12.
How to study for tests? It is a major mistake to just read solutions to problems!
tl;dr
How to learn for the tests? „Noway.” You can not learn it, you have to practice to improve your skill.
Each subject requires a different approach to study for the test. For a history test you keep reading through the material, memorize the important dates, what happened to whom and where. For math you need to remember quite a few theorems, probably their prooves but you still need to practice solving related problems.
Programming is more or less like math but there are very few theorems to remember and you need to practice solving more problems.
Typical mistakes during preparation for a programming test
If you follow an inappropropriate method, it brings you no good.
- Enormous mistake to start studying for the test the previuos evening. Impossible to achive anything useful.
- It is a big mistake to just read the materials on the webpage or any other resources. It is a very bad idea to view the sample solutions provided for lab and practice problems. It gives you no skill to solve even a very similar task! It does not improve your algorithmic thinking, it does not give you experience.
- If you saw the solution for a particular problem, there is a very slight chance you can reproduce it – unless you are Rainman. Even if you fully understood it, there is a big chance – considering the stress – that you can not put it down on the test. There is a big creative part in programming; if you always look at the sample solution you lose the most interesting part.
- A big mistake is to rely on solved ST/MT problems of the previous years. This year the problems might be similar but they also might be completely dissimilar. Some of the problems might be similar to old ones but the chance that they are the same is almost zero.
- A serious mistake is to rely on the reference sheet. There are no solutions on that sheet. It can be
used for example to check the sequence of parameters of a library function, or what percent sequence
prints a hexadecimal value in
printf()
. - It is a mistake, too to squeeze the solution of a large problem into a single block of code.
- It is a mistake to use and trust whatever you find on the internet. If someone likes to write forum posts it does not mean he is good at programming. Look at this horrible roman number program.
Good practices and methods for studying programming
- Do try to solve the problems! If you know what you need to use for the solution (e.g. a pointer) but you use it in a wrong way try to identify the mistake yourself! Do not look at the sample solution immediately but rather look at the relevant part of your lecture notes. If it does not help then look at the explanation of the solution. Only as a last resort look at the relevant part of the solution but still try to complete the program on your own!
- Practice using your computer. The compiler checks the grammar and you can test your code! Use the debugger!
Put a lot of
printf()
-s to see how things work in the code you just typed in! - Enable warning messages in the compiler (in Code::Blocks Settings/Compiler and make sure the following two checkboxes are on: -Wall, -pedantic). You will learn a lot from the warning messages. Do not build&run but just build otherwise you will not see the warnings.
Advice for algorithm building
- Is there a digit 3 in the following sequence:
20275922897612919478450610623615547
? How many consonants are there in the wordmicrominiaturization
? What you just did to find the answers were the algorithms. Put it down using C language and the program would realize the same algorithm. Computers were invented to do such boring tasks. - If you ever consider copy/paste-ing while writing a program do not do it. Rather use a loop or a function to do repetitive tasks. Will you have time on the test to put down the same lines of code twice or even more times?
- Always concentrate on one thing at a time! If some solution seems too complicated then partition
it into functions using
top-down design methodology.
Example
„Which is the greatest prime that is less than 2012 and the sum of its digits is 14.” First we should realize that counting downwards from 2012, the first such number that we find is exactly the number we are looking for. So „while not such, count downwards”:
What does such mean here? Prime and 14 is the sum of its digits:year = 2012; while (!such) year--;
Put downyear = 2012; while (!(prime(year) && sumofdigits(year)==14)) year--;
main()
before this loop, put aprintf()
and areturn
after it, an#include
at the top of the page, and it has been started. To write the remaining two functions is almost trivial. - If you have not written the program to check for digit 3 in the sequence above, and the other one that counts the consonants in the text, write them now! They could have been problems in a MT.