Why C? a Roundabout Answer

Total Page:16

File Type:pdf, Size:1020Kb

Why C? a Roundabout Answer Why C? a roundabout answer I. Refresher C was preceded by a programming language named B (circa 1970). B in turn evolved from a much older command programming language named BCPL. Command programming languages, in contrast to high order programming languages, are relatively modest languages designed to manipulate the computer's operating environment rather than solve general computational problems; they are the forerunners of today's modern computer operating systems. C is the brainchild of a Bell Laboratories scientist named Dennis Ritchie, developed to go hand and glove with the Unix operating system. Unix in turn is attributed to another Bell Laboratories scientist named Ken Thompson (who also authored B). The fact that well over 90% of Unix can be described by using programs written in C is what makes it feasible to implement Unix as the operating system for a large variety of computing environments, including today's PCs. This close relationship to Unix is the major reason C has continued to be so widely implemented and used, and is a major consideration for incorporating it into computer science curricula. It is only because AT&T was not in the computing business at the time Bell Laboratories' scientists were developing Unix and C that Unix is not a single- vendor commercial product such as MicroSoft's Windows. It is worth noting that Linux and Free BSD (Berkley Software Distribution), modern variants of Unix, are at present the only generally available alternatives to Windows for PC environments. Linux is "freeware" crafted and maintained by a fairly large group of computing professionals who don't want a computing world defined only by commercial interests. Free BSD is also “freeware”, but has its origins in proprietary systems and, unlike the Linux Gnu general public licensing, allows propriety derivatives (such as Apple’s). On the other hand, Free BSD has tighter control over recognized releases. II. C/C++/Java – which comes first, the chicken or the egg? Mathematicians once thought that they could eliminate steps in the process of developing students "mathematical maturity" by doing a carefully orchestrated "pre-calculus to real analysis" sequence (they were wrong). They basically forgot the (sometimes painful) processes that they themselves had gone through to gain their own level of mathematical maturity. There is a similar "computational maturity" that must be developed in students, which evolves from basic computational problem solving, through data and machine structures, to the abstractions that object-oriented environments seek to represent. From this perspective, the object-oriented paradigm is one that needs to be introduced later, not sooner. C++ is just C with object-oriented extensions. Java is an object-oriented language whose syntax is derived from C/C++. A huge percentage of commercial software is written in C++. So why not "teach" C++ or Java as the first language? The better question is why not start students with the object paradigm? That approach assumes that the student has already achieved, or can acquire in parallel, computational maturity, never mind the realities of implementation and implementation environment that characterize commercial programming environments. The argument for using a commercial product in the first place is the pragmatic demand that instruction employ commercially useful software products, usually attended by a non-trivial development environment. It is altogether too easy for the complexity of such software products to shift instructional emphasis away from fundamental objectives, in effect retarding acquisition of critically needed computational maturity. While C shares some of these characteristics with C++ and Java, its level of complexity and the weight of its environment pales in comparison. III. A First Objective The objective of the first computing course is (or at least should be) to learn how to solve problems computationally, not how to manipulate the syntax of some flavor of high level language. The solution space for solving computational problems is captured within the C language subset of either C++ or Java. A commercial implementation of C++ or Java includes a plethora of classes, objects, and methods, many of which are ancillary to the objective of learning how to solve problems computationally. Moreover, these implementations typically come with industrial strength development environments, which also must be taught in order to use the product. In a perfect world, we would NOT introduce students to the discipline of computing via a course titled "introduction to programming in xxx". If the first course is "intro to programming in xxx", then course emphasis is already pegged to syntax issues and the development environment at the expense of solving computational problems. Inevitably, the more complex the programming environment is, the less the emphasis on solving computational problems. Using C for solving computational problems (or C within C++) is a pragmatic choice that minimizes the impact of environment on objective. It helps that C implicitly supports a transition to object oriented development because of its syntactic relationship to either C++ or Java. C has the added advantage of its intimate relationship to Unix and its practical utility for writing low-level programs in other computing contexts. IV. Some Noteworthy Advantages and Disadvantages of C C has advantages other than its intimate relationship to Unix. Most noteworthy is that it can be successfully described in a very few pages, as Kernighan and Ritchie proved (their book pretty much covers everything, and includes a tutorial, a description of the Unix interface, and a lexical description of C, all in about 200 pages). Contrast this with any reference of note for Java. In C, complex structures and operations, such as those associated with I/O and strings, are relegated to libraries. This means that the syntactic structure for solving computational problems is free of clutter that can confuse the programming environment with the solution space. C also has some very real pitfalls. First of all the syntax does not conform to lay usage, most prominently a = b vs. a == b. There are the implementation realities of the various data types. The relationship between arrays of characters and character strings exemplifies the perils and pitfalls of pointer manipulation. The very things that make the language useful for low-level programming are potential points of confusion for novices. The predefined function libraries can complicate instruction (consider the pow routine and its several variations as just one example). Of course, on the pragmatic side, many of these characteristics facilitate discussion of system programs and can be used to illustrate the nuts and bolts of the inner organization of the hardware. For example, it is easy to devise a C program to examine integers at the bit level to determine how they are implemented on a specific machine. V. Why C? C is a subset of the most widely used development language, C++. It is the means within C++ for solving computational problems and manipulating data. You cannot use C++ effectively until you have learned how to solve computational problems and manipulate data in C. Users often confuse the language with the implementation environment. Both C++ and Java have complex development environments making extensive use of predefined classes, objects, and methods. The underlying mechanism for solving computational problems, however, is still C. C is implicitly supported in any Unix environment, including development tools common to all Unix implementations. There are "standard" C libraries that are included with any C implementation; the structures employed in C++ or Java systems development may not survive from one release to the next. VI. What Learning Environment? It isn't hard to justify C as "mother tongue". It may be harder to decide on the environment in which to learn C, if for no other reason because C is used in many contexts other than Unix environments. Absent a specific context for learning to program in C, the close relationship between C and Unix tends to support using the basic Unix command line interface as the generic learning environment. Given the wide deployment of Unix systems, there is also advantage gained from working with the standard Unix environment. The counterpoint is that the Unix command interface is pretty clunky when compared to the typical desktop. However, no X-Windows standard GUI seems to be on the horizon, and program development environments for PCs, as excellent as many are, are tied to the context of single user workstations and PC operating systems. Since the Unix command line environment is the likely constant for the foreseeable future, it is the pragmatic choice for the base learning environment. Since there is an ANSI standard for C, the base environment can be supplemented (“user responsibility”) with some degree of confidence by other environments where advantageous. VII. Denouement Over the short history of computing, the programming of digital computers has progressed through a series of programming languages. The development of formal language theory instigated much of this work. New programming paradigms and specific application needs (first for basic systems purposes and later for user interfaces) spurred the evolution of programming languages to where we find them today. C dates from about the middle of this history, and has had an ANSI standard definition now for more than 10 years. C compilers exist for all manner of processors, which makes the language useful for applications other than conventional application programming. The maturing of the object paradigm has led to object-oriented extensions such as C++ and languages employing C syntax, such as Java, to better serve complex systems development needs. No programming language is without its shortcomings and C is no exception. The objective of learning how to solve problems computationally has been addressed through a spectrum of languages, perhaps initiated with FORTRAN. The one common thread throughout has been the use of procedural structures for decisions and loops to mimic the reasoning paradigms of mathematics.
Recommended publications
  • B-Prolog User's Manual
    B-Prolog User's Manual (Version 8.1) Prolog, Agent, and Constraint Programming Neng-Fa Zhou Afany Software & CUNY & Kyutech Copyright c Afany Software, 1994-2014. Last updated February 23, 2014 Preface Welcome to B-Prolog, a versatile and efficient constraint logic programming (CLP) system. B-Prolog is being brought to you by Afany Software. The birth of CLP is a milestone in the history of programming languages. CLP combines two declarative programming paradigms: logic programming and constraint solving. The declarative nature has proven appealing in numerous ap- plications, including computer-aided design and verification, databases, software engineering, optimization, configuration, graphical user interfaces, and language processing. It greatly enhances the productivity of software development and soft- ware maintainability. In addition, because of the availability of efficient constraint- solving, memory management, and compilation techniques, CLP programs can be more efficient than their counterparts that are written in procedural languages. B-Prolog is a Prolog system with extensions for programming concurrency, constraints, and interactive graphics. The system is based on a significantly refined WAM [1], called TOAM Jr. [19] (a successor of TOAM [16]), which facilitates software emulation. In addition to a TOAM emulator with a garbage collector that is written in C, the system consists of a compiler and an interpreter that are written in Prolog, and a library of built-in predicates that are written in C and in Prolog. B-Prolog does not only accept standard-form Prolog programs, but also accepts matching clauses, in which the determinacy and input/output unifications are explicitly denoted. Matching clauses are compiled into more compact and faster code than standard-form clauses.
    [Show full text]
  • Cobol Vs Standards and Conventions
    Number: 11.10 COBOL VS STANDARDS AND CONVENTIONS July 2005 Number: 11.10 Effective: 07/01/05 TABLE OF CONTENTS 1 INTRODUCTION .................................................................................................................................................. 1 1.1 PURPOSE .................................................................................................................................................. 1 1.2 SCOPE ...................................................................................................................................................... 1 1.3 APPLICABILITY ........................................................................................................................................... 2 1.4 MAINFRAME COMPUTER PROCESSING ....................................................................................................... 2 1.5 MAINFRAME PRODUCTION JOB MANAGEMENT ............................................................................................ 2 1.6 COMMENTS AND SUGGESTIONS ................................................................................................................. 3 2 COBOL DESIGN STANDARDS .......................................................................................................................... 3 2.1 IDENTIFICATION DIVISION .................................................................................................................. 4 2.1.1 PROGRAM-ID ..........................................................................................................................
    [Show full text]
  • A Quick Reference to C Programming Language
    A Quick Reference to C Programming Language Structure of a C Program #include(stdio.h) /* include IO library */ #include... /* include other files */ #define.. /* define constants */ /* Declare global variables*/) (variable type)(variable list); /* Define program functions */ (type returned)(function name)(parameter list) (declaration of parameter types) { (declaration of local variables); (body of function code); } /* Define main function*/ main ((optional argc and argv arguments)) (optional declaration parameters) { (declaration of local variables); (body of main function code); } Comments Format: /*(body of comment) */ Example: /*This is a comment in C*/ Constant Declarations Format: #define(constant name)(constant value) Example: #define MAXIMUM 1000 Type Definitions Format: typedef(datatype)(symbolic name); Example: typedef int KILOGRAMS; Variables Declarations: Format: (variable type)(name 1)(name 2),...; Example: int firstnum, secondnum; char alpha; int firstarray[10]; int doublearray[2][5]; char firststring[1O]; Initializing: Format: (variable type)(name)=(value); Example: int firstnum=5; Assignments: Format: (name)=(value); Example: firstnum=5; Alpha='a'; Unions Declarations: Format: union(tag) {(type)(member name); (type)(member name); ... }(variable name); Example: union demotagname {int a; float b; }demovarname; Assignment: Format: (tag).(member name)=(value); demovarname.a=1; demovarname.b=4.6; Structures Declarations: Format: struct(tag) {(type)(variable); (type)(variable); ... }(variable list); Example: struct student {int
    [Show full text]
  • A Tutorial Introduction to the Language B
    A TUTORIAL INTRODUCTION TO THE LANGUAGE B B. W. Kernighan Bell Laboratories Murray Hill, New Jersey 1. Introduction B is a new computer language designed and implemented at Murray Hill. It runs and is actively supported and documented on the H6070 TSS system at Murray Hill. B is particularly suited for non-numeric computations, typified by system programming. These usually involve many complex logical decisions, computations on integers and fields of words, especially charac- ters and bit strings, and no floating point. B programs for such operations are substantially easier to write and understand than GMAP programs. The generated code is quite good. Implementation of simple TSS subsystems is an especially good use for B. B is reminiscent of BCPL [2] , for those who can remember. The original design and implementation are the work of K. L. Thompson and D. M. Ritchie; their original 6070 version has been substantially improved by S. C. Johnson, who also wrote the runtime library. This memo is a tutorial to make learning B as painless as possible. Most of the features of the language are mentioned in passing, but only the most important are stressed. Users who would like the full story should consult A User’s Reference to B on MH-TSS, by S. C. Johnson [1], which should be read for details any- way. We will assume that the user is familiar with the mysteries of TSS, such as creating files, text editing, and the like, and has programmed in some language before. Throughout, the symbolism (->n) implies that a topic will be expanded upon in section n of this manual.
    [Show full text]
  • Quick Tips and Tricks: Perl Regular Expressions in SAS® Pratap S
    Paper 4005-2019 Quick Tips and Tricks: Perl Regular Expressions in SAS® Pratap S. Kunwar, Jinson Erinjeri, Emmes Corporation. ABSTRACT Programming with text strings or patterns in SAS® can be complicated without the knowledge of Perl regular expressions. Just knowing the basics of regular expressions (PRX functions) will sharpen anyone's programming skills. Having attended a few SAS conferences lately, we have noticed that there are few presentations on this topic and many programmers tend to avoid learning and applying the regular expressions. Also, many of them are not aware of the capabilities of these functions in SAS. In this presentation, we present quick tips on these expressions with various applications which will enable anyone learn this topic with ease. INTRODUCTION SAS has numerous character (string) functions which are very useful in manipulating character fields. Every SAS programmer is generally familiar with basic character functions such as SUBSTR, SCAN, STRIP, INDEX, UPCASE, LOWCASE, CAT, ANY, NOT, COMPARE, COMPBL, COMPRESS, FIND, TRANSLATE, TRANWRD etc. Though these common functions are very handy for simple string manipulations, they are not built for complex pattern matching and search-and-replace operations. Regular expressions (RegEx) are both flexible and powerful and are widely used in popular programming languages such as Perl, Python, JavaScript, PHP, .NET and many more for pattern matching and translating character strings. Regular expressions skills can be easily ported to other languages like SQL., However, unlike SQL, RegEx itself is not a programming language, but simply defines a search pattern that describes text. Learning regular expressions starts with understanding of character classes and metacharacters.
    [Show full text]
  • The Programming Language Concurrent Pascal
    IEEE TRANSACTIONS ON SOFTWARE ENGINEERING, VOL. SE-I, No.2, JUNE 1975 199 The Programming Language Concurrent Pascal PER BRINCH HANSEN Abstract-The paper describes a new programming language Disk buffer for structured programming of computer operating systems. It e.lt­ tends the sequential programming language Pascal with concurx:~t programming tools called processes and monitors. Section I eltplains these concepts informally by means of pictures illustrating a hier­ archical design of a simple spooling system. Section II uses the same enmple to introduce the language notation. The main contribu~on of Concurrent Pascal is to extend the monitor concept with an .ex­ Producer process Consumer process plicit hierarchy Of access' rights to shared data structures that can Fig. 1. Process communication. be stated in the program text and checked by a compiler. Index Terms-Abstract data types, access rights, classes, con­ current processes, concurrent programming languages, hierarchical operating systems, monitors, scheduling, structured multiprogram­ ming. Access rights Private data Sequential 1. THE PURPOSE OF CONCURRENT PASCAL program A. Background Fig. 2. Process. INCE 1972 I have been working on a new programming .. language for structured programming of computer S The next picture shows a process component in more operating systems. This language is called Concurrent detail (Fig. 2). Pascal. It extends the sequential programming language A process consists of a private data structure and a Pascal with concurrent programming tools called processes sequential program that can operate on the data. One and monitors [1J-[3]' process cannot operate on the private data of another This is an informal description of Concurrent Pascal.
    [Show full text]
  • Introduction to Shell Programming Using Bash Part I
    Introduction to shell programming using bash Part I Deniz Savas and Michael Griffiths 2005-2011 Corporate Information and Computing Services The University of Sheffield Email [email protected] [email protected] Presentation Outline • Introduction • Why use shell programs • Basics of shell programming • Using variables and parameters • User Input during shell script execution • Arithmetical operations on shell variables • Aliases • Debugging shell scripts • References Introduction • What is ‘shell’ ? • Why write shell programs? • Types of shell What is ‘shell’ ? • Provides an Interface to the UNIX Operating System • It is a command interpreter – Built on top of the kernel – Enables users to run services provided by the UNIX OS • In its simplest form a series of commands in a file is a shell program that saves having to retype commands to perform common tasks. • Shell provides a secure interface between the user and the ‘kernel’ of the operating system. Why write shell programs? • Run tasks customised for different systems. Variety of environment variables such as the operating system version and type can be detected within a script and necessary action taken to enable correct operation of a program. • Create the primary user interface for a variety of programming tasks. For example- to start up a package with a selection of options. • Write programs for controlling the routinely performed jobs run on a system. For example- to take backups when the system is idle. • Write job scripts for submission to a job-scheduler such as the sun- grid-engine. For example- to run your own programs in batch mode. Types of Unix shells • sh Bourne Shell (Original Shell) (Steven Bourne of AT&T) • csh C-Shell (C-like Syntax)(Bill Joy of Univ.
    [Show full text]
  • An Analysis of the D Programming Language Sumanth Yenduri University of Mississippi- Long Beach
    View metadata, citation and similar papers at core.ac.uk brought to you by CORE provided by CSUSB ScholarWorks Journal of International Technology and Information Management Volume 16 | Issue 3 Article 7 2007 An Analysis of the D Programming Language Sumanth Yenduri University of Mississippi- Long Beach Louise Perkins University of Southern Mississippi- Long Beach Md. Sarder University of Southern Mississippi- Long Beach Follow this and additional works at: http://scholarworks.lib.csusb.edu/jitim Part of the Business Intelligence Commons, E-Commerce Commons, Management Information Systems Commons, Management Sciences and Quantitative Methods Commons, Operational Research Commons, and the Technology and Innovation Commons Recommended Citation Yenduri, Sumanth; Perkins, Louise; and Sarder, Md. (2007) "An Analysis of the D Programming Language," Journal of International Technology and Information Management: Vol. 16: Iss. 3, Article 7. Available at: http://scholarworks.lib.csusb.edu/jitim/vol16/iss3/7 This Article is brought to you for free and open access by CSUSB ScholarWorks. It has been accepted for inclusion in Journal of International Technology and Information Management by an authorized administrator of CSUSB ScholarWorks. For more information, please contact [email protected]. Analysis of Programming Language D Journal of International Technology and Information Management An Analysis of the D Programming Language Sumanth Yenduri Louise Perkins Md. Sarder University of Southern Mississippi - Long Beach ABSTRACT The C language and its derivatives have been some of the dominant higher-level languages used, and the maturity has stemmed several newer languages that, while still relatively young, possess the strength of decades of trials and experimentation with programming concepts.
    [Show full text]
  • C Programming Tutorial
    C Programming Tutorial C PROGRAMMING TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i COPYRIGHT & DISCLAIMER NOTICE All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at [email protected] ii Table of Contents C Language Overview .............................................................. 1 Facts about C ............................................................................................... 1 Why to use C ? ............................................................................................. 2 C Programs .................................................................................................. 2 C Environment Setup ............................................................... 3 Text Editor ................................................................................................... 3 The C Compiler ............................................................................................ 3 Installation on Unix/Linux ............................................................................
    [Show full text]
  • Shell Script: the Shell Is the Part of the UNIX That Is Most Visible to the User. It Receives and Interprets the Commands Entered by the User
    Shell Script: The shell is the part of the UNIX that is most visible to the user. It receives and interprets the commands entered by the user. In many respects, this makes it the most important component of the UNIX structure. To do anything in the system, we should give the shell a command. If the command requires a utility, the shell requests that the kernel execute the utility. If the command requires an application program, the shell requests that it be run. The standard shells are of different types as There are two major parts to a shell. The first is the interpreter. The interpreter reads your commands and works with the kernel to execute them. The second part of the shell is a programming capability that allows you to write a shell (command) script. A shell script is a file that contains shell commands that perform a useful function. It is also known as shell program. Three additional shells are used in UNIX today. The Bourne shell, developed by Steve Bourne at the AT&T labs, is the oldest. Because it is the oldest and most primitive, it is not used on many systems today. An enhanced version of Bourne shell, called Bash (Bourne again shell), is used in Linux. The C shell, developed in Berkeley by Bill Joy, received its name from the fact that its commands were supposed to look like C statements. A compatible version of C shell, called tcsh is used in Linux. The Korn shell, developed by David Korn also of the AT&T labs, is the newest and most powerful.
    [Show full text]
  • Programming Languages and Translators
    Programming Languages and Translators Ronghui Gu Spring 2019 Columbia University 1 Instructor Prof. Ronghui Gu 515 Computer Science Building [email protected] Oce hours: Thursdays 1:30 - 2:30 PM / by appointment Prof. Stephen A. Edwards and Prof. Baishakhi Rey also teach 4115. ∗These slides are borrowed from Prof. Edwards. 2 What is a Programming Language? A programming language is a notation that a person and a computer can both understand. • It allows you to express what is the task to compute • It allows a computer to execute the computation task Every programming language has a syntax and semantics. • Syntax: how characters combine to form a program • Semantics: what the program means 3 Components of a language: Syntax How characters combine to form a program. Calculate the n-th Fibonacci number. is syntactically correct English, but isn’t a Java program. c l a s s Foo { p u b l i c int j; p u b l i c int foo(int k){ return j+k;} } is syntactically correct Java, but isn’t C. 4 Specifying Syntax Usually done with a context-free grammar. Typical syntax for algebraic expressions: expr ! expr + expr j expr − expr j expr ∗ expr j expr = expr j ( expr ) j digits 5 Components of a language: Semantics What a well-formed program “means.” The semantics of C says this computes the nth Fibonacci number. i n t fib(int n) { i n t a=0,b=1; i n t i; f o r (i=1 ; i<n ; i++){ i n t c=a+b; a = b ; b = c ; } return b; } 6 Semantics Something may be syntactically correct but semantically nonsensical The rock jumped through the hairy planet.
    [Show full text]
  • An Introduction to Prolog
    Appendix A An Introduction to Prolog A.1 A Short Background Prolog was designed in the 1970s by Alain Colmerauer and a team of researchers with the idea – new at that time – that it was possible to use logic to represent knowledge and to write programs. More precisely, Prolog uses a subset of predicate logic and draws its structure from theoretical works of earlier logicians such as Herbrand (1930) and Robinson (1965) on the automation of theorem proving. Prolog was originally intended for the writing of natural language processing applications. Because of its conciseness and simplicity, it became popular well beyond this domain and now has adepts in areas such as: • Formal logic and associated forms of programming • Reasoning modeling • Database programming • Planning, and so on. This chapter is a short review of Prolog. In-depth tutorials include: in English, Bratko (2012), Clocksin and Mellish (2003), Covington et al. (1997), and Sterling and Shapiro (1994); in French, Giannesini et al. (1985); and in German, Baumann (1991). Boizumault (1988, 1993) contain a didactical implementation of Prolog in Lisp. Prolog foundations rest on first-order logic. Apt (1997), Burke and Foxley (1996), Delahaye (1986), and Lloyd (1987) examine theoretical links between this part of logic and Prolog. Colmerauer started his work at the University of Montréal, and a first version of the language was implemented at the University of Marseilles in 1972. Colmerauer and Roussel (1996) tell the story of the birth of Prolog, including their try-and-fail experimentation to select tractable algorithms from the mass of results provided by research in logic.
    [Show full text]