VNUHCM
Bài trước Bài kế tiếp
  • Nội dung học
  • Trợ giúp
    Bạn có thắc mắc khi đang học?
    Hướng dẫn cách học Những câu hỏi thường gặp Email cho giáo vụ
    • Tiếng Việt
    • English
    • Thông tin Thành viên
    • Khoá học đăng ký
    • Đăng xuất
  • Cohota
  • HƯỚNG DẪN HỌC TẬP

  • Xem chi tiết >>
    Bạn đã hoàn thành 0% khoá học
  • HƯỚNG DẪN SINH VIÊN ĐĂNG NHẬP HỆ THỐNG
    • Hướng dẫn đăng nhập
    • Hướng dẫn vào khóa học
  • Introduction
    • Welcome
  • Unit 1: Values
    • Introduction - Unit 1: Values
    • Get Started With Values
    • Play with Values
    • Playground Basics
    • Naming and Identifiers
    • Simulation
    • Strings
    • Constants and Variables
    • Word Games
    • Build a PhotoFrame App
    • Design for People
  • Episode 1: The TV Club
    • Introduction - Episode 1: The TV Club
    • Searching for Content
    • Sharing Personal Information
    • Ordering Online
    • Reflection: Episode 1
  • Unit 2: Algorithms
    • Introduction - Unit 2: Algorithms
    • Get Started with Algorithms
    • Play with Programs
    • Functions
    • Types
    • Parameters and Results
    • Making Decisions
    • BoogieBot
    • Data Visualization
    • Build a QuestionBot App
    • Design an Experience
  • Episode 2: The Viewing Party
    • Introduction - Episode 2: The Viewing Party
    • Accessing the Show
    • Streaming on the Network
    • Reflection: Episode 2
  • Unit 3: Organizing Data
    • Introduction - Unit 3: Organizing Data
    • Get Started with Organizing Data
    • Play with Complex Data
    • Instances, Methods, and Properties
    • Arrays and Loops
    • Structures
    • Enums and Switch
    • Testing Code
    • Processing Data
    • Pixel Art
    • Password Security
    • Visualization Revisited
    • Build a BouncyBall App
    • Design a Prototype
  • Episode 3: Sharing Photos
    • Introduction - Episode 3: Sharing Photos
    • Capturing Images
    • Posting on Social Media
    • Reflection: Episode 3
  • Unit 4: Building Apps
    • Introduction - Unit 4: Building Apps
    • Get Started with App Development
    • Play with App Components
    • Color Picker
    • ChatBot
    • Rock, Paper, Scissors
    • MemeMaker
    • Build an ElementQuiz App
    • Design for Impact
  • Appendix
    • Episode Technical Concepts
    • Glossary
Tổng quan điểm khóa học
Đánh giá

Tiến độ
Tên tiêu chí Trọng số (%) Điểm Tiến độ (%)
Unit 1: Values

Get Started With Values

Unit 1: Values|Get started

What Is Programming?

Computers are made by people. They only know what people have told them. And they only do what people tell them to do. When you program a computer, you’re telling it what you want it to know and what to do with that information.

Programming is all about inputs and outputs. Inputs are what people provide to the computer by tapping with their fingers, typing on a keyboard, talking, taking a photo, and other activities. The program tells the computer how to use that information—for example, sending it somewhere, transforming it, or analyzing it.

After working with the inputs, the program produces outputs, such as a drawing, a slide presentation, a chart or graph, or maybe just a big list of numbers. Both inputs and outputs can take many forms: tactile, audio, visual, or text.

Explore this:

Consider your favorite app on your phone.

Brainstorm the ways you might provide input to the app. Remember to consider all the sensors in the phone, not just the screen-based inputs.

What forms of output does the app generate?

Values

The inputs and outputs of a program are the information it works with. Another word for information is data. Before you started this course, you might have thought about data as lots of numbers. But everything in our world can be captured and described by some form of data—and then analyzed, stored, and shared by computers and the programs that run on them.

Explore this:

Take a photo of an everyday object.

Now use Markup to identify as many different physical attributes of that object as you can. Think about components, size, colors, materials, and textures.

You’ve just captured physical data about the object. What other data might you use to describe the object?

image: hand-draw sketch of an object (maybe with a polaroid type frame) with handwritten attributes around it

Data is a collection of individual values. For example, you can describe the object in your photo by specifying a value, or set of values, for each attribute. All these values, taken together, work as a data set that describes the object.

Like any programming language, Swift has ways to express and manipulate data. In fact, the term for representing a value—whether it’s a simple number or the result of a calculation—is expression. In this unit, you’ll learn how to use values and expressions to explore an idea or to solve a problem.

Naming and Identifiers

Naming is critical to understanding and communicating all the data in the world around us. In everyday life, people use names so that they can refer to the named thing as a whole, without having to think about all its details.

Imagine you’re an intergalactic explorer and you arrive on a new planet teeming with alien lifeforms. How would you tell your colleagues which alien has a taste for human or which one is good for a chat? You’d give them names. At first, you might say, “The yellow wobbly one with eyes on stalks and sticky tentacles that lives in the methane swamp.” But to save time, you’d probably agree on a name—so you can say, for example, “Look out! Bananacle Monster!” when a tentacle is reaching for your buddy’s ankle. Right?

Naming is a form of abstraction. When people use a name to refer to something, they can think about the relevant attributes of the named thing (like the fact that it might want to eat you) without having to think about absolutely everything they know about it. Abstraction lets us hide the details of something so they can focus on what’s important.

Naming is an important skill in programming too. In programming, you need to create clear, descriptive names—called identifiers —that reveal the intent of your code. If you choose good identifiers, your code will be easy to read and edit. As a result, other programmers will be able to work with your code and collaborate with you more effectively, and your code will be easier to debug. And when you return to code you wrote months earlier, you’ll be able to remember your original thought process.

Explore this:

Compare these two notes.

Which one will be more useful months later, when you come back to your decorating project and want to buy enough paint to do the whole apartment the same color?

notes with calculations for painting a room presented as handwritten on scraps of paper

Now imagine you’re designing a new game. Draw a quick sketch of your game design, and name as many important components of the game as you can. Include visual elements as well as the elements that determine how the game works.

You can start naming your identifiers with camel case, the convention coders use in Swift. In camel case, you begin each identifier with a lowercase letter and then use uppercase letters to start each additional word, for example, speedOfCar, roadFriction, and tireDamage. Use clear, descriptive names that will help you remember your intent when you come back to your design.

Strings

Look at just about any app—messaging apps, news readers, social media, maps, you name it—and you’ll see text. Even camera apps might use text to label buttons and controls.

In most programming languages, including Swift, text values are called strings and are composed of characters. The name “string” reflects the idea that the characters are in a specific sequence, like beads on a string. This is important because the order of the characters gives a string its meaning. For example, consider these four characters: O, P, S, and T. They could be strung together as POST, TOPS, SPOT, STOP, OPTS, or POTS. Each string has a different meaning, even though it uses the same characters.

image of beads in no particular order, then strung on a string to read ‘STOP’

Characters in a string can be letters, numbers, punctuation marks, symbols, and even emoji. Invisible things, like spaces and tabs, are characters too.

Explore this:

Imagine you’re tasked with creating chatbot responses to the user inputs below.

Chatbots are programs that interact with the user by interpreting strings and responding with strings. You can respond with a maximum of 20 characters—and don’t forget to count spaces and punctuation marks!

Your challenge is to design creative, funny responses using all the different types of characters available to you.

cartoon-ish ‘bot’ contemplating speech bubbles with the following statements in messenger type bubbles and fonts

Constants and Variables

When you create an identifier—when you call something by a name—in a program, you also need to declare whether it’s a constant or a variable. As these terms suggest, the value of a constant doesn’t change, while the value of a variable may change.

Constants are useful because their values will never change, which lets programmers make assumptions about the code that uses them. That certainty can reduce the chance of making mistakes in code and can make it easier to find the mistakes that do happen.

Variables change as the program runs, often in response to inputs or actions. For example, the score in a game is a variable, the amount of money in your bank account is a variable, and the time it takes to travel somewhere is a variable. In each case, the value can change even though the type of data remains the same.

Explore this:

Imagine your life is a program.

What about you are constants, and what are variables?

For example:

  • My eye color is a constant, but my hair length is a variable.
  • My date of birth is a constant, but my street address is a variable.

Simulation

Programmers often use simulations to replicate real-world systems and to predict their behavior. The creators of a simulation choose which aspects of the system they’re interested in measuring, and those decisions impact its design. Think about a crash test dummy. The dummy simulates a human body, but of course it’s not an exact replica. In designing a crash dummy, the creators choose which features of the human body are relevant for their test—such as the body’s mechanical response to impact, with particular focus on the skull and the neck.

sketch of a crash test dummy

A computer simulation works the same way. By modeling a system in a computer simulation, people can see how the system responds to change, and they can test hypotheses. In fact, computer simulations have enabled researchers to predict internal injuries in crashes more accurately than road tests using physical dummies.

To build a simulation, programmers need to consider which aspects of the system we’ll model and how those aspects will change. Sound familiar? Simulations are built on variables. In fact, computer simulations are powerful because of the incredible number of values they can compute for each variable and the interaction among many hundreds, thousands, or even millions of variables.

Explore this:

Imagine you work as a car safety engineer.

If you were building a crash simulation to determine the effectiveness of airbags, what variables might you consider?

List as many as you can, then combine your list with your classmates to create a comprehensive list of variables.

Consider the combined list. Why would running a computer simulation be better than conducting tests with real cars and dummies?

Computer simulations are a great example of abstraction in action. When you select the features of a system to simulate (omitting those that aren’t relevant to your task), you’re using abstraction. And without all that unnecessary detail, you can work more efficiently and more effectively.

Báo lỗi