programming languages and software engineering
Post on 31-Dec-2015
29 Views
Preview:
DESCRIPTION
TRANSCRIPT
Programming Languages and Software Engineering
Topics
• Discuss some of the underlying commonalities and differences among programming languages
• Explain what there is to learn about software engineering beyond programming
Learn Programming in Ten Years(Peter Norvig)
• It takes time/practice/experience to learn to become a good programmer
• You can learn syntax in one semester (or from a book), but...
• Need to built up a repertoire of problems you have previously solved, so when you face a new problem, you can draw upon your prior experience, you’ve seen it before – “design patterns”
• Norvig’s suggestions:– Get interested in programming, and do some
because it is fun..– Program. The best kind of learning is learning by
doing.– Talk with other programmers; read other programs. – Work on projects with other programmers. – Work on projects after other programmers. – Learn at least a half dozen programming
languages. – Remember that there is a "computer" in "computer
science". Understand how it works.
• In CSCE 121, we teach C++ because it is widely used for large industrial applications.– Many additional computational concepts are
introduced in this course, such as how compilers work, object-oriented design, etc.
• There are many other languages - do you need to learn them all?
• Assembler• Fortran, Pascal, COBOL, Basic• Ada, Modula, PL/1, Simula, MatLAB• Haskell, LISP, Scheme• C, C++, C#, Objective-C• Smalltalk, Java, Javascript• PERL, PHP, TCL, Python, Ruby• csh, awk, sed• Prolog – a logic-based language for making
inferences from knowledge bases• Postscript – a stack-based language for printers
source: http://calvinx.com/tag/programming-languages/
Two Interesting Questions
• Why are there such a bewildering array of languages? – Historical artifact – some languages evolved into, or
inspired, other languages– Some languages started out as experiments to test
new ideas or features, like OO and message-passing in Smalltalk
– Some languages are more suited for certain applications, like Fortran for numerical computing, or PERL/Python for processing text files
– There are special-purpose languages like Postscript (or MatLAB, Simula) that are custom-designed for certain tasks (printing, simulations...)
Two Interesting Questions
• Isn’t C++ overkill for writing low-level code like drivers/controllers/firmware? wouldn’t C be much more efficient with less overhead?– This is a common misconception– By this reasoning, why not use assembler?– Modern C++ compilers have many optimizations that
make code fast/competitive– Most importantly, C++ allows code to be expressed in
a more comprehensible (generic, factored) way that facilitates maintainability and long-term use of code over many years
• These issues often outweigh a few extra microseconds• The original programmer might be long gone, and someone
else has to find and fix a bug
import sysif __name__==“__main__”:
a = int(sys.argv[1]) b = int(sys.argv[2])
if a<b: b,a = a,b while b>0:
r = a%b a,b = b,r print “GCD is”,a
#include <stdio.h>void main(int argc,char*argv){ int a,b,temp; sscanf(argv[1],”%d”,&a); sscanf(argv[2],”%d”,&b);
if (a<b) { temp=a; a=b; b=temp; } while (b>0) { int r=a%b; a=b; b=r; } printf(“GCD is %d\n”,a);}
public class GCD { public static void main(String[] args) { int a,b,temp;a=Integer.parseInt(args[0]);b=Integer.parseInt(args[1]);
if (a<b) { temp=a; a=b; b=temp; } while (b>0) { int r=a%b; a=b; b=r; } System.out.println( "GCD is "+a); } }
Programming• The same algorithm can be implemented in
many programming languages.in C in Python in Java
• Point #1: Once you understand the general principles (which you will learn in CSCE 314), you just have to learn the “syntactic variations” in each language
• Point #2: There are some unique language differences/features including: user-created types, polymorphism, list comprehension, exceptions, function objects...
• In CSCE 314, you will learn the structure of languages and what unites them, so you can eventually learn to program in any of them
• Major classes of languages– Imperative/procedural languages (“block-structured”)
• Pascal, Fortran, C, Ada...
– Functional languages (“expression evaluation”)• Scheme, LISP, Haskell...
– Object-oriented (encapsulation, “message passing”)• Smalltalk, Java, Objective-C, C++
– Logic-programming• Prolog
– (of course, some languages blur these distinctions)
• I already showed examples of procedural programming• Here is the functional version of factorial and GCD
written in LISP:– (this is an interactive command line I typed into)
>(defun fact (n) (if (<= n 1) 1 (* n (fact (- n 1)))))FACT
>(fact 10)3628800
>(defun gcd (x y) (if (< x y) (gcd y x) (if (= y 0) x (gcd y (mod x y)))))GCD
>(gcd 112 40) // “running a program” is done by “evaluating an expression”8
• Interpreted vs. compiled languages– interpreters – read in lines and execute directly– compilers
• convert source code to low-level language (.exe, assembly language, executable CPU instructions)
• have to learn about regular expressions, parsing, syntax and semantics, optimization...
• Block structure– think how the “body” of a for loop or if statement is marked in
different languages (“}”, “endfor”, change of indentation)• Type systems
– can users define new “types” and operations on them? like structs and classes, example: Complex #s
• Object-oriented languages– classes, inheritance, polymorphism...
• Extensions for: concurrency, exception-handling, real-time applications...
• Here is an example of an object-oriented definition of Rectangles in Java
public class Rectangle { int height,width; // interval variables
// initializer public Rectangle(int a,int b) { height=a; width=b; }
int area() { return height*width; }}
static Rectangle BoundingBox( Rectangle A,Rectangle B){ int h=max(A.height,B.height); int w=max(A.width,B.width); Rectangle C=new Rectangle(h,w); return C;}
public static void main(String[] args) { Rectangle P=new Rectangle(3,2); Rectangle Q=new Rectangle(1,4); Rectangle R=BoundingBox(p,q);
System.out.println( “P:(3,2) area="+P.area()); System.out.println( “Q:(1x4) area="+Q.area()); System.out.println( “R:(3x4) area="+R.area()); }
> java local/testRectangleP:(3,2) area=6Q:(1x4) area=4R:(3x4) area=12
Learning Unix (part of CSCE 312/Systems)
• Why learn this? Is it necessary?• Many command-line development tools
– (compared to IDEs like MS Visual Studio)
• Unix has well-defined concepts and principles– Executables, flags, pipes, streams, sockets... – Multitasking
• Many powerful tools for software development:– Editors like Emacs– Compilers like g++– make files (for multi-file projects)– Debuggers like gdb– Source-code control like CVS or SVN
Software Engineering (CSCE 431)• Software engineering usually involves working in teams• Requirements gathering/writing specifications (with customer)• UML (Unified Modeling Language)
– Diagram out how your modules work and interact• Libraries – reuse of code
– e.g. APIs for image processing, network access, speech recog...– Large projects have many dependencies
• Testing – defining test cases as important as writing code• Documentation
– Explain how things work, why it was designed that way, ASSUMPTIONS, alternatives, limitations...
• Version control – Issue new number with each change to file, e.g. v3.0.12– Critical so you can identify and undo mistakes
• Life-cycle models– Waterfall, rapid prototyping, extreme programming (partners)...– Metrics for tracking/estimating number of bugs over time
top related