\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{\_allisonwalker} \pdfinfo{ /Title (3500-midterm.pdf) /Creator (Cheatography) /Author (\_allisonwalker) /Subject (3500 Midterm Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{22661B} \definecolor{LightBackground}{HTML}{F8FAF7} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{3500 Midterm Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{\_allisonwalker} via \textcolor{DarkBackground}{\uline{cheatography.com/181463/cs/37727/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}\_allisonwalker \\ \uline{cheatography.com/allisonwalker} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 16th March, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 1}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Abstraction}}\{\{nl\}\}Removing( or hiding) unnecessary complication/detail\{\{nl\}\}Good: Array.Sort();\{\{nl\}\}Bad: nested for loops etc.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Abstraction Levels}}\{\{nl\}\}Programming Languages(Assembly low) ← High\{\{nl\}\} Compiler\{\{nl\}\}OS\{\{nl\}\}Architecture\{\{nl\}\}Circuits\{\{nl\}\}Physics ← Low\{\{nl\}\}API- Defines operations (and efficiencies)} \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{API-Application Programming Interface}}\{\{nl\}\} High level specs of ops, e.g. Array, Add, Remove, Contains, IsEmpty, Graphics.Draw, etc.} \tn % Row Count 10 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Levels within Programs}}\{\{nl\}\}API ← High\{\{nl\}\}Classes/Data Structs\{\{nl\}\}Functions/Methods\{\{nl\}\}Variables/Statements\{\{nl\}\}Types/Operators ← Low\{\{nl\}\}} \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Software Practices Stepps}}\{\{nl\}\} 1. Analysis – what do we need to do?\{\{nl\}\} 2. Design – how do we do it? \{\{nl\}\}3. Implement it - Coding Yay!\{\{nl\}\} 4. Test, debug, improve\{\{nl\}\} 5. Go back to 1-4 as needed} \tn % Row Count 19 (+ 5) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Why Comment/Document?}}\{\{nl\}\} Your code (in the RW™) will outlive you. Make your successor's life easier Make your (future) life easier\{\{nl\}\}} \tn % Row Count 23 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{XML Syntax}}\{\{nl\}\} \textless{}tag\textgreater{} info \textless{}/tag\textgreater{} e.g., \{\{nl\}\}\textless{}summary\textgreater{} … \textless{}/summary\{\{nl\}\} \textless{}param name='val'\textgreater{} … \textless{}/param\textgreater{}} \tn % Row Count 26 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{When to Comment?}}\{\{nl\}\} ALL files must have a header comment!\{\{nl\}\} ALL methods must have a header comment \{\{nl\}\}All fields/properties should have a comment} \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 1 (cont)}} \tn % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Why XML?}}\{\{nl\}\} Machine readable, parsable, intellisensable} \tn % Row Count 2 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{C\# source files can have structured comments that produce API documentation for the types defined in those files. The C\# compiler produces an XML file that contains structured data representing the comments and the API signatures. Other tools can process that XML output to create human-readable documentation in the form of web pages or PDF files, for example.} \tn % Row Count 10 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 2}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Delegates}}\{\{nl\}\}A delegate is a way to provide a TYPE for a function return type, parameter list/types\{\{nl\}\}You can use delegate types to store functions in variables "call" those saved functions using the variable name} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{Delegates are fully object-oriented, delegates encapsulate both an object instance and a method. \{\{nl\}\}Delegates allow methods to be passed as parameters. \{\{nl\}\}Delegates can be used to define callback methods.\{\{nl\}\} Delegates can be chained together; for example, multiple methods can be called on a single event.\{\{nl\}\} Methods don't have to match the delegate type exactly. i.e. Variance in Delegates.} \tn % Row Count 14 (+ 9) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Delegate is the definition}} of the "Type" of function. Lookup is just a name I choose!} \tn % Row Count 16 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Example}} public delegate int Lookup( string name );} \tn % Row Count 18 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Delegates as Params}}\{\{nl\}\}Delegates allow you to "pass" functions to other functions int doit(string x)\{ … \} // ← Meets Delegate Requirements\{\{nl\}\} …\{\{nl\}\}Evaluate("1+var", doit)} \tn % Row Count 22 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 3}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{C\# Similarities w/ Java}}\{\{nl\}\}Compiled to an intermediate form Run with a "runtime environment"\{\{nl\}\}Automatic memory management\{\{nl\}\}Syntax mostly the same (or one-to-one transition)} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{C\# Differences w/ Java}}\{\{nl\}\}C\# functions are "first-class" (see delegates)\{\{nl\}\} Generics can use primitives (List\textless{}int\textgreater{} vs. \textless{}Integer\textgreater{})} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{C\# Access Modifiers}}\{\{nl\}\}public, protected, and private are the same as in Java. Internal means any method in the compilation unit (e.g., project) can treat the variable as public, but "outside" users treat it as private. \{\{nl\}\}Why do we have these?\{\{nl\}\} Answer: Because programmers are human and programming is hard. These modifiers "say": Only allow the person most familiar with the code to make changes to data; e.g., the library code itself has private variables (such as the stacks) and only the person writing that code "knows enough" to use them. The "outside world" user just uses the Evaluate method.} \tn % Row Count 20 (+ 13) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Readonly declaration}}\{\{nl\}\}readonly int max\_stack\_depth = 5;\{\{nl\}\} "variable" can only be set in constructor (or in field declaration)} \tn % Row Count 23 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Interfaces}}\{\{nl\}\}Same as java\{\{nl\}\} Contract for a method (somewhat like a delegate)} \tn % Row Count 25 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Namespaces}}\{\{nl\}\} Keep common terms separate e.g.,\{\{nl\}\}namespace Math \{ public Vector\{...\} \} \{\{nl\}\}namespace Collections \{ public Vector \{ … \} \}\{\{nl\}\}Requires "using" statement using Math;} \tn % Row Count 29 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Escaped Strings}}\{\{nl\}\}How do you put a "new line" into a string? \{\{nl\}\}Answer: "\textbackslash{}n" The \textbackslash{} (back slash) is called the "Escape Character"\{\{nl\}\}Used to combine "regular characters", i.e., 'n' and '\textbackslash{}' to form a special character Common escaped characters: /t, /n, /e\{\{nl\}\} Example: string filename = "c:\textbackslash{}\textbackslash{}documents\textbackslash{}\textbackslash{}files\textbackslash{}\textbackslash{}abc.txt"; Note: Unix uses slashes, so you don't have to "double up": (e.g., /home/germain)} \tn % Row Count 38 (+ 9) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 3 (cont)}} \tn % Row 7 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Verbatim Strings}}\{\{nl\}\}Use the @ symbol\{\{nl\}\} Escaped strings are ugly :( hard to read )\{\{nl\}\} Remove some of the ugliness:\{\{nl\}\}string filename = "c:\textbackslash{}\textbackslash{}documents\textbackslash{}\textbackslash{}files\textbackslash{}\textbackslash{}abc.txt"; vs. BAD: string filename = "c:\textbackslash{}documents\textbackslash{}files\textbackslash{}abc.txt"; GOOD: string filename = @"c:\textbackslash{}documents\textbackslash{}files\textbackslash{}abc.txt"; Useful sometimes in regular expressions} \tn % Row Count 8 (+ 8) % Row 8 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Interpolated Strings - \$}}\{\{nl\}\}Do This! (Almost always!) \{\{nl\}\}How do you put variable values into a string?\{\{nl\}\} Old, Bad way: string s = "Your score of " + score + " is a good one!"; \{\{nl\}\}New, Good way: string s = \$"Your score of \{score\} is a good one!";} \tn % Row Count 14 (+ 6) % Row 9 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Solutions \& Projects}}\{\{nl\}\}Solution → Spreadsheet Contains:\{\{nl\}\}Projects \seqsplit{FormulaEvaluator (Library} Application)\{\{nl\}\}FormulaEvaluatorTester (Console Application)\{\{nl\}\} Projects Contain:\{\{nl\}\}code files, etc. \{\{nl\}\}Contain References to other projects/libraries\{\{nl\}\} Tester must "reference" FormulaEvaluator} \tn % Row Count 21 (+ 7) % Row 10 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Lambdas}}\{\{nl\}\}Shorthand notation for: Defining small anonymous functions Inline\{\{nl\}\}Useful for: Testing, "One offs", Some GUI applications, etc.\{\{nl\}\}Syntax: \{\{nl\}\}( {[}param1, param2, …{]} ) =\textgreater{} \{ code \};\{\{nl\}\}( {[}param1, param2, …{]}) =\textgreater{} expression to return;} \tn % Row Count 27 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 4}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Version Control Use}}\{\{nl\}\}Collaborative development\{\{nl\}\}Branching/Merging Code\{\{nl\}\}archeology/File history\{\{nl\}\}Differences\{\{nl\}\}Backup} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{GIT Functions}}\{\{nl\}\}Committing: Save work as a "Version" with a "Message" \{\{nl\}\}Branching: Try something else out which may or may not come back into the main branch later via Merging. \{\{nl\}\}Push/Pull: Send changes from one place to another \{\{nl\}\}TAG: Like a "bookmark" to find a particular state of your code\{\{nl\}\}Code History: Compare one Commit to Another\{\{nl\}\} Diffs Split vs. Unified} \tn % Row Count 12 (+ 9) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Extensions}}\{\{nl\}\}Extensions allow us to add "dot methods" to classes we don't own, use this new functionality as if it is "built in"\{\{nl\}\}Example: \seqsplit{name.CapitalizeFirstLetters(} );} \tn % Row Count 16 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{IEnumerable}}\{\{nl\}\}Guarantees that something is countable and can be iterated over Arrays, Lists, Trees, Dictionaries, etc ← all are IEnumerable \{\{nl\}\}Can convert the above to "base" types using: toList, toArray\{\{nl\}\} Allows support for: foreach loop\{\{nl\}\}Has a templated type\{\{nl\}\} Is an Interface: GetEnumerator\{\{nl\}\}Current (array → int current = 0; )\{\{nl\}\}MoveNext (array → current++; ) \{\{nl\}\}Reset() (array → current = 0; )} \tn % Row Count 25 (+ 9) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Interface}}\{\{nl\}\}A specification guaranteeing that an implementing class will have certain functions \{\{nl\}\}Guarantee made by the compiler\{\{nl\}\}There is no guarantee the functions work, just that they are there.\{\{nl\}\} Aside: Useful also with Polymorphism: \{\{nl\}\}Movable x; // A Movable must have a .move() method \{\{nl\}\}Car c = new Car(); \{\{nl\}\}x = c; // public class Car : Movable\{\{nl\}\} x.move(); c.move()} \tn % Row Count 34 (+ 9) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 4 (cont)}} \tn % Row 5 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Enumerator}}\{\{nl\}\}Enumerator is an object that allows iterating over the object} \tn % Row Count 2 (+ 2) % Row 6 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{IEnumerable}}\{\{nl\}\}A high level type (interface) that allows us to apply actions to a list of objects \{\{nl\}\}Useful with foreach loop \{\{nl\}\}Useful when we don't care (or know) the underlying data structure \{\{nl\}\}Makes our code more robust and general!} \tn % Row Count 8 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 5}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Unit Tests}}\{\{nl\}\}Test the "smallest" pieces of the software system \{{[}nl\}\}E.g., methods \{\{nl\}\}Simplifies tests, simplifies debugging \{\{nl\}\}"Easy" to find the failure point} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Self Contained Testsing}}\{\{nl\}\}Tests should not rely on "outside" state\{\{nl\}\} Test should:\{\{nl\}\} define data (e.g., build a Dependency Graph) \{\{nl\}\}Execute algorithm (e.g., remove/add dependencies) \{{[}nl\}\}Verify (e.g., using asserts)} \tn % Row Count 9 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Code Review}}\{\{nl\}\}Higher Quality Code \{\{nl\}\}Fewer Defects \{\{nl\}\}Easier to Maintain\{\{nl\}\} Developer Training Learn about other parts of codebase Learn about other techniques} \tn % Row Count 13 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 6}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Immutable}}\{\{nl\}\}Strings are immutable, they cannot change.\{\{nl\}\} Thus once we write:\{\{nl\}\}string s = "jim"; \{\{nl\}\}That string object will \_always\_ contain "jim"\{\{nl\}\} Question: s = "jess" does not change the string, but instead creates a reference.} \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Mutable}}\{\{nl\}\} Example: a stack is mutable (it can be changed), \{\{nl\}\}Stringbuilder class allows us to modify strings} \tn % Row Count 9 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Methods that Modify(Mutate) an Object}}\{\{nl\}\}are called mutators \{\{nl\}\}The stack class is "Mutable" \{\{nl\}\}Can be modified after creation\{\{nl\}\} The string class is "Immutable" \{\{nl\}\}Cannot be modified after creation\{\{nl\}\}Q: How can you make any object Immutable (to a programmer using your object?) \{\{nl\}\}A: Make all \seqsplit{fields/Properties/setters} PRIVATE! (protected)} \tn % Row Count 17 (+ 8) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Properties}}\{\{nl\}\}C\# has a convenient notation for building getters/setters\{\{nl\}\} Can control public/private of get and set independently \{\{nl\}\} Often properties are "backed" by private member fields\{\{nl\}\} As always, member fields should default to private \{\{nl\}\}"private" properties can often just be private member variables\{\{nl\}\}Example:\{\{nl\}\}a private property could be used for lazy instantiation of an expensive field: e.g., private password ( get 🡪 if password==null, do expensive password get operation)} \tn % Row Count 28 (+ 11) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Properties}}\{\{nl\}\}Properties are similar to named fields in the object\{\{nl\}\} Properties should be aspects of an object that can be understood independently of the rest of the representation \{\{nl\}\}Think, for example, of the current hour of the day (from a Date class where internal representation is seconds since a prior date) \{\{nl\}\}Public properties (which is usually the case) provide a "contract" with user of your code\{\{nl\}\} Has a convenient notation for building getters/setters\{{[}nl\}\} Can control access to get and set (i.e., private) independently \{\{nl\}\} As always, don't make every member variable public \{\{nl\}\} "private" properties can often just be private member variables} \tn % Row Count 42 (+ 14) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 6 (cont)}} \tn % Row 5 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Func v.s. Delegate Notation}}\{\{nl\}\}If you aren't going to have (1) any useful/descriptive words, or (2) Or it is a "one off" then use "Func" notation \{\{nl\}\}delegate int MathOnTwoNumbers(int x1, intx2);\{\{nl\}\} int add(int a, int b) \{ … \} \{\{nl\}\}AddTwoNumbers f1 = (a,b) =\textgreater{} a+b; // lambda to fulfill Delegate \{\{nl\}\}Func\textless{}int,int,int\textgreater{} f2 = (a,b) =\textgreater{} a+b; // lambda to fulfill Func\{\{nl\}\} AddTwoNumbers f3 = add; // regular function to fulfill Delegate\{\{nl\}\} Func\textless{}int,int,int\textgreater{} f4 = add; // regular function to fulfill Func} \tn % Row Count 12 (+ 12) % Row 6 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Delgate v.s. Func}}\{\{nl\}\}Why Use Delegate? \{\{nl\}\}Named, Documented, Provides More Context\{\{nl\}\} Evaluate(string formula, VariableLookUpMethod lookup) \{\{nl\}\}Why Use Func? \{\{nl\}\}Shortcut, Types are "right there to see"\{\{nl\}\} Evaluate(string formula, Func\textless{}string,int\textgreater{} lookup)} \tn % Row Count 18 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 7}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Global Variables}}\{\{nl\}\}Data that is accessible from "anywhere" in the program\{\{nl\}\} If a method modifies one, it is a "hidden side-effect" \{\{nl\}\}Software Practice - Almost always:\{\{nl\}\} Best Case: Data → Function → return New Data\{\{nl\}\} Nothing else changes!\{\{nl\}\} Okay Case: Data → Function → parameters "change" (see out/ref params)} \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Memory}}\{\{nl\}\}Stack \{\{nl\}\}Methods (and their Variables) \{\{nl\}\}Heap\{\{nl\}\} Objects\{\{nl\}\}Methods go on the Stack \{\{nl\}\}Variables in Methods go on the Stack\{\{nl\}\} Objects go on the Heap\{\{nl\}\} Changing something about a "Shared" (Aliased) variables is "seen" by all other aliased variables} \tn % Row Count 14 (+ 6) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Memory Diagram}}\{\{nl\}\}Every function should be labeled on the stack\{\{nl\}\} Every variable is kept on the call/activation stack\{\{nl\}\} References (to objects) have "arrows" to heap \{\{nl\}\}Value variables have values on stack \{\{nl\}\}Object methods should show "this" explicitly on the stack\{\{nl\}\} Every new object is kept on the heap} \tn % Row Count 21 (+ 7) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Pass by Value \& Ref}}\{\{nl\}\}By Value\{\{nl\}\} - a copy of the value is added to the stack frame of the called method \{\{nl\}\}By Reference\{\{nl\}\} - a "pointer" to the object is added to the stack frame of the called method} \tn % Row Count 26 (+ 5) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{In, Out, Ref Params}}\{\{nl\}\}In\{\{nl\}\} - makes Reference constant\{\{nl\}\} WARNING: does not make object constant\{\{nl\}\} Out\{\{nl\}\} - refers to calling methods variable \{\{nl\}\}Places object "in" calling methods variable\{\{nl\}\} Must be assigned a value\{\{nl\}\} Cannot use "what was there before" \{\{nl\}\}Ref\{\{nl\}\} - refers to calling method variable \{\{nl\}\}Can use what is there\{\{nl\}\} Does not have to assign a value \{\{nl\}\}Out and Ref the same except compiler enforces semantics} \tn % Row Count 36 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 7 (cont)}} \tn % Row 5 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Structs}}\{\{nl\}\}Structs are like VALUE types\{\{nl\}\} They go on the Stack\{\{nl\}\} Unless part of an object\{\{nl\}\}Let's Draw a picture for \{\{nl\}\}struct Pt \{ int x; int y; \} main() \{ Pt pt1 = new pt(); Pt pt2;} \tn % Row Count 5 (+ 5) % Row 6 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Structs}}\{\{nl\}\}Constructors allowed, but not required \{\{nl\}\}new() → calls constructor\{\{nl\}\} Does not put object on heap\{\{nl\}\} Can have methods \{\{nl\}\}Getters/Setters/Properties \{\{nl\}\}Usually do not!\{\{nl\}\}Why do structs go on the stack? \{\{nl\}\}Efficiency! \{\{nl\}\}No allocation!\{\{nl\}\} No deallocation/Garbage Collection.} \tn % Row Count 12 (+ 7) % Row 7 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Memory Efficency}}\{\{nl\}\}the closer the data is to the CPU the faster the memory (and the more costly, thus there is less of it)} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 8}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{IEnumerable}}\{\{nl\}\}What is the "High Level English" meaning of an IEnumerable? \{\{nl\}\}Guarantees a "list" of "stuff" coming back. \{\{nl\}\} What are some classes that implement IEnumerable?\{\{nl\}\} List, HashTable, BST, Array, etc. \{\{nl\}\}IEnumerable iterable = new BST(); \{\{nl\}\}IEnumerable iterable = new List\textless{}string\textgreater{}( … ); // etc \{\{nl\}\}What does an IEnumerable "give you"? \{\{nl\}\}A way for OUTSIDE CODE to "walk" the data: \{\{nl\}\}foreach (var item in iterable) \{ Print(item); \}} \tn % Row Count 10 (+ 10) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{IEnumerable uses an Enumerator}}\{\{nl\}\}Implemented by an Enumerator Class \{\{nl\}\}Enumerator has low level functionality \{\{nl\}\}Bool ← MoveNext // if there is another item, return true \{\{nl\}\}Current // return the current item} \tn % Row Count 15 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Linq}}\{\{nl\}\}Adds "Database-like" syntax to C\# (somewhat modeled on SQL database language).\{\{nl\}\}Can convert IEnumerable to Arrays or Lists\{\{nl\}\}Using System.Linq; \{\{nl\}\}public void doit( IEnumerable container ) \{ \{\{nl\}\} List list = container.ToList();} \tn % Row Count 21 (+ 6) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Yield Return}}\{\{nl\}\}C\# has a way to Only partially execute a function \{\{nl\}\}Can later return and complete more of it later! \{\{nl\}\}This is called: Yield Return\{\{nl\}\}Yield Return SAVES the entire execution state of the method call (i.e., the call (activation) stack) for continued execution at a future point!} \tn % Row Count 28 (+ 7) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Yield Return Explained}}\{\{nl\}\}When the line with yield return is encountered: \{\{nl\}\}The runtime saves the entire STATE of the method\{\{nl\}\} Local Variables \{\{nl\}\}Parameters \{\{nl\}\}When the method is called again, the runtime restores the state and continues\{\{nl\}\} From the last point of execution!} \tn % Row Count 34 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 8 (cont)}} \tn % Row 5 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Why we need Yield Return}}\{\{nl\}\}Example: Imagine a GUI with a button that populates a textbox with the next prime. \{\{nl\}\}static IEnumerator iterator = \seqsplit{next\_prime().GetEnumerator();} // actually need Enumerator\{\{nl\}\} void button\_action() \{\{nl\}\}\{\{\{nl\}\} iterator.MoveNext(); // hidden: computes next prime and saves state of method \{\{nl\}\} text\_box.Text = iterator.Current; \{\{nl\}\}\}} \tn % Row Count 8 (+ 8) % Row 6 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{REGEX}}\{\{nl\}\}{[}abc{]} ← Square Brackets: match any character in here \{\{nl\}\}a|b ← OR - Match an 'a' or 'b' character \{\{nl\}\}a{\emph{ ← Match zero or more (little) a's\{\{nl\}\} d+ ← Match one or more (little) d's\{\{nl\}\} \textbackslash{}d+ ← Escape: Match one or more digits! \{\{nl\}\}\textbackslash{}s ← Match whitespace \{\{nl\}\} a? ← Match zero or one little a's \{\{nl\}\}(a}}) ← If we find this, put it in "group" 1\{\{nl\}\} a\$ ← a at end of string!} \tn % Row Count 17 (+ 9) % Row 7 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Yield Return}}\{\{nl\}\}Use when you either \{\{nl\}\} CANNOT create entire list of results \{\{nl\}\}TOO COSTLY to create entire list of results\{\{nl\}\} Need to SPREAD computation over longer time Might not need all values!\{\{nl\}\} Question: Binary Search Tree with Nodes \{\{nl\}\} \{ Node left; Node right;\} \{\{nl\}\}How would you build the iterator?\{\{nl\}\}Answer: yield return can use recursion!} \tn % Row Count 25 (+ 8) % Row 8 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Yield Return BSTpseudocode}}\{\{nl\}\}IEnumerable traverse( Node current ) \{\{nl\}\}\{ \{\{nl\}\} if (current == null) return; \{\{nl\}\} yield return this.Value; \{\{nl\}\} traverse ( this.left ); \{\{nl\}\} traverse ( this.right );\{\{nl\}\} \}} \tn % Row Count 30 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 8 (cont)}} \tn % Row 9 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Func ⇔ Delegate shortcut}}\{\{nl\}\}public delegate string Normalize(string); // Definition \{\{nl\}\}Normalize function = s =\textgreater{} s; // Usage with Lambda\{\{nl\}\} Func\textless{}string,string\textgreater{} function = s=\textgreater{} s; // Func notation \{\{nl\}\}Func is simply inline (shortcut) notation for delegates without a name.} \tn % Row Count 6 (+ 6) % Row 10 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{What does == do?}}\{\{nl\}\}== is REFERENCE equality\{\{nl\}\} Are X and Y the same object in memory. \{\{nl\}\}overloaded == \{\{nl\}\}Can mean anything you want it to mean, but…\{\{nl\}\} Usually means VALUE equivalence "jim" == "jim" \{\{nl\}\}.Equals \{\{nl\}\}Means value equivalence} \tn % Row Count 12 (+ 6) % Row 11 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{DRY -Don't Repeate Yourself}}\{\{nl\}\}Dry is a fundamental principles of good software development\{\{nl\}\} Don't repeat Data! \{\{nl\}\}Violate sometimes for speed (can be a good reason)\{\{nl\}\} Don't repeat Code!\{\{nl\}\} Violate sometimes because we are lazy (bad reason)\{\{nl\}\}Example: using extensions is a good dry practice} \tn % Row Count 19 (+ 7) % Row 12 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Dry Code}}\{\{nl\}\}Move common code to helper method(s) Make Library for common code Use Extensions Library} \tn % Row Count 22 (+ 3) % Row 13 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{What is an Invariant?}}\{\{nl\}\}A condition that must always be true. \{\{nl\}\}For example: \{\{nl\}\} If A1 depends on B1 \{\{nl\}\}Then B1 must have A1 as a dependee} \tn % Row Count 26 (+ 4) % Row 14 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{How do we ensure the Invariant on this?}}\{\{nl\}\}public void ReplaceDependents(string s, IEnumerable\textless{}string\textgreater{} newDependents) \{ \}\{\{nl\}\}Answer: this function should not touch Map 1 or Map 2 Answer 2: this function should only use addDependency and removeDependency} \tn % Row Count 32 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 8 (cont)}} \tn % Row 15 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{MVC}}\{\{nl\}\}Model - Data (and some methods to compute on data) \{\{nl\}\}View - What the user sees \{\{nl\}\}Controller - Interactions between User and Model} \tn % Row Count 3 (+ 3) % Row 16 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{NameSpaces}}\{\{nl\}\}SpreadsheetUtilities\{\{nl\}\} Internal namespace to your project for your use/protection\{\{nl\}\} SS ← Added to project now\{\{nl\}\} External namespace your project "shows" to the world, similar to System, or Math, or Collections…} \tn % Row Count 8 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 9}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Abstract Class}}\{\{nl\}\}Defines WHAT must be done (via methods) \{\{nl\}\}Defines Return and Parameter Type Signatures\{\{nl\}\} Defines generic (reusable) code \{\{nl\}\}Defines generic data (if applicable)\{\{nl\}\} A child class can only implement one\{\{nl\}\} Can have a constructor} \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Interfaces}}\{\{nl\}\}Defines WHAT must be done (via methods) \{\{nl\}\}Defines Return and Parameter Type Signatures\{\{nl\}\} No Code\{\{nl\}\} No Data \{\{nl\}\}A class can implement many\{\{nl\}\} No constructor} \tn % Row Count 10 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{MVC}}\{\{nl\}\}Model - Working on this now\{\{nl\}\} Data→ Cells - Contents / Values \{\{nl\}\}Functionality → Dependencies \{\{nl\}\}(See requirements in Abstract class)\{\{nl\}\} View - GUI (not working on this now)\{\{nl\}\} Controller - actions available to user\{\{nl\}\} often initiated through the GUI\{\{nl\}\} Not working on this now} \tn % Row Count 17 (+ 7) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Why Comment?}}\{\{nl\}\}Shows that you understand your code \{\{nl\}\}Allows partners and future developers to understand your code before reading it line by line\{\{nl\}\} Can be used PRIOR to coding to set specifications/reminders \{\{nl\}\}Can be "scraped" to provide external documentation} \tn % Row Count 23 (+ 6) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{\textless{}inheritdoc\textgreater{}}}\{\{nl\}\}Does just that. \{{[}nl\}\}Inherits documentation from parent (class) \{\{nl\}\}Why is this DRY?\{\{nl\}\}DRY since we don't repeat ourselves/code} \tn % Row Count 27 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{How/When to Comment}}\{\{nl\}\}Header Comment vs. Inline\{\{nl\}\} Header - High-level overview of desired functionality\{\{nl\}\} Don't "re-write" code in comments \{\{nl\}\}Question: What is "comment rot"?\{\{nl\}\} Inline\{\{nl\}\} For sections of a long function (alternatively, helper methods) \{\{nl\}\}For tricky code\{\{nl\}\} Use descriptive variable names to alleviate the need for some comments} \tn % Row Count 35 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 9 (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Self-Documenting Code}}\{\{nl\}\}Wrong - "Don't Comment your Code!" \{\{nl\}\}Right Comment for Why \{\{nl\}\}Provide links to algorithms, examples, docs \{\{nl\}\}Rename complicated expressions with understandable names} \tn % Row Count 5 (+ 5) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{DRY}}\{\{nl\}\}Do not repeat yourself \{\{nl\}\}Do not repeat code \{\{nl\}\}Use helper methods \{\{nl\}\}Do not repeat data* \{\{nl\}\}Transform requests/inputs into a single standard form \{\{nl\}\}Question: when "can" we repeat data\{\{nl\}\}Answer: in a very local location (e.g., a single class file) where invariants are set (e.g., input into the dependents always updates dependees) and only if we get a strong efficiency boost that (in your expert opinion) is worth the SE hit.} \tn % Row Count 15 (+ 10) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Yield Return}}\{\{nl\}\}Used for Enumerations (IEnumerable) \{\{nl\}\}Operationally: Saves Code/Method Call Stack\{\{nl\}\} Used for: "infinite" or "costly" enumerations} \tn % Row Count 19 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 10}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{GSP- Good Software Practices}}\{\{nl\}\}Good use of Versioning\{\{nl\}\} Multiple Commits. Good Commit Messages \{\{nl\}\}Tags at "Releases"\{\{nl\}\} Good use of Testing \{\{nl\}\}Extensive Unit Tests\{\{nl\}\} Well named/useful tests.\{\{nl\}\}Documentation \{\{nl\}\}READMEs\{\{nl\}\} Located in Solution Folder (and all Project Folders) \{\{nl\}\}Hour tracking \{\{nl\}\}Software Practice Section\{\{nl\}\} Header Comments\{\{nl\}\} Who, what, verification\{\{nl\}\} Method and Field Documentation} \tn % Row Count 10 (+ 10) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Diagrams}}\{\{nl\}\}Intrinsically encode: \{\{nl\}\} Basic functionality of each piece \{\{nl\}\}How pieces fit together to form the whole \{\{nl\}\}Overall design philosophy} \tn % Row Count 14 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{UML -Unified Modeling Language}}\{\{nl\}\}Unified Modeling Language \{\{nl\}\} "Syntax" for drawing diagrams \{\{nl\}\} Programming Language agnostic\{\{nl\}\}Not all fields/methods need to be shown \{\{nl\}\} Only those required for an understanding} \tn % Row Count 19 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{UML Visibility Modifiers}}\{\{nl\}\}- private \{\{nl\}\}+ public\{\{nl\}\} \# protected \{\{nl\}\}underline static} \tn % Row Count 21 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Connectivity}}\{\{nl\}\}Arrow indicates that one class is aware of another Direction indicates whom is aware of whom} \tn % Row Count 24 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Aggregation}}\{\{nl\}\}Something is composed of independent entities \{\{nl\}\} When the "container" goes away, the entities do not ("weak" ownership)\{\{nl\}\} e.g. A Course containing Students, but the students don't "go away" when the course is cancelled.} \tn % Row Count 30 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 10 (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Composition}}\{\{nl\}\}Entities within are not whole on their own ("strong" ownership)\{\{nl\}\} e.g. A Student containing a Transcript, and the transcript "goes away" when the student leaves the University} \tn % Row Count 5 (+ 5) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Diagrams}}\{\{nl\}\}UML: \{\{nl\}\}Formal\{\{nl\}\} Persistent documentation \{\{nl\}\}"Suggests" more information\{\{nl\}\} Whiteboard: \{\{nl\}\}Less Formal \{\{nl\}\}Might be erased\{\{nl\}\} Likely to "miss" information\{\{nl\}\} This information is likely to be somewhere else (API file)} \tn % Row Count 11 (+ 6) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Incremental Testing}}\{\{nl\}\} Test incrementally! \{\{nl\}\} The longer you go without testing, the bigger your "haystack" becomes\{\{nl\}\}Catch design flaws early \{\{nl\}\} Problems will become apparent before bolting it all together\{\{nl\}\} Keep the "haystack" small! \{\{nl\}\} Testing is a lot like debugging} \tn % Row Count 18 (+ 7) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Complex Systems}}\{\{nl\}\}Butterfly effect\{\{nl\}\} Even for a tiny change in an obscure region of the code Run the test suite!} \tn % Row Count 21 (+ 3) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Regression Testing}}\{\{nl\}\}Regression refers to "going backward" (regressing)\{\{nl\}\} When new code is added the number of bugs goes up, therefore the code "regresses"\{\{nl\}\} Try to minimize this\{\{nl\}\}Run existing (old) tests regularly\{\{nl\}\} As code changes, tests might start failing\{\{nl\}\} Note: Sometimes the Test needs to be updated \{\{nl\}\} Test suite continuously grows \{\{nl\}\}Never discard a valid test!\{\{nl\}\}Must start test suite on "day one" \{\{nl\}\}or it won't get done\{\{nl\}\} Must keep tests up to date (prioritize them) \{\{nl\}\}Or it won't get done\{\{nl\}\} Must run tests every day \{\{nl\}\}Or it won't get done!} \tn % Row Count 34 (+ 13) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 10 (cont)}} \tn % Row 11 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Smoke Tests}}\{\{nl\}\}Subset of full suite \{\{nl\}\}should run in \textless{} 5 minutes \{\{nl\}\}if your entire suite runs quickly, use them all! \{\{nl\}\} Try to pick broad range of coverage \{\{nl\}\}Run them after every compile} \tn % Row Count 5 (+ 5) % Row 12 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Code Coverage}}\{\{nl\}\}100\% coverage is often difficult\{\{nl\}\} Huge systems – countless paths\{\{nl\}\} Irregular interaction (e.g. GUIs)\{\{nl\}\} That being said:\{\{nl\}\} "Model" code is easier to cover\{\{nl\}\} Eliminate "dead" code \{\{nl\}\}You have access to the "white box"} \tn % Row Count 11 (+ 6) % Row 13 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Gray Box Tests}}\{\{nl\}\}Combine Black Box and White Box \{\{nl\}\}First, design tests of the specification (black)\{\{nl\}\} Then, design tests for code coverage (white) \{\{nl\}\} Keep them both in a test suite} \tn % Row Count 15 (+ 4) % Row 14 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Debug Assertations}}\{\{nl\}\} Assertations in regular code:\{\{nl\}\}Debug.Assert(some condition); \{\{nl\}\} Condition should always be true – fails otherwise \{\{nl\}\} Sprinkle these throughout your code where invariants should hold \{\{nl\}\} Get removed in release builds – important for performance!\{\{nl\}\}Use them if your code assumes preconditions \{\{nl\}\}Good use of assertions can save countless hours of debugging\{\{nl\}\} Fail Fast!} \tn % Row Count 24 (+ 9) % Row 15 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Variable/Object Review}}\{\{nl\}\}An "empty" (class) variable is a placeholder for an object\{\{nl\}\} An "empty" (value type) variable is a value \{\{nl\}\}For example: \{\{nl\}\}int x;\{\{nl\}\} Student s;} \tn % Row Count 28 (+ 4) % Row 16 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Explicit Nullables Syntax}}\{\{nl\}\}? - The Question Mark is used to denote that a variable is allowed to contain nulls:\{\{nl\}\}} \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 10 (cont)}} \tn % Row 17 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{How to use Explicit Nullables}}\{\{nl\}\}If there is a case where you may need a variable or parameter to contain nulls, write it like so: \{\{nl\}\}public Student? function(Student? s) // s may contain null\{\{nl\}\} \{ \{\{nl\}\} Student? temp = s; // temp may contain null \{\{nl\}\} … \{\{nl\}\} return temp; \{\{nl\}\}\}} \tn % Row Count 7 (+ 7) % Row 18 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{How to use Non-Nullables}}\{\{nl\}\}Non nullables REPLACE the old syntax: \{\{nl\}\}public Student function(Student s) // s must contain an object\{\{nl\}\} \{ \{\{nl\}\} Student temp = s; // temp must contain an object \{\{nl\}\} … \{\{nl\}\}return temp; // temp cannot contain null (compiler enforced) \{\{nl\}\}\}} \tn % Row Count 14 (+ 7) % Row 19 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Nullables}}\{\{nl\}\}Summary: \{\{nl\}\}Class c; \{\{nl\}\}Good software practice: do not allow variable to contain null values\{\{nl\}\} OLD way - code does not enforce this (in fact it implies c contains null) \{\{nl\}\}NEW way - code/compiler enforces \{\{nl\}\}Therefore Class? c = null; // allows null\{\{nl\}\} Class c = new(); // does not allow null\{\{nl\}\} Enforced by compiler for a given Project!} \tn % Row Count 22 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 11}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Testing}}\{\{nl\}\}Coverage != Good Tests\{\{nl\}\} Necessary but Not Sufficient\{\{nl\}\} Tests should be small and targeted \{\{nl\}\}(Hence Unit Tests) \{\{nl\}\}A \_deep\_ understanding of the project goals is very important to understanding the code \{\{nl\}\}A full reading of all specifications (both in the starter code and written documentation) is necessary!\{\{nl\}\}Stress Tests show correct use of complexity/big O \{\{nl\}\}Harder to write\{\{nl\}\} Harder to debug} \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Information Storage and Retrieval}}\{\{nl\}\}Saving and restoring information is fundamental to real programs \{\{nl\}\}Solutions:\{\{nl\}\} Files ← Old fashion (but still useful ;\textasciicircum{}) \{\{nl\}\}XML/JSON/ETC\{\{nl\}\} Databases ← Modern \{\{nl\}\}SQL/MySQL/Mongo/SQLite/Firebase/etc.} \tn % Row Count 15 (+ 6) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Saving Files}}\{\{nl\}\}Need a "protocol" (i.e., what does a file structure mean?)\{\{nl\}\} XML and JSON \{\{nl\}\}Notations for saving information \{\{nl\}\} Machine readable \{\{nl\}\}Supported by Abstractions and Libraries} \tn % Row Count 20 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Using Statement}}\{\{nl\}\}Forces "cleanup"! \{\{nl\}\}Operating System must close file \{\{nl\}\}Try renaming a file while Visual Studio is open with it\{\{nl\}\} Advice for CS 3505 \{\{nl\}\}C++ → Destructor\{\{nl\}\} All objects have an explicit action they take when they are no longer referenced/used\{\{nl\}\}Translates into: \{\{nl\}\}Try\{\{nl\}\} Finally\{\{nl\}\} (always done regardless of exception status) \{\{nl\}\}Can only be used on Disposable Objects \{\{nl\}\}Should always be used on Disposable Objects! \{\{nl\}\}For Files, the finally closes the file stream!} \tn % Row Count 31 (+ 11) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 11 (cont)}} \tn % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{XML-Attributes}}\{\{nl\}\}Attributes - inside of tag \textless{} \textgreater{}s \{\{nl\}\}Add extra information to tag \{\{nl\}\}Probably should be avoided (most of the time*)\{\{nl\}\} Examples:\{\{nl\}\} \textless{}teacher name="Jim"\textgreater{} \{\{nl\}\}\textless{}param name="length"\textgreater{} \{\{nl\}\}\textless{}list type="number"\textgreater{}\{\{nl\}\} \textless{}record id="57"\textgreater{}} \tn % Row Count 6 (+ 6) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{JSON vs. XML}}\{\{nl\}\}JSON newer; \{\{nl\}\}XML older; \{\{nl\}\}Both "do the job"\{\{nl\}\} Both machine readable/parsable\{\{nl\}\} Same abstractions \{\{nl\}\}JSON ← Many (? most ?) Web applications use this} \tn % Row Count 10 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{JSON}}\{\{nl\}\}JSON – Representation – Object is \{\}\{\{nl\}\}Key Name/Value:\{\{nl\}\}\{ "key" : "value" \}\{\{nl\}\}Value can be a JSON object\{\{nl\}\}\{ "key" : \{ key1 : value, key2 : value \} \} \{\{nl\}\} JSON Arrays:\{\{nl\}\}\{ "key" : {[} \{ key: value, … \}, \{ … \}, … {]} \}} \tn % Row Count 16 (+ 6) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Reflection}}\{\{nl\}\}Computer language can inspect runtime objects\{\{nl\}\} Field Names\{\{nl\}\} Types\{\{nl\}\} Etc} \tn % Row Count 19 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Serialization}}\{\{nl\}\}Uses Reflection to determine Run-Time structure of object\{\{nl\}\} Turns this structure into a machine readable format\{\{nl\}\} Can do this automagically} \tn % Row Count 23 (+ 4) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{XML Serialization}}\{\{nl\}\}You can either use the sample code (with small modifications) \{\{nl\}\}As many programmers before you have done\{\{nl\}\} Read documentation on XML serialization and use this technique} \tn % Row Count 28 (+ 5) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Properties vs. Fields}}\{\{nl\}\}Serialization works on Properties instead of fields\{\{nl\}\} Field: int name; \{\{nl\}\}Property: int Name \{ get; set; \}\{\{nl\}\} Warning \{\{nl\}\}Default serialization works on public Properties. \{\{nl\}\}If you want Private access, or to change the names, you must use some "meta-tags"} \tn % Row Count 35 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 12}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Business Logic}}\{\{nl\}\}Where does the business logic error checking go?\{\{nl\}\} M, V, or C ? \{\{nl\}\} Answer: \{\{nl\}\}Model and Controller (mainly) but also in the View! ←Trick Question! \{\{nl\}\}Example:\{\{nl\}\} Model checks for cycles in graph\{\{nl\}\} Controller does input sanitization \{\{nl\}\}View only allows inputs in valid cells; View restricts input to only numbers (where appropriate)} \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Spreadsheet ⇔ MVC}}\{\{nl\}\}Which of the following is a Model, a View, or a Controller? \{\{nl\}\} FormulaEvaluator - Model \{\{nl\}\}DependencyGraph - Model\{\{nl\}\} Formula - Model\{\{nl\}\} Spreadsheet - Model \{\{nl\}\}GUI - Controller and View} \tn % Row Count 13 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{GUI}}\{\{nl\}\}Real world programs (usually using GUIs) are driven by inputs\{\{nl\}\} Unpredictable (based on human input) \{\{nl\}\}Execution is non-deterministic \{\{nl\}\}You don't know the order of the users actions…} \tn % Row Count 18 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Design Pattern: Notifier ⇔ Listener}}\{\{nl\}\}Event: any occurrence that may require action by "someone" else\{\{nl\}\} Making sure the "right event" gets to the Right place is challenging! \{\{nl\}\}Listeners: "subscribe" to an event \{\{nl\}\}Notifier: "sends" the event\{\{nl\}\} Listeners take action upon "hearing"} \tn % Row Count 25 (+ 7) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{C\# Event Handling}}\{\{nl\}\}Note: Directly supported by the language! \{\{nl\}\}Define a delegate for handling the event \{\{nl\}\}All handlers match this signature\{\{nl\}\} Declare an event (in the notifier)\{\{nl\}\} Register a handler (in the listener) \{\{nl\}\}Trigger the event (in the notifier)} \tn % Row Count 31 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 12 (cont)}} \tn % Row 5 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{C\# Events}}\{\{nl\}\}First, define a delegate for handling the event:\{\{nl\}\} delegate void \seqsplit{CancellationEventHandler();} \{\{nl\}\}All handlers must match this signature! \{\{nl\}\}void return – No Parameters!\{\{nl\}\}Next, declare an event (in the notifier):\{\{nl\}\} class University \{\{\{nl\}\} event \seqsplit{ CancellationEventHandler} canceller;\{\{nl\}\} // Keyword Type Field Name} \tn % Row Count 8 (+ 8) % Row 6 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Event Abstraction}}\{\{nl\}\} The event syntax provides: \{\{nl\}\}a list\{\{nl\}\} a foreach loop\{\{nl\}\} an assignment operator \{\{nl\}\} All "hidden" (abstracted) with simple/compact syntax!} \tn % Row Count 12 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 13}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Good Software Practices}}\{\{nl\}\}All of the techniques and principles (e.g., DRY) that we discuss are designed to give developers "Best Practices" for creating code that:\{\{nl\}\} a. Contains fewer defects\{\{nl\}\} b. Is more maintainable\{\{nl\}\} Easier to understand\{\{nl\}\} Easier to modify\{\{nl\}\} Safer to modify (see (a) above)} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{SOLID Code}}\{\{nl\}\}Single Responsibility\{\{nl\}\} Open-closed principle\{\{nl\}\} Liskov substitution principle \{\{nl\}\}Interface segregation principle\{\{nl\}\} Dependency Inversion} \tn % Row Count 11 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{(S)ingle Responsibility}}\{\{nl\}\}Each class (dare we say even method) should have a single responsibility \{\{nl\}\} Example: the spreadsheet model does not deal with: \{\{nl\}\}The GUI \{\{nl\}\}Dependency Graph\{\{nl\}\} (Other than by using the DependencyGraph library)} \tn % Row Count 17 (+ 6) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{(O)pen-Closed Principle}}\{\{nl\}\}Best practice is NOT to modify existing code.\{\{nl\}\} Why?\{\{nl\}\} Added functionality is added by "extending"\{\{nl\}\} Inheritance \{\{nl\}\}Subclassing in C\#\{\{nl\}\} Extension ( void doit (this Type, params) \{ \} )\{\{nl\}\} Example: stack class is not re-written but helper methods, such as "IsOnTop", are added} \tn % Row Count 24 (+ 7) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{(L)iskov Substitution Principle}}\{\{nl\}\}Variables in a program of a give (Parent) type should be replaceable with instances of their subtypes without altering the correctness of the code.\{\{nl\}\} Example: The need for an Abstract Spreadsheet can be fulfilled with any students Spreadsheet implementation} \tn % Row Count 31 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 13 (cont)}} \tn % Row 5 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{(I)nterface Segregation Principle}}\{\{nl\}\}Many small interface specifications are better than one large one \{\{nl\}\}"Child" classes can implement multiple interfaces as necessary \{\{nl\}\}Not a good example from Spreadsheet\{\{nl\}\} Example: IDisposable \{\{nl\}\}Only one method – Dispose} \tn % Row Count 6 (+ 6) % Row 6 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{(D)ependency Inversion Principle}}\{\{nl\}\}Classes should depend upon Abstraction not Concreteness.\{\{nl\}\} Where possible, variables/fields should be Interfaces or Abstract Classes rather than a concreted class. \{\{nl\}\}Example: Spreadsheet GUI should have an Abstract Spreadsheet member variable, not a Spreadsheet. \{\{nl\}\} This allows flexibility in expanding the project in the future\{\{nl\}\} class GUI \{\{nl\}\}\{ \{\{nl\}\} private Spreadsheet Spreadsheet; // WRONG \{\{nl\}\}private AbstractSpreadsheet Spreadsheet; // CORRECT} \tn % Row Count 17 (+ 11) % Row 7 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{How do you"start" becoming a better software engineer?}}\{\{nl\}\}Q: How do we get all of this "stuff" into our program.\{\{nl\}\} Suggestion:\{\{nl\}\} Concentrate on the S (single responsibility) \{\{nl\}\}Remember the O (open/closed) when using other code\{\{nl\}\} Try to remember to define (and use) Interfaces \{\{nl\}\}Upon modifying (adding features to) the code, refactor to increase SOLIDness \{\{nl\}\}As you grow more skilled, consider SOLID from the start} \tn % Row Count 26 (+ 9) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 14}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Software Practice and Parallel}}\{\{nl\}\}Does Parallel make code easier to understand? \{\{nl\}\}Does Parallel make code have fewer defects?\{\{nl\}\}NO!\{\{nl\}\} It might inspire you to better document, but it is intrinsically more complicated than single thread execution \{\{nl\}\}So why do we do it?\{\{nl\}\} Answer: efficiency gains out weight complexity\{\{nl\}\} We must be even more diligent in our naming, documentation, testing, etc., when writing parallel code} \tn % Row Count 9 (+ 9) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Moore's Law}}\{\{nl\}\}•Gordon Moore, 1975: Transistor density will double every 2 years\{\{nl\}\}What does this mean?\{\{nl\}\} • It does not mean: processors get 2x faster every 2 years} \tn % Row Count 13 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Dennard Scaling}}\{\{nl\}\} Robert Dennard, 1974: As transistors shrink, power-density remains constant \{\{nl\}\}•What does this mean?\{\{nl\}\}} \tn % Row Count 16 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Moores + Dennard}}\{\{nl\}\}•What does this NOT mean? \{\{nl\}\}• That computers automatically get faster\{\{nl\}\} •What does this mean? \{\{nl\}\}• In part, it means we're getting lots of cores \{\{nl\}\}•We have to figure out how to use those cores!} \tn % Row Count 21 (+ 5) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Parallel Computing}}\{\{nl\}\}•We told the algorithm how to divide the work \{\{nl\}\}•And more importantly, how to combine the results\{\{nl\}\} •Writing code without thinking about parallelism will not (usually) produce a parallel solution} \tn % Row Count 26 (+ 5) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Thread}}\{\{nl\}\}•Thread: a single sequential subprocess \{\{nl\}\}• Almost like its own program \{\{nl\}\}•Multi-threading is the ability of a computer to execute multiple threads concurrently} \tn % Row Count 30 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 14 (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Non-Blocking}}\{\{nl\}\} •thread.Start() is a non-blocking statement \{\{nl\}\}• It returns right away \{\{nl\}\}• Even though the other thread is still running\{\{nl\}\}•thread.Join() is blocking \{\{nl\}\}• Calling thread waits until thread finishes \{\{nl\}\}• What defines when thread is finished?\{\{nl\}\} • When the work function returns} \tn % Row Count 7 (+ 7) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Timing}}\{\{nl\}\}•You can not make any assumptions about how long some computing operation will take \{\{nl\}\}•With concurrency, there is no guarantee about the order in which events occur} \tn % Row Count 11 (+ 4) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Concurrent}}\{\{nl\}\}•Concurrent\{\{nl\}\} • Multiple tasks running\{\{nl\}\} • Thread can be interrupted, preempted at any time \{\{nl\}\}•Achieved by either: \{\{nl\}\}• OS rapidly switching threads/processes \{\{nl\}\}• Two threads/processes executing simultaneously\{\{nl\}\}•Concurrency via Context Switching} \tn % Row Count 18 (+ 7) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Parallel}}\{\{nl\}\}•Parallel (simultaneous) \{\{nl\}\}• Actually at the same time (same cycle)\{\{nl\}\} • Parallelism is concurrency \{\{nl\}\}• Usually results in performance gains \{\{nl\}\}•Concurrency is not (necessarily) parallelism} \tn % Row Count 23 (+ 5) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Multi-Threading}}\{\{nl\}\}•Multithreading does not (necessarily) mean parallel \{\{nl\}\}• But it does mean concurrent\{\{nl\}\} •The issues that arise with multithreaded programming are due to concurrency, not parallelism} \tn % Row Count 28 (+ 5) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{SMT}}\{\{nl\}\}•Simultaneous multithreading \{\{nl\}\}•The ability of a core to execute multiple threads simultaneously \{\{nl\}\}•Intel calls it "hyperthreading" \{\{nl\}\}• (a little more to it than this)} \tn % Row Count 33 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 14 (cont)}} \tn % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{C\# Form}}\{\{nl\}\}•How does a C\# Form control program flow? \{\{nl\}\}static void Main()\{\{nl\}\}\{\{\{nl\}\} ... \{\{nl\}\}Application.Run(new Form1()); \{\{nl\}\}\}\{\{nl\}\} public Form1()\{\{nl\}\}\{\{\{nl\}\} InitializeComponent(); \{\{nl\}\}\}} \tn % Row Count 5 (+ 5) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Message Loop}}\{\{nl\}\}•A Form is an "application message loop"\{\{nl\}\} •System creates a new thread to run the loop \{\{nl\}\}•Thread essentially runs this code: \{\{nl\}\}while(m = NextMessage()) \{\{nl\}\}\{ \{\{nl\}\}HandleMessage(m);\{\{nl\}\} \} \{\{nl\}\}•Messages are placed in to the thread's "queue" by the OS \{\{nl\}\}•When the mouse is moved\{\{nl\}\} •When the mouse is clicked\{\{nl\}\} •When a key is pressed\{\{nl\}\} •When a window is resized \{\{nl\}\}•etc… \{\{nl\}\}•Most of the time, handling the message is just invoking event handlers} \tn % Row Count 16 (+ 11) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Handeling Messages}}\{\{nl\}\}while(m = NextMessage())\{\{nl\}\} \{ \{\{nl\}\}HandleMessage(m);\{\{nl\}\} \} \{\{nl\}\}•If handling the message is expensive, then other messages get stalled \{\{nl\}\}•GUI becomes unresponsive} \tn % Row Count 21 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 15}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Modals(Pop-Ups)}}\{\{nl\}\}async void doit() \{ //async bool DisplayAlert( … )\{\{nl\}\} overwrite = await DisplayAlert( \{\{nl\}\} "Warning", // Title\{\{nl\}\} "Spreadsheet changed, do you want to continue?", // Message \{\{nl\}\}"Yes", // True choice\{\{nl\}\} "No" ); // False Choice} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Partials}}\{\{nl\}\}// file: YourCode.cs\{\{nl\}\} class MainPage XML → MauiCode.cs\{\{nl\}\} \{ partial class MainPage \{\{nl\}\}… \{\{nl\}\}\}} \tn % Row Count 12 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Good Software Practices lead to}}\{\{nl\}\}Better Architecture 🡪 FDMM \{\{nl\}\}MVC, Client Server, Event Driven \{\{nl\}\}Use of "tried and tested" libraries\{\{nl\}\} SOLID → FDMM \{\{nl\}\}Smaller "units" (multiple single responsibility functions) \{\{nl\}\}Documentation 🡪 FDMM \{\{nl\}\}Versioning 🡪 FDMM \{\{nl\}\}Testing 🡪 FDMM \{\{nl\}\}Design Patterns → FDMM \{\{nl\}\}FDMM – Fewer Defects, More Maintainable} \tn % Row Count 21 (+ 9) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Open/Closed Example}}\{\{nl\}\}Modifying the code in \_working\_ software can lead to defects\{\{nl\}\} New software needs more functionality.\{\{nl\}\} Avenues of "Openness" \{\{nl\}\}Extend \{\{nl\}\}Inherit\{\{nl\}\} Open for extension/Closed for modification} \tn % Row Count 26 (+ 5) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Code Alignment}}\{\{nl\}\}Makes code: \{\{nl\}\}Easier to Read \{\{nl\}\}Easier to spot "one offs" or "copy paste" mistakes \{\{nl\}\} float thousands = 1000; \{\{nl\}\} float millions = 1000000; \{\{nl\}\} float billions = 100000000;\{\{nl\}\}Even Better: Use number underscores} \tn % Row Count 32 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 15 (cont)}} \tn % Row 5 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Threads vs. Tasks}}\{\{nl\}\}You may read about/hear about "Tasks"\{\{nl\}\} Both allow processes to run in parallel. \{\{nl\}\}Task is a higher level abstraction with additional functionality: \{\{nl\}\}Can return a result \{\{nl\}\}Can be cancelled \{\{nl\}\}Can use Async and Await keywords* \{\{nl\}\}Can use the "Thread Pool" \{\{nl\}\}For our current purposes, there is little difference.} \tn % Row Count 8 (+ 8) % Row 6 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Shared Data is Problematic}}\{\{nl\}\}Parallelism \{\{nl\}\} When possible do work on separate data\{\{nl\}\} When NOT use locking \{\{nl\}\} We'll talk more about this later \{\{nl\}\} Slows down the process} \tn % Row Count 12 (+ 4) % Row 7 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Key Methods}}\{\{nl\}\}Constructor: \{\{nl\}\} worker1 = new Thread(() =\textgreater{} function()); \{\{nl\}\}Start – actually begin the work \{\{nl\}\}worker1.Start() \{\{nl\}\}Join – wait for that work to be done \{\{nl\}\} worker1.Join()} \tn % Row Count 17 (+ 5) % Row 8 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Parallel Vocab}}\{\{nl\}\}Thread \{\{nl\}\}A separate unit of execution (assigned a method/function)\{\{nl\}\} Race Condition\{\{nl\}\} Two (or more) threads have access to same data at the same time \{\{nl\}\}Lock \{\{nl\}\}Protects a critical region of code (which almost always should contain a shared resource, e.g., a common variable/data structure) \{\{nl\}\}Deadlock \{\{nl\}\}Two+ threads are waiting for each other in order to continue} \tn % Row Count 26 (+ 9) % Row 9 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Deadlock Example}}\{\{nl\}\} Note: You won't get Deadlock in Spreadsheet GUI \{\{nl\}\}Need at least two locks\{\{nl\}\} Only shared resource might be GUI widgets (e.g., buttons)\{\{nl\}\} Should "turn these off" when doing a long computation \{\{nl\}\}Protected by Backgroundworker Semantics and/or Invoke} \tn % Row Count 32 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 15 (cont)}} \tn % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Characteristics of GSP}}\{\{nl\}\}Defects (bugs) Reduction \{\{nl\}\}Testing, Architecture, SOLID\{\{nl\}\} Maintainability \{\{nl\}\}Understandable/Readable \{\{nl\}\}Testing 🡪 Regression resistant} \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 16}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Software Practice - Problem Solving(Coding)}}\{\{nl\}\}Problem: I want to choose where to save a file (spreadsheet) in my MAUI application\{\{nl\}\} Solution: \{\{nl\}\}Software Practice in practice\{\{nl\}\}Step 1: Google - choose good keywords\{\{nl\}\}Step 2: Stackoverflow - verify it "looks legit"\{\{nl\}\}Step 3: Nuget and Troubleshoot\{\{nl\}\}} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Networks}}\{\{nl\}\}We will cover the introductory concepts about program to program communication over a network\{\{nl\}\} For a deeper understanding, take CS 4480 - Networking} \tn % Row Count 11 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Two way Communication}}\{\{nl\}\}Address and recipient\{\{nl\}\} Address and sender} \tn % Row Count 13 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Identification Information}}\{\{nl\}\}Real World (i.e., Apartment) \{\{nl\}\}Address (\# street state zip),\{\{nl\}\} Mailbox/Apartment (\#) \{\{nl\}\} Computer \{\{nl\}\}URL: e.g., www.cs.utah.edu (human readable) \{\{nl\}\}Really IP Address: e.g., \seqsplit{ 155.98.65.24 (machine} readable) \{\{nl\}\}Port: e.g., 80} \tn % Row Count 19 (+ 6) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Architecture: Client ⬄ Server}}\{\{nl\}\}Client wants to do some "work"/"play" \{\{nl\}\}Server controls functionality\{\{nl\}\} Client usually shows the GUI\{\{nl\}\} Server usually manages the Model/Data} \tn % Row Count 24 (+ 5) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{DNS -Domain Name System}}\{\{nl\}\}How do you know "where" Jess lives?\{\{nl\}\}Need an Address?\{\{nl\}\} Could ask operator 🡪 \{\{nl\}\}"Where is the Jess' House?" \{\{nl\}\}I suppose you could ask Google…\{\{nl\}\}How do you know "where" cs.utah.edu lives?\{\{nl\}\}DNS 🡪 Domain Name System\{\{nl\}\} Provides "IP Address" \{\{nl\}\}Need a computer address: \{\{nl\}\}Where is:\{\{nl\}\} cs.utah.edu\{\{nl\}\}Aside: how do you know where DNS lives?\{\{nl\}\}Google DNS:\{\{nl\}\}Configure your network settings to use the IP addresses\{\{nl\}\} 8.8.8.8 and 8.8.4.4 as your DNS servers. \{\{nl\}\} If you decide to try Google Public DNS, your client programs will perform all DNS lookups using Google Public DNS.} \tn % Row Count 38 (+ 14) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 16 (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{IP Version 6 and local nets: Too many computers…}}\{\{nl\}\}Note IPv4 vs. IPv6 (number of addresses) \{\{nl\}\}Think license plates in Utah vs. California \{\{nl\}\} Local network: 192.0.0.1\{\{nl\}\} Most of your home routers} \tn % Row Count 5 (+ 5) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Ports -"MAIL BOXES" ASSOCIATED WITH SPECIFIC PROGRAMS}}\{\{nl\}\}Once at the "building", distribute to the recipient} \tn % Row Count 8 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Client ⬄ Server Communications}}\{\{nl\}\}Needs: \{\{nl\}\}The address of the server machine\{\{nl\}\} Initial port to talk to\{\{nl\}\} A unique port for future communication \{\{nl\}\}The Protocol(s)!} \tn % Row Count 12 (+ 4) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Can you have multiple Clients ⬄ with a single Server?}}\{\{nl\}\} see stackoverflow?} \tn % Row Count 14 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Initial Port vs. Continuing Port}}\{\{nl\}\}For Query/Response programs (e.g., a web server): \{\{nl\}\}the server will use a specific low port that is "known" so anyone can make an initial connection \{\{nl\}\}i.e., 80 \{\{nl\}\}Ongoing connections will be moved to a different (high) port number\{\{nl\}\} So that new clients can talk to server at the same time} \tn % Row Count 21 (+ 7) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Ports -1 }}\{\{nl\}\}"Mailbox Numbers" for the computer \{\{nl\}\} Unique to for each program \{\{nl\}\}If you try to "open" a port that is already in use you will get an error \{\{nl\}\}Note: this could happen if you try to run/debug two versions of the same program at the same time\{\{nl\}\} Numbers \{\{nl\}\}Range: 0 - 64k\{\{nl\}\}taken over -\textgreater{} used so much they have become defaults…} \tn % Row Count 29 (+ 8) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Ports -2}}\{\{nl\}\}Who decides number?\{\{nl\}\} Some programs have official ports \{\{nl\}\}Other programs have "taken" over ports \{\{nl\}\}Some ports screened/blocked by firewalls!\{\{nl\}\} Especially low ports under 1000} \tn % Row Count 34 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 16 (cont)}} \tn % Row 13 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Sockets -OPENING CONNECTIONS BETWEEN CLIENTS AND SERVER}}\{\{nl\}\}Socket 🡪 Unique Channel between Sender and Receiver\{\{nl\}\}Client asks the Server for connection. \{\{nl\}\} A Socket is defined!} \tn % Row Count 4 (+ 4) % Row 14 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Socket}}\{\{nl\}\}An identifier representing a particular point to point communication connection between two pieces of software \{\{nl\}\}My IP ADDRESS \{\{nl\}\}Their IP ADDRESS \{\{nl\}\}My Port Number \{\{nl\}\}Their Port Number \{\{nl\}\} Combined into a single unique communication channel} \tn % Row Count 10 (+ 6) % Row 15 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Network Protocols}}\{\{nl\}\}Agreed order and format of data for communication\{\{nl\}\} What protocols do we have in this classroom?\{\{nl\}\}Hand raise 🡪 Professor Calls Upon 🡪 Acknowledged person answers\{\{nl\}\} Professor says Answer Clicker Question 🡪 Students input data} \tn % Row Count 16 (+ 6) % Row 16 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{XML Commenting Protocols}}\{\{nl\}\}How do we define comments about parameters?\{\{nl\}\}\textless{}param name="abc"\textgreater{} info \textless{}/param\textgreater{}} \tn % Row Count 19 (+ 3) % Row 17 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{IP -Internet Protocol}}\{\{nl\}\}Responsible for sending packets of information from host to host\{\{nl\}\} Hand-wave Hand-wave Hand-wave \{\{nl\}\}(or Abstraction/Separation of concerns)\{\{nl\}\} The internet and C\#'s usage of it just works!} \tn % Row Count 24 (+ 5) % Row 18 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{TCP -Transmission Control Protocol}}\{\{nl\}\}Runs on top of IP (Internet Protocol) \{\{nl\}\}One to One Reliable Communication \{\{nl\}\}Data will arrive \{\{nl\}\}Verified Ordering \{\{nl\}\}Verified Uncorrupted \{\{nl\}\} Does not verify when data arrives or how much arrives at a given time! \{\{nl\}\}C\# libraries do all the work for you\{\{nl\}\} Take the Networking course! CS 4480} \tn % Row Count 32 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 16 (cont)}} \tn % Row 19 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{UDP -User Datagram Protocol}}\{\{nl\}\}Alternative to TCP\{\{nl\}\} No Handshaking – no persistent connection \{\{nl\}\}No guarantee of \{\{nl\}\}Delivery \{\{nl\}\}Ordering \{\{nl\}\}Duplication Protection \{\{nl\}\}Why would we use this?\{\{nl\}\}Faster – less overhead} \tn % Row Count 5 (+ 5) % Row 20 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Basic Network Communication Facts:}}\{\{nl\}\}Happen at the BYTE level!!!! \{\{nl\}\}Your program must \{\{nl\}\} Translate useful data into bytes and \{\{nl\}\}Translate bytes into useful data (e.g., strings, objects, etc) \{\{nl\}\}TCP does not guarantee \{\{nl\}\}When Information Goes Out \{\{nl\}\}When Information Arrives \{\{nl\}\}How much information is sent at any one time… \{\{nl\}\}TCP does guarantee \{\{nl\}\}order and validity} \tn % Row Count 14 (+ 9) % Row 21 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Stacking Protocols}}\{\{nl\}\} Web browsing looks something like this \{\{nl\}\} HTTP \{\{nl\}\} TCP \{\{nl\}\} IP} \tn % Row Count 17 (+ 3) % Row 22 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Need our own Protocol}}\{\{nl\}\} If you can't guarantee when or how much data the program receives, how do you know when you have a full message: \{\{nl\}\} jim is great… ☺ \{\{nl\}\}…ly overrated ☹\{\{nl\}\}Answer: define a protocol \{\{nl\}\}For example: the character '.' will mean we are done: \{\{nl\}\}jim is great.\{\{nl\}\} Problems? \{\{nl\}\}Other Suggestions? \{\{nl\}\}How about writing the number of characters as the first byte?} \tn % Row Count 26 (+ 9) % Row 23 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Communication Example}}\{\{nl\}\} Question:\{\{nl\}\}Have you written a Program to Communicate with another Program?\{\{nl\}\} Answer:\{\{nl\}\}The Spreadsheet communicates with "another program" (itself) via saving data} \tn % Row Count 31 (+ 5) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 16 (cont)}} \tn % Row 24 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{What the server's connection thread does}}\{\{nl\}\} A SERVER DOES TWO THINGS: \{\{nl\}\}"NETWORK STUFF" (E.G., HANDLE MULTIPLE CLIENT REQUESTS AND CONNECTIONS)\{\{nl\}\} "APPLICATION STUFF" (E.G., MANAGES A GAME)} \tn % Row Count 5 (+ 5) % Row 25 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{TCP Handling in C\#}}\{\{nl\}\} A TCPListener object is at the heart of the server. \{\{nl\}\}Listens on a specific port for incoming connection requests. \{\{nl\}\} TcpListener \{\{nl\}\}BeginAcceptSocket – Wait for request to arrive\{\{nl\}\} EndAcceptSocket - Obtains the Socket.} \tn % Row Count 11 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 17}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{GSP Overview}}\{\{nl\}\} GSPs refer to tools, techniques, processes, etc., that are used to ensure our code is:\{\{nl\}\} Easier to maintain\{\{nl\}\} Contains fewer defects \{\{nl\}\}Examples include: \{\{nl\}\} Versioning (git/github/github projects) \{\{nl\}\}Design Patterns \{\{nl\}\}System Architecture decisions (e.g., MVC)\{\{nl\}\} SOLID, DRY \{\{nl\}\}Diagramming/UML \{\{nl\}\}Testing\{\{nl\}\} Unit Testing, Integration Testing, open/closed-box testing, C\# test syntax, e.g., TestClass(){]}…)} \tn % Row Count 10 (+ 10) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Chat Client Examples}}\{\{nl\}\} Some Key Issues: \{\{nl\}\} What is a stringbuilder (as opposed to a string)? \{nl\}\}Why do we use it?\{\{nl\}\} What is a byte{[}{]} (as opposed to a string)? \{\{nl\}\}Why do we use it? \{\{nl\}\}What are character encodings (UTF8)? \{\{nl\}\}Can we convert between these?\{\{nl\}\}} \tn % Row Count 16 (+ 6) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{More Key Issues}}\{\{nl\}\} Watch for Race Conditions in your code \{\{nl\}\}What values can multiple threads access? \{\{nl\}\}E.g., Client array \{\{nl\}\} Removing items from a shared list \{\{nl\}\}Network Realities \{\{nl\}\}How much data comes at once? \{\{nl\}\}Protocols: "what is a message?"\{\{nl\}\} 127.0.0.1 (localhost)} \tn % Row Count 23 (+ 7) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{Simple Chat Client/Server Key Methods}}\{\{nl\}\} Key Methods \{\{nl\}\}BeginAcceptSocket\{\{nl\}\} Wait for someone to talk to you \{\{nl\}\}BeginConnect \{\{nl\}\}(Ask to) Start talking to someone else \{\{nl\}\}BeginSend, EndSend \{\{nl\}\}Send data\{\{nl\}\} BeginReceive, EndReceive \{\{nl\}\}Receive data} \tn % Row Count 29 (+ 6) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Simple Chat Client/Server Key Concepts}}\{\{nl\}\}Key Concepts \{\{nl\}\} "Event" callbacks\{\{nl\}\} Older vs. Newer \{\{nl\}\} Await Async} \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Lec 17 (cont)}} \tn % Row 5 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Continued Key Issues}}\{\{nl\}\} How do you convert from an "object type" to an "actual" Type?\{\{nl\}\} Why is IAsyncResult.AsyncState not typed…. \{\{nl\}\}What is meant by an Event (Receive Event) loop?\{\{nl\}\}} \tn % Row Count 5 (+ 5) % Row 6 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{{\bf{New Version of Code}}\{\{nl\}\} Async - tells the system that the code may "pause" and "return" later \{\{nl\}\}Allows other threads to execute \{\{nl\}\}Await - tells the system to "wait" here (pause thread) until an "event" happens \{\{nl\}\}Let's look at the tcpclient version of the code.} \tn % Row Count 11 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}