[an error occurred while processing this directive] [an error occurred while processing this directive] Skip to the content of the web site.

5.5.5 Source Code

The most dangerous element which can be included in a slide is source code. There are very few times where source code can actually add to a technical presentation. Source code, by its very nature, is verbose and consequently, as soon as it is displayed on the screen, all technical audience member will begin reading the source code while you will lose the non-technical component of your audience.

If your audience contains a significant proportion of non-technical individuals, you should focus on what the source code does rather than the source code itself.

Even with a technical audience, there are few cases where source code is appropriate: source code often spans thousands of lines whereas at most twenty lines of code can be easily displayed on a single screen. Source code spanning multiple slides is even more difficult to comprehend.

Typeface and Font

Source code should be formatted with a serifed and usually a monospaced font such as bold Consolas, Courier New, Lucida Sans or Lucida Sans Typewriter. Whatever your choice, it is essential that the numbers 0 and 1 are displayed differently from the letters O, and I and l. Consolas uses a slashed zero to differentiate it from a capital O. Consolas uses a slashed zero which makes a clear distinction between the two.

Minimizing Displayed Source Code

If you must show source code, only show the source code which is appropriate to the presentation. If there is a significant portion of code which is irrelevant to the audience, either replace it with ellipsis or colour the source code grey.

Alternatives

To display a class declaration, it is often better to use an appropriate Class Diagram as opposed to printing the source code. Consider the binary min-heap shown in Source Code 1. This spans 25 lines of text while the corresponding class diagram shown in Figure 1 is easier to read and more condense.

Source Code 1. A binary min-heap class declaration.

template <typename Object> class BinaryMinHeap { private: int count; int initial_capacity; int current_capacity; Object * heap; public: BinaryMinHeap( int = 10 ); BinaryMinHeap( const BinaryMinHeap & ); ~BinaryMinHeap(); BinaryMinHeap & operator = ( const BinaryMinHeap & ); int size() const; int capacity() const; bool empty() const; bool full() const; Object head() const; Object retrieve( int ) const; bool member( const Object & obj ) const; void push_heap( const Object & ); Object pop_heap(); bool remove( const Object & obj ); void clear(); };
BinaryMinHeap
− count:Integer
− initial_capacity:Integer
− current_capacity:Integer
− heap[1..* ordered]:Object
+ create( in n:Integer = 10 )
+ create( clone:BinaryMinHeap )
+ destroy()
+ size():Integer
+ capacity():Integer
+ full():Boolean
+ empty():Boolean
+ head():Object
+ member( in obj:Object ):Boolean

+ push_heap( in obj:Object )
+ pop_heap():Object
+ remove( in obj:Object ):Boolean
+ clear()

Figure 1. A class diagram corresponding to the class declaration in Source Code 1.

Demonstration of New Features

In one presentation, the author was attempting to demonstrate how a new means of automatically dealing with parameters where the parameters would processed before they are passed onto the procedure. This was meant to lead to a default an automatic handling of parameters, as opposed to each procedure using different code to process what is passed which leads to different processing of the same parameter types resulting in:

An example of the original parameter processing is shown in Source Code 1, while the new version is shown in Source Code 2.

Source Code 1. Demonstration of procedure procession of parameters.

plot := procedure( expr::algebraic, rng::{name, name=algebraic..algebraic},
	{color = `red`, thickness::posint = 1, label = ""} )
	local pcolor, plabel;

	if color::symbol then
		pcolor := Plots:-ColorLookup( color );
	else if color::COLOR( symbol, posint, posint, posint ) then
		pcolor := color;
	else
		error "Invalid color: %1", color;
	end if;

	if label::string then
		plabel := label;
	else if label::symbol then
		plabel := convert( label, string );
	else
		plabel := sprintf( "%a", label );
	end if;

	# body of procedure
end proc:

Source Code 2. Demonstration of automatic processing of parameters.

plot := procedure( expr::algebraic, rng::{name, name=algebraic..algebraic},
	{color::=color = `red`, thickness::posint = 1, label::=string = ""} )

	# body of procedure
end proc:

This demonstrated clearly the benefits of automatic parameter processing. Note the appropriate use of colour to highlight the differences in the code. It would, however, be wrong to show the actual implementation of the new automatic parameter processing feature in a technical presentation.

[an error occurred while processing this directive]