 Selamat malam lagi. Ini adalah kali pertama saya melihat ini. Ah, okey. Saya mencari ini. Ini adalah Gopher. Edition Singapura. Jadi Gopher Malayan. Dan titik saya, jika saya cakap dengan cepat, oops, tinggalkan. Okey, tak mengapa. Tunggu. Ia tak mahu. Jika saya cakap dengan cepat, Ia adalah Gopher. Ia adalah pandai. Semua kita mempunyai kapasiti mental. Pujet minum. Satu-satunya kita boleh menjaga lebih banyak perkara dalam minum kita. Satu-satunya kita boleh menjaga lebih banyak perkara dalam minum kita. Tetapi dalam semua kes, ia mempunyai. Jadi apa maksud anda dengan pujet minum? Jika anda tahu bagaimana untuk mengambil kereta, ia adalah istimewa. Anda masih mempunyai... Anda masih perlu tahu bagaimana anda berjalan. Jadi ia mempunyai energi dan pujet minum. Jadi, perkara yang saya cuba tanya adalah, apa pilihan anda sekarang? Apa yang anda sekarang buat hari ini? Dan apa yang anda ingin lakukan esok? Jadi, bagaimanapun, jika saya sekarang mempunyai perkara dalam web, terutamanya web front-ends, saya tahu javascript dengan baik-baik saja. Tetapi, saya ingin menulis perkara di belakang. Saya ingin menulis perkara di belakang. Saya ingin menulis perkara di api. Anda beruntung. Anda beruntung. Kerana, anda boleh menulis perkara di belakang di javascript. Ia dipanggil node.js. Anda masih perlu tahu tentang keputusan untuk menulis perkara di api. Anda masih perlu belajar tentang domain itu. Tetapi, anda tidak perlu belajar bahagian baru. Kerana belajar perkara baru mengalami budget minda. Dan ia susah. Sebelum datang untuk pergi, saya menggunakan javascript. Jadi, saya tahu javascript dengan baik-baik saja. Dan saya ingin menulis perkara di web front-ends. Anda boleh menulis perkara di web front-ends di javascript. Ia tidak mungkin. Tetapi, ia seperti menggunakan perkara untuk menulis perkara. Saya ingin mengenai perkara yang saya cuba membuat adalah anda perlu mempunyai perkara yang betul. Jadi, apa yang baik untuk membuat perang? Jadi, perang adalah baik untuk membuat perang dalam peringkatan. Perang itu tidak baik untuk membawa perang. Perang adalah baik untuk menulis perkara di belakang di javascript. Perang adalah baik untuk menjadi... Baiklah, ini berbicara. Tetapi, orang yang telah menulis perkara di belakang fikir ia sebenarnya cukup mudah untuk membaca dan faham. Ia baik untuk mempunyai perkara yang baik-baik saja namun perkara yang penting untuk menulis perkara di belakang di javascript yang saya akan bercakap tentang sekejap. Ia mempunyai perkara yang betul. Dan perkara yang terbaik untuk saya, ia adalah javascript. Ia adalah javascript. Perang adalah sederhana. Ia adalah peringkatan yang pertama. Jangan lupa fmt dan去了km. Ia bukan detonari printing hari. Ia saja menyeimbang perang. Ia discrimination padav. Var touchdown yang dirilis, ahora itu pelala derandam gimana bagi perang tanpa di hadiah dan reagasi searching di bawah. Ia akan men mortalis diversi. Orang yang berkongsi dari javanah, keadaan, atau bahasa yang merah, akan mencari goh yang sedang berkenal. Goh adalah kongsi kongsi kongsi. Saya suka mencari contoh ini. Adakah kamu fikir program ini akan mengerjakan? Adakah kamu fikir program ini akan mempunyai? Adakah kamu akan mempunyai? Ia tidak akan mempunyai. Berapa banyak kamu telah menerima pembentangan kamu? Saya akan menerima pembentangan. Biar kita lalui pembentangan error. Pembentangan error tidak terlalu teruk sebenarnya. Jadi, apa yang telah dibuat adalah mengambil html ini, memasukkan ke dalam file tempuri, disebabkan compile0.go, dan pembentangan compiler yang tidak dapat dipakai b type string dalam keadaan untuk menggunakan. Adakah kamu boleh melakukannya dalam javascript? Ya atau tidak? Ya. Biar saya memberitahu. Biar saya meletakkan mikrofon untuk sekejap. Jadi, saya... Baiklah, terima kasih. Jadi, saya betul-betul menerima pembentangan error. Sekarang, saya adalah pembentangan error. Javascript tidak terlalu teruk. Saya memulangkan pembentangan error. Sebenarnya, tidak benar. Javascript adalah langgan yang cukup baik. Tapi, kami dalam go-talk. Jadi, kita bercakap tentang go-talk. Baiklah, ini tidak sangat jelas. Macam mana kuatnya type save adalah go? Kenapa type save-nya semua? Tapi biar kita melihat kode ini dan kita lihat jika ia akan memulangkan semua. Saya mengelak kota seorang type yang dimanak sebagai pembentangan. Over here, I declare a variable i. It's of type minum and I assign it the value 2. Over here, I assign a variable j of type int integer of value 3. Can I assign i and j in Java? Can or not? Can. In Node.js, definitely can. In Go? No. Let's see the error message. Some of you already guessed the answer is no. Let's look at the error message. Cannot use type j. Cannot use j, type integer, as type minum. So minum, even though it was derived from an integer, is a separate type in Go. So it is very, very, very strongly typed. And this is very useful if you write big code. If you write code that is shared with loads of programmers. It's also very useful for code you have written years ago. This is the equivalent of keeping everything in its right place and the right place for everything. But there's always two sides to a coin. Keeping everything in its right place takes a lot of time, a lot of bookkeeping. Node.js allows you to throw things all over a place, a teenager's bedroom. Node.js is like a teenager's bedroom. Go is like a well-kept, well-groomed house. So strong static typing allows you to catch most errors at compile time. And the runtime is quite predictable. In other words, after compiling and you deploy to production, you can expect predictable performance. But the flip side of it is if you are trying to throw away, throw together a short script, a language like Node.js, Python, Ruby is much more appropriate. So guess the message is what do you want to do? What do you already know? And what do you want to do in the future? So decide whether you want to learn Go. Let me try to convince you that Go is worth learning. So Go has implicitly satisfied interfaces. Those coming from Java know about Java interfaces. Go tries to keep keeping a house in order, static typing, strong static typing, more pleasant. So over here, I declare an interface type. It's called quantifier. And it's got one method in it called quantify. And quantify takes nothing and returns an integer. So over here, I declare another type, my str or my string. It's derived from type string. And it also has a quantify method. Now, how do I know that it's a method? This funny syntax, which Go created, the way you read this line means quantify is a method of s of type my string which returns an integer. That's how you read it. So basically, it's a method of my string. It says printf means print to the screen, quantifying s. It's length of s. It returns the length of s as the final value. This is just a side effect. It's just to print out the string. Now, I declare another type called myint, and it's derived from integer. And to quantify this integer, I determine whether it's positive, negative or zero. That's simple code for that. So let's cut to the chase. Well, this code work. Let's go through line by line. That's just a print statement. This line is interesting. Oh, by the way, Go has this funny reverse declaration syntax. So variable Q is of type quantifier. That's what it means. It's not quantifier, it's of type Q. It's the other way around. So variable Q is of type quantifier. So the quantifier has a quantify method. Q equals myint3. Now, that's another funny Go language syntax. All it's saying is take3 and make it myint. So I'm casting 3 to myint. Think of it like a constructor in Java. So that's a constructor kind of thing. Print Q quantify. So 3 is a numeric. It's positive, so it should be 1. I guess so. Q equals mystringABC and the length of ABC is 3. So if we run this program, the first one should be 1, the second one should be 3. Let's check it out. And true enough, it is 1 and 3. Now, let me edit my presentation and re-run it. Anybody learn how to edit your presentation and re-run it? Let's change this to minus 4. Let's editing my presentation. This is written in Go, by the way. Real cool stuff. And let's run it again. So now it shows up as minus 1. Can everybody at the back see the bottom rows? Good. Now, no surprise if I change it to 0. It should be 0. Let's run it. And it shows up as 0. If I change this to a 4-letter word, or 5-letter word, it just returns the length of the string. Now, I'm going to show you Go's C roots. Anybody know C here? Good. What do you think will happen here? 0x20ac. That's a hexadecimal number. What do you think will happen here? Volunteers? Shall I tell you the answer? Will it work? One character? Well, let's try it out. Quantifying Euro. 0x20ac is the unicode for Euro. The Euro symbol. And the Euro symbol is a single character string. And it says 3. Because the single character string is actually an integer. And it's of length 3. Rarely confusing stuff. But here are the things that will trip you up. It's C roots. All right. Why is this useful? Why are these interfaces useful? Now let's say I have another type called exam paper. And exam paper you submitted it as suyin.doc. I shouldn't use Microsoft. I should use Google stuff. That's the URL for my exam paper submission. And let's say exam paper is to grade me. Quantify. How do you test this kind of stuff? It's difficult, right? It's going to make a service call. Go out to the internet. Grab the real exam paper and try to test it. And that's not very predictable. The internet connection may be down. I may have changed my exam. My exam submission. But I can have fake exam paper to HTTPSdoesnotmatter.suyin.doc. It never makes the internet call. But fake exam paper because it satisfies, quantify. It works. And it's great for testing. So this is how I use interfaces all the time. But this way of defining interfaces is very, very useful. Because in Java, or similar languages, you must say this class implements this. And you may find that the implements may be implements A, B, C, D, E, F, G until the end. It may be a very, very long string of implements. In Go, there is no implements keyword. It's implicit implementation. So long as it's got a quantified method, it works. The most fantastic example of this is IO reader and IO writer. You can print line to a database because it IO reads. Okay. So that is the second reason why Go is such a good language. If I'm losing any of you, if you want to ask any questions, just shout out, interrupt me. Yes. So Java has... If you have a functional interface, Java 8 onwards has functional interfaces. And the question is, if you use a functional interface of Java, you have this kind of capability sort of. And how is it different from the Java interface? Well, I like to think Go started it first. Java copied it. But that's actually a very good question. Go, JavaScript... Sorry. Leave Go office. JavaScript, Node.js, Java, Kotlin, all the new modern languages. If you hear one of the authors of Go speak, his name is Robert Pike, interesting speaker. He says, all these languages are becoming more and more alike. They're getting more and more features. Java is getting functional features. Node.js is trying to get classes. So all these languages are converging. More or less the same language, perhaps with slightly different syntax. Go is different. Go is a very, very limited... I don't want to use this word, but it is quite relevant. Limited stupid basic language. It is designed so that anybody coming from a C-like language can look at it and sort of understand it. It's designed so that you can write code that is efficient, that compiles quickly. And when you look at it five years later, you can still understand it. Go is designed somewhat like Python was designed. Python was designed to be clear and easily readable. So many people have actually come from Python to Go. Why? Because Python is really slow. Global interpreter lock. I came to Go, not from Python, but from Ruby. Ruby is a fantastic language. It makes developers like me who write in Ruby very happy. It's a very, very fun language. But... But... But yes, global interpreter lock. It's really slow. But that wasn't my issue. It was fast enough. Ruby was fast enough for me. But Ruby code, because it was so fun to write, when you look at it five years later, what am I trying to write here? Go tries to circumvent that problem. But anyway, let's go to Go's third feature which I want to talk about, which is concurrency. Which is something which for a person new to programming, finds it really hard. And for a person who does JavaScript, finds it quite hard as well. So, over here I declare a function. It's called plus. And all it does forever and forever prints the plus sign. That's all it does. After one second, it prints another plus forever and ever. Here we have basically the same routine, but it prints out a period. It prints out a dot. Okay. Most of us, when we start out writing code, we write code like this. This won't compile. So, let's run it like this. This won't compile at all. It's got some weird error message. About to execute select. So, I'm about to execute select. Fatal. All go routines are sleep. Deadlock. Which means there is something in go called a go routine. And it's detected a deadlock and it's crashed the program and it's exited it. So, okay. Let's make the program work. Let's fix me. Okay. Let's run plus. Let's run this program. Okay. Pluses are running. But my aim is to run plus and dot at the same time. Concurrently. So, as a beginner programmer, I will do that. Of course. Do you think that will work? No. Why? Sequential. Sequential execution. Plus is holding on to the CPU. It doesn't want to let go. Let's prove it. Yes. Plus is hogging the CPU. It doesn't want to let go. It doesn't let dot any time to run at all. Okay. I am the creator. I'm the writer of this program. Now dot can run. Correct? Yeah, dot runs. But I want go plus and dot to run at the same time. How do I do that? Anybody? We've got go experts here. Come on. Ah, yes. The go keyword. What does the go keyword do? Start a go routine. Let's do that. I added three characters. G, O, and a space. And I've turned a regular routine into a go routine into a routine that doesn't block. Let's prove it. It doesn't block. It works. But hold on. This part of the code is not executing. This part of the code which says about to execute select is not executing. How do I get that to execute as well? How? You guys are learning fast. Put another make dot a go routine. So let's do that. Bang. Now, there's something interesting here. This comes from print line go concurrency. This comes from about to execute select and then the pluses and dots. What has actually happened here is the program ran. Put that into the background. It's running independently in the background. Put that in the background. That took a few hundred microseconds. Fraction of a millisecond. So in a fraction of a millisecond or maybe a millisecond later, the print line executed. And I needed to put this select here. Select is a statement which actually tries to determine which go routine is ready to run. But if I remove that select, if I remove the wait forever, what do you think will happen? The program would actually... Program will terminate. The program will terminate. What happened to my go routines? So if the main thread actually go routine terminate. If main terminates, the go routines terminate. Let's prove that. So no more select. It's commented out. By the way, the double slash if you've not figured it out, it's a comment. Program exited. No dots, no plus. So that's another feature of go. It has garbage collected the go routines. Go is a garbage collected language with a very, very, very performant garbage collector. Those people coming from Java, every now and then when the garbage collector collects garbage, it stops the world. The whole system stops. Go, garbage collector used to be like that as well. Stop the world for a few hundred milliseconds. The latest version of go stops the world for a few hundred microseconds. So it doesn't really stop the world. But those people who know JavaScript, who know Node.js that's nothing new. Node.js has concurrency as well. So let's prove it. I'll put it here. F12 to get a console. So over here I've defined two JavaScript functions. Function plus and function dot. And this is very JavaScript. So every 1,000 milliseconds lock to the console a plus. Every 1,000 milliseconds lock to the console a minus. Not minus a dot. So when I run that well, pluses go on. Two pluses, four pluses, five pluses go on and on. If I run dot, if I can type, now you got plus and dots. So JavaScript can do what go does. Mind budget. If you know JavaScript, do you want to learn go? Okay. Was it the same? Sort of. Sort of the same. What I just did in my web browser was I made use of a web worker which will consume roughly equivalent to one Java thread equivalent to one operating system level thread. So if my computer has four cores it can run four threads at the same time. At the same time. It can have many, many threads but it can only run four of them at the same time. A go routine is not like the JavaScript web worker. No. A go routine, well, a million go routines can share one thread. Somebody actually did a demo. A million go routine share one thread. So it's a very simple, very lightweight go routine. Almost does nothing. But still, a million go routines can share one thread. And on a four core machine you get four million go routines. So the next point I'm trying to make is after Java 8, guess who they copied? Guess who they copied? They copy go. Ideas are very old. Ideas are very, very old. Go routine is actually not the correct word to use. It's correct in go but it came from a paper called Concurrent Sequential Processes. It's called Co-Routines spelled with a C. Nobody paid attention to co-routines except for Erlang for a long, long time. Then Go came out and said co-routines are cool and I'm going to brand them go routines. And then everybody started saying Kotlin wants it as well. Java wants it as well. So all these languages are becoming more or less the same language with difference in text. They're getting features. Sebelum datang as you already know I programmed in Java and I was looking for a better Java. So I thought Scala is good. Scala is horrible. Scala is an extremely powerful language you don't get me wrong. It can do everything. You can write DSL domain specific languages in Java. It is so big but I can't read my code after one week. I can be so undisciplined that I cannot read my own code after one week. That is Scala. Anyway, how good is Go's concurrency? That's another thing I want to highlight about Go. Is Go's concurrency good? Go is designed the birthplace of Go was actually Google. We are at its birthplace to organization not here but organization and Go was invented the story goes when you're trying to compile a big C++ program that big C++ program took about 40 minutes to compile they compile the equivalent program in Go and it took less than a minute few seconds but compile time is one thing how performant is it? This is a whole web browser now those people working in Node.js they say I can have express and I can write a similarly short web browser in 3 lines or 4 lines or 2 lines let's besides the point the point is can Node.js perform on my really crappy laptop 11,000 requests per second with almost no optimization? Well Go optimization compared with Nginx same laptop running a static website all it does is serve hello world it came out with about the same 10,000 requests per second 11,000 requests per second it's within the error bands what I'm trying to say here is for beginner who knows nothing about OS tuning who knows nothing about concurrency he can write code that's production ready as good as Nginx so Go is designed for heavy duty back-end service production ready back-end service really good really performant easy to read easy to extend back-end service and my favourite feature of all Java done right if you use pure Go Go in other words you don't link against a C library you can link Go against a C library that's called C Go if you don't use C Go or use Windows specific DLLs or Mac specific libraries you can all you need to do to cross compile turn off C Go C Go enable equals 0 turn off C Go specify the operating system i've got clients that insist on using Windows what they do noni Windows old Windows 386 Windows not x64 go build hello world it generates an EXE file a Windows 386 EXE file let's look at the complete list AIX wow Android Darwin what's dragonfly don't know what dragonfly is FreeBSD some funny OS called Illumos I don't know about it ah this is really really really interesting Javascript Wasm WebAssembly Yes Go can compile to Javascript WebAssembly binaries and these people are using it because they want to play games on the web browser and Go is so performant they put a whole game engine in the WebAssembly with with physics and everything in there nice target but for Go it's just another target it targets all these platforms my platform happens to be Linux AMD 64 so let's go back to the presentation if you want the code download the whole presentation download it's there suyin, github lots of other presentations there as well but this one is there and you can run your presentation like I ran my presentation thanks for listening thank you questions, comments flame wars, yes so let's go able to handle machine learning package for that okay the question was usually machine learning folks use something like python and python is a fantastic language for machine learning because python was written by judo voin rossam by pronouncing that name all wrong he's a mathematics professor so before tensorflow came out you had numpy and python was an absolutely great language in that area go is not it's not a machine language optimized language it's the wrong tool to use go for machine language but go is very very good for data engineering before you can do machine learning you need to get your data in shape you need to clean your data so go has dataflow libraries which can clean up massive amounts of data really quickly but not the actual machine learning itself any other questions, comments reactions do you like go is it worth learning yes okay my friend here has a difficult question for me he promised me a difficult question doesn't matter, I'll repeat your question okay you can try oh it's working yes it's working yeah it's a weird question maybe and I don't know if it actually fits in here but I will pose it anyway so when you compile go you get a static binary which can go big pretty fast very big so that's why actually people like to put it into docker containers because you can use a very small container to run the self-contained go binary okay but I think you just confused half the audience very big binary but very small docker container okay continue I mean you use a basic alpine container with a few megabytes of stuff in there and you can run your go binary if you assume that you have for instance one physical machine that for some reason runs like a thousand container running the same go binary it's called Kubernetes, yes and let's say for some reason the go binary that needs to be lowered is like 60 megabytes what is a big go binary right is there to your knowledge any optimization in using the memory from the side of the Linux I think I have read that it does this with normal C binaries using common libraries that you just have one copy in your memory but all the instances running use kind of the same copy okay I guess you can summarize the question is in summarize the question is can you share memory effectively if you got 60 instances of the same thing can you share memory sort of kind of you use the same binary code from the memory or does it use 60 or 1000 copies of it which eats up a lot of memory it will eats up it will be 60 times the memory okay first let's answer actually this is a very very good question let me attack let me attack the first question first let me address the first question first go binaries can get pretty big pretty fast that hello world was about 1 to 2 megabytes why is it so big why is a hello world almost 2 megabytes yes when you write a java class a hello world in java class and the class file is a few hundred bytes a go executable is a few megabytes almost 2 megabytes but the java file can't run on its own you need the JVM which is 50 megabytes or more the last time I check the entire JVM for go the entire go runtime is embedded in the binary the entire go runtime that handles go routines the entire go runtime all this smart implicit interfaces the entire go runtime that does strong static types is embedded in that 1 or 2 megabytes in that hello world so most go binaries are self-contained most net HTTP is not self-contained but you can make it self-contained and you can make it a pure go thing net HTTP or the net library actually makes use of the operating systems resolver library which means it's a dynamically linked library and many pure go purists don't like it so they turn off sego and you can produce a pure go binary and that consumes maybe about 5 megabytes to 8 megabytes the entire web browser resolver stack so that's why go binaries can get big quite fast the entire docker binary was written in go and it's about 50 megabytes so really really huge projects like docker kubernetes, kubectl kubectl they weigh in roughly tens of megabytes when you deploy a go binary in a docker container i don't use alpine because i just use from scratch in docker terms from scratch means start with an empty container empty docker container and if my go binary is 5 megabytes my docker container is 5 megabytes really tiny docker containers so the mantra for go is don't communicate by sharing memory don't communicate by sharing memory share memory by communicating so everything in go is independent and unshared non-shared you communicate across different processes using channels any other comments, questions, reactions if not i think yes so you have used apache benchmark to test that hello world yes i've used apache benchmark to test the web browser hello world so that is pure static content which is getting solved so it could perform better so go right fit to use higher intensive task because if i'm using go lang to build up my back end system then i'll have to perform right fit business logic and that could have the higher okay let me repeat the question for the audience the question was is go now because that hello world was static content static web browsers everybody knows it's blazingly fast any person can write a fast static web browser the question was is go the right tool for higher intensive dynamic content and absolutely that's the purpose of go it's designed to have very very fast IO intensive stuff if everything is compute intensive like video encoding go will not be very effective because the compute or CPU resource hungry process will grab the CPU but if it is IO intensive go is the perfect fit much much much much better than Node.js Node.js rock the world because in multiplex a lot of IO intensive process onto one thread go multiplex the same thing actually go sort of copy Node.js in that sense but not on one thread on all available threads if you have a 64 core CPU 64 processes can be called to task versus one process in Node.js any other? yes okay tekchun say other speakers need a chance as well so apart from this highly static type so what's the goal men or JP trying to solve the problem what problems is trying to solve the first question second question is is it effective when we have a limited CPU or limited memory other than the Java okay what is go good for writing back-end service full stock go is fantastic for writing back-end service second question is go resource hungry does go require a lot of resources like Java for example and the answer is no go is very very efficient next to C in terms of efficiency if C was the go standard as 1 it uses 100% go would use maybe about 110% maybe 105% so it is very very resource efficient thank you