Ways I wish my education had been different: Part 1 – Programming

From time to time, I look back on my years of education and note that many things could have been done to better prepare me for where I am today. I could reflect on things that could have been done better in elementary, middle and high school, but at this point that was so far in the past that things have probably changed substantially. Instead, I would like to comment a bit about my college education, both undergraduate and graduate, particularly the lack luster way I was taught programming.

As an undergraduate, there was no computational physics course, but we were required to take an introductory level programming course. This is a great idea. I think that people in just about every science should have some programming experience as it can be a very powerful tool for data analysis, and sometimes it’s very nice to run a simulation of some model you are working with. However, the way that my Introduction to C++ course was taught makes absolutely no sense when looking back, and I don’t think it would even had made sense for a computer science major.

That course focused on having us learn how to write algorithms, the one that sticks out in my mind was the bubble sort program we had to write, which also makes a good discussion point. For those of you who have written some code in C++, you probably know that there the standard library has the <algorithm> header, which among other things contains a sorting algorithm. So, you could write a bubble sorting algorithm in your code like

int myvecsize = myvec.size();
for (int i = 0; i < myvecsize; ++i) {
    if (myvec[i] > myvec[i+1]) {
        int temp = myvec[i+1];
        myvec[i+1] = myvec[i];
        myvec[i] = temp;
        i = -1;

but why? The above takes 9 lines and gets very slow as the size of your list of numbers grows. If you want to do the same thing with the standard library functions you need only

std::sort(myvec.begin(), myvec.end());

This is much simpler to code, and uses a much faster algorithm than anything most people would be able to write. So, why not have introductory programming courses actually teach you to use the tools available in that language? Then you could focus on how to actually write good programs that do very useful things instead of writing inefficient algorithms which can be easily replaced with functions in a standard library.

There are those that would argue that it’s important to understand how different algorithms work, and I don’t disagree with that. The standard library function is a bit of black box. You put data in, it does something, and gives you back a sorted list. You have no idea what it actually did to sort the data. However, functions in the standard library are functions which have been thoroughly tested before being included. So sure, maybe you should be skeptical of some library that was written by one person and is used by next to no one, but the standard library shouldn’t cause problems as long as the functions are used properly. Not to mention, the standard library sorting function doesn’t use bubble sort, because it’s horribly inefficient, so you don’t even learn how that algorithm works.

In fact, if the introductory course instructor said, “Today, we’re going to write a program that sorts a list of numbers. We’ll be using the standard library algorithm, so first let’s talk about how that algorithm works, then we’ll discuss how to use it in a program.”, that would be fantastic! Give a brief overview of the actual algorithm that it uses, show how to use it in code, and then maybe even go beyond the simple standard usage above to sort different data structures.

Moving away from the specific example now, a lot of people that take introductory programming courses will likely never take additional courses in programming. In fact, my entire intro class was made up of fellow physics/astronomy students. Given this, I think the goal should be to teach how to actually program in the language which should include using functions in a standard library when available. Teach a very practical programming course and have higher level programming classes teach computer science students how to develop algorithms.

Of course, the other approach is to have individual department offer a computational course geared towards that specific subject. This would likely be the most useful to students in that department as they would learn the language most often used in their field and learn a number of things that are very useful. However, with universities seeing tighter and tighter budgets, adding courses is difficult.

In the end, I wish my education had been more like this: Require an introductory programming course in the first year, and have that course focus on using functions that are built into the languages standard library. Have all additional courses taught by the department include some computational work throughout the course. For example, in an undergraduate mechanics course you could have the students write programs to simulate different interactions between objects, or in an undergraduate E&M course you could have students write programs to calculate the electric or magnetic field strength at a give location for some complex setup that would be too difficult to calculate analytically. Upper level laboratory courses should emphasize data analysis with programming using methods commonly used in that field. I think this would give students a more practical knowledge of programming as well as preparing them for a future in their fields.

That’s what I think. How about you? What was your introductory programming course like? Post a comment below!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s