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

#1 2007-06-10 21:25:30

jasa
Scratcher
Registered: 2007-06-10
Posts: 2

Refactoring Variables (names)

Hi all,

Refactoring is to change a variable name (more important for globals)
and, in an automatic way, the "old" name is changed to the "new"
name in all the scripts belonging to the project.

Doesn't seem too difficult to implement (search-replace?)

Thanks to the creators for the nice scratch system (I'm trying
to engage my 11 years old daughter in programming with it)

JA

Offline

 

#2 2007-06-11 13:22:00

Canthiar
Scratcher
Registered: 2007-05-16
Posts: 100+

Re: Refactoring Variables (names)

Refactoring would be great.  If there was a way that I could switch a variable from being global to local or local to global that would be a big help, as well.

Offline

 

#3 2007-06-11 13:56:21

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

Re: Refactoring Variables (names)

Refactoring is a lot more than just changing variable names.
It refers to major redesign of data structures and program architecture, splitting the problem up differently.

Despite the mis-use of the word "refactoring" I support the idea of providing easy variable renaming.  It should also be easy to switch between local and global scope for a variable.
I've often set up a sprite with a local variable, then much later wanted to communicate that value to a new sprite.

The variables would be much easier to work with if there was only one "set <variable> to <value>" and one "change <variable> by <value>" using pull-down lists like for the messages to do the variable names.  The variable pane would not get so cluttered then and there would not need to be nearly as much scolling to find variables.

Option-click (or right-click) on variable blocks should allow you to change which variable it is, just like option-click on operation blocks allows changing the operation.

Offline

 

#4 2007-06-11 14:27:15

rauscher
Scratcher
Registered: 2007-05-30
Posts: 16

Re: Refactoring Variables (names)

Why would you want to change the scope of a variable in mid execution?  That seems perilous to me and, at least bad structure.

Offline

 

#5 2007-06-11 15:17:07

weissjd
Scratcher
Registered: 2007-05-16
Posts: 64

Re: Refactoring Variables (names)

Not during execution, during design. It would be nice if you created a variable that was local to a sprite to be able to make it global (or vice versa) without having to delete and recreate it.

Offline

 

#6 2007-06-11 23:54:20

DrJim
Scratcher
Registered: 2007-05-26
Posts: 100+

Re: Refactoring Variables (names)

Changing a variable's scope from global to local still seems risky to me, no matter when you do it.  If this is what is being proposed, at the very minimum you should get a message saying what other code segments (or sprites)  you are going to affect and allow a yes/no choice before it actually happens.

Last edited by DrJim (2007-06-11 23:55:01)

Offline

 

#7 2007-06-12 00:39:38

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

Re: Refactoring Variables (names)

Certainly changing the scope of a variable could be risky, so confirmation is appropriate.
But it is much better to be able to change the scope of the variable than to have to manually go through all scripts on all sprites looking for the variable and checking the subtle difference in color!

Offline

 

#8 2007-07-03 21:23:52

jasa
Scratcher
Registered: 2007-06-10
Posts: 2

Re: Refactoring Variables (names)

Hi all

Nice discussion. Indeed I underestimated the meaning
of refactoring.

In fact, refactoring is much more than changing
variable name. It can be even more deeper than modifying
program architecture: it can be re-programming in a different
language (this is not possible with Scratch, as far as I know).

Will sometime be available a Scratch SDK where one could
make his/her own library of "bricks"? (this is like making its
own subroutines...)

Of course, collective variables such as an "array variable", or better
a "hash variable", would allow for less "verbose" programming.

Finally, some means of creating a "procedure" or "function" or
"subroutine " with the current (1.1) programming environment
would be nice.

Perhaps one day one can  "script" the bricks with Python or Lua :-)

JA

PS: by the way, anyone knows if Scratch  is based in Smalltalk?

Offline

 

#9 2007-07-03 23:06:58

toontownmiser
Scratcher
Registered: 2007-06-28
Posts: 18

Re: Refactoring Variables (names)

PS: by the way, anyone knows if Scratch  is based in Smalltalk?

~

Yes, it is, at least the Squeak interpreter is.


Algebra I Lesson for Today:
(cat)+(dog)=(fish)
Given: c=1, a=1, t=2  d=1,o=1, g=2 and f=1, i=1, s=2, s=2
True or False?

Offline

 

#10 2007-07-04 01:58:48

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: Refactoring Variables (names)

The variables would be much easier to work with if there was only one "set <variable> to <value>" and one "change <variable> by <value>" using pull-down lists like for the messages to do the variable names.  The variable pane would not get so cluttered then and there would not need to be nearly as much scolling to find variables.

For complex projects yes-  but for using it to introduce the whole concept of variables to beginners, the present model works very well.

My class wanted to introduce object picking up in MarbleRacer and we needed a variable to keep a count of the items picked up and the present way seemed to very easy for them to grasp.

But if I had a lot of variables - then your right - the area would become very cluttered  :-(

regards

Simon

Offline

 

#11 2009-06-30 08:50:38

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: Refactoring Variables (names)

Jens made XML scripts that do what i think you are asking for.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

Board footer