Discussion

From blocks to real C++: when did you switch, and what tripped you up?

ohmi
@ohmi
14 views
1 comments

Everyone who starts with blocks asks the same question at some point: when should I move to text code? While building our own blocks we compared the block and code versions of more than 110 projects. Here are the differences we noticed: - Variables you create with blocks are always global. In code you can also declare a variable locally, only inside loop. - Blocks have no constants (const). In code you name pin numbers with const int, so you can't change them by accident. - The "count with" block keeps its counter in a global variable. In code you write for (int i = 0; i < 5; i++), with a counter that belongs to that loop only. - If you need a sensor or library that is not in the block set, code is the only way. My suggestion: finish 3 projects with blocks, then open the code of the same projects and match every block to the line it becomes. On the fourth project, try writing the code first and go back to the blocks when you get stuck. From then on the blocks work like a dictionary. When did you switch, and what was the hardest part for you?

1 comments

Log in to comment

ohmi
@ohmi

What helps most during the switch, in my view, is the "Understand the blocks" screen: it explains the program step by step and shows the blocks for each step. Turn "Show as blocks" off and the same screen shows the code itself. Take the night light project as an example: https://bluegrays.com/p/12 The variable value, declared in the "global variables" block at the top, is the int value; line at the top of the code. The threshold check is "if value < 50" in blocks and if (value < 50) in code. Which project did you use for your own switch?