Type conversion best practice

341 views
Skip to first unread message

Bart Butenaers

unread,
Sep 3, 2018, 3:15:57 AM9/3/18
to Blockly
Hi everybody,

The type checking in Blockly is really a blessing, to prevent users from doing weird things.

However in some some cases a type conversion is needed.
For example we have a custom block that requires a String, which will be displayed on the screen.
But some of our users now wanted to display a number, but this isn't accepted by our custom block:

blockly_type_conversion.png

We could solve this in a couple of ways, but I'm not sure which is the best way to go:

  • Instead of only allowing 'String' as input we could allow multiple types:

"output": ['String', 'Number']

And the code converter of the custom block could generate a parseInt(inputValue) when a number is passed. 
  • Add new type converter blocks, e.g. a int-to-string-converter block:

blockly_convert_int.png

The advantage of this is that you need to write the conversion only once (in contradiction to the first solution, where the conversion logic needs to be repeated in all blocks that need it).  But how can a non-technical user see which conversion he needs.  He only sees in the editor that both blocks cannot be linked together.  But I don't think he can see why it is rejected?  Is there a solution to visalize that?
  • Others ???
Any tips on how to handle this?

Thanks !!!!
Bart Butenaers

TRUNG NGUYỄN HOÀNG ĐỨC

unread,
Sep 3, 2018, 6:21:46 AM9/3/18
to blo...@googlegroups.com
Non-technical doesnt need system performances. You should perform conversion all the time

Vào Th 2, 3 thg 9, 2018 lúc 14:16 Bart Butenaers <bart.bu...@gmail.com> đã viết:
--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Bart Butenaers

unread,
Sep 3, 2018, 8:49:56 AM9/3/18
to Blockly
Hi Trung,

By "perform conversion all the time" do you mean proposal 1, i.e. allow more types in those nodes and do conversions all over the place?
Thanks for responding!  
Bart

TRUNG NGUYỄN HOÀNG ĐỨC

unread,
Sep 3, 2018, 9:08:35 AM9/3/18
to blo...@googlegroups.com
Yea , convert everything ( number , float ... ) to string , it will
surely slow down the system .
But a wise note is that computer time is much cheaper than human time
, the time it takes for an user to drop a "conversion block" worth
much more than a controller to do extra works with every conversion .
For more advance user , you surely need to use conversion block !.

Bart Butenaers

unread,
Sep 3, 2018, 4:06:57 PM9/3/18
to blo...@googlegroups.com
Ok, thanks a lot for your explanation !

Simon Walters

unread,
Sep 4, 2018, 10:59:15 AM9/4/18
to Blockly


On Monday, 3 September 2018 14:08:35 UTC+1, TRUNG NGUYỄN HOÀNG ĐỨC wrote:
Yea , convert everything ( number , float ... ) to string , it will
surely slow down the system .
But a wise note is that computer time is much cheaper than human time
, the time it takes for an user to drop a "conversion block" worth
much more than a controller to do extra works with every conversion .
For more advance user , you surely need to use conversion block !.


I'm a big believer in Trung's philosophy - especially with block languages - they should be as type agnostic as possible :) 
Reply all
Reply to author
Forward
0 new messages