CS 15L

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Make/Makefiles

"to make the target, first make all its dependencies, then perform all the actions" - if the target names a file that is newer than all of the files it depends on, then the actions in that rule will not be performed (They don't need to be, since in that case the target is already up-to-date with respect to its dependencies) Target: dependencies action make -C lib/ target - where target is the command in the make file and lib/ is the directory/folder of the make file

Components of a good Development Environment

- A source code version control system - A fully automated testing system - A fully automated compile/build system - Frequent build/integrate/distribute policy

Default files for shell start up

- Standard input (stdin): Usually from the keyboard (0) - Standard output (stdout): Usually to the terminal (1) - Standard error (stderr): Usually to the terminal (2) Programs use these three files when reading, writing, or reporting errors/diagnostics

Unix Varieties

-Solaris: -Linux: -MacOSX:

git

-a distributed version control system

Regression testing

-every time you make changes to the code, run additional tests -> make sure old features work after adding new ones

hprof

-uses Java Virtual Machine Tool Framework -you do not modify your source code in any way, instead, specify hprof as an "agent library" when you start the JVM: java -agentlib:hprof=option MyProg Energy: hprof option myProgram options: cpu= (default being off) 1. samples: starts a thread and periodically wakes up to sample where the software is executing, outputs ranked results of time spent in these methods 2. times: inserts bytes of code in beginning and end of methods to time them, outputs ranked results, much more accurate than samples but can slow it down considerably 3. old Space: hprof heap=option + jhat myProgram options: 1. dump: It tells HPROF to generate stack traces, from which you can see where memory was allocated. 2. sites: you get a dump of all live objects in the heap. 3. all: defaults, shows both format: hprof format=a | b (a = regular text, b = binary, default being regular) myProgram

project (ANT)

1 in each ANT XML file, contains 3 attributes: - name - default: defines which target to compile if not specified - basedir Syntax: <project name="myProj" default="jar" basedir=".">

Types of Collections

1. Collection: The root of the collection hierarchy. A collection represents a group of objects known as its elements. The Collection interface is the least common denominator that all collections implement and is used to pass collections around and to manipulate them when maximum generality is desired (Java does not provide an implementation for this interface) 2. Set: a collection that cannot contain duplicate elements 3. List: an ordered collection, can contain duplicates 4. Queue: a collection used to hold multiple items prior to processing (FIFO) 5. Deque:a collection used to hold multiple items prior to processing (FIFO or LIFO) 6. Map: an object that maps keys to values, no duplicate keys

Debugging Steps

1. Understand the system 2. Identify the problem 3. Reproduce the problem 4. Diagnose the cause of the problem 5. Fix the problem 6. Reflect and learn from this problem, and this fix

3 areas of a local Git project

1. Working Directory (unmodified/modified files) 2. Staging Area (staged files) 3. Repository (committed files)

2 modes of vi (command line full screen editor)

1. command mode (also called edit mode) • Default • Most powerful feature of the vi editor • Allows for efficient navigation and editing of existing text. 2. insert • Used to enter text into a file (exited via Esc key) • Multiple ways to enter this mode • Not efficient for navigation or editing!

# of vim modes

6

vi Commands

:w -> writes but does not exit :x (or ZZ) -> writes and exits :q! -> no changes :r file1-> switches file1 to workspace :w FileB -> makes current workspace into a new file called FileB without affecting the file being edited (:w! FileB if FileB already exists) h = left j = down k = up l = right $ = end of line 0 = beginning of line u = undo change dd = delete line dw = delete word r = replace char Read only mode: vi -R FileA -> opens FileA in vi read only mode :q (or ZZ) no changes + same ":w FileB" command s as above Recovery Mode: vi -r FileA -> opens FileA in vi recovery mode :w (or ZZ) -> writes workspace to opened file :q (or :q!) -> no changes + same ":w FileB" command s as above

Formatter logging subclasses

A Formatter provides support for formatting LogRecords. Typically each logging Handler will have a Formatter associated with it. The Formatter takes a LogRecord and converts it to a string. Some formatters (such as the XMLFormatter) need to wrap head and tail strings around a set of formatted records. The getHeader and getTail methods can be used to obtain these strings. XMLFormatter: Format a LogRecord into a standard XML format through the public String format(LogRecord record) method SimpleFormatter: Print a brief summary of the LogRecord in a human readable format. The summary will typically be 1 or 2 lines. String.format(format, date, source, logger, level, message, thrown); to change the format -> the java.util.Formatter.format=" %arg#<obj type i.e. s for string> etc." 0. format - the java.util.Formatter format string specified in the java.util.logging.SimpleFormatter.format property or the default format. 1. date - a Date object representing event time of the log record. 2. source - a string representing the caller, if available; otherwise, the logger's name. 3. logger - the logger's name. 4. level - the log level. 5. message - the formatted log message returned from the Formatter.formatMessage(LogRecord) method 6. thrown - a string representing the throwable associated with the log record and its backtrace beginning with a newline character, if any; otherwise, an empty string.

Logger subclass

A Logger object is used to log messages for a specific system or application component -Each Logger has a "Level" associated with it. This reflects a minimum Level that this logger cares about. If a Logger's level is set to null, then its effective level is inherited from its parent ctor: public static Logger logger = Logger.getLogger("string); -> getLogger(String) creates a logger nameoflogger.loggerLevel(String) -> logs a message at that level (not capitalized) nameoflogger.log(LoggerRecord record) ->log a log record nameoflogger.log(Level level, String Message)-> log a message with no arguments (arguments can be added with another parameter after the message; level is LEVEL.capitalizedLevel

Pipes

A pipe is used to redirect the output of one command to the input of another. - "|" = pipe symbol

logging framework

Benefits: - Specify the origin of a log entry (which application, which class, which method, etc.) - Specify the content of the log entry - Specify the level of importance of the log entry - Control what importance levels are actually being logged - Control where the log entries are recorded - Analyze resulting log files

Unix Commands

Commands = programs Processes -> execute programs Files = collections of data .. = one level up . = current directory ls = list files in directory (-a) (add a pattern and * to search for files that start with the pattern) mkdir = makes a new directory * = wildcard pwd = print working directory cp = copy file into directory mv = Move or rename files rm = Remove or delete file clear = clears terminal grep <str><files> = find which lines contain a certain word in a file cat = reads one or more files and prints them to standard output sort = sorts lines alphabetically or numerically man = online manual for commands (i.e. man ls) wc = gives a count of words/lines/chars (-l = line count, -w word count, -c byte count, -m char count) chmod = category of user (user (u), group (g), others (o), all (a)) , read, write, execute i.e. u+x allows user to execute u-rwx means user can't do anything = can also assign permission

Logging

Def: automatically recording and diagnostic output from a program -only logs when the level of the message is greater than or equal to the level of the logger or handler Important classes: 1. Logger 2. Handler 3. Formatter 4. Level i.e. public static Logger logger = new Logger("logger", mylib); Handler handler = new ConsoleHandler(); handler.setFormatter(new SimpleFormatter()); logger.addHandler(handler); Benefits: Logging output can be useful during development and testing, but also in production code (i.e. A web server could log IP address of incoming http requests) -can use stderr output or file output but its better to use the logging framework

Shell Scripts

Definition: script written for the Shell -> UNIX/LINUX commands -> Shell programming syntax Syntax: scriptName.sh - first line: #!/bin/sh (!# is location of the shell that will be run) -all other lines starting with # are comments -to execute use ./scriptfile.sh or <source> ./scriptfile.sh

Variables for Shell Scripts

Definition: symbolic names that represent values stored in memory Global: Environment and configuration variables, capitalized (When you login, there will be a large number of global System variables that are already defined. These can be freely referenced and used in your shell scripts) Local Variables: Within a shell script, you can create as many new variables as needed. Any variable created in this manner remains in existence only within that shell. Special Variables: Variable array/list example: #!/bin/sh a=(1 2 3) echo ${a[*]} echo ${a[0]} Results: 1 2 3 1

Handler subclasses

Each Logger object must have one or more Handler objects associated with it, to actually log any log messages - ConsoleHandler : log to stderr. Each Logger has this handler by default. - FileHandler : log to a file, with controllable log file rotation. - SocketHandler : connect to a logging server over a TCP/IP socket.

Normal/command mode (vim)

Enter with: -esc or ctrl-c For navigation and manipulation of text. This is the mode that vim will usually start in, most powerful mode

Command Line mode (vim)

Enter with: - : , / , ? For entering editor commands

Insert Mode (vim)

Enter with: - aoics (AOICS) For inserting new text, not efficient for navigation

Visual Mode (vim)

Enter with: - v , V , ctrl-v For navigation and manipulation of text selections.

Performance

Excessive Logging and profiling can slow performance -Correctness is favored over performance

git diff

File differences for unstaged, modified files

IDE

Integrated Development Environment Typically consists of: - code editor - a compiler - a Debugger - a GUI

Why have makefiles

It allows you to automate certain tasks, specifically designed because large programs had to compile lots of files and recompile them when changes are made

3 parts of UNIX

Kernel: Shell: Interface between the user and the kernel, starts automatically when you login, Allows programming (shell scripting) within the shell environment Programs: commands are programs,. processes are executing programs Apps -> Programs -> Shell -> Kernel -> CPU

Scientific Method of Debugging

Once problem has been identified and reproduced: 1. Make a guess as to what in program is causing the problem 2. Conduct an experiment to see if your guess is correct 3. If the result of the experiment contradicts the guess, go to 1 4. If more tests are needed to strongly confirm the guess, go to 2 5. OK, now you have a good guess about what the problem is, and can consider a fix

Global Variables

SHELL = Current shell DISPLAY = Used by X-Windows system to identify the display HOME = Fully qualified name of your login directory PATH = Search path for commands MANPATH = Search path for <man> pages PS1 & PS2 = Primary and Secondary prompt strings USER = Your login name TERM = terminal type PWD = Current working directory

Data Structure performance

Struct: Insert: Delete: 1. Linked List: O(1) O(1) 2. Priority Queue: (logn) O(1) 3. ArrayList: O(1) O(1) 4. Vector: O(1) O(1) 5. ArrayDeque: O(1) O(1) 6. Stack: O(1) O(1)

Target (ANT)

Target contains a name and optionally "depends" and "description" ● Each target contains multiple tasks, which are actions that need execution ● There can be dependencies between targets

Redirecting Standard input/output

Using > will truncate the file to zero length (i.e. make it empty) if it exists. If you want to append to the file instead, use >> 1. $ java IO < somefile = Redirect standard input to read from a file 2. $ java IO > afile1 = Redirect standard output to write to a file 3. $ java IO 1> afile2 = Redirect standard output explicitly as FD 1 4. $ java IO 2> afile3 = Redirect standard error to write to a file 5. $ java IO 2> afile4 > afile5 = Redirect standard error and standard output to different files 6. $ java IO > onefile 2> anotherfile < yetanotherfile = Redirect everything! 7. $ java IO >> afile1 = Redirect standard output to append to a file 8. $ java IO 2>> afile3 = Redirect standard error to append to a file 9. $ java IO > afile 2>&1 = To redirect stderr and stdout to the same file 10. $ java IO > /dev/null = View standard error, discard standard output 11. $ java IO 2> /dev/null = View standard output, discard standard error

what is a branch in git

a lightweight movable pointer to one of these commits. The default branch name in Git is master. As you initially make commits, you're given a master branch that points to the last commit you made. Every time you commit, it moves forward automatically.

git add

add/stage a new file to your repository

git remote add

adding a remote server

cw (vim)

change/replace to the end of the line adding a number (i.e. c2w) changes the next to words

get checkout <branch>

checkout new branch, checking out means switching branches

git commit -m "messege"

commit staged changes to your repository

the Level class

contains public static named constants used to specify the importance level of log messages (messages must have a level to be logged), and to control which log records are actually logged -each Logger and Handler has a level set for it, messages below this level are ignored highest to lowest importance: Level.SEVERE Level.WARNING Level.INFO Level.CONFIG Level.FINE Level.FINER Level.FINEST

git branch <branchname>

creates a new branch

de (vim)

cut from here to the end of the word 4de = cuts the next 4 words D - deletes to the end of the line d/foo - deletes until the next occurrence of foo

Loops

for loops: for arg in list do <command(s)> done while loops: while <this_command_execute_successfully> do <this command and this command> done -{1..5} means from 1 to 5 (inlcusive)

Conditionals

i.e. if command executes successfully or [ command ] then execute command elif this command executes successfully then execute this command and execute this command else execute default command fi -[ conditional ] --include spaces in conditionals

git init

initialize a new git repository

b (vim)

jump backwards to the start of the word

$

jump to the end of the line

gg (vim)

jump to the first line of the document

^ (vim)

jump to the first non-blank character of the line

G (vim)

jump to the last line of the document

0

jump to the start of the line

e (vim)

jumps forwards to the end of the word

w (vim)

jumps forwards to the start of the word

git log

log all of the commits made to the repository

get merge <branchname>

merge branch with current branch

Ant (Another Neat Tool)

open source Java based tool for automating the build process (Similar to make but implemented using Java), platform independent -XML based format -each Ant XML file contains 1 project and one target (can have more targets)

git pull

pull changes from a remote server

git push

push changes to a remote server

$

references a variable's contents

:range/pattern/replacement (vim)

replaces pattern with replacement in the specified range -add /g to the end and put %s for range for the entire document example of range: :11,15s/me/you -> replaces me with you in lines 11-15 inclusive, must have s after the range

?

search backwards for pattern

/ (vim)

search for pattern

git status

shows the status of the file in the directory

Redirection

stdout: • ls > MyFiles.text • cat > temp1.txt • cat >> temp1.txt stdin: • mail [email protected] < message

Time Commands

summarize time (and optionally other) costs of the entire execution of a program two versions: 1. the bash shell built-in time 2. and /usr/bin/time to time a java app: time java MyApp To time a Java application using /usr/bin/time, with verbose output: /usr/bin/time -v java MyApp

gdb

to compile with: $gcc -g -o myprogram myprogram.c -> -g produces debugging info To start: gdb ./myprogram (typically a.out) Commands: 1. run (to run your program) 2. break x (where x is the name of your function in your program, line number) 3. next (executes one more line, without stepping into the function if called) 4. continue (when the program has stopped, it resumes execution) 5. step (executes one more line, stepping into a function if called) 6. print x (where x is an expression that can involve constants and variables) 7. quit (to quit out of gdb)

Cost Functions

used for profiling->want to look at any resource that your application depends on (i.e. battery) - Time cost: how many instructions will be executed -> Time Unix time command - Space cost: how many variables will be created ->hprof heap option + jhat - Energy cost: usually determined by CPU and memory usage -> hprof cpu option

yy (vim)

yank/copy line y$ = yank/copy to end of line y2y = copy 2 lines including this one (same and 2yy)

Test Driven Development Cons

• Does not test the full software • Requires team buy-in • Same developer coding and testing a feature • Can consume too much time

Test Driven Development Pros

• Increased productivity • Results in modular and extensible software • Leads to better code functionality and cleaner interfaces • Leads to concise goal driven code


संबंधित स्टडी सेट्स

ch 62 Musculoskeletal Trauma (fractures, traction, amputations)

View Set

Chapter 46 Bowel Elimination (Kish's Lecture)

View Set

CHP 3: Leadership Qualities, Characteristics of Followers, and Situational Factors

View Set

AQA A-level Biology - Topic 2A - Eukaryotic cells and organelles

View Set

Nursing Fund- raquel_yniguez/ Study sets for exam 4

View Set

Chapter 14: Exploring Social Media & e-Business

View Set