Progressive disclosure of code samples?

6 views
Skip to first unread message

Ned Batchelder

unread,
Jan 24, 2009, 5:26:38 PM1/24/09
to bruce...@googlegroups.com
I love the bullet mode that exposes the bullets one at a time. I'd like
to be able to do the same with code samples. I have two use cases in mind:

1) Just like the bullet mode, expose more of the code with each click.
I'd use this for a Python interactive session, for example.
>>> 2+2
4
>>> len("hello")
5
First bruce would show the 2+2 lines, then clicking would add the
len("hello") lines to the screen.

2) Successive highlighting. In this case, the entire block of code
would be visible the entire time, but successive blocks would be
highlighted with each click. This would be for discussing the parts of
a function definition, for example, where the entire function needs to
be shown for context, but I want to draw the eye to the component of the
moment. The highlighting could be a box outline, or a different
background color, or the entire code sample could be slightly grayed
out, with the highlighted section in full saturation.

What I don't know is how to indicate the division of the code. I'm not
proposing that mode 1 would "understand" Python console sections.
Somehow, the code would need to be marked up to indicate the divisions.
One possibility is simply using a sequence of code sections:

.. code:: python

# ext1.py: a Hello World module.

"""A minimal module."""

.. code:: python
def hello_world():
"""Say hello."""
return "hello, world!"

I don't know if this would wreck the layout of the code.

In any case, I don't have a complete design, much less implementation.

--Ned.

--
Ned Batchelder, http://nedbatchelder.com


Richard Jones

unread,
Jan 24, 2009, 5:56:27 PM1/24/09
to bruce...@googlegroups.com
On Sun, 25 Jan 2009, Ned Batchelder wrote:
> I love the bullet mode that exposes the bullets one at a time. I'd like
> to be able to do the same with code samples. I have two use cases in mind:
>
> 1) Just like the bullet mode, expose more of the code with each click.
> I'd use this for a Python interactive session, for example.
>
> >>> 2+2
>
> 4
>
> >>> len("hello")
>
> 5
> First bruce would show the 2+2 lines, then clicking would add the
> len("hello") lines to the screen.

The interactive session is intended to inlude auto-typing as it had in
previous Bruce releases. I've just not had a chance to implement it yet.
Patches welcome, but do let me know if you're going to do it.

Of course if your code samples are as short as the above then you could just
type them in - that's the whole point of the interactive interpreter ;)


> 2) Successive highlighting. In this case, the entire block of code
> would be visible the entire time, but successive blocks would be
> highlighted with each click.

Again this is something that Bruce had in a previous incarnation. I'm just not
sure how to specify the highlighting in the input text.


> What I don't know is how to indicate the division of the code. I'm not
> proposing that mode 1 would "understand" Python console sections.
> Somehow, the code would need to be marked up to indicate the divisions.
> One possibility is simply using a sequence of code sections:

Hmm, I'm not sure I like this approach as it breaks things up too much. My
original thought was to have arguments to the code directive indicating line
blocks.

.. code:: python
:highlight: 1
:highlight: 2
:highlight: 2-4

# ext1.py: a Hello World module.
"""A minimal module."""

def hello_world():
"""Say hello."""
return "hello, world!"


Richard

Ned Batchelder

unread,
Jan 24, 2009, 6:04:59 PM1/24/09
to bruce...@googlegroups.com


Richard Jones wrote:
On Sun, 25 Jan 2009, Ned Batchelder wrote:
  
I love the bullet mode that exposes the bullets one at a time.  I'd like
to be able to do the same with code samples.  I have two use cases in mind:

1) Just like the bullet mode, expose more of the code with each click.
I'd use this for a Python interactive session, for example.

       >>> 2+2

       4

       >>> len("hello")

       5
First bruce would show the 2+2 lines, then clicking would add the
len("hello") lines to the screen.
    
The interactive session is intended to inlude auto-typing as it had in 
previous Bruce releases. I've just not had a chance to implement it yet. 
Patches welcome, but do let me know if you're going to do it.

Of course if your code samples are as short as the above then you could just 
type them in - that's the whole point of the interactive interpreter ;)

  
As cool as the interactive interpreter is, I'm afraid my speaking skills won't allow me to attempt such a daring move as typing during the presentation! :)

  
2) Successive highlighting.  In this case, the entire block of code
would be visible the entire time, but successive blocks would be
highlighted with each click.
    
Again this is something that Bruce had in a previous incarnation. I'm just not 
sure how to specify the highlighting in the input text.


  
What I don't know is how to indicate the division of the code.  I'm not
proposing that mode 1 would "understand" Python console sections.
Somehow, the code would need to be marked up to indicate the divisions.
One possibility is simply using a sequence of code sections:
    
Hmm, I'm not sure I like this approach as it breaks things up too much. My 
original thought was to have arguments to the code directive indicating line 
blocks.

.. code:: python
   :highlight: 1
   :highlight: 2
   :highlight: 2-4

   # ext1.py: a Hello World module.
   """A minimal module."""
   def hello_world():
       """Say hello."""
       return "hello, world!"

  
This would work for me...
    Richard





  

Richard Jones

unread,
Jan 24, 2009, 6:44:52 PM1/24/09
to bruce...@googlegroups.com
On Sun, 25 Jan 2009, Ned Batchelder wrote:
> As cool as the interactive interpreter is, I'm afraid my speaking skills
> won't allow me to attempt such a daring move as typing during the
> presentation! :)

Well, the auto-typing feature is for you! Hit random keys on the keyboard and
actual code appears on screen. Guaranteed to impress the audience. I could
even code it to introduce the occasional typo and correction.


Richard


Ned Batchelder

unread,
Jan 24, 2009, 7:01:44 PM1/24/09
to bruce...@googlegroups.com
Nice!

--Ned.

Richard Jones

unread,
Jan 24, 2009, 9:50:37 PM1/24/09
to bruce...@googlegroups.com
On Sun, 25 Jan 2009, Ned Batchelder wrote:
> Nice!

Sure, I just need to get around to writing it ;)

Reply all
Reply to author
Forward
0 new messages