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

#4326 2011-12-16 05:14:01

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

"Personally I think that's a great decision for lowering the threshold for kids and beginners, and I do hope that our decision to abandon these special-cased list variables in favor of first-class lists doesn't put too much of a strain on our target audience."
I totally approve your view. In Byob the coexistence of "named" lists and "first-class" lists was the result of historyical "sedimentation".

What I mean with my example iis  that in some custom blocks like "map over" "append" etc you need to set (not declare) the "script variable" resul to a void list. If you forget to do so, your block does not work, but you also you don't get any error message. As I said it in a previous msg, it took me hours to find this "error". But now I know it. Such a problem is not an issue, and is a part of the "learning process" that each programmer has to go through, whichever the language is. Many previous msg above that there are others comparable cases. It will be easy - in the futureSnap! documentation  (perfect as we know brian) -to undeline such cases.

Offline

 

#4327 2011-12-16 09:54:07

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

xly wrote:

you need to set (not declare) the "script variable" resul to a void list. If you forget to do so, your block does not work, but you also you don't get any error message.

That's a BYOB bug, I'd say.  Applying list operations to a non-list should be an error.

(But I think it's open for discussion whether the operations that have two different color versions for lists and strings, such as LENGTH, should be combined into one, or maybe both exist but take both kinds of inputs.  Or maybe applying list operations to a string should treat it as a sentence, so ITEM 1 OF (the quick brown fox) would report "the"!)

EDIT:  When talking about the possibility of making Snap! more sensitive to user errors, bear in mind that we're going to invent something friendlier than glowing red to report errors.  Imagine an error-specific popup dialog with choices like "DID YOU MEAN TO SET (foo) TO [LIST] FIRST?"  And one of the choices would always be "Start Debugger."

Last edited by bharvey (2011-12-16 09:57:30)


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4328 2011-12-16 10:45:55

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

@ bharvey "LENGTH, should be combined into one, or maybe both exist but take both kinds of inputs. "
Similarly I've been caught with this type of error, where inavertently I'd selected the "green" LENGTH instead of the "brown" one. I give you a low profile suggestion " avoid to give the same name for LENGTH of list and LENGTH of word. But anyhow it's the game of test-and-learn process.

Offline

 

#4329 2011-12-16 10:49:46

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I've got a question for you computer gods: what's a "class"? I've started on a journey to learn Objective-C, and for some reason, though I can use Classes, I can't pinpoint what they are. I do know that they're files you add to a project. But I feel a .js file isn't exactly a class in a HTML page. I see classes as two distinct types, just as I see JavaScript functions: an object (data type) and a function (collection of code). So there's an NSString class that gives you the String data type and related functions and initializers, like the JS String object, and there's an AppDelegate class or DocumentController class that's a collection of code. That's all I've figured out, please help me out.


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#4330 2011-12-16 10:55:29

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I think we should have an error popup at the source block:
http://i40.tinypic.com/s6oug4.jpg
and highlight all the custom-block calls that lead to it in red.


nXIII

Offline

 

#4331 2011-12-16 11:30:22

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

I think we should have an error popup at the source block:
http://i40.tinypic.com/s6oug4.jpg
and highlight all the custom-block calls that lead to it in red.

I'm assuming that [Debug] would return the call stack much like squeak does, am I right?


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#4332 2011-12-16 11:59:25

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

Presently, when I SET test to "toto" and tries to run ITEM 1 OF test I get he following error message "Problem : type error Object toto has no method "at". I think it is enough !
The same with Byob gives a "blank"

Offline

 

#4333 2011-12-16 12:04:12

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I think there should be a block called (cast () to ()) block where the first input accepts anything and the second input is a dropdown with all of the data type names (number, string, list, reporter, predicate, boolean, object) and it will turn one data type into another. If the type of the first input is the second inpit, it is reported unchanged, otherwise it is changed according to the following rules:

To convert to strings:
A number converts to the equivelent string (e.g. the number 45 converts to the string "45"),
A list casts all of it's items to strings and joins the items together (like the ([list] as text) block),
A boolean becomes the string "true" or "false",
A string stays the same,
Anything else is a blank string "",

To convert to numbers:
A string converts to a number in the same way as scratch (if the string is a number it is that number otherwise it is 0),
A boolean is converted to 1 if it is true, 0 if it is false,
Anything else is 0,

To convert to lists:
A string is a list of words of if it is only one word, it is a list of letters,
A boolean is an empty list if it is false, or a list of 1 item which is the number 1 if it is true,
Anything else is a list of 1 item which is the origanal item,

To convert to booleans:
Blank string, the string "false", 0, the stage, or an empty list is false, anything else is true,

To convert to reporters:
Simply encapsulated in (the () block),

To convert to predicates:
Simply encapsulated in (the (cast () to (boolean)) block),

To convert to objects:
For a string, if there is a sprite whoose name is the string or whose name is the string "sprite" joined to the name of the string, that sprite is reported, otherwise the stage is reported,
Anything else is cast to a string then follows the same rules as a string.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#4334 2011-12-16 14:14:45

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

I've got a question for you computer gods: what's a "class"? [...] I do know that they're files you add to a project. [...]

Well, the only god around here is Jens (coincidentally, he and I have been arguing about just this godhood question recently  smile ), but I'll give it a stab anyway.

There's no necessary connection between classes and files, although it's convenient to name a file after a class.  But often a program has a zillion tiny class definitions and it'd be overkill to have one per file.  (I wouldn't be surprised, I guess, to learn that some particular language I don't use requires one per file.)

In a class/instance language, a class is a kind of object, and an instance is a particular one.  So, for example, there could be a class Point with an instance (3,4).  BYOB/Snap! and JS are both prototyping OOP languages, in which there is no class/instance distinction, just a hierarchy of parents and children.

(Class/instance languages, typically compiled rather than interpreted, are good for large team projects, in which the entire object hierarchy is planned out before any code is written.  Prototyping languages, often interpreted and therefore interactive, are good for one-person seat-of-pants tinkering, in which you design an object interactively and incrementally, then when you like it you say "give me six more like this one" (but can still go on tinkering with the parent and have the changes reflected in the children).)

One of the central hallmarks of object oriented programming is that an object is both a data structure and a collection of methods.  (Arguably, a method is just a procedure-valued datum.)  It's typical, but not required, that the class contains the methods and the instances contain the non-method data.  For example, each instance of Point will have its own x-coordinate and y-coordinate (data), but the distance-from-origin method is the same for all points and therefore lives in the class.

(Exceptions are possible both ways.  Instance-specific methods are rare -- not allowed in many OOP languages -- but class variables aren't so uncommon.)

I think the above is what's confusing you.  Some classes, because of their particular purpose, will be very method-heavy, and an instance will have relatively little specific data.  (In the extreme case, you occasionally see a class that's meant to have only one instance, which has no data at all, just to collect a bunch of procedures in one place.)  Other classes, for different purposes, will have a ton of instance-specific data and not so many methods.  But these are positions on a continuum, not an either-or duality.

Does that help, or am I misunderstanding the question?

Last edited by bharvey (2011-12-16 22:38:35)


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4335 2011-12-16 14:22:40

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

I think we should have an error popup at the source block:
http://i40.tinypic.com/s6oug4.jpg
and highlight all the custom-block calls that lead to it in red.

Nice.  One quibble: "Ignore" is not quite the right thing for a reporter.  Instead it would have to be "report the value ___."  Or maybe "Use ___ as the list input."  The choices would depend on the exact error; for example, if the problem in an ITEM block is giving an item number past the end of the list, there might be two options, one to give a different index and one to give a different list.

N-1 of the custom block calls on the stack will be hidden in other custom blocks' definitions.  Do we open block editors for all of them, in order to show the red highlighting?  I think that would be too overwhelming.  But I wouldn't mind seeing a stack trace, or maybe just the first three hops of a stack trace and a "more" button, in the form

Called by (picture of block with actual input values)
Called by... etc.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4336 2011-12-16 14:28:06

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

MathWizz wrote:

I'm assuming that [Debug] would return the call stack much like squeak does, am I right?

Basically, but there's a lot of information to present (the calling blocks, the values of local variables, the object (sprite/stage) that's running this block, its variables...  We have to invent palatable ways to give the user access to all that without just blasting it all onto the screen at once.

A debugger should also be able to single-step, to set breakpoints, maybe to run in slow mode (what Scratch calls single stepping), maybe even to run backwards (having kept a lot of snapshot information).


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4337 2011-12-16 14:30:56

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

xly wrote:

avoid to give the same name for LENGTH of list and LENGTH of word.

That's another idea.  Call one NUMBER OF LETTERS IN and the other NUMBER OF ITEMS IN or something.

But anyhow it's the game of test-and-learn process.

Well, that will be true to some extent no matter what we do.  But I don't think we should go out of our way to make errors obscure!


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4338 2011-12-16 14:39:28

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

xly wrote:

Presently, when I SET test to "toto" and tries to run ITEM 1 OF test I get he following error message "Problem : type error Object toto has no method "at". I think it is enough !
The same with Byob gives a "blank"

No, it's not enough -- this is what I meant about not going out of our way to make errors obscure.  What you're seeing is a Javascript message for the benefit of Jens, not the intended message for users.  In this case the error should be "toto isn't a list."  Maybe even "Did you mean (orange variable blob named toto)?"


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4339 2011-12-16 14:46:35

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

I think there should be a block called (cast () to ())

I think some of those rules are so sensible that we don't even need the explicit cast, e.g., between strings and numbers.  Others are pretty far-fetched, e.g., most things cast into a list of length 1 but with a few exceptions.

Basically, I would like users not to have to think about types very much, except to make sure they are giving blocks sensible inputs.  In a few cases, we have been interpreting strings as variable names, but I think that should be done with an explicit VARIABLE NAMED (text slot) block, not a general CAST mechanism.  More generally, any explicit cast should make it clear what the rule is, and we should avoid thinking of things as casting that can be understood other ways.

For example, why explicitly cast a value into a one-item list containing that value, when you can just use the LIST block, which expresses your meaning much more straightforwardly.

This seems to be my theme for the week: treating each case separately in designing the language.
I'm glad to have all these different kinds of examples to talk about, because I have to convince Jens of the general idea before I can bring him around on treating variable blobs differently from other reporters when it comes to grey-bordering.  smile


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4340 2011-12-17 03:14:45

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Hardmath123 wrote:

I've got a question for you computer gods: what's a "class"? [...] I do know that they're files you add to a project. [...]

Well, the only god around here is Jens (coincidentally, he and I have been arguing about just this godhood question recently  smile ), but I'll give it a stab anyway.
[...]
Does that help, or am I misunderstanding the question?

I think I got it, thanks for the explanation. Here's how I see it now:
(I'm taking JS as prototype based and Objective-C for Class/instance-based language examples.)
A JavaScript function or object declared as "var foo = new String("blah");" is like an Objective C class initializer (It's like NSString *foo = [[NSString alloc] initWithString:@"blah"];). So a JavaScript function declared as "function foo() {}" is in fact a sort of class initializer which can initialize (and control) an object, or just do something and return an "empty" object.
Assuming that bit is correct, I think the "proper" way to create a JavaScript function would be the "function(arg) {}" syntax, which is like "-(returnType)function:(type)arg {}" Objective-C code.
Is that how it is?

EDIT: Truncated your quote, fixed a smiley glitch...
EDIT: Still couldn't fix the smiley glitch...

Last edited by Hardmath123 (2011-12-17 03:20:47)


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#4341 2011-12-17 04:00:46

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

@bharvey
I'm far from being a programming expert, and I give you the layman point of view.
Instead of assigning strict types "beforehand" to data we can control the variable type when it is needed.
Take the example of "divide by zero error". If needed one can write a reporter block NONUL to avoid a division by zero.Similarly one can test with LENGTH OF the error  of looking for item n+3 of a list with only n itams. .By making ourself these control blocks we can customize the error message with a global variable ERROR set to report a code number.
My question is :  Is it possible for a Snap! programmer to know afterhand , if needed, that such variable is a number, a string, a list, a word, a script, a letter , a sprite, a costume etc ?

Offline

 

#4342 2011-12-17 07:23:06

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

It might get a bit annoying if every error stops the script. What if there was a block called (ignore errors in () ) which will evaluate it's input but if there is an error (such as trying to divide by 0) it just returns a blank string. Even better there could be a try/catch exeption mechanism  like in many programming languages. It will look like
http://i39.tinypic.com/1j82he.gif
and will run the input in the try part but if there is an error it will terminate and set the upvar exeption to the error message and run the catch part. There will also be a |show error message ()| block to display an errormessage in a red dialogue box and a |throw error message ()| block to throw errors. An error message will be a list and will be displayed as every item in the list seperated by new lines so you could put in a short dispcription of the error (such as "procedure called without reporting") followed by the block that caused the error and then the script that caused the error and the sprite it was in. This try/catch mechanism could be used to create the (ignore errors in ()) block like this:

{(ignore errors in (unevaluated input))}
try {
  report (call(unevaluated input))
}
catch (exeption) {
  report ()
}


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#4343 2011-12-17 12:02:43

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

So a JavaScript function declared as "function foo() {}" is in fact a sort of class initializer which can initialize (and control) an object, or just do something and return an "empty" object.

Yeah, except of course that in JS not everything is an object, and you can have function increment(x) {return x+1}; returning a number instead of an object.  I think that's right anyway.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4344 2011-12-17 12:23:58

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

xly wrote:

Instead of assigning strict types "beforehand" to data we can control the variable type when it is needed.
Take the example of "divide by zero error". If needed one can write a reporter block NONUL to avoid a division by zero.

Sure, but that isn't a type error.  A type error would be more like trying to divide by a string or a list.

This isn't just a quibble about terminology; if you're dividing by zero it's almost certainly because you're dividing by a variable, and that variable's value is of the correct type (i.e., number), but unexpectedly came out zero.  So the real error is earlier in the program when that value was computed.  But if you're dividing by a string, it's because you did something incoherent right at that point in the program, putting an expression in the divisor slot that couldn't possibly come out right.

So it makes sense for us to handle different kinds of errors differently, maybe.

But also, I don't think we should make it the expectation that everyone surround every input expression with a domain check.  That would be a huge distraction from actually writing the program you want to write!

Is it possible for a Snap! programmer to know afterhand , if needed, that such variable is a number, a string, a list, a word, a script, a letter , a sprite, a costume etc ?

In the Operators menu there's a IS ___ A ___? block, where the second slot is a pulldown of types.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4345 2011-12-17 12:26:00

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

Even better there could be a try/catch exception mechanism  like in many programming languages.

Yeah, we'll probably add something along those lines.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4346 2011-12-17 14:25:49

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

In the Operators menu there's a IS ___ A ___? block, where the second slot is a pulldown of types.
Indeed ! It's perfect !

Offline

 

#4347 2011-12-19 00:49:11

14God
Scratcher
Registered: 2008-11-14
Posts: 100+

Re: BYOB 3 - Discussion Thread

xly wrote:

In the Operators menu there's a IS ___ A ___? block, where the second slot is a pulldown of types.
Indeed ! It's perfect !

might be nice if object ancestry was handled by the IS__A__? block... and by ancestry I mean checking if a object is a child of another, of course objects are a ways off for snap.

Last edited by 14God (2011-12-19 00:50:35)


http://cs.berkeley.edu/~bh/sig4.png
Logic and reason have led me to atheism... but I'm stuck with the name  tongue

Offline

 

#4348 2011-12-19 01:54:47

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

14God wrote:

might be nice if object ancestry was handled by the IS__A__? block... and by ancestry I mean checking if a object is a child of another, of course objects are a ways off for snap.

We do (in BYOB 3.1) have the ATTRIBUTE [PARENT] and ATTRIBUTE [CHILDREN] capability, so you can find out the ancestry of an object.  The IS/A block presents a disjoint and complete list of basic types, so everything is exactly one type for IS/A purposes.  Objects' abstract types are complicated; the predicate you want should return True about the object's grandparents, etc., too.


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#4349 2011-12-21 12:08:15

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: BYOB 3 - Discussion Thread

i did make a block in the block libary called (ancestor) which will report it's "oldest" ancestor and if it has no parents it reports the sprite that called it. Using that block it will be possible to make a block to report a list of all ancestors (parents, grandparents, ect)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#4350 2011-12-26 17:11:18

EvilGenius
Scratcher
Registered: 2010-01-02
Posts: 14

Re: BYOB 3 - Discussion Thread

I was thinking about trying to implement one of my favorite programming constructs, call-with-current-continuation, in BYOB. For those that don't know this is a block that takes a procedure A and calls A with a procedure B. B, when called, will jump back into the original context and return the value it was called with to wherever call-with-current-continuation was originally. Anyway, I thought about how to capture the whole local environment, especially sprites' local variable values. I think an elegant addition to BYOB which would allow this would be an analog to sprite(all sprites); attribute(all attributes) which would return a list of all variable values, x position, etc.. of a sprite.

Offline

 

Board footer