While mentoring a FIRST® LEGO® League team, I had a chance to show the kids (who are in an elementary school) how to use the My Block Builder tool while programming their LEGO® Mindstorms robots.

A My Block is a combination of one or more blocks that are grouped into a single block. Once a My Block is created, you can use it in multiple programs.
From: LEGO® Mindstorms EV3 Information

It's like defining an external function, but with blocks, and makes for great program shorteners (instead of having 20 or so blocks, 2 or three times, the students learn to make one single My Block, 2 or three times).

However, the students seem to be forgetting, repeatedly, that this tool exists. Only when I point out "why not use a My Block, instead of copy-pasting a lot of blocks?", do they use the My Block tool.

I'd like them to understand when they should use My Block, (and hopefully why, because it might give them insight on external functions later on, should they choose to study CS) without having me point out the tool. There are many use cases for My Block, so giving them a list of situations doesn't work (I've tried, to incredible failure).

What can I do to help the team members understand when they can and should use My Block?

  • $\begingroup$ The link dose not go to a page that explains what a MyBlock is. I am assuming that it is just a way to define a your own block ( a procedure, what you ( and the C programming language ) are calling a function). But can you tell me what the distinction between external and not external. $\endgroup$ – ctrl-alt-delor Aug 2 '17 at 20:59
  • $\begingroup$ @richard think of it as creating a DLL with one method in it, and then simply using that one method from the DLL, But not only once and more than one DLL. For that matter, external or not external doesn't really make a difference $\endgroup$ – ItamarG3 Aug 2 '17 at 21:02
  • $\begingroup$ You are creating small programs with <11year olds. And you want them to create multiple object files. And to see an advantage of this? $\endgroup$ – ctrl-alt-delor Aug 2 '17 at 21:06
  • $\begingroup$ @richard it's really a bit much to explain in comments if you're not familiar with the software or with Lego Mindstorms $\endgroup$ – ItamarG3 Aug 2 '17 at 21:07

Four relatively easy ideas would be to:

  1. Conduct periodic code reviews where you point out style issues like these. If you make code reviews a regular thing, the repetition should hopefully help students eventually start using functions independently. Since your students are in elementary school, this should obviously be a very lightweight and informal code review.
  2. Develop an automatic style checker for whatever language you're using to perform these sorts of style checks for them. (Hopefully, whatever language you're using is exportable into a text-based or otherwise structured format that actually does permit this sort of analysis.)
  3. Heavily emphasize that if the students are at any point copying-and-pasting, they're doing something wrong. Make it clear that copying-and-pasting is a sin. (This is assuming whatever language you're using is actually usable enough to make this a truth rather then a lie.)
  4. Give them a short style guide to follow; include a note about eliminating redundancy using functions/myblocks in the style guide. This will probably be more effective with older students.

If you have control over how students learn to code, a broader (and probably more effective) strategies would be to teach students how to use your MyBlocks/functions first and foremost, almost before anything else.

That is, teach them the absolute bare minimum functionality to make something happen, then teach them how to decompose a large problem into smaller subtasks, and have them create a MyBlock for each subtask. I would do this first, before teaching them things like control flow, variables, etc... Basically, make the idea of "refactoring" and "identifying subproblems" one of your first lessons.

The hope is that if you make using functions/MyBlocks one of your very first lessons, they're less likely to pick up the bad habit of writing redundant code.

  • $\begingroup$ 1, 2 and 3 are superb. Really useful. (Might even make my regex skills better) $\endgroup$ – ItamarG3 Aug 2 '17 at 20:14

This is what happens when you put the cart before the horse. The kids know syntax, but do not understand programming. This is very common. The kid see what they are trying to do as as commands in code when actually it is a series of tasks that need to be planned prior to sitting in front of a computer typing code.

Get the kids away from the keyboard. Lay out the tasks. Build a flow chart or pseudo code. Once the program is understood in the task setting (groups of things to be done) then start to code. The My Blocks will make sense to them. Programming in front of the keyboard will always lead to the problem you are having.


You need to show them the value of the MyBlocks (procedures): easier to modify, easier to read.

  1. Get them to write a program that would need a procedure or cut and paste. Then get them to make a small change. This will also be a small change to the code if they have made their own procedures, but a big change if they used cut and paste. Keep giving them these changes until they ask for a solution. Then use your teacher skills to remind them of the MyBlocks.

  2. Show them two programs: one with cut and paste, one with MyBlocks. Have them in teams some with one version some with the other. Get then to work out what it does. Time them. Them swap over with a different example. Discuss why the version with MyBlocks was easier/faster to read.

I don't tend to focus on the memory saving aspect; memory is cheep, and early optimisation is a bad idea. “optimise for readability, and maintainability, (and big O, when they are older) let the compiler do the rest.”

  • $\begingroup$ MyBlocks aren't like functions in that way. You need to reuse the tool for creating them if you want to make a change. That's why I didn't want much to do with the functions analogy, because it isn't such a good one. Also, what does "teaching skills" mean? Not quite sure I understand $\endgroup$ – ItamarG3 Aug 2 '17 at 21:05
  • $\begingroup$ May be the kids are right, may be it is better not to use them. I said “teacher skills”, to mean that after that you carry on being a teacher, but it is outside the scope of the question. I would probably respond to the question with a question, to try to lead them to using the MyBlocks. $\endgroup$ – ctrl-alt-delor Aug 2 '17 at 21:16
  • $\begingroup$ Can you give an example of what kind of program would have this feature? I don't understand what you're saying in this answer. $\endgroup$ – Ben I. Aug 3 '17 at 12:08
  • $\begingroup$ @BenI. If you cut and paste, then choose to change the code, then you have to change every copy. $\endgroup$ – ctrl-alt-delor Aug 3 '17 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.