Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
888 views

Python First Programming

This document discusses choosing Python as the first programming language for all engineering students, rather than C/C++. It argues that Python meets the dual needs of solving mathematical problems rapidly through exploration, while also teaching basic programming concepts. The document outlines the attributes of an ideal first programming language, including being easy to learn and use, enabling productivity, supporting exploratory computing and large programs, teaching data structures and algorithms, including numerical methods libraries, and allowing data visualization. It concludes Python has these attributes and better meets the needs of both computer science and non-computer science engineering students.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
888 views

Python First Programming

This document discusses choosing Python as the first programming language for all engineering students, rather than C/C++. It argues that Python meets the dual needs of solving mathematical problems rapidly through exploration, while also teaching basic programming concepts. The document outlines the attributes of an ideal first programming language, including being easy to learn and use, enabling productivity, supporting exploratory computing and large programs, teaching data structures and algorithms, including numerical methods libraries, and allowing data visualization. It concludes Python has these attributes and better meets the needs of both computer science and non-computer science engineering students.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Python as the First Programming Language for Engineers

Satish Annigeri A.B. Raju


VTU, Belagavi KLETU, Hubballi

March 2017

1 Introduction
Engineers conceive, analyse, design and build a variety of physical entities including buildings,
infrastructure, machinery, equipment, aerospace and marine structures and many more. They
also build non-physical entities such as computer programs. While programming is the pri-
mary activity of computer science engineers, engineers of other disciplines use it as a tool to

T
solve problems. In an engineering office, automation of repeated tasks is typically done using
spreadsheets and programs written in languages such as MATLAB. Many engineering disci-
plines require the use of modeling, analysis and design tools based on finite element analysis,
computational fluid dynamics or other methods requiring complex mathematical computations.
Such software require domain knowledge and are developed by non-computer science engineers.
AF
Thus, computer programming is an essential skill for non-computer science engineers.
Engineering undergraduate curricula across India include a course on computer program-
ming, usually C, taught to first year engineering students. Computer programming is con-
sidered a basic and necessary skill for students across all engineering disciplines, along with
others such as Mathematics, Physics, Chemistry and elements of Civil, Mechanical, Electrical
and Electronics engineering. It can be presumed that programming is intended to be used
by non-computer science engineers as a tool for solving problems. If that be the case, the
programming language taught to non-computer science engineers must be able to solve math-
ematical problems quickly and efficiently. Computer science engineers will go on to learn a
DR

variety of programming languages to address different application needs and will also study
related computer science topics such as data structures, algorithms, software engineering. To
them, the first programming language is only a starting point.
This paper reviews the need for an engineering student to learn programming, the likely
applications of programming in different engineering disciplines, and a comparison of relative
strengths and weaknesses of C and Python as the first programming language taught to first
year engineering students. It points to the strengths of Python as the first programming lan-
guage for students of all disciplines, specially for students of non-computer science disciplines.
The search is for a programming language that meets the basic computing needs of engineers
of all disciplines as well as the advanced needs of a small portion of non-computer science
engineers. It makes the case for Python as the first programming language taught to students
of all engineering disciplines and change the current tilt in favour of computer science students
a little towards non-computer science students. It also looks at the challenges in implementing
this in Universities with a large number of affiliated colleges.

2 Programming and Engineers


The question “Why should engineers learn programming?” has different answers for computer
science and non-computer science engineers. For compute science engineers, programming is
an essential part of their career and not a mere problem solving tool. To solve the wide variety

1
of problems from different domains, computer science engineers must learn several program-
ming languages to meet these varying needs. They also have to learn other aspects related
to programming such as data structures, algorithms, software architecture and technologies.
On the other hand, non-computer science engineers tend to use programming as a problem
solving tool, especially mathematical problems. They do not formally study data structures,
algorithms, software engineering and associated technologies.
Engineers apply the principles of science and mathematics to develop solutions to technical
problems. They conceive, design, develop, test and supervise construction or manufacture of
systems, products and services and maintain and manage them for use by people. Each disci-
pline of engineering place emphasis on different types of systems, but the goal remains the same
- functionality, economy, safety, sustainability and benefit to people. Mathematics and science
are the underpinning on which all engineering disciplines are developed. Engineers, especially
those belonging to the non-computer science disciplines, model physical systems and processes
in the real world as mathematical models so they can better understand the phenomena and
reliably predict their behaviour and performance. This ability to simulate real systems and
processes using mathematics is an integral part of engineering, especially systems which have
been thoroughly studied and validated through theory and experiments. Mathematical mod-

T
els lead to mathematical equations and must be solved in order to understand and predict
system behaviour. At the present time, computer programming using numerical methods is
the predominant approach to solving mathematical equations. Hence it is essential that every
engineer know a programming language that helps her in solving mathematical equations.
Based on computing needs, engineers can be broadly divided into computer science and non-
AF
computer science engineers. Computer science engineers have a broad range of requirements,
both mathematical and non-mathematical. They also study programming from the broader
perspective of data structures, algorithms, software analysis, design and engineering. They
also study the principles underlying programming languages themselves. On the other hand,
non-computer science engineers have a relatively narrow range of requirements mainly centred
around mathematical applications. They do not formally study other aspects of computer
science and engineering. Nevertheless, computer programming has become a necessary tool for
every engineer where it may soon replace electronic calculators.
Programming languages that are used to solve mathematical problems include Fortran,
MATLAB, Scilab. While C/C++ can be used for mathematical applications, learning to use
DR

them for this purpose poses a steep learning curve. The popularity of MATLAB and Scilab
for mathematical applications is primarily due to the fact that they make the programmer
productive very quickly. This is because they have a simple syntax, offer matrix as a basic
data structure, provide well tested libraries for many numerical methods and provide 2D and
3D data visualization capabilities. But they suffer from the fact that they are a specialized
programming language tailor made for mathematical applications and do not fulfil the needs
of students of computer science.
C/C++ are excellent programming languages that meet the needs of computer science
students addressing their need for system programming, network programming, information
management systems, web and mobile applications. But they have a steep learning curve and
do not support rapid prototyping and exploratory computing that is becoming the norm in
almost every engineering discipline, even in computer science areas such as machine learning
and data science.
It can therefore be argued that the first programming language taught to first year engi-
neering students of all disciplines must meet the dual requirements of being able to solve math-
ematical problems rapidly and through exploration while at the same time being amenable to
teach basic programming concepts such as data structures and algorithms. Students of com-
puter science can go on to study C/C++ and other programming languages more suited to
systems programming and other requirements later in their curriculum.
The scope of this paper is restricted to the choice of a programming language that is suitable

2
to be taught to first year engineering students across all disciplines. It is not a comparison
of the merits and demerits of the languages themselves. It considers the aspects of teaching
the course and assessment of students for having achieved the stated outcomes and finally the
extent to which it meets the basic needs of all students and a part of those students with
advanced needs.

3 Attributes of an Ideal First Programming Language


Accepting the two varying requirements of non-computer science and computer science stu-
dents, identifying the ideal first programming language requires the identification of desirable
attributes of such a language. Some of them are listed below:
1. Must be easy to learn and to teach.
2. Must make a programmer productive in a short time.
3. Must have a development environment that encourages both exploratory computing as
well as permit development of large programs with support for modularity and OOP.

T
4. Must have programming language constructs and built-in data structures to teach basic
concepts of computer science including data structures and algorithms.
5. Must have built-in data structures suited for mathematical applications and have a good
library of numerical methods.
AF
6. Must support data visualization in 2D and 3D and quickly generate publication quality
graphs.
7. Must have libraries, modules or packages for advanced applications that are easy to learn
and use.
Choosing a programming language that is easy to learn is important for a beginner, but its
usefulness is limited if it does not have the ability to subsequently scale to other application
areas. It is therefore useful to identify areas of application beyond the basic needs of mathe-
matics and data structures and algorithms. A language that is able to scale well to advanced
DR

areas of application would be useful. A list of advanced applications could be:


1. Database access and Management Information Systems (MIS) applications.
2. Web and mobile application development.
3. Network programming, system and network administration.
4. Scientific computing - image processing, computer vision.
5. Machine learning, data science.
6. Solid modelling, finite element analysis, computational fluid dynamics.
7. Computer aided modelling and design in several areas of engineering.
8. Geographic information systems, geospatial engineering.
9. Bioinformatics.
A programming language that is easy and fun to teach and learn, makes a programmer
productive quickly, allows a programmer to quickly script simple solutions and meet some or
all of the above advanced requirements of a student would be the ideal choice. It must provide
the basic computing skills that every engineer needs, but a student who wishes to go further
must be able to go the distance.

3
4 Strengths and weaknesses of C/C++
C is an excellent programming language and the parent programming languages for most other
programming languages. Many child languages maintain a high level of compatibility with C
and depend on it when they need speed of execution. Thus MATLAB, Scilab and Python can
use modules written in C/C++ when required. Being statically typed, it is safe to program
and results in high execution speed. For this reason, it is the first choice when it comes to
system programming, databases, network programming, game programming. Java is another
language that has similar capabilities, except perhaps in system programming.
C is used in mathematical applications too, but because it lacks a built-in data structure
for dynamic arrays, its application to this area requires the use of libraries that are difficult
to understand and use. Especially concepts such as pointers, dynamic memory allocation to
implement multi-dimensioned arrays require some effort and takes the focus away from the
problem being solved. While this problem can be addressed by libraries, many of which exist
and are popular, it is still a non-trivial exercise using C for mathematical applications. For
the same reason, even though a good number of numerical method libraries are available, C
is still a daunting proposition for a beginner when it comes to mathematical applications.

T
Being statically typed, it is not amenable to exploratory computing and programmers become
productive only after a long initial learning phase. For these reasons, C would not be considered
the ideal first programming language to teach programming to first year engineering students.

5 Strengths and weaknesses of Python


AF
Python is famous and widely recognised as being easy to learn and use. This is primarily
because it is dynamically typed, has a large number of built-in data types (that would be
considered user defined types in C), has a simple syntax with which data can be passed into
and out of functions and has support for OOP. Its REPL (read, evaluate, print loop), similar
to those in MATLAB, Scilab and R, makes it extremely easy and intuitive for a beginner and
encourages exploratory computing. But unlike MATLAB and Scilab, it has the IDEs and
language constructs that allow one to write and maintain large programs.
The commonly used version of Python is implemented in C and is called CPython (ver-
DR

sions of Python that run under Java Virtual Machine – Jython and .Net CLR – IronPython
are also available). It maintains full compatibility with C and C libraries can be easily used
within Python as modules. The strength of Python is that it was designed to be easy to learn
and over time has acquired an entire ecosystem of modules and packages for a wide variety
of applications. Python fans call this feature of Python “batteries included” to imply that al-
most everything you wish to do is already included within the language and not external to it.
One such package, NumPy, implements the multi-dimensional array. Another package, SciPy,
builds on top of NumPy and implements a large number of numerical methods. Matplotlib im-
plements the plotting functions that mimic those in MATLAB so that anyone already familiar
with MATLAB can become productive almost immediately. Further, Pandas implements the
DataFrame popular with R programmers and packages like scikit-image, scikit-learn, PpenCV
not only make it possible to write programs for image processing, machine learning and com-
puter vision, but also easy and fun. Several C libraries are available within Python, and many
a times, are more intuitive to use in Python than in C. Python has packages for a wide variety
of applications such as database access, web application frameworks, network programming.
Several large programs are in production use proving that easy does not necessarily mean it is
good only for beginners and cannot be put to production use. In recent time, Python has seen
wide adoption in machine learning and data science applications. Its ability to quickly explore
different approaches to solving a problem have made it especially suited to these areas.
One of Python’s major strength is its community and its ecosystem around the community.

4
Its openness has encouraged the development of a large number of modules and packages for
a wide variety of applications ranging from scientific computing to network programming and
system administration. It is called a “glue” language because of its ability to quickly roll out
scripts that can combine a variety of tasks that work across platforms. This has been possible
because Python is a free and open source software and community.
One great benefit of Python for educators is the Jupyter Notebook and related ecosystem.
Jupyter Notebooks is a web based exploratory programming environment for Python and
many other similar languages such as Julia (the Ju in Jupyter), Scilab and others. Code
can be written in code cells and cells can be executed independently and output, both text
and graphics, appears below the cell. A notebook can also have rich text documentation in
Markdown text cells which allows inclusion of mathematical equations in LATEX format along
with rich media in the form of images and video. A notebook is a text file and amenable
to version control and sharing with others who have installed Python and Jupyter Notebook
package. A notebook can be converted to HTML and PDF formats. It is possible to assess
assignments submitted by students by a server which can automatically evaluate code and
determine if the code passes all tests designed by the teacher. JupyterLab is an extension of
the Notebook into a full IDE hosted within a web browser and promises greater programmer

T
productivity.
Python has its weaknesses. Dynamic data types, which is a stated strength of Python, is
also its weakness. This aspect of Python makes it slow in execution. There are workarounds to
increase execution speed and learning to use them is quite trivial. However, another weakness
arising out of dynamic typing is the difficulty to write and maintain very large code bases as
AF
data types are not explicitly specified in the program. There is no workaround to this problem
other than thoroughly documenting the source code. Then there is the (in)famous GIL (Global
Interpreter Lock) which prevents it from using multiple cores present in modern day CPUs
and preventing its use for multi-thread programming. While there are workarounds to this
problem, learning to overcome it requires some effort.
Despite these weaknesses, Python has seen increasing adoption in recent times and is being
taught as the first programming languages to undergraduate students in a number of leading US
universities. Python’s strengths far outweigh its weaknesses, especially when it is considered
as the first programming language to engineering students. Things that can be achieved with
minimal effort and things that can be achieved if a student puts in the required effort are far
DR

greater with Python than with C.

6 Planning to Introduce Python as the First Programming


Language
Changing over from teaching programming using C to Python requires careful thought, plan-
ning and execution. Especially if it is to be implemented across a large number of colleges.
While the large number of colleges and students is in itself a challenge, the variation in the
culture of individual colleges and their relative strengths and weaknesses need thorough study
before such a change is implemented. Following points need to be considered:

1. Clear definition of the objective of teaching computer programming to engineering stu-


dents of all disciplines and the expected outcomes. In the Outcome Based Educa-
tion (OBE) framework, these are the Learning Objectives and Course Outcomes.

2. Design of curriculum based on clearly articulated and well defined learning objectives
and course outcomes.

3. Training of faculty to help them understand and absorb the objectives, outcomes, cur-
riculum content, mode of delivery and assessment.

5
4. Providing access to the software and tools to students and faculty.

5. Providing self study material to help students learn the language by themselves, thereby
reducing the burden on faculty because they can now focus on applications of the language
rather than on its syntax.

The first three points can be addressed by the University by constituting a committee of
experienced faculty as well as representatives of industry. It is important to include faculty
and industry personnel from both computer science and non-computer science background
backgrounds. Including Python evangelists, professional bodies that promote Python and
companies using Python technologies into the committee will be beneficial. Some organizations
that can be considered are the Spoken Tutorial team and Python team of the FOSSEE project
at IIT Bombay, Python Software Society of India. Preparing a list of existing application
software and technologies based on Python from all fields of engineering would be a good
starting point. The committee must deliberate on the role of programming in engineering,
content that needs to be taught at first year of engineering, the way it must be taught and
and assessed. The committee must publish a framework based on which learning objectives
and course outcomes can be defined. The relative importance to be placed on syntax and

T
applications must be defined. These in turn must drive the definition of curriculum content,
delivery and assessment. This course is amenable to problem oriented learning, with teaching
placing a focus around solving problems close to real life. The lab course could include simple
exercises to reinforce and test the learning of syntax and data types, define a set of real
problems based on the academic content student has already mastered at PUC/10+2 level and
AF
end with asking the student to choose a problem of her own liking and deliver a solution using
everything she has learnt during the course.
An important aspect of planning is to decide who will teach the course. Traditionally, C
programming is taught by faculty from computer science or related departments. Curriculum
includes theory classes supplemented by lab sessions with a set of problems that are well defined
leaving no scope for the student to apply her own thinking. Considering the large strength of
first year engineering students in every college, and the fact that Python is easy to learn and
has applications in scientific computing, it is possible to involve faculty of any department.
Use of Jupyter Notebooks would be a great help in teaching as well as assessment.
DR

Python has several advantages compared to C, when it comes to the remaining points
in the above list. Being free and open source, faculty and students have access to licensed
software and development tools free of cost and perpetually for use both at college and away
from college. They also have access to new versions of the software that will be available in the
future. There are a large number of MOOCs and online tutorials that teach Python. Python
language is itself accompanied by excellent documentation and several excellent and highly
respected free books are available in electronic form for self-directed learning by students and
faculty.

7 Some Python Resources


Here is a short list of resources to download, learn, use and apply Python for a variety of
applications:

7.1 Software, IDEs, Modules and Packages


1. Python home page http://www.python.org is the home page of Python programming
language.

2. Python Package Index http://pypi.python.org is the official repository for all Python
modules and packages.

6
3. IPython interactive environment https://ipython.org is a REPL with access to local
filesystem and several tweaks such as code completion, built-in help and magic functions.
4. Jupyter notebooks http://jupyter.org/ is a coding and documentation environment
hosted within a web browser.
5. Spyder https://github.com/spyder-ide/spyder is an IDE for Python.
6. Anaconda https://www.continuum.io/ is a scientific Python distribution with all com-
monly required scientific packages installed through a single downloadable file.
7. JuputerLab https://github.com/jupyterlab/jupyterlab is an extensible computa-
tional environment for Jupyter.

7.2 Scientific Computing Applications


1. NumPy http://www.numpy.org/ implements a powerful and efficient n-dimensional ar-
ray data structure, sophisticated functions for array operations and numerical methods
and tools for integrating C/C++ and Fortran code.

T
2. SciPy http://www.scipy.org/ depends on NumPy and provides a large collection of
user-friendly and efficient numerical routines.
3. Matplotlib http://matplotlib.org/ implements 2D graph plotting functions that mimic
those in MATLAB.
AF
4. Pandas http://pandas.pydata.org/ is a data analysis library that depends on NumPy
and provides high-performance, easy-to-use data structures and data analysis tools for
Python.
5. scikit-image http://scikit-image.org/ is a collection of algorithms for image process-
ing.
6. scikit-learn http://scikit-learn.org/ depends on NumPy, SciPy and Matplotlib. It
implements a range of machine learning, preprocessing, cross-validation and visualization
algorithms.
DR

7. statsmodels http://statsmodels.sourceforge.net/ is a Python module that allows


users to explore data, estimate statistical models, and perform statistical tests.
8. PyOpt http://www.pyopt.org/ is a Python-based package for formulating and solv-
ing nonlinear constrained optimization problems in an efficient, reusable and portable
manner.

7.3 Database Access, GUI, Web and Mobile Applications


1. SQLAlchemy is an object relational mapper.
2. wxPython is a GUI toolkit for desktop applications.
3. PyQt is a GUI toolkit for desktop applications.
4. PySide is a GUI toolkit for desktop applications.
5. Django is a web application framework.
6. Flask is a web application framework.
7. web2py is a web application framework.
8. Kivy is a web and mobile application framework.

7
7.4 Web Scraping, Network Programming and System Administration
1. BeautifulSoup https://www.crummy.com/software/BeautifulSoup/bs4/doc/ is a Python
library designed for screen-scraping.

2. Scrapy https://scrapy.org/ is a framework for extracting data from websites.

3. Requests http://www.python-requests.org/en/master/ is a HTTP library.

4. Werkzeug http://werkzeug.pocoo.org/ is a WSGI utility library for Python.

5. Twisted https://twistedmatrix.com/trac/ is an event-driven networking engine writ-


ten in Python.

6. Ansible https://www.ansible.com/ is an open source system automation tool.

7. Fabric http://docs.fabfile.org/en/1.13/ is a library for simplifying system admin-


istration tasks.

8. Salt https://saltstack.com/community/ is an open source infrastructure management

T
tool.

9. Chef https://www.chef.io/chef/ is a systems and cloud infrastructure automation


framework.

10. Puppet https://puppet.com/ is IT Automation and configuration management soft-


ware.
AF
7.5 Learning Resources
1. Allen Downey et al, How to Think Like a Computer Scientist: Learning with Python,
Green Tea Press, 2002

2. Mark Pilgrim, Dive into Python, Apress,

3. Zed A. Shaw, Learn Python the Hard Way, Addison-Wesley Professional, 2013
DR

4. SciPy Lecture Notes

5. Thomas J. Sargent and John Stachursky, Quantative Economics

6. IIT Bombay Spoken Tutorial Project

7. List of MOOCs using Python https://www.mooc-list.com/tags/python

8. Learn Python website

9. List of books on Python https://wiki.python.org/moin/PythonBooks

8 Other Contenders
There are a few programming languages that show great promise and can be serious contenders
that are as good as or better than Python in different areas where Python is considered good.
In the scientific computing space, Julia promises to do everything that Python scientific stack
does but faster. A JIT compiler speeds up execution. Multiple dispatch allows the programmer
to use dynamic types when she needs rapid prototyping and static typing when she needs
speed of execution. It has greater compatibility with C, Python and R and executes code in
those languages inline, provided they are all configured correctly. Within a short time, Julia

8
has garnered tremendous interest and large and supportive community resulting in a large
number of packages that parallel those available in Python and R. Julia supports parallel and
distributed computing and does not have the Global Interpreter Lock (GIL) that forces Python
to be single threaded. It is yet to have as many packages as are available for Python, but for
scientific computing, the gap is not too wide. However, only time can reveal the extent to which
Julia can compete when it comes to general purpose computing beyond scientific computing.
But it promises to be a great new language to look forward to in the scientific computing field.
Created at Google in 2007, Go promises to be a modern system programming language
that is compiled, statically typed, memory safe and has garbage collection and concurrent
programming. It now has a large number of packages and software in production use. For
computer science students, it is the language to look forward to.

9 Conclusions
Python scores high on ease of teaching and learning, programmer productivity, application to
mathematical computing and has the data types and control structures suitable to teach basic
computer science concepts. It is therefore a good choice as the first programming language

T
taught to first year engineering students of all disciplines. While it serves the basic needs
of students of all disciplines, it is able to scale well for production use in a wide variety of
application areas. Switching from C to teaching Python to first year engineering students
will require prior thinking on the objectives of teaching programming to engineering students
and thorough planning and implementation of training and orientation for both faculty and
students.
AF
DR

You might also like