Hi everyone, welcome to the first lecture. The title of this lecture is Introduction to Programming Languages. The goals of this course is to learn new languages quickly. There are so many programming languages like Ada, Assembly, C, C++ and you name it. And you know what, new languages are coming up like at this moment. So I'd like to teach you how to learn new languages quickly and how to evaluate languages and pick the best for a given task. So when you work at a company or when you have your own company, you'd like to make some good software. And different tasks have different proposals and different requirements. And depending on that the best languages are different. So you better learn to evaluate different programming languages and pick the best one for your job. And the third one is to know when and how to design a new language by yourself. What are the abstractions that you'd like to have? How do they interact with the other features? And what should be expressible, and what should not be. These things are really important to make good software. So this is a quote from one of the students who took this course like several years ago. And he wrote this comment in some page, and he said that it's really difficult to express precisely. I didn't know that this course is going to be really effective in real words software, but now that I came out of the school and work in a real life, I learned a lot from this course. Myself as a software design developer before taking this course and after taking this course is really different. And there are many things that programming languages have for the convenience of the programmers, but they are really important. If you don't know those things then you may encounter some limits when you have challenging problem to implement. So I hope that you can enjoy this course and learn this stuff from this course. And there are several approaches about programming languages. The traditional approaches to have survey approach. Like this week we have an imperative language. Next week we have a functional program language, then logical program language, then object oriented languages like that. There are many kinds of paradigms and many program languages. So you can learn, you can actually see various kinds of languages, but you may not be able to understand the depth of that. The second approach is to have definitional entrepreneur approach. It's also a very well known approach and there's a really good textbook about that. And the third approaches to learn the programming languages Mathematically. It's a rigorous approach and I love this textbook, Types and Programming Languages by Benjamin Pierce. This course is not one of those three approaches. This course is to learn programming languages by implementing interpreters. So in this course we are going to use Scala as the implementation language. By using Scholar, you can implement various kinds of languages and their interpreters. You do not need to know about Scala because we will let you learn by yourself the Scala programming language. And you are going to implement interpreters of various kinds of small, tiny languages that grow over time in Scala. If you don't get what I'm saying now, don't worry, you're going to learn that throughout this semester. There are interpreters and compilers. I said that you are going to implement interpreters for various kinds of languages throughout this semester, right? What are interpreters? An interpreter takes a program and produces a result. So this desktop calculator, it takes arithmetic expressions like 3 plus 5, 42 minus 2, kind of things, right? They are expressions or programs and the calculator calculates that and gives you a result. A Scala also has this interpreter. Interpreters are good for understanding program behaviors because when you give a program to the interpreter, it's going to understand that interprets the program and gives you the answer. Wow, it's easy to understand its behavior, it's easy to implement. But the problem is when you have program and when you like to evaluate that multiple times with different input values, you need to run them multiple times from scratch, from the beginning till the end. So it's open, inefficient. So there is a Compiler. A compiler takes a program and produces another program. What, then what's the point? The point is a compiler takes a source court program and then analyzes the program and tries to optimize some part or check some errors kind of things. So when you run some bad programming an interpreter, the interpreter is going to run it anyway and throws an exception or errors at runtime. But compiler, it does not run it from the beginning. It's going to analyze a given program and find some errors and reject the programs with problems. And it's going to compile good programs to a better version. In a sense that when you run this compiled version, it's going to be much faster. An example is gcc C compiler, javac java compiler, scalac scala compiler. So when you take a C program and passes that to a compiler, the C compiler recompile is that and produces an object code. , a java compiler retakes the java source code program compares that to a java byte code. And while that compiles they have a program, it's going to check some types or some properties and reject bad programs. And if the programs are good, it's going to compile that to a by code file. And when you run the bike could file, it's going to be much faster than interpreters. So that's good for speed, but it's a bit more complex. And if you are interested in interpreters or even compilers then take this sort of compiler of course, Either in your school or six for 20 at Kaist resources. We wrote the textbook for this course. We didn't have textbooks for some time, but the head of ta they awesome had th gaming home. He started writing this text book to help students. So the title is Introduction to Programming Languages, and this course is heavily. Inspired by the PLT group. You can check the website and this lecture is going to be based on Chapter one introduction of the textbook. And I recommend you to kind of helping materials. The first one is programming in scala Marty Oderski, that creator of the scallop program language wrote several books and the first edition is available for free online. The last one is by Shrim at Brown University PLAI. In short that is another good book about programming languages. So I recommend those two books for you. But I strongly recommend you to read our own textbook. Scala is the implementation language for this course. I've been using various kinds of programming languages like C, java or Camel, Haskell. It's not simply language and out of all those programming languages, I love the most. Why? Scala is a functional programming language with object oriented features. Someone may say Scala is an object oriented language with functional language features. There are many other languages that use both features. But I think personally this is my just personal opinion, scala is the best language that takes advantage of two words. And you can take a look at this website and Scala is a growable language. Scala means scalable language. Language that grows according to user's demands, isn't it cool? A programming language grows over time following the programmers needs, is it even possible? Yeah, that person is Martin Oderski who is the creator of the scala programming language. He's giving a talk and in this slide there's another person, right? His name is Guy Steele. He's one of the authors of the java language specification and Guy still was my PI, my mentor when I was worked at Sun Microsystems. And Guy is an awesome person and he's a great researcher and programming language designer and Guy still gave a talk at Usla 1998. The picture was when he was giving this keynote talk at Usla and that photo was so awesome. Guy is still designed the top really carefully. So the talks script is now a journal paper and Martin Oderski is referring to Guy's talk and saying that it's an absolute piece of beauty. So I strongly recommend you to watch the video that you're going to love it. I bet. So let's have several exercises about scala. I recommend you to play with scala. I'm going to give you just a little examples and you may have some feel about scala while listening to what I'm saying, but you'd better spend your own time with examples. You may want to follow my example and type them and see the results and check that. But I think you do better try your own weird example, like what's going to happen if I do this, what's going to happen if I do that. Why and why not? That process is going to give you a better feeling about this new language to you scala and see that they design decisions and differences from your favorite language. They may be c java javascript or python, I don't know what is your favorite language but depending on your favorite language it may take some time for you to be familiar with scala. So from the beginning please spend your precious time with scala. Then you're going to be much easier to following this course over the time. Okay lets see REPL. What is REPL? Read, evaluate print, loop, read, evaluate, print, loop. That's called REPL. So many languages like scala and other languages they provide REPL for programmers to be familiarized with this new language. So what is scala? Let's see. When you have this cursor you type some expression, 2 times 3 enter then it says you didn't give you the name. I will give you the name res 0 whose type is integer and its value is 6. No surprise, right? When you want to have a name you're going to use val for value. Val a is a name, it's value is 10 then scala says yeah you are defining a new name whose type is integer whose value is 10. Like this val b equals a plus 1 then yeah sure b value is 11. How about this? A yeah, recently I said a's value is 10 but now I'd like to increase its value by 1. There is an error. It says reassignment to val is an error. What? It's not an assignment because we made it val instead of var. We're going to talk about mutation and variables later. Just remember that when you introduce a name using val, you cannot change its value. Functions. Functions that's one of the most important concepts in programming languages. In scala when you define a function, you are going to use this keyword def defined. I'm defining on your function whose name is add which takes two parameters a and b whose types are integers. And the result is going to have type integer. So scala asks you to write down all those types. Yeah. You may find it irritating but it's going to help you later and the body says it's a plus b add two arguments. When you call the function, you name the function with arguments. The scala checks types of programs at compile times. So when your program has a problem before around time it can check that and reject the code and let you know and hey you better fix this problem. The function add specifies the type to arguments and its results as Int. The type of the identifier m is also specified as Int. There can be multiple expressions in the body when you have another function fun it tests a+1, a minus 2, a times 3. It didn't give their names. It didn't return anything and when we call this function. With failure 10, it's going to be 11, it's going to be 8, it's going to be 30. So the result is going to be, what do you think? 30. So it does not need to use return statement and the value of the last expression is the result. If you do not follow what I just said try scala, eastern scala type down, write down what I just said and see the result by yourself. It's going to be fun. Type inference. So it's annoying to write down all the types. So why am I supposed to do them by myself? So scala allows programmers to omit type notation and infer that, that's called type inference. The result type of this add function, it's omitted, the result type of add and the type of int are not specified this time. In the previous slide, we wrote those types and in this slide we didn't. But scala infers them for your convenience. Yeah, that's good, right? But, only little type and some small fraction of the program, not parameter types for example, let's see. If you omit type annotations for parameters and just say a + b. Hey, you know, add takes two numbers and it's addition of numbers. So you do better in for that a and b are integers. If the language itself is smart. If the compiler is smart enough to infer that, you can omit the type annotations but scala does not infer them. But as I said Haskeli and ML they are smart enough to infer them. So if you prefer to do that, go study scala, I mean ML and Haskell but it's scala. Scala asks programmers to write down those types so that you can check types easily. Expression oriented programming. It may be a new paradigm for you, java and C are statement oriented. And when you evaluate a statement it's going to have side effects. But scala is more like functional language in a sense that expressions have values. Unlike C and Java, scala supports expression oriented programming and expressions have values. So in this example, when you have if expression, in C and Java, if statements are used and they do not have values, they're just side effects. But in this expression, if it's an expression depending on the condition value, it's going to have -1 or -2. The value of this expression has -1 or -2. This if expression may have hello word string values. So in that sense they are expression oriented values. So, because every expression has value, the function body does not need to explicitly return a value. In this function error message depending on this argument value error code 1,2 or 3. It's going to return one of these string values. There's no return statement but the value of the expression is the value of the function call. So finally, I'd like to emphasize important concepts in programming. No matter which programming languages you use, if you are good software developers, you better keep these things in mind. Test driven development, when you write some software, some programs start writing test cases before writing programs, tests are going to be your friend, your savior, right? Write the simplest code first you can too and you can so that you can pass the test. If your code doesn't do everything you wanted to, write more tests and repeat it. So writing code and tests in tandem, that's going to be the most important lesson today. Tests are great source of documentation. You know comments? They are not excusable, when you start, write comments and write some code, you may find some errors in your code and fix that but you may forget fixing revising the comment. So it's really often happen that the comments and quotes do not synch. So, tests are going to be better comments and they can documentation. They are precise, they are excludable and always in sync with your code. So write your tests only and as many as possible they are going to protect your cooked Okay, this is it for the first lecture. I hope you enjoyed this course and play a lot with scola. Now, let's see whether you are following what I've just said. There's a quiz. Let's read the problem. Select one that is not true for compilers. One, a compiler takes a program and produces a program. Two, the Java compiler takes a Java program and produces a Java bytecode file. Tree, executing compiled programs is usually faster than executing programs with interpreters. Four, a desktop calculator is an example compiler. What do you think? What is not true for compilers? Yes, number four, a desktop compiler takes an arithmetic expression and produces its results right away, which is an example interpreter.