Week 7 " Reuse Your Own Code Top 20 Tools of All Time CS 212 – Spring 2008 (

Week 7 " Reuse Your Own Code Top 20 Tools of All Time CS 212 – Spring 2008 (

Programming Language as a Tool Software Tools ! Use the language that best fits your task ! Think small " Write little programs that test various concepts " Test them! " Comment them! " Build collections of these little programs Week 7 " Reuse your own code Top 20 Tools of All Time CS 212 – Spring 2008 (http://uk.gizmodo.com/) Languages for Different Domains Scripting Languages ! General purpose ! Concurrent/distributed ! A script is a sequence of ! Example scripting languages: " Examples: Lisp, Algol, PL/1, processes common commands made into a Unix shell, Python, Perl, Scheme, Java, Python " Control of multiple threads single program Tcl (Tool command language) ! Systems programming " Examples: Ada, Oz, Smalltalk, " Unix uses shell scripts " Emphasis on efficiency and Java " The shell is the interactive ! Some Python code: tight control of data ! Educational interface to Unix structures " " Examples: Basic, Haskell, You can combine commands class Stack (object): " Examples: C, C++, Forth, Pascal, Python, Scheme, from the Unix shell to create def __init__ (self): Modula-2 Smalltalk programs self.stack = [ ] ! Scripting ! Various other domains def put (self, item): self.stack.append(item) " ! Examples: Unix shell, Perl, " Discrete event simulation: A scripting language is usually def get (self): Python, Ruby, Tcl Simula " Easy to learn return self.stack.pop() " Web scripting: Javascript " Interpreted instead of def isEmpty (self): " Realtime applications: Ada compiled return len(self.stack) == 0 " Text processing: Snobol, Perl " Printing: Postscript " … A Programming Language Controversy Programming Language Weirdness ! “Go To Statement Considered ! Weird languages Harmful” " Whitespace " Edsger Dijkstra, Communications # Only spaces, tabs, and newlines are significant of the ACM (March 1968) # A great language for security since a program can be printed onto plain paper and stored without worrying about an adversary reading the code ☺ ! Sparked long-running discussion on " var'aq whether “go to” is necessary or # Based on the grammatical structure of the Klingon language desirable ! Led to concept of structured " Proponents of “go to” presented programming examples where code was more " Idea: Code is clearer if we ! Weird concepts readable using “go to” restrict ourselves to just a " Polyglot code " At the time few control structures # Code that is valid for multiple languages # No break " Loops have single entry, single # Usually takes advantage of the different ways that comments are indicated # No continue in the different languages # No exceptions exit " Quine # A program whose only output is its own source code # Not considered valid to use the empty program 1 Integrated Development Environments Unix ! An IDE usually includes ! You should know how to use ! Original version by Ken Thompson ! Philosophy (Bell Labs) in 1969 " " Source code editor (usually a debugger! Almost everything is a text file " Little programs (utilities) to do with color highlighting) " Place breakpoints ! An interactive, multi-user little tasks " Compiler or interpreter " Step through code operating system (not the first " Connect programs with pipes & redirection " Tools for “build # Step over such system, but an early one) # % who | sort | lpr automation” (i.e., keeps # Step into # Print an alphabetical list of who is track of what needs to be # Step out of… ! Unix is closely tied to the active on the system ! Linux is an open software version recompiled) " Examine current call-stack development of C of Unix " Debugger " Unix was originally written in PDP- " Examine values of active 7 Assembly Language " Since 1991 " Class browser (for variables " Then in B # Linus Torvalds (the kernel) languages with classes) # Some debuggers allow you " Then in C # Richard Stallman (GNU) " to change a variable value " B and C were basically created to Widely used for high-performance write Unix computing ! Examples: DrJava, Eclipse " In Eclipse: As you type, ! Debuggers are usually much ! Mac OS X is built on Unix gives you list of options + more effective than placing documentation print-statements Regular Expressions Makefiles ! Common goal: search/match/do ! Some of the rules for regular ! Used when ! Once you have a makefile stuff with strings expressions compiling/recompiling a large " You recompile whatever is " A regular character matches system (many interdependent necessary by typing make ! Idea: use special strings to itself files) match other strings " A . matches any character " Checks which files have ! To create a makefile " * implies 0 or more changed and only recompiles " Some characters are meta- " Common strategy is to find occurrences (of preceding those that are necessary characters some examples and modify item) " Because of dependencies, them " more than just the changed + implies 1 or more " There are automated tools for ! Regular expressions are closely files can need to be occurrences building makefiles related to finite state " \ implies following character is recompiled automata (CS 381/481) treated as a regular character " Also keeps track of compiler ! Modern IDEs often provide " [ … ] matches any one options character from within the ! Why not recompile everything? tools for managing the build process brackets; - can be used to " Expensive indicate a range " Order of compilation can be ! A regular expression in Java important "((\\.[0-9]+)|([0-9]+\\.[0-9]*))" Memory Management Garbage Collection ! Modern programs are ! Manual memory management ! Want to keep any object ! Once “not-in-use” objects " Long running bugs that can be reached from are found " Make dynamic use of " Dangling pointers program’s variables " Can reclaim the memory memory # Memory has been freed, " Either directly or through for re-use but part of the code is other objects that can be " Can also compact memory still trying to use it reached ! Garbage collector # I.e., move all the “in-use” " Memory leaks " Program’s variables = objects to another " Some languages (e.g., Java, # Memory that is no longer anything in the call stack memory block (without C#) use a garbage used, but is not freed gaps between objects) collector to reclaim unused # Long running program ⇒ memory run out of memory " Other languages (e.g., C, C++) require programmers to manage their own ! There are tools to help memory catch such bugs " E.g., purify for C, C++ 2 Garbage Collector Schemes Use of Standard Data Structures ! Mark and Sweep ! For either scheme ! Packages for widely-useful ! For example, Java provides " Mark every object as “not-in- " Can “stop the world” data structures " Interfaces use” " Can interleave (i.e., take turns) " Java Collections # List, Map, Set " Starting from the call stack, " Can run concurrently Framework " visit every reachable object, Classes marking it as “in-use” " C++ STL (Standard # ArrayList, LinkedList, ! Java’s current garbage " Everything still marked “not- Template Library) HashMap, TreeMap, in-use” can be reclaimed collector HashSet, TreeSet " A 2-tier scheme (old " " Provide tools for Algorithms generation; new generation) # Arrays.sort, ! Reference Counting # Sorting & searching " A mark-and-sweep method Arrays.search,… " Every object keeps a count of # Iteration " With compaction how many pointers reference # List it # Set " When count is zero, memory ! Java’s garbage collection # Map (or dictionary) can be reclaimed scheme has changed as new # Stack " Problem: cycles! Java versions were released # Queue # Priority Queue Version Control Profiling Tools ! Allows you to keep track of ! CVS (Concurrent Version ! People are notoriously bad at predicting the most changes for a large project System) computationally expensive parts of a program " Can back up to old version " Open source " Rule of thumb (Pareto Principle): 80% of the time is spent in if changes create problems " Widely used tool for 20% of the code " Multiple contributors can version control " No use improving the code that isn’t executed often work on the system " Maintains a history of all " How do you determine where your program is spending its time? changes made ! Part of the data produced by a profiler (Python) " Supports branching, ncalls tottime percall cumtime percall filename:lineno(function) allowing several lines of 2521 0.227 0.000 1.734 0.001 Drawing.py:102(update) 7333 0.355 0.000 0.983 0.000 Drawing.py:244(transform) development 4347 0.324 0.000 4.176 0.001 Drawing.py:64(draw) " Provides mechanisms for 3649 0.212 0.000 1.570 0.000 Geometry.py:106(angles) merging branches back 56 0.001 0.000 0.001 0.000 Geometry.py:16(__init__) 343160 9.818 0.000 12.759 0.000 Geometry.py:162(_determinant) together when desired 8579 0.816 0.000 13.928 0.002 Geometry.py:171(cross) ! SVN (Subversion) 4279 0.132 0.000 0.447 0.000 Geometry.py:184(transpose) " An alternative to CVS ! Java has a built-in profiler (hprof); there are many others More Advanced Profiling Documentation Generators ! Need additional profiling ! Example: ! Comments (esp. specifications) are as important as tools for applications that VTune Performance the code itself " Are multithreaded Analyzer (from Intel) " Determine successful use of code " Use multiple cores " Can monitor # Memory usage " Determine whether code can be maintained # Performance during file " Creation/maintenance = 1/10 I/O ! Documentation belongs in code (or as close to it as # Thread overhead and synchronization possible) # Load balancing " “Code evolves, documentation drifts away” # Idle time " Put specs in comments next to code when possible

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us