Mohannad Elhamod

Contemporary Pedagogy

The Efficacy of Coding Exercises in the Classroom

During my academic life, I have had the opportunity to be both a student instructed on computer science subjects, and an instructor facilitating classes on such subjects. My experience allows me to critique some pedagogical approaches that are currently practiced in the computer science community. Here, I would like to address the feasibility of incorporating coding demos in the classroom.

Generally, computer science instructors elect to deliver theoretical content in class, aided with some visual illustrations. However, the vast majority of computer science subjects necessitate conducting some coding exercises to clarify and demonstrate the concepts outlined in the curriculum. The problem is that the cost associated with both preparing and delivering such coding exercises is non-trivial. This cost is commonly cited as the excuse for largely ignoring this important teaching component. As a result, most instructors leave coding for homework. Moreover, many professors claim that students need to struggle on their own to truly learn important concepts.

Nonetheless, there is no denying that the most determined instructor will still find writing and executing code during lecture time cumbersome and slow, which easily leads to students losing attention. In this article, I attempt to address this issue by exploring some questions and answering them based on my opinion and experience.


Is it the duty of the instructor to include coding as part of the class instruction mode? Alternatively, is it better to leave such matter for the assignments?

I firmly believe that in order to nurture a well-rounded computer scientist, an instructor aught to incorporate coding in any computer science subject. In fact, I would argue that computer science has now permeated most other fields. I am personally familiar with projects in other departments that would not be possible without a co-advisor in the computer science department. Examples are air traffic simulations, forestry studies using satellite imaging, solving complex fluid dynamics equations using high-speed computing, and species classification using machine learning. In these, and many other examples, a complete and in-depth understanding of the problem and solving it cannot be achieved without going through the code that generates/processes the data and/or solves the problem.
One the other hand, I am not advocating for hand-holding the class through every single coding piece in the material. The healthiest approach, in my opinion, is that some coding demos should be conducted in class to get the students familiar with the process of coding for pertinent problems in their field and to illustrate some powerful concepts that would otherwise be dry to introduce through theory. Once the students are acquainted with the practice, then some more coding exercises can be included in the assignments such that the students are encouraged to dive deeper and acquire a more concrete understanding.


Are coding exercises during class time beneficial or a distraction from optimal learning? 

I think the answer to this questions is one of those that begs for a change of perspective rather than a definitive response. Most of the tools we use in our lives can both be good and bad, depending on how they are used. For example, grading can be a tool for incentivizing students to explore and learn. But it can also be a tool to demotivate students, intimidate them, and train them to do the bare minimum if they do not understand the purpose of the work. Similarly, coding exercises, if done properly, can be very effective and insightful. There are many complex and abstract concepts that become easy to grasp once an interactive coding demo is integrated into teaching them. I have had so many “aha” moments during my academic years exactly when I, through coding, experimented with difficult concepts regardless of the number of texts I read and the presentations I attended prior to that moment. In fact, the same has happened to me while I was preparing for a class I was teaching myself. On the other hand, if these exercises are not planned carefully, they can turn out flimsy and disconnect the student’s attention. For example, there are tons of coding demos online for a variety of computer science subjects. But, they are not all equal. There are several factors at play here, such as the instructor’s skill at narrating the code, the speed of scrolling through the code, the quality of the code itself, and even details as subtle as the resolution of the platform used.


What is the best form by which coding could be incorporated into class instruction (e.g. coding from scratch, simple and quick interactive demoing, group exercises in class, etc.)?

Historically, I have only encountered class coding sessions in workshops or classes that solely teach some coding language. In those instances, I have found that coding from scratch is a terrible practice. First, coding from scratch is error-prone and requires that the teacher memorizes exactly what they want to show and how it is coded. Any time spent making syntax or semantic mistakes is a waste of the students’ time and disengages their stream of attention, possibly leading to confusion. Second, writing code from scratch will necessarily is slow by definition. This means that class time is not utilized efficiently and the slow pace might lead to boredom. I have personally found that coding from scratch tends to deliver below expectations.
Alternatively, in a class I have taught recently, I decided to demo some coding exercises by first writing and then practicing them well before class. Also, I created a dedicated piece of code that allows the parameters of the coded experiment to be easily adjustable. This helped me illustrate different scenarios, including outliers and interesting extremes, without the need to rewrite too much code. The outcome of this practice surpassed my expectation. Not only did it achieve the intended goal, but this approach also piqued the students curiosity as they started asking questions about different hypothetical scenarios. It was then easy to try those scenarios of interest and engage in a discussion about the, often surprising, results.
One thing I have not tried, but intend to do in future classes, is moving the stage from my podium to the students’ desks. I would like to experiment with grouping students together and having them go through the demo themselves. I believe that, given such an opportunity, the students will have more freedom and space to be creative and interact with the code, while still having the instructor’s assurance and support during class. This would neutralize their anxiousness about having to “get it right” on their own later at home, it would boost their confidence about being able to do it on their own, and it would free their mental energy to be focused on exploring rather than simply reproducing the results from class.

In summary, I believe there is ample opportunity for computer science instructors to innovate and experiment with different modes of coding demos and their integration into the classroom. It is important, however, that instructors put themselves in the students shoes in order to understand the strengths and weaknesses of their approaches. If done properly, such techniques could tremendously boost our students’ confidence and familiarity with the subject matter.

Leave a Reply

Your email address will not be published. Required fields are marked *