Announcement

Collapse
No announcement yet.

Miscellaneous Blocks Programming Questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Miscellaneous Blocks Programming Questions

    I'm a SW mentor for FTC Team 8695. I've got several questions that I'd like to have answers before I can guide my young middle school programmers using "Blocks Programming".

    1. When a variable is declared, it its scope automatically 'global'? If a variable is used within a function and shares a name with a variable in another function or from the main execution block - for example, a loop Index variable, or temporary variable - is that variable going to have unexpected behavior? I'm hesitant to encourage the use of global variables when I know what kind of trouble they can cause. Should I be concerned about this when trying to teach younger students beginning programming techniques?

    2. Somewhat related to the first question. If you pass a value into another function through an input argument (parameter), I can access that input parameter from the 'variables' menu. However, if the input parameter name has the same name as another variable in the program, how does one make sure that they're accessing the parameter passed in to the function verses accessing the variable defined in another portion of the block design.

    3. Is there a way to create a user defined function outside of a blocks program that can be reused by other blocks programs? Or do you have to manually copy any user functions between block programs?

    4. Are there any "Blocks Programming" manuals besides this one (http://www.ortop.org/ftc/BlocksProgr...enceManual.pdf) that would have answers to some of these questions?

    5. Are there any online "Blocks Programming" servers that Students could use when they don't have access to the team phones?


  • #2
    "1. When a variable is declared, it its scope automatically 'global'? If a variable is used within a function and shares a name with a variable in another function or from the main execution block - for example, a loop Index variable, or temporary variable - is that variable going to have unexpected behavior? I'm hesitant to encourage the use of global variables when I know what kind of trouble they can cause. Should I be concerned about this when trying to teach younger students beginning programming techniques?"

    Yes, Blocks variables are global. I don't know of a way to create a local variable other than a formal variable of a function.

    "2. Somewhat related to the first question. If you pass a value into another function through an input argument (parameter), I can access that input parameter from the 'variables' menu. However, if the input parameter name has the same name as another variable in the program, how does one make sure that they're accessing the parameter passed in to the function verses accessing the variable defined in another portion of the block design."

    Blocks tries to keep you from using the same name for a global variable as for a formal variable of a function. You can, however, trick it into allowing you to do so. I will investigate what happens when you do, but I would discourage team members from doing so because even if the global and formal variables with the same name behave in a predicable way, the dual use of a variable name will be quite confusing to those trying to understand and op mode and/or debug it.

    "3. Is there a way to create a user defined function outside of a blocks program that can be reused by other blocks programs? Or do you have to manually copy any user functions between block programs?"

    Yes, at this time, the only way to reuse a function is to manually copy it to another blocks program.

    "4. Are there any "Blocks Programming" manuals besides this one (http://www.ortop.org/ftc/BlocksProgr...enceManual.pdf) that would have answers to some of these questions?"

    Not that I know of. I will add answers to your questions to this reference manual.

    "5. Are there any online "Blocks Programming" servers that Students could use when they don't have access to the team phones?"

    No.

    Keep those questions coming!

    ...Bruce

    Comment


    • #3
      When I said I didn't know of another Blocks Programming manual I forgot about the online Blockly documentation. FTC Blocks Programming was built from the Blockly technology. As such it inherits some of its features from Blockly. Blockly is documented via a Wiki at https://github.com/google/blockly/wiki

      Here's what the Blockly Wiki says about variables:

      We use the term variable the same as it is used in mathematics and in other programming languages: a named value that can be changed (varies). Variables can be created in several different ways.

      - Every count with and for each block uses a variable and defines its values. These values can only be used within the block. A traditional computer science term for these are loop variables.
      - User-defined functions (also known as "procedures") can define inputs, which creates variables that can be used only within the function. These are traditionally called "parameters" or "arguments".
      - Users may create variables at any time through the "set" block. These are traditionally called "global variables". Blockly does not support local variables.

      Comment

      Working...
      X