"C" as Part of a Mechanical Engineering Curriculum


getmedia/0a805987-b2ca-43e4-9e33-8a0e31a940e3/C-as-part-of-mech-engineering.bmp.aspx?width=60&height=60&ext=.bmp
Teacher with Students


Most engineering programs expect undergraduates to take computer programming, but requirements vary widely. My institution, the University of California, Davis, requires electrical engineering students to take four programming courses, but mechanical engineering students take just one course.

Which language should students learn? As more mechanical devices add electronic controls, the choice of language becomes more critical.

In 1998 Matlab replaced the more traditional FORTRAN as one of the four required courses for UC Davis electrical engineers and in the mechanical engineering curriculum as well. But after four years, our students’ programming skills had declined compared with those who had taken FORTRAN.

In one project, the design of a robot for gathering samples on Mars, only students proficient in the C programming language could program the specified Atmel 8-bit microcontroller. After noting that Matlab alone was insufficient for serious programming, we redesigned our curriculum in 2003 to combine C with an introduction to Matlab.

Why C?

An introductory programming course should use a non-proprietary programming language that adheres to an international standard. A standardized language is stable, and its evolution is supported and maintained by industry and overseen by technical standards committees and other stakeholders.

As a language, C continues to evolve but remains backward compatible. As long as it conforms to the C99 standard, a compiler will work with programs written in C89. Matlab, by contrast, is a proprietary mathematical programming language that makes collaboration difficult with individuals not running Matlab.

C has arguably become the most common programming language, both in engineering and elsewhere. More than 90 percent of desktop computer programs, from operating systems to word processors, are written in C or its relative, C++. C runs on all platforms, and most other languages may be translated into C.

In the Programming Language Popularity Website, C tops the list, while C++ is fourth. FORTRAN is No. 21 and Matlab is nowhere to be seen.

C is especially useful for mechanical engineers because it is the language of choice for hardware interfaces, and commonly used for data acquisition and real-time robotic control. C is also the most widely used language for programming embedded processors: Of the 9 billion microprocessors manufactured in 2005, 8.8 billion were embedded.

Despite experiencing a somewhat steep learning curve, students of C gain valuable knowledge of data types, compiling, linking, and optimization, and receive a solid foundation for acquiring advanced programming skills. Once students know C, they can learn other languages more easily, particularly those that borrow heavily from C.

Users can either compile or interpret a C program. C interpreters let students execute a single line without compilation, thus providing immediate feedback. Some C interpreters also contain graphical plotting and advanced numerical computing capabilities typically found in mathematical programming languages.


Teaching C in Context

Just as learning foreign languages helps students understand their native tongue, learning C with other languages sheds light on the fundamentals of computer programming.

For example FORTRAN, which dates back to the 1950s, remains one of the primary professional programming languages, especially for such computationally intensive programs as computational fluid dynamics. FORTRAN is therefore one of the best candidates for mechanical engineering students to compare with C.

C99, ratified in 1999, includes features that enable it to be optimized as efficiently as the equivalent FORTRAN programs. C99 also supports complex numbers and variable length arrays that are useful in engineering and science.
 
An introductory programming course should focus on problem-solving. Our course, which runs for one academic quarter (10 weeks), must cover a lot of ground. Due to time constraints, we teach students both C and Matlab, and provide handouts on FORTRAN as a second programming language.

Their solid foundation in C helps our students learn Matlab quickly. We demonstrate the strength and some unique features of Matlab by having students use it to re-solve many of the same problems that they tackled earlier while learning C.

With a solid foundation in C, mechanical engineering students are well prepared for today’s projects, which increasingly integrate mechanical hardware with control software. Students acquire the foundation to learn more advanced, mathematical programming languages, and to take advantage of new and emerging computing paradigms.

[Adapted from “C for the Course” by Harry H. Cheng, University of California, Davis, for Mechanical Engineering, September 2009.]

As more mechanical devices add electronic controls, the choice of language becomes more critical.

getmedia/0a805987-b2ca-43e4-9e33-8a0e31a940e3/C-as-part-of-mech-engineering.bmp.aspx?width=60&height=60&ext=.bmp

March 2011

by Harry H. Cheng, University of California, Davis