Presentation is loading. Please wait.

Presentation is loading. Please wait.

CISC/CMPE320 - Prof. McLeod

Similar presentations


Presentation on theme: "CISC/CMPE320 - Prof. McLeod"— Presentation transcript:

1 CISC/CMPE320 - Prof. McLeod
Winter 2013 CISC/CMPE320 8/25/2018 CISC/CMPE320 Notices Teamwork: You don’t have to, but if you wish to send RAD completion notices and links out, send them to your “mentor” instead. Assignment 2 due Friday, this week. Fall 2017 CISC/CMPE320 - Prof. McLeod Prof. Alan McLeod

2 CISC/CMPE320 - Prof. McLeod
Today Finish up Operator Overloading. Repositories. Fall 2017 CISC/CMPE320 - Prof. McLeod

3 Overloading the Function Call Operator: ( )
Allows an object to behave as if it is a function. Called a function object. The only operator where the number of arguments is not fixed or limited to one or two. See the RandomInt class. Used in the STL. Fall 2017 CISC/CMPE320 - Prof. McLeod

4 Aside - inline Functions
Used in the RandomInt class. Used when the function body is short: ≤ 3 assignment statements. one conditional. one return. An inline function is not placed on the activation record stack, but is expanded in place and so is executed faster. Must be in the declaration file. The downside is that a copy is made every time the function is invoked – so it should be short. Fall 2017 CISC/CMPE320 - Prof. McLeod

5 Seldom Overloaded Operators
Address-of, & boolean logic, &&, || The comma, , Member access through pointer, ->* Not really useful… Overloading new, new[], delete and delete[] may be a bit more useful, but they are difficult to do properly and seldom really worth doing. Fall 2017 CISC/CMPE320 - Prof. McLeod

6 CISC/CMPE320 - Prof. McLeod
Final Cautions Beginning C++ programmers can get enthused about operator overloading! Make sure that the overloadings you code make sense to anyone reading your code. If they do not, write a member function that does the same thing instead. Fall 2017 CISC/CMPE320 - Prof. McLeod

7 CISC/CMPE320 - Prof. McLeod
Final Cautions, Cont. Don’t forget that you cannot change operator precedence. Suppose we overloaded the operator ^ for our complex number class to give us exponentiation: a = -1 + e ^ (i * pi) Normally the exponentiation would take place first in a normal mathematical expression. But ^ actually has a lower precedence than arithmetic operators since it is a boolean operator. What you actually get is: a = (-1 + e) ^ ((i * pi)) Fall 2017 CISC/CMPE320 - Prof. McLeod

8 CISC/CMPE320 - Prof. McLeod
Final Cautions, Cont. In this case, it would be much better to forget the overloading and just use a member function instead: a = -1 + pow(e, (i * pi)) Fall 2017 CISC/CMPE320 - Prof. McLeod

9 CISC/CMPE320 - Prof. McLeod
Repositories What if two or more people want to edit the same file at the same time? Option 1: make them take turns But then only one person can be working at any time And how do you enforce the rule? Option 2: patch up differences afterwards Requires a lot of re-working Stuff always gets lost Fall 2017 CISC/CMPE320 - Prof. McLeod

10 CISC/CMPE320 - Prof. McLeod
Repositories, Cont. Fall 2017 CISC/CMPE320 - Prof. McLeod

11 CISC/CMPE320 - Prof. McLeod
Repositories, Cont. Keep the master copy of the file in a central repository. Each author edits a working copy. When they're ready to share their changes, they commit them to the repository. Other people can then do an update to get those changes. Even one coder can take advantage of this system if he works on multiple machines. Fall 2017 CISC/CMPE320 - Prof. McLeod

12 CISC/CMPE320 - Prof. McLeod
Version Control You might find that your work has gone completely in the wrong direction or you find that the errors are piling up – you might need to throw away some work and return to an earlier version of the software. Or you might just need to know the author of the latest changes to a file. Fall 2017 CISC/CMPE320 - Prof. McLeod

13 CISC/CMPE320 - Prof. McLeod
Version Control, Cont. The repository can store previous versions and keep track of who commits what and when: Fall 2017 CISC/CMPE320 - Prof. McLeod

14 CISC/CMPE320 - Prof. McLeod
Repositories in Use Commercial ($$): Perforce: Older: CVS: Replaced CVS: Subversion (or “SVN”): CVS: “Concurrent Versions System” SVN: “Apache Subversion” or just “Subversion” Fall 2017 CISC/CMPE320 - Prof. McLeod

15 CISC/CMPE320 - Prof. McLeod
Best? - Git Stands for “Git”. Originally designed by Linus Torvalds starting in 2005 (what else did he design?). Built for Linux kernel development. Every git working directory is a full blown repository. Much faster and smaller footprint than SVN or CVS. Less required server interaction! Fall 2017 CISC/CMPE320 - Prof. McLeod

16 CISC/CMPE320 - Prof. McLeod
Git Structure (Image from Wikipedia) Your local repository consists of three “trees”: The working directory is just that – the files that you are currently working on. The index is a staging area. The local repository contains links to your last commits. Fall 2017 CISC/CMPE320 - Prof. McLeod

17 CISC/CMPE320 - Prof. McLeod
Git Terms You clone to create your repository. You add to put files in the staging area. When you are ready, you commit files to your local repository. You have created a snapshot of your repository. A push sends your snapshot out to the remote repository. Other users will get your updates by using a “fetch” or a “pull”. Fall 2017 CISC/CMPE320 - Prof. McLeod

18 CISC/CMPE320 - Prof. McLeod
Git Terms, Cont. A fetch just updates your local repository and adds information to your log files and version records. It is pretty harmless and should be done frequently. A pull carries out a fetch followed by a merge of the Head branch. This will update the files in your working directory to the latest versions. If two people have changed the same file before the merge operation you get a merge conflict that has to be resolved. Fall 2017 CISC/CMPE320 - Prof. McLeod

19 CISC/CMPE320 - Prof. McLeod
Server in Git This is a de-centralized repository system. Everyone has a repository and all the necessary history and version log information in compressed format. Interaction with your local repository is very fast. You can do a lot of work without having to do a push. The server acts mainly to facilitate communication between all the separate repositories. In SVN and CVS the server is the single repository. Fall 2017 CISC/CMPE320 - Prof. McLeod

20 CISC/CMPE320 - Prof. McLeod
Git Branching Features can be developed in an isolated way by creating a branch. Eventually it will merge back to the “master” branch. Fall 2017 CISC/CMPE320 - Prof. McLeod

21 Repositories in Use, Cont.
You need a server, we have bitbucket on caslab. Or (if you were not in this class) you could use a cloud-based server. And local client software. Such as “GitKraken”, “SourceTree” or “SmartGit”, etc. Many others, or your IDE (like Eclipse or Visual Studio) will have a git client built right into it. Also popular: GitLab and GitHub. Fall 2017 CISC/CMPE320 - Prof. McLeod

22 CISC/CMPE320 - Prof. McLeod
Conflicts What happens when two people commit the same file? Fall 2017 CISC/CMPE320 - Prof. McLeod

23 CISC/CMPE320 - Prof. McLeod
Resolving Conflicts How to prevent? Option 1: only allow one person to have a writeable copy at any time (lock the file). This is called pessimistic concurrency or lock, modify, unlock. Used in Microsoft Visual SourceSafe. Option 2: let people edit, and resolve conflicts afterward by merging files. Called optimistic concurrency or copy, modify, merge. “It's easier to get forgiveness than permission”. Most modern systems (including Subversion) do this. Fall 2017 CISC/CMPE320 - Prof. McLeod

24 Resolving Conflicts, Cont.
Using Git “terminology”: Hermione attempts a push, but Ron has done a push after Hermione has fetched (or cloned). Hermione’s push will be rejected, even if she has not changed the same files that Ron has changed. Hermione must do a fetch and merge to get Ron’s changes before she can push. Ron’s changes will be applied and then Hermione’s changes will be re-applied. Fall 2017 CISC/CMPE320 - Prof. McLeod

25 Resolving Conflicts, Cont.
It may be that changes do not overlap, so a merge will work automatically, but if there is a conflict: The resolution process allows one person to view a merged file, with the differences marked. This person decides which revisions to keep/discard. Only works for text files, not binary files. If more than two people submit the same file – then the project needs better management… Fall 2017 CISC/CMPE320 - Prof. McLeod

26 Conflict Resolution, Cont.
Fall 2017 CISC/CMPE320 - Prof. McLeod

27 CISC/CMPE320 - Prof. McLeod
Repositories, Cont. Note that not only are file changes tracked and recorded but directory structure changes are also monitored. Always add a comment when you commit noting your changes in a general way and why you made those changes. Was this a response to a bug fix, for example? Did you run your unit tests on your code before you committed? Fall 2017 CISC/CMPE320 - Prof. McLeod

28 CISC/CMPE320 - Prof. McLeod
How to Use Git, Cont. Fall 2017 CISC/CMPE320 - Prof. McLeod

29 CISC/CMPE320 - Prof. McLeod
Fall 2017 CISC/CMPE320 - Prof. McLeod


Download ppt "CISC/CMPE320 - Prof. McLeod"

Similar presentations


Ads by Google