It might be the improvement but, yeah. Hard to say.
Okay. Good morning everyone.
Let's go ahead.
You actually don't need that terminal.
So, let's go and get started so just review where we are right now, we're up to now it's lecture 12.
So February, 18.
Next week is a break.
And so coming back is March, march 2 that will the midterm review, and then we'll the midterm exam, we will discuss solutions for assignment to just before the midterm exam.
So, my plan now so I'm.
Second March 1.
How's the sound to everyone in terms of assignment due date so.
When you say midnight, the 23rd is that also means 2am the 24th. Okay, fine.
Ha, too am
a lot of my dissertation was done between 10pm and 2am.
So, anyway. Any questions about about this. Again, you think questions or more points scheduled interviews so like we would schedule it after the exams for I'm confused about that part.
So the idea is that you'll do the midterm, the niche will get graded.
And you'll have solutions for the midterm, and then there'll be interviews.
Oh okay, because there's no point in having an interview to discuss the midterm until the midterm has been graded. Gotcha.
All right. Thanks.
No problem.
Any other questions.
So Mitchell, will be assignment on bright space which is the same for.
Yes, but the money. That's exactly it so.
So, two hours,
which is.
92 hours for like a final exam, it just so happens in this class on time, class period is two hours so I could give you shouldn't feel time pressure too much.
Well, you feel some time pressure.
Any questions or that why haven't made it up yet, but it will be probably like 25 or something.
So there were that many.
So, bottles.
Not product, price close a few or not. I have to see how many questions makes sense given the material.
But again, it's the test should not be bad if you understand the material the assignments.
So just because you got the code word does not mean you understand the material. So, make sure you explain what's going on.
You shouldn't need to be googling things in the middle of the midterm, it is open book.
good mental model going to class.
So, the interview really is more just going through and seeing what points you missed, and just trying to understand why you miss points, and if it turns out you got them all right and then there are probably more ask you questions about what you got
right but my goal is really to see what do you understand, you know, and is this matching up with what's on the test because really, what's my goal I'm an educator, ultimately, and this is a learning opportunity you've gone through and answer these questions
you made mistakes and now I can talk to you about it and see. Well, where's your misunderstanding hopefully give you some tips for moving forward.
tutorial tutorial five.
My position on 25 is not directly covering the first two assignments, but if you look at it and then look at swift you and realize the differences that helps you think, oh, that's what's with you is doing.
So, it's worthwhile.
Does making notes help for the exam, again, it's not a memorization thing so you can look at your life, making notes is potentially useful but
I'm more of a like do I actually know what this code is doing. I mean, when you look at these things go like, what the heck is.
Now, I'll have a sign up sheet for the interviews.
I'm hoping for.
max will come up over the break.
I'm not playing with interviewing, all of you because that's a lot of interviews I probably will do more like half will see, but if I, if I request that you do an interview, then it's mandatory.
Good.
Well the office hours on the way to ask something about we don't fully understand get checked off the tutorial that we are yes I'll definitely have office hours on the 20 days.
And always feel free to message me on teams. If you find that you have some question or something we, the general questions, post it on one of the discussion forums and you know me and other people can chime in if you have something that's that you feel
you only want to ask me, just send me a direct message, you can email me, I think it's better to send me a direct message. And then we can, if necessary, we can schedule a time to talk.
So, I will only talk to you during off so just that's the only time I guaranteed to be around.
Thank you.
Anything, um, let's move on then I would say more questions, but feel free to ask so I am open to answering questions about assignment to or the other tutorials.
If you have something about them please let me know. Otherwise, I want to talk about tutorial six.
I want to, because we are moving on to Android development again, this I think will actually help you understand what's going on with this because it's all about building your mental model.
So I will try contrasting this with the other stuff.
Oh.
Okay, well let's move on.
So, Here we go, we've got
text analyzer running here, this is the Android version.
Oh, nothing there. The analysis node uppercase to count.
So basically the program we've been expecting nothing particularly exciting.
I will however make note of a bug.
What Well, yes, but this is a bug, we will not discuss how to solve it, but it's something you should be aware of. So let's rotate this. So you notice when you rotate it didn't rotate this little thing right there you got click on.
And then it rotates.
And I don't know if you can quite see this and see if I can see here, notice what happened there.
So choosing analysis mode, I will choose count, count is here, hello there stays there.
But now let me.
Rotate again, this thing here.
And please choose analysis but it forgets my menu selection, when I rotate.
So y'all say yeah so basically I do a rotation you first go up here, go to rotate left go to rotate right rotate, but then you have to like click right here, there's a way to enable otter rotation, I forget what the setting is.
So like the but forget see you go here. Count it remembers that but this will be important later but just want to show you that notice in iOS we didn't have to do that.
NATO.
How do you enable remembers how to enable otter rotation.
Let me know I know there's a way to do it but I forgot.
How does rotating change values that doesn't seem intuitive. So, yeah.
Notice on iOS we didn't have to worry about that. But we do have to worry about such things on Android.
Anyway, let's talk about the structure of an Android project.
So, there's a whole crap load more stuff here and then when you see on iOS, we actually almost all this stuff has an equivalent and iOS is just don't worry about it so much in kind of it this is a little bit more in your face with Android.
So there's our main activity.
This thing so this is basically equivalent to content view.
And by the way, there's all these nice little things for folding up things like these dots that means that stuff has been hidden from you.
Good to know this is, you know, this is there but sometimes you need to see it.
But yeah, we have our code here, this is much more like storyboard Of course because we have this Caitlyn file, and you have this XML file, which we can go
over.
There we go.
So you see we've got this, this view here where we see the design of it. There's also a insanely awesome this blueprint mode, which kind of shows more where things are and how they're related to each other.
But then of course we can go to the code view where we can actually see XML he knows the XML heck of a lot cleaner on iOS. But I will say, you have to probably spend more time the XML mode here then maybe an expo.
So looking at this, so first off let's look at what this layout actually is.
I can't trust it. Yeah.
Yeah, it's kind of very good contrast the year.
There's some basic things about saying okay here's the thing they're xml version. There's all this stuff you're basically you can mostly ignore this except to know that.
Whereas this context, this is all in the context of main activity. So this matters because this is essentially saying we're in the context of activity kt.
Well, I think it's actually in the context of this class.
But, so this matters but then we just have our descriptions of the widgets and the widgets, all have a button, it has an ID. This is very much like on a webpage you want an ID for referring to the HTML in your, in your JavaScript.
For those of you know web programming but you know you have an ID we're going to use that to access this from code.
And then we say the layout with layout height. So rap content, which is sort of a thing saying yeah try to make it fit but you know, might have to wrap, as opposed to truncated.
I got this margin top okay 26 display pixels. So that means, I just like card code that is a value to the space that down a bit.
And then I'll explain these other two here but then there's this, the text of this analysis mode that's what's in the button.
Then layout constraint to end start up to top so starting and our left and right.
You might say why isn't it say left and right well because I think it reverses if you change the direction of the text, not completely sure, but instead of left right, it's starting and is the left right thing and top and bottom is the top and the bottom.
So we're saying constrain the end of this one so the left side to the end of parents so what the view that it's inside of the same thing for the right side, you know, start and end and then the top of this is constrained to the top of the pack.
So that's what we want to be up against basically 26 display pixels from the very top.
What's the duty the Android app prefix
this these are just XML name spaces, I don't really know exactly, honestly you don't type this stuff in from scratch. This is stuff that you would have to go look up or let the ID generate for you in terms of like the exact XML for this, but
I mean for waking. Yeah, I mean I feel like the app layer is used for layout things and Android user more functional things but
I don't know.
Seems pretty arbitrary to me.
But, so yeah, but so but this but these app layout constraints business hangouts later, then we have this text view. That's our.
That's our viewing of this now this is the headline taxes text analyzer. You know, we give it an ID the ID is always in your ID plus slashing the name of it.
By convention and not sure.
But then we have nothing saying what text appearance. Now, notice the compatibility coming in here, scroll bar here, it says, text our periods, app compact display to this app compact thing is part of the Google supply frameworks for dealing with compatibility
across different versions of Android.
By default Android Studio makes you use those which is, which is convenient, but also if you care about just doing things on open source platform that might be a problem.
Bold layout, but now it's now we say left and right is basically connect to the outer thing but the top and bottom are constrained to go you know the top of this is the bottom of the button menu button, and the bottom of this is the top of text field.
So here's our text field.
Same basic thing and then the text you down here.
So the.
Okay, so what I was I'm
almost this stuff is just basically layout, it just basically saying, This is what it's going to look like.
Except for one line.
And that one line is this right here.
Android on click showman.
So here is a connection from the layout to the code.
That means that when we click on this button.
We call the show menu method.
Let's but now let's go over to main activity here so now we get no app compact activity again when everything is compact stuff. This is all the Google Play Services stuff, which is wrapping multiple versions of Android functionality up, but there's a
class of type this, and we look through here will notice that show menu is a function.
The function that takes an option of a view, which is, you know, what was the view is in and then we basically say, do a pop up menu.
Basically on that button that v is basically the button, and then here's where we make the button.
And so that this this part should seem pretty straightforward we've you know menus a pop up menu and you know this, the. So here we go through analysis keys.
You've seen that before and we make meant we add them to the menu basically all those strings. And then, and then we basically say what to do when you click on these items and then show them.
But this. So what, so do you know what this double colon means
I don't know what that is.
So notice we didn't see any so mostly this kind of looks like Caitlyn.
What are the differences, you'll see here with this code. Notice we have vows instead of, let's
We say fun instead of funk function. When we declare a function we just say Colin's the argued for the return value, rather than an arrow.
Is it a scope resolution up read resolution operate like and see.
It's, it's kind of a scope. I think it's basically a scope resolution function, although it doesn't quite make sense.
Clearly, is that what this is is our menu item click is a function.
I want to pass that function as a closure. And so whenever you do whenever you want to pass a reference to a function. Treat it like an anonymous closure passing it around or something, you basically sticking to colon in front of them going like, you
will know it's a function.
Why do I have to say this, it just, if you don't do this as he says Do you want to call the function. It's like no I want to pass a reference to it become a treat as a first class function.
Stick to Colin's in front of it.
Fine.
So, and in fact, this is what you'll see. So this coach look very, very familiar here now this is direct translation of the code that we've seen before.
But what you'll notice is count to count characters colon colon count characters. I just,
I forget what the inline closure syntax is and Caitlyn.
I can do that I should remember it being really annoying. So instead I just defined the function separately I didn't try doing the in line and just use these references here.
I'll show an inline function later I mean, we do use inline function. So, but, but yeah so these are functions so this I want to pass up, you know, This is a map, referencing the two
others, so Oh but the.
So we saw that the show menu, that's kind of what you know that's not too complicated knows we're having a regular for loop to do things, but if we go back to
tutorial five.
We look at how we made the menu.
You know, for mode and analysis keys. This is essentially the equivalent code.
Right. But here I was actually passing in.
This is a little function that I've defined.
I didn't do the inline function here.
The function that's being called their update analysis is still here. Update analysis is going to be called on menu item click is what's going to do it, we define that explicitly then notice was a do it just calls.
And notice was a do it just calls. It just gets what the mode is from the title of the,
of the menu item that was passed in, we set that to the analysis mode and then we just call it update analysis.
So, if you just go through I mean this is worth going through and follow me. I can't explain all of this in full detail without boring you I think I'm already boring you a lot with with going through this.
But what I can show us a couple of things just note. Notice how we define maps. So here in New I wanted to find a map here I just said.
But analysis equals this, you know, do this you know how this funny syntax for this is saying, this is a string that the map and match the string to a function that takes a string and returns a string.
Instead of this.
We have this.
We have this we have mutable map, which takes a string, and that was an opportunity string and AK function one. So what is k function one. This is a function that takes a string as an art, a one art is a function that takes one argument.
And, and has returned values so the one argument for this case is a string, and the return value is a straight.
And so those two things and then we make a mutable map of.
And we give it this a lot more verbose.
But maybe clear I don't know, depends on what you like, but that's certainly more verbose but not horrible again look at how many can we define the set.
So here we defined a set, we say, upper cases, no let upper cases set of character character, and then we give all the stuff here, here is that we save vow, uppercase set of.
And then we give a list of characters
is, is if uppercase contains see what I have here is a per taste contains see to string, because this is a set of, you know, characters, as I see when you do this here this is a character on a string.
And so characters you have to convert to a string here, don't have to do that.
Here I do count plus equal one your account plus equal one.
I see if I can actually bring this code
should let me just
what's,
what's worth doing is
comparing this code side by side, just to understand how
sure not these things are so count, upper.
You know the differences like oh wow they're definitely differences but
it's more annoying languages having all these little differences and syntax.
And that's the reason why I want to start with a direct translation.
Another important thing to note is this stuff. So this was all ideology, remember we had to drag and connection on next code between the things those little outlets in order to link up this code with what was happening the XML and actually it was happening
on the XML but that was really painful thing so you have little circles and you connect them know that in Android Studio.
Instead, what we do is we define the variables here.
So we know we have tea. And we have analysis result.
Turns out, we don't need those other two here so much. But we define those two. But we define them as private variables we say late in it because they're not going to initialize window us first created is going to initialize on create and on create it
sets those values by using this thing called find you by by ID in the ID is all our.id dot the name of the thing we want. So this is where I think the convention comes into the plus.
In the XML, you'll notice that we have these names that go start with outside plus ID slash t
Id slushy so this is T, and the same business analysis result. So, if you look up here, we do our dot layout dot activity main are the different bits are the ID, T.
In here we do our ID data analysis resolved.
So we're doing these find view by ID.
But in storyboard instead of doing these find you by IDs, which declare these IP outlets and then we do this connection pointing thing between the two, same result.
Different philosophy.
This, I'll be honest, the five view by ID is more verbose, but I like it more because I really hate drawing between them. And just those me just doing in the gooey way I get it why you'd want to do it but it's just annoys me.
So, so yeah.
The other big difference to notice, which is not here is.
So, when is update analysis called.
It's called whenever we have during the week you know basically when you do analysis there. And this do analysis function is called whenever there's a change in the state of the of the of the text entry widget
is so good question here so what's what's going on with our. What the hell is this thing are is provided by the, it's not the Android API, per se. It's, I would say it's more the build environment it's something that's in the IDP you get these constants
that are different. I guess it's not the ID, but the great old build environment. It defines these constants for you.
This r dot something which lets you refer this is what lets you access things in the XML, and various other various other files. So, the XML file so like this is, I want to refer to, you know, the activity set content you, this is how I associate this
code with this XML.
This is, this is the key operation for connecting those two.
Now,
on Android the code is primary and it connects the XML. I feel like on iOS story with XML is primary and it connects to the code,
slightly different in terms of priority.
But yeah, this is defined for you automatically. And what's even better is when you're in the, in the developer if I want to say something like, if I want to say like, you know, r.id dot, and it will actually pop up all the things that are, you know,
things that knows this puck, the first thing that comes up or the stuff from like, NASA's button menu and also have Coyote. They're all right there.
If I say layout.
You know, and then it automatically says what layouts, do I have.
And there are other ones there but it kind of gives you the most obvious one, so there's a lot of good auto completion here. And frankly, coding this without that with.
Like for example,
when you, when other thing to know is like you have these inputs here. How did they remember, and get all of these inputs and outputs. I didn't do this directly.
What I did was.
So let's let's just delete one of these.
So what you'll notice now is that, so if I had typed this here, you know little nit analysis results, and I said text you, and it's a text view and I go like it's in red.
I just click on it,
it will right click on it show contact button If I click on it.
And so here you can just say, import.
And then it automatically adds in the import line here. So that's how I did all these imports was I typed in saying oh, that's not defined. Okay, go to the context menu and select Import and then it pops up.
Now if it's something that way, this, I shouldn't need to import this as you need to find in my code. Then you go like Oh Do I have a typo or something like that.
Yes.
Yeah, your life really.
I'll tell you that.
Modern, it is have extensive help for things like auto complete and documentation stuff like that.
I
other programming languages, don't need it so much I mean, Java, what this really came to the fore with Java, because Java is just so many bits and pieces that connect in such complicated ways and keep it on your head is just nuts.
So having an IDP help you with it is essential, is essential when I'm programming See, I don't need an ID even do things like that because things are just so much smaller.
And it's just, you know, I might be a look at man page look at stuff but it's just I you know I definitely don't need that. Or even when I'm profit programming JavaScript and yeah I have to look up, you know, a pleasant but I don't hear I'm constantly
relying on the development environment to help me out because there's just all these connections that are just there and I can't.
Yeah, painful.
I don't I do not prefer coding and languages that require this much help from it.
But these are the languages for developing on modern mobile devices.
Say what you will.
Ah, What else
all online 21, I have a question mark.
Oh, online 21, I have a question mark. Question mark here is exactly the same semantics the naming is different, but it's essentially the same semantics, as Swift, which means that
in Swift it's called optional types in Caitlyn I'll remember what it is, but basically, This could be no more a bundle.
So if it's just declared as a bundle that it has to have a valid bundle associated with it. Here it could be bundle, or no.
So, I have to.
If I go to use that value I would first have to check to see whether it's know before doing anything with it, you'll see we have question marks in a few places here.
So like here like we have a question mark here because this could be a function that couldn't because we're looking up something in a map. This map could in fact not have analysis mode in it that value there.
and so we have the question mark here to saying this could be no button the next line, what we do is we check to see if a mouse function does not equal No, and we do that, and it will actually tell you if you don't check for it immediately.
We're using it, it's going to get very annoyed with you, Caitlyn does not require the whole if let thing, it just lets you do the check on the next line.
Six of one half dozen the other just slightly different style, but same concept.
Exactly the same concept,
which is probably one of the big I mean that's the big difference between programming and Caitlyn as it conceptually, as opposed to Java. You have to care about whether a value was known.
Now, what I want to mention here was awesome it was, how do we, how does the display get updated in storyboard. And how does it get updated. So, let's, let's go.
Let's go back to the tutorial to
tutorial to, we define a.
We defined a text field.
Here's the text field.
Here's the you know which is associated with this value TT is here.
Question is, when is the views updated the views are updated. When state changes
when does this happen, we don't explicitly call this we actually completed the views. This just happens automatically.
In storyboard.
The screen is updated by this, we use this update analysis we have to manually update the display. And what we do here is we run the analysis function.
And we do this now. So, as opposed to this automatically happen every screen update we call this whenever this needs to happen when does this get called this get called in a few places.
One is they get called when this, when the screen is first created so we update the mouse then, and then it's also called whenever we, when we select a menu item, it will, you know, after it sets the analysis mode changes it, then again we have to update
the state of things because, you know, we change the value there, so we call it the analysis, and then when you type something. This do analysis is tied to the widget we said specified that on changed when this happens so we can actually see this in the
XML year, I think.
XML year, I think. Yeah. So here we have this action selector do analysis destination year event type editing change so when edit when some edit happens, it will call do analysis and do analysis will do this
in an Android.
We again have to do things like storyboard so when we first create the thing we have to update the screen when someone clicks on a menu item, we have to, you know, change the analysis mode based on what was selected here, and then we update the screen.
But then, and then we have our update analysis which updates the widgets and it checks to see you know is the text not know, then we get the analysis function and if we do have a valid analysis function, we you know we call analysis function on the input,
we have to correct to a string because it's not it's this editable thing but then we convert to a string we get that there and we set the result they always say please choose analysis.
This is all same.
But in order to do the update to the screen as characters are tight, we have to instead over, we have to we have to create this object text watcher and text Walker has three methods that have to be overridden basically like after the text change that
You know what do you do before the text change or on text days, you have to override all three you can override just one it will give you an error if you don't do this. So, before on, I don't care I just care, after the Texas change. And when that's changed. I call, we
So notice this progression. We go from, you know, here the Android way is, we associate a text change listener, with the text field in that text change, you know thing, then has methods for doing things based on the state of the field and in that we say
well you know the text has changed so better update the screen, and so we call our function storyboard. We things are a bit simpler.
We still have to manually call update analysis, but we just have to specify on the widget itself.
We say you know on the widget itself so this is part of the definition here of.
We see this year, only show it, and I'll show it to you actually in.
Since I have it up.
Not that one.
Okay, let's go here.
So, let me open up here.
Open recent text analyze it you
know what that's called TechStars three sorry to a text analyzer.
Oh.
So text analyze the three remember we've specified this. So here we simply click on something else here okay so that's not there but we click on that, you know, text that entry widget.
Come on, update the screen. There we go.
And here we saw it says we're saying this widget send these events, and the event says when you know there's all these different events I could associate with your touchdown whatever here, when the text is change editing changed, called do analysis and
do analysis here is here this is the function thing and we have this little connection here, and you click on it you can see is connected to main storyboard, you know, t here, we can disassociate that but this is what calls calls update analysis.
And then of course we go to, you know, swift UI.
We have none of this stuff.
We just have a state variable.
We just have the state variable here T. Since we defined as a state variable.
And since we've up you know said it's, you know, the text field will update it. And then we have the results you dependent on it.
Using, you know, Sophie look here the.
Yeah, things are quite responsive when I share screens.
So, again, here we have our view here, this just, you know, analysis mode. Now it's functional user input user input as a spring here of analysis of user input is associated with
analysis road user input is associated with T here. So that's how we have the connection to t.
We've just specified these relationships.
And we don't care how the updates happened,
it's reasonable to ask.
With up with all these things.
date.
Swift you I let us allow us to override updates.
No, not really.
The big advantages with you is that since you're not made up don't have direct control over when the updates happen. But, it results in less code and and fewer bugs.
Think about like all this stuff you have to do like this is such a small program.
But notice how much code we've got here we got 97 lines of code of code, followed by a 59 casino think XML.
If you go over to know how big was text analyzer to.
This was 64 lines of code and layout.
That's everything.
Me, what happens if you forget to put the updates in here, what am I forget to do this update here What if I forgot to do this update here are some of the program.
Otherwise, basically you get little display glitches of various kinds, you know, forget this and the things won't change when I type.
I forget this whole thing won't change when I type, if I forget this one here and on create will have stale display until the user does something, if we forget this one you'll change the menu, but it won't actually change the result until you type something.
So, you have manual control, which means you have to make sure you don't make mistakes, and essentially what Swift.
So, and that's where it really comes down to you so we're whole classes of mistakes starkly by getting things right compile time and you just don't have to worry about afterwards.
Anyway, we're at 1230. You guys, this is just what I wanted to cover in terms of getting you to think more closely about what's going on with swift UI.
And that's why I felt okay covering the stuff before the midterm, even though they're not directly on the midterm because this is all in forming your mental model.
I'm happy to stick around, I'm going to stick around now, I'm happy to check offs, answer questions.