This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2007-05-27 01:29:55

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Parentheses

I have found that complex math expressions sometimes get hard to read, because there are no visible parentheses, though the nesting of blocks implies them.  The nesting is a rather subtle clue, particularly when code is printed out and reproduced.

Putting explicit parentheses around each operator, would make the code more readable and not require any major changes (just the appearance of the +, -, *, / blocks).

For an example of a hard-to-read expression is in my histogram program:
http://scratch.mit.edu/projects/kevin_karplus/6813
in the add_to_hist script of the histogram sprite.

Offline

 

#2 2007-05-27 19:44:09

jay
Scratch Team
Registered: 2007-03-11
Posts: 59

Re: Parentheses

Oooo. I see what you mean about that being hard to read. It's a pretty complex math expression. I'm impressed that it is readable at all. But it might be an area that could be improved. So thanks for the suggestion. One way to simplify it is to do it in several steps by storing intermediate values in another variable. Sometimes when I do this, I end up being able to better think about the expression, but not always.

Offline

 

#3 2007-05-28 03:13:48

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: Parentheses

I considered using intermediate variables, but I did not want to clutter up the variable pane.  Each new variable takes up a *lot* of space on the pane.  I wish that you had used pull-down menus for variables, like you did for messages, so there were only three blocks for variables (set, change, and value).  It would eliminate a lot of clutter on the variable pane and make changing a variable name much easier. 

I can see the point to having separate blocks for the value of the variables, but the set and change blocks would be much better with pull-down lists.

Offline

 

Board footer