So. Okay, as we'll see that your yeah it's better and let's okay.
Good morning, folks. let's get started so the plan for today is to go over the midterm solutions, and then I think it was to was my plan here. so i'm supposed to talk about Yeah, So today.
We're supposed to talk midterm solutions and operating systems.
So we will see how that goes. So now you have to.
So have you all gone through your midterm grades.
I know some of you have signed up for interviews this afternoon.
I will randomly select people, and I will email you with them to sign up.
So please make sure you check your email later today. I will send a message.
Once i've sent all the emails so if you don't get an email.
You will lace yourself. so i'll mess it on team one does, but not
So I yeah, you can go ahead and sign up for interviews.
Now, if you want to volunteer it's there on on teams under the Sas spreadsheet, why do I have to say so?
See? Yes, go ahead and sign up if you want you to sew. Okay.
So please go ahead and sign up for interviews Well, let's go it out.
Go through the solution. So they are right here and it term solutions and you don't.
I do not you can sign up at any time up to you it's it's just it's just a spread.
It's just a sign-up. sheet so I will say the average for the class for grades.
I had to check it again, but it was around. It was between an a minus and an A.
It was actually quite good. So most of you did very well on the on the midterm, i'll talk about the questions that gave you problems.
So the first one question one create a simple swift Ui proton that shows the low world at the bottom of the screen can all be give the kinds of content that we've done But only so I realized it was actually technically
a little ambiguous because it could have been the entire file.
But all I was looking for was just struct, so I should have said a struck content view.
But if you gave me the entire, you know contents of the file that would have been great.
All the additional parts is having the include swift ui, and you could have the little the content view preview.
That only is useful used in the previewer it's not used in
It's not actually used runt runtime so we can have that or not.
These note. The interviews are scheduled right now for Monday and Tuesday. so please do sign up for the interviews as soon as you can, because they're on Monday.
And Tuesday I can add more slots outwards, but I would really like to finish them by Tuesday.
Most of you got this, you know you have a spacer, you know. you just need one spacer at the top, and then it puts the text to the bottom.
So a few of you had some really weird solutions for the some of you tried doing like geology things and stuff was like, Yeah, but it's like you just do this.
It's simple. Okay, So then, for this one what will be the value of colors up to phase with code is executed array of 3 strings, right? blue green.
So are all. Almost everyone got these things you know have got you know Here's the array, and no because then you'd be defined at some that was immutable.
3. How could you change text analyzer? 2 so that yes, so that up, you know, textileizer mode, and we're both current.
And also at that This one, when I create this question this is the solution I was originally thinking of.
But i'm sorry I was not thinking of this first. solution. I was thinking of this solution creates why I originally signed at 4 points, because I thought it was me a little longer.
But actually, you can just added on right here, and that works perfectly fine.
But the way I was thinking of doing is you change this to pass in analysis, mode not a binding variable.
And then you changed. how was displayed? So that was this was my original thought.
But just having it aptile and sticking in there.
Perfectly fine works. Well, the when you select a new mode of text analyzer to the analysis of the text, immediately changes what parts of the programming content you're not Swift are responsible. making sure. the analysis results is updated when a new mode is
selected this question. You did very badly on. Lots of people missed this.
I would even say most of you missed this. A lot of you tried talking about how the code?
Well, this part of the code you know calculates the result and other things, and it's like a specific question is saying what parts of the program are responsible, making sure the analysis result is updated with a new mode is selected it's not saying what's the
code for the update is making sure the update happens and that's the it's analysis.
Mode is declared as a state variable and because it's declared as a state variable.
Any any view that references. it will be updated when the variable changes note the difference from Android.
We do not have this functionality in android and Thus we must manually make a function such as update analysis that we call at the right places, and if we don't call it the right places, the variable state and the display state will
get out sink. That cannot happen in Swift. You are. Yeah.
So? Yes, the answer was, this was not supposed to be that.
Yeah, the answer is, post me simple. Yes. but yeah, a lot of you missed this.
Why, in 73 is 77 textile use of for loop.
Can you place this for loop at the for each loop?
Now, many of you of you put this as a set of a for each loop.
All caps. You put a lowercase f for each, and yes, you could replace it with a for each that just takes a closure of some kind, and then calls it many times with the argument.
You know, I think you could use a lowercase f for each, and if you said that I gave you half credit, what I explicitly said, such as the one online's 56 to 61.
I say 56 to 61 you look here what's in 56 through 61.
It's. this it's in a view it's a very different thing from the lowercase for each irritating Kate.
But that's why I made a reference to the lines and the I think so many of you got this right.
You can't do it because a for each loop creased Great sift, you know.
Switch, Watt swift ui views it's not for arbitrary flow control and you can only use it in a view.
So you couldn't use it in this function so that that now is skin your you know the difference. Do you know what's weird about these capital for each thing, and that it is this weird view thing it's not an ordinary
loop that's, what I was asking there. how could you add a button erase input to text analyzer, 2 that erases the current user.
Input please place it. They place it after the user input area.
But above the result area. Literally, all you need is this button erase input action.
This. most of you got this This was I mostly saw some of you had some slightly more complicated syntax.
Some of you use the nice syntax where you can just say a race input, close it, and then just put the closure right after the closed parentheses.
We, which which is a cool, which is an interesting swift ui idiom.
For me. it always bugs me but because I like like what's this open code, I mean I understand why it's useful, but I don't know if that's syntax irritates me a bit but that's
perfectly fine, perfectly he'll I should have given you credit for that so most of you got this but note this is a closure so.
But again, we all got this remote pick view or 2 what's the purpose of images?
And what kind of data structure is it? There was a number of you who had issues with this in terms of everyone got there just what everyone got.
There was a dictionary. I gave you I think something great, so you call it map, which is basically the same thing.
But it's a dictionary technically I mean I said to say it was dictionary that maps strings to strings.
But if you said dictionary, I gave you credit for that purpose.
Part I gave a lot of partial mark so I that's 1 point for the dictionary thing, and then for the purpose.
Well, I was looking for so a lot of you just put it's a It maps the you know.
Maps a string to a url right Yes, but what's it?
For? Why does the program have it? What is it used for?
So, while looking for something about, be sure you know, names are displayed and known images, and it lets you.
You know it stores. It so here's the image name yeah, So something explanations really invest.
But something about why, what it's doing in the program not just what it is.
That's what I was looking for, so I a lot of you got like one and a half hour to for this song.
You know some ones, but some of you got choose, but I definitely a lot of partial marks on this one.
So when, after running the following code, what type is
What type is past, what are its contents the type? Basically, you got, you know, passes an array of strings.
Actually, technically it's substrings, the whole substrate type, I find, is, I understand, why it has that basically you. The reason why it has a substring type is probably because it doesn't allocate any more space and just
uses internally pointers to into an existing string.
But that substrate type is, I find, weird but passes an array of strings with the contents of this.
Almost all of you got this I say if you're array a string.
This. I didn't need some a few of you set upstream, but I have started literary strings.
So what is a substrate? A substring is a specific type that you get for things that take substrings from strings, so up to partial string from another existing string, and when you have a substring type it really
means that , This is what it really means is this is not an independent data structure.
The substring is related to a string so you can't Have them have the substance separate from the underlying string a string.
Is an independent data structure. So when you're first if you're just trying to get pieces of this let's say I want to use a certain part of this you know if I know which part I want it wouldn't have to
turnvert them all in strings, because we convert to a string. it's doing a copy a substring. It probably doesn't copy the whole data structure.
It just has references to it so it's just these are all like this.
This array here has a bunch of pointers, probably pointing to the parts of this.
So wolf you're right I mean it's like Why not just call the strings?
I mean I it. It really is an implementation thing that they're trying to probably save 200 save some space or something.
But I yeah, anywhere you're gonna use it you never pass on a substring.
Substrings are returned to you, and you almost always are going to do anything with it.
Convert it to a string so yeah so I don't I don't like this that's why you need an app if you if you just said string that's how I think of it I didn't think of upstream
but triple tap actions well supported. Swift.
You, I explain and give evidence. most of you got this but a significant minority.
Well, what's a sigma if some of you did not get this?
I tend to think those you didn't get this do the assignment or kind of skipped over part of it, because very clearly there was a question on the assignment that showed you that Yeah, I mean Some of you said it.
Was supported. but it doesn't but if you do it there's an interference with other ones I should have given you full credit for that.
But the idea here is you put in a triple tap, and then you put in a double thing, put in a doubletop and a single tap that works fine.
You put a tripletop, a double tap at a single tap the double tap doesn't work because the double the the triple.
Either you get triple tap or you get a bunch of single time.
It's on this. This is yeah this one was almost like Did you remember from the assignment when we did that thing?
Lines 81 to 92. and what pick viewer call a number of methods that modify the state behavior.
The displayed image is the order of this method call significant.
How do you know almost everyone got this? This was you all.
You all got this, and most of you referred to this question the assignment or talk us.
There is a couple of places where there's very there's a number of order dependencies in this cuddle.
If you look at so reese if you're resizable has to be before scale effect.
I think nothing scale to fit has to be before scale effect those things.
Position, Really, position, position is relative to scale, effect and rotation effect changes how they behave, and really dictation, effect, and scale effects should be before them.
They are the ordering of the tap gestures some people has talked about, because if you have one before 2, then the 2 one will do anything.
So there's a number of dependent you know things that will potentially change.
Some of them can be moved around a bit like You just switched the dragging and magnifying gestures.
It'll be the same but yeah there's definitely an order of dependence, However, place and Okay, so that and then 11, when specifying a gesture handler when would you use it on change handler and when we use an unended
handler give a specific example for each. So most of you got this.
Some of you were a little where you lost points. Most of you got on changed.
Some of you were a little. You mentioned what our existing program uses for the on-ended, but some of you were rather unclear.
Why that was needed. So some of you lost marks for that I mean.
The main thing is knowing. What What would you do with an ended gesture?
You know you could help me if you just describe some scenario where it made sense.
Then actually given the credit. But for these sort of things you can use examples from the assignments we've given.
But like I ask a more exam abstract thing I would you'd be just as good as describing some arbitrary application. You know.
Even you know things that you've you know other apps that you view, or a game, or something like that you don't have to refer the assignment directly.
And that's it so again you mostly did very well in the midterm.
I I was I was thinking it wouldn't I didn't think I made it particularly hard.
But but that was a I was happy to see Now you don't do that. That would be a great example.
Yeah, like the on change the dragons. Yes, exactly. Yep.
Yep I want to i'm a little bit quicker so, Poll. here, Baba, I think the early remainder, you know moderately.
Let's say no i'm not gonna make it easy.
I mean I have the grades for knowing how it is i'm more the procures like just now you've seen your grades like I didn't have to this poll after you've actually seen the grade
i'm Not the difficulty of the of the final exam will be based on the second half. and so that's kind of different from this.
See what? Yeah. So you have not responded yet. Go on, guys.
Do the poll up for the final. The final is going to be on. So it's going to have Swift Ui and Kotland, you know, and Android.
So the languages there'll be some swift and some copper, and and they're expect there to be some questions connecting the 2.
Let's see how the poet so Yeah, so it looks like 30.
You thought it was pretty easy, but two-thirds were.
No one. So it's very difficult. Okay, yeah that sounds about right Any other specific questions.
Otherwise that's what I talk a little bit about operating systems I'm not sure what I want to talk about operates systems fillless system.
So one thing to know about both so if you have other questions i'm happy to talk about them. but I just wanted to give you a just a little introduction to what you're going to hear about in operating systems third year
so both Android and Ios are built on unix-like systems.
So when I say unix like, I mean Unix is really a family of operating systems.
You have their descendant to a system that was created in the early seventies.
So it's like a 50 year legacy. so anyone know the basic architecture of modern operating says Well, what's a process?
Zoom know what a process is. They all know that term.
So if I go over, not in operating a series of step, a process to do something in it.
A process in a process is just a running program. A process is a running program.
So when you if I go over to let's see do I have my home, we want there's a command line one.
But so if you go to something like this any modern computer you'll see listings like this. you get a task manager on windows, you get activity monitor on Mac Os on Linux. I normally do things like this and I
can see what's running. Oh, my backups running in the background.
So these are all processes. These are running programs now we what's the difference.
So so this is the I. So a process is the abstraction that allows multiple programs to run on the computer at the same time, like right now on this computer, I have this text editor Emacs: running.
I have so zoom running, I have a web browser running, and they're all running at the same time. logically.
They're all interactively doing things that i even if I had one core.
You know, we now have multi-core systems. But even if I had one core that all these programs could still run at the same time, they just would take turns so.
So this is the basic idea of what's happening under the system is we don't have one program running getting access to all the ram and all of the processing power. you have many programs running ram is partitioned between each of
these running programs, and the cpu is multiplexed so that you know the Cpu can a given cpu can.
A given core can only one run program at a time, but you let a program run, and then you interrupt it and switch over and run another program and then switch over to run another program and the switching can happen very fast.
Like when one hundredth or even less of a second so it seems to the user that they're all running at the same time. and the process is the abstraction that's used for discussing this combination of a running program
getting some out of memory and some amount of cpu time.
And if you go over to these system monitors it tells you information about that tells you what percentage of the Cpu it's getting telling you how much memory it has so how much disk it's accessing you know like
all this, all these stats let's tell you about Who's getting up because they're all sharing the same set of resources.
So the operating system kernel the part of the system.
That implements this opera, this process abstraction, and is the one that forces the sharing between these running programs.
So our processes divided. so that if you have less running, each gets to run more often.
Yes, the fewer processes but it's not that simple because some processes need more.
Cpu time than others actually most of the processes on your system are mostly sleeping. they're mostly not doing they're sleeping. They're not doing any work.
So you notice that all these ones that say they're there.
But they're way basically they're waiting for them to be asked to do something.
So most of the time they have no work to do. So they sit there waiting for a request, and when they get a request, then they, you know, kick into action.
They do stuff. but then other ones are busy doing stuff like, for example, this duplicity process.
In Deja do. They are backup processes. They are creating a backup right now, and so they are running
So fr you know some fraction of the time and i'll say wealthy.
So if I cpu time, who's damaged So Zoom is taking up most of my cpu time and duplicity, saving this now interesting contrast, this says 28%, this view says like 200%, because here one
100% in this view means that you're using an entire core and this machine has for the view of Linux 8 quarters.
It's actually a 4 core machine which is hyper-threaded.
So to the operating system it looks like 8 cores.
So 8 programs can be running at the same time. 8 processes.
And so here this is talking in terms of a fraction of like of those
How many Cores you're taking up year this is in terms of total things you'll notice here. if you add all this up.
It's at most, getting up to like 40% there's still a lot of headroom for this thing to run.
So does each process specify a minimum amount of dedicated resources or some problems?
May I take up multiple course? Yes, some processes. yeah, some.
Well, i'll show you a process that's definitely multi-threaded that takes up multiple cores.
We use all the time your web browser. cure Web browser takes up multiple cores, and we'll I mean, if you do some stuff in your web browser, it will suck up as much resources as you give
it The fact that my web browser has one tab open, and it's only running this, you know this ain't taken much chrome is particularly demanding.
Yes, but all Major Web Browsers, if given the right pages to load, will take up a lot as many resources that you throw at them.
So when we So the Os so the operating system kernel is the one that facilitates a sharing between these process implets process abstraction address the operating system kernel is the program that's
in charge. . Sorry i'll what Why, what happens I miss the context for your question joke.
If you want to elaborate or just speak, why chromosome?
Demanding The original reason why Chrome is so demanding is because it allocated a process to each open tab.
And so thus in other browsers, would share have multiple tabs in the same process.
Chrome required a process per tab. And so you have a lot of tabs.
You have a lot of processes. but other browsers are increasingly have moved to a process per tab model.
So that's. some of them are so you can't There are, yeah, some of the I think there are ways to set quotas on the problem.
And there are. there are even like things that let you see which tabs are taking up.
Which are the most resources. But the honestly. a web browser is kind of an operating system to itself.
But that's what you have with chrome os is it's, you know, to think, do make the web browser the entire Os.
But yeah, yeah, it's chromebook. you but even there there's Linux underneath.
Because there is more stuff actually running on chromebook than just But the operating some kernel is a program that facilitates sharing between.
You know, you know, sharing between running processes. Yeah, actually. but it implements the running, you know, running process things up.
The key idea of how the kernel runs is so regular processes run on the Cpu.
What's known as user mode in user mode It's inherently locked down.
It doesn't have access to everything on the system but in kernel mode, you know, when you're running the kernel it's running in supervisor mode in the cpu so as access to
everything. So what's a this is Why, plus they won't whale? They're waiting now to accomplish That's why device.
Driver errors are so dangerous because if there's a problem in your kernel.
That can crash all your processes if there's a problem in an individual process.
It crashes, but all the other processes keep running modern system.
Older computers before you have this kind of architecture. One program crashes.
Everything was gone. but a modest systems of you know my text editor freaks out. It won't mess up the rest of my system. I can.
That's why I can close it and then everything's fine operating systems on mobile and desktop are basically the same.
So you have the same basic pros and processes especially on Ios processes are much more sandbox from each other.
They can't just freely interact like right Now, my emacs process can interact with my web browser without much issue.
They can send messages to each other and mess with each other, and stuff. but that's not the case on Ios.
Those processes are much more separated. there's been many more connections added between them.
But it's still much more restricted than a desktop os and same thing for android, although android is built on a system that allows for more communication between the parts, so you have extensive the
the other big difference that you don't really see on desktop operating system like if I want to access the address book or a camera, or you know, location of the laptop normally read any printing program, has access
to that. but in a mobile operating system you have extent, this extensive permission infrastructure.
We haven't really talked about that will definitely be talking about that in 2,601 that these you have the programs have to have special permission to access those things and nowadays that's often implemented by a little
interactive dialog box. but on Android they also have these whole manifests where they say what permissions they want.
The the permission infrastructure on Android is much more extensive.
Apple has many fewer permissions, because mostly it just says, No, because, apple reserves a lot of the lower-level stuff to itself.
It does allow third-party apps to do a lot of things, and when it does allow it does it in very specific ways.
Android that all the mechanisms are specified through permissions and an old dial android you could replace almost any component.
And just say, Okay, this other one is handling this task although that's increasingly locked down in modern android environments.
I have much more to say on operating systems.
I teach a whole class on this. but this is actually the core of stuff.
I'm happy to answer questions about it. but otherwise I don't need to fill your brain with too much stuff.
I just wanted to like. just give you a little bit of a mental model of what's happening underneath your computer.
And signed to be learn about as you go through the curriculum any final questions.
Happy to talk about this more, or you might see me in 3,000.
I will be teaching 3,000 in the fall I will not be teaching at the year after. I will be on sabbatical.