Check out a free preview of the full The Hard Parts of UI Development course

The "Display Content" Lesson is part of the full, The Hard Parts of UI Development course featured in this preview video. Here's what you'd learn in this lesson:

Will describes the process of using a programming language to model how content show be displayed on a screen. The model is stored in an object and rendered in the application or browser. This representation is referred to as the DOM: Document Object Model.


Transcript from the "Display Content" Lesson

>> Let's start with goal 1. Display content. So I don't know if any of you have been an ever watched charge at the or any of these sort of talks the people do diagramming through their code running. The output of saving or running code in JavaScript already most programming languages is actually is saving data in a computer, under the hood you can't see it.

When you do let lights equal seven, and determined for to get to seven likes. When you save likes as seven, we draw it when we whiteboard, if we ever do that. We draw it on the blackboard visually, but it ain't visual. It's output is very much definitely not visual.

It's output inside the computer. You know what? With user interface engineering, the output is visual. It's pixels on a screen. And pixels on the screen, there's a lot of them. In that little window there with what's on your mind, maybe there's like, I don't know. Yeah, I should have looked that up before.

I mean 2,000,000 pixels to like 8 million pixels, every single one of those is a little dot that we need to code for. If the output of writing JavaScript is saving data, that's actually literally in the computer saving, switching zeros and ones, transistors on and off in the computer.

But there's no visual output for that. Even though we draw it, so there is. There's no visual output for that. Whereas with user interface, it's visual output. It's actually pixels on a screen. So my goodness, we've got to actually write content to define exactly where those pixels are.

So we've got two days to do just this screen here. So let's get started pixel by pixel. This is not a joke. [LAUGH]. Maybe it's a joke. We're gonna have to start with just the top right hand corner, because we've got a lot of pixels to write here people.

So we'll start with just this first one here. We're gonna write some code to display that first pixel here. This is not a joke maybe it is. It is about 100 pixels across you know from the edge of the page roughly and maybe it's like 900 pixels up.

So maybe my code will be something like I guess I can right pixel hopefully I can do that. And then I can write 100. Let's say x sort of across. It's like x coordinates. And then 900. Maybe x 100 I don't know we can make this up as we go, right?

Maybe y 900. Actually, to be fair, I could even do this like that. I can have my code live wherever I want. I'm the syntax designer of this and I'd made it like that.
>> [LAUGH]
>> Happy with that.
>> [LAUGH]
>> Look at that beautiful. And that's my first pixel, done.

Okay, settle in people because we've got a lot of pixels to draw. Who would like to draw their next one? I think we'll have Justice. Justice take a guess, just intuit for me, what might my next line of code be, to draw my next Pixel in this W that's gonna make up what's on your mind on this page that we've gotta somehow display this content.

Someone's gonna do it Justice?
>> Probably a pixel that's maybe 101 pixels.
>> Brilliant. Yes exactly 101. I don't know why my syntax is like this. And then maybe 900 and no, 800 and. What do you think? [INAUDIBLE]
>> By the way, I hope this becomes a montage in the recorded version.

[LAUGH]. So that no one has to actually sit through this. John, you're back up. John, what might be our next pixel?
>> Pixel?
>> I'm gonna write it because I want us all to suffer here.
>> [LAUGH] Yeah, x is 102.
>> Yes.
>> And y is 898.

>> Beautiful, and look at my weird syntax I invented for this. It was very strange, okay. Beautiful, next one, A toy, it's gonna be a montage. [LAUGH]. Okay, all right. Obviously we are not gonna keep going, there must be a better way. In programming with data, with JavaScript or any other program language Python whatever, where our output is saved data.

In this case, our output is pixels on the display, on the screen. In most programming I was able to save data right and then we can change that data so the output then is the data changed. I know it sounds funny to think but that's the core feature of a programming language is changing state in the computer.

Changing data by adding numbers to it taking numbers away adding elements removed yeah. Whereas that, we have shorthands. We do not have to allocate the exact position in memory, its exact address in whatever sort of ones and zeros in the computer's hardware. We do not have to write the code to allocate that, someone else has done that for us.

There are keywords like let that say please now go and find the next position in memory that we can use you do the work of that, and then save the value that we're assigning here in that position. And don't even worry about dealing with addresses. This label is English language label, whatever we call it likes is going to refer to that position from now on because, you use the keyword let right before.

Okay, that's wonderful. Whatever goes even high level, you have functions like sum that take, and listen numbers one, two and three and call them function sum. And now we are able to add those numbers together. But by the way, let's think about that which great languages have all the languages have functional sum, right?

Any modern language would have a built in function, sum. Any, all of them, especially JavaScript, unfortunately not. But most do. We have much more useful Reduce.
>> [LAUGH]
>> Which we all love, and can do some for us in a way that's almost unreadable. All right, good. So we must hopefully have something similar here.

Well, people have designed these program actually won't invent it. Well, they literally met they were derived from the sky they were invented and designed. So given that what would be if I if my output of this is this text? What's on your mind? If that's my output what will be the most intuitive and look programming languages is one intuition they will flexibility but they want intuition.

What be the most intuitive way I could write code? It please cannot be this. This was untenable thing my favorite word to use in talks untenable. What would be a much more tenable? I know that's a phrase that may not even be real word. What would be a much more tenable, way of producing the output of what's on your mind that text on the page.

I'm going to pull what would be the most intuitive way of having the text what's on your mind? What would be my Code say I have my code here that's going to produce the text what's on your mind?
>> Knowing HTML I would either use a paragraph or label.

>> All this is too much information already. Or we might absolutely what do I add to it most minimal?
>> If I want you to show what's on your mind, I might write the text what's on your mind?
>> Yes, spot on, it's almost too obvious. Paul showing us some real sophistication there.

But what's on your mind might become exactly what's on your mind in my page. If I tried to be really intuitive and you know what? That'd be amazing. Would it be had that Charles maybe it's gonna happen who knows there's on line one. Line two, if I wanted to display what side an input field into which I can type text, what am I right or input.

And unfortunately that's going to, and this is maybe where our friend Paul was suggesting having some sort of let the computer know whether it's going to be text or something else. Maybe here, we don't want it to write input, we want it to show an input. So we can put some square brackets around it, We use those quite a lot.

Let's put something else around it.
>> [LAUGH]
>> Let's put some triangle brackets. I know we don't use them very much. That's nice. And that could display us a box on the screen beautiful.. And then All right we're getting it okay. Maybe everyone there we go do button and that would produce a button and then if you just wrote the text, Publish right next to it, maybe that shows up in the screen.

I don't know this language would be too intuitive though. There's no way that we're hiring people in the six figures developing user interfaces using a language this intuitive. And to be fair, I'm a bit suspicious about it anyway. I'm a bit suspicious about it anyway because, it's not clear to me how I'd know.

So in theory, writing what's on your mind and then having that displayed some, other tool, some other engine's gonna have to have been running to convert this into elements on the screen. And to be fair animate on the screen, there's a lot of questions. I can change my window size in a web browser, and all of these are gonna change their position and their pixels on the screen.

I'm gonna have to work all that out unless there's some way in which I can have a very simple. What will be my most simple way of describing what's on this screen? I could have even done it here I could list down the page and create element by element, a list maybe in describing what's gonna be on the screen.

I can have some sort of list, that takes each of these elements. And all I have to do is add to that list and figure out nothing else. Have no other thoughts about what pixels are gonna be on the screen, how to think about the layout. And instead, all I have to do is go through a list of elements that I wanna have on the screen, an ordered list, by the order they are on the page, they get added to this list.

Just like a JavaScript list, and then rely on some sort of, I don't know, layout and render engine that can convert that list of elements into actual, Pixels on the screen itself. But this is far too appealing. Is it far too intuitive? There's no way this language exists, and we're still charging for even this content.

There's no way I should imagine a job that is very unhelpful. But It does. What is this language called, Paul?
>> HTML.
>> This is called HTML. People, do not underestimate it. We don't even teach it at Codesmith. That's how intuitive it is. This is something where we can list down the page in order and the elements will show up in that respective order on the web page.

Our HTML file, literally all we have to do, maybe one of the first things we did on a computer each of us, is save like, I don't know, app, write in a text file. And then input dot HTML, and then load it into the web browser arousing off screen load it into the web browser.

And that text will be read past is a term they use PARSE passed and turned into line by line elements on a list. A simplified list that a simple list of elements now totally is implemented as an object. But this list here of elements will then be automatically converted onto the screen.

And all we have to do is write text this list. What language is this list going to be stored in? Well, the one that the web browser is mostly built in, which is C++, but we don't have to interface with it. We don't have to work on it directly.

We instead get to list out and have each of these automatically added to this list. That is a simplified version of this page. So here's our page, Here's our list. And it's a simplified version so that we don't have to worry about the individual pixels, cuz there are thousands of different device types.

There are tablets, phones, laptops. There are thousands different sizes our window of screen can be. If we don't think about any of it, all we do is list out our individual elements and rely on some sort of engine. We'll learn more about it that lays out and figure out the exact pixels that get displayed on this page.

And that's it. We add each of our elements. So into this list here, we'd have the string what's on your mind? We literally get to in from our HTML affect this list in C++, that determines what gets displayed on the page. We add our input. And each of these will then be turned into the specific elements, that describe that particular work for that particular device.

That's it. People, this is called HTML, this C++ list, and this page. I guess this list here, we need to give it a name. I am presuming it's name is the list of elements on the page. L E P. I literally come up with different invented names every time.

No, it's not actually a list, it's technically an object. So maybe an object just gives it a bit more flexibility, allows it to have a bit more specific structure. So it's technically an object, so maybe it's an object. And it's a representation of the page and your representation of something.

If you've built your sort of LEGO model, it's all I know, is a representation of a real thing. So the LEGO model of Riverdale I actually don't know about that. I like that when I saw that in the store, the Lego representation Of, what do I like, the, there's a new gaming truck from Lego Friends, I think.

I haven't even used, I haven't seen it, but you can play a game. You can be a gamer in it. So, Lego presented a gaming truck. Yeah. Is not the real gaming truck. It's a simplified with bricks version of it. Well, this is a simplified with elements in an object, version of the page that all we have to do is add to that list, almost push almost a pen to that list.

So this is known as a model. Not a representation, but a model of the real thing. A Lego model, models the real gaming truck. So this is a model technically here. So a model in object form. So object model, of the page. Up well, this is an app.

So is it really an object model of the page or not the model the app? So I think maybe Omar no okay. All right. So this a user calls a document because it was literally like a list of links and text, so it was like a document. So, O M D, okay fine.

DOM. A list in JavaScript, a model of the document, the page, stored in an object format in C++. That enables us to not have to interact directly with pixels and work out. That code at the top there was absolutely untenable. Instead, we get to write almost functions. Think of these as functions being called.

This input says, please go and create on this list of elements A single element of type input. And then we have to think nothing more about it determining the exact content displayed on the page is then handled by the render engine.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now