 good morning. Good day to my fellow Aussies here in the audience. I'd like to start off by thanking Michael for giving me the opportunity to speak today. This is the first largest conference that I've actually been able to speak at. So it's a privilege and thank you, Michael, not for just giving me the privilege, but for organizing all of this. It's really great. So I'm going to start off with a little bit about me, okay? So I come from somewhere around there, Sydney, but currently for the last four years I've been living somewhere around there, which is supposed to be Malaysia. This map isn't very good. So yeah, back in Sydney I helped to grow the Sydney PHP group. I did that for many years and I left it with a bunch of very capable fellow developers and it's thriving today, which is great. While I was there I did help to establish the Fun Conference, which is an unconference, a bit of a pun, and that's an annual event and I think this year they're coming up to the sixth Fun Conference and that gets about 100 to 150 attendees. So if you're in Australia towards the end of the year, or maybe the beginning of next year, I'm not sure when they're running at this time, check it out, it's really great. So I currently work for a company called Zinios and I am the CTO, but primarily my role is the guy in charge of all the research and development. So my job is to basically try cool new stuff. So a lot of the stuff that you guys have been presenting today is probably something I will go back and I will spend a few weeks checking out and seeing if it's something that we want to use in our products or any of the sister companies that we're associated with as well. Okay, my other job is to build frameworks. So I actually have spent the past year and a half building a considerably large hack framework and an application platform built on top of that framework. So I'd like to start today by speaking a little bit about how I got started with hack. So I originally started in 2009 when there was no hack and there was no HHBM. I was brought into a company named SpinFX in Australia and they had a rather large software application written in PHP 5.2 and backed by MongoDB. Okay, so it was a big data app. I mean, it was doing thousands of transactions a day, but not hundreds of thousands, but it was collecting and storing quite a lot of records. And it was getting to the point where it couldn't handle the capacity due to some architectural problems. So I was brought in to build the new version of this software. So back then PHP 5.3 was just released and, as you all know, that was one of PHP's biggest releases. It hadn't had any significant changes for a while and this introduced a lot of great new features. Unfortunately at the time, none of the frameworks actually supported these new features. They were in development, but they weren't ready and we needed something that was ready, but it just wasn't there yet. So we wanted to take advantage of all these things. So we decided to roll our own framework, as you do. All right, so around that time, Facebook was showing off HP HP. So that was the hip-hop PHP. It wasn't called the virtual machine back then. And I actually ended up writing a piece of software, which was a message queue, in PHP 5.3 backed by HP HP. And I wrote that to complement the existing software, which we were trying to keep alive until the new software was ready. So it was able to take a lot of the post-processing of all the data and queue that up and manage that in the background without hammering the rest of the system, which was an ongoing issue. So, yeah, when I played around with it, I was very impressed. It was very fast. It was really, really fast. To a PHP developer back then, there was nothing else like it. All right. So what is HP HP? It's a transpiler. And essentially it converts your PHP into C++. And it compiles that into binary and then runs that as highly optimized code. And that was great. It had some issues with development. Namely, it was difficult because it kind of had the C problem, where you had to constantly compile. But they introduced something called, I think it was called HP HP I, which was a more of an interactive mode, more like what we have now with PHP or even hack. And that alleviated the issues for a little while. Right. So we wanted to support HP HP in our new framework. But the problem was it had a lot of gaps. One of the biggest gaps was the fact that SPL was almost non-existent. So it didn't work. Fundamentally, under the hood, it needed to understand what methods and functionality was already available from PHP to be able to interpret that and whatnot. So what we end up doing is we filled the gaps. We rewrote the SPL libraries in native PHP, just use the line code. And we compiled that in and ran that with all of our apps. So that filled that. That was one example of many that we had to fill. But that's how we got through it. So Nutshell was born. Nutshell is our framework written in PHP 53. We got a lot of mileage out of this. And even up until last year, we were still using it in pretty large production sites. So let's skip forward a few years. So it's now 2013. And this is when Facebook has just released the hip-hop virtual machine. So they've re-engineered everything. It's now a virtual machine, very much like FPM. So it runs the same way. And it was initially designed to be a great drop-in replacement for FPM. So you could drop it in and your code should just run with all the benefits that HHVM would offer. And that's like an immediate speed boost. So it uses far less memory. And essentially, a lot of developers tried to use this, but it had issues. Mostly issues around existing frameworks, which a lot of you use, you know, Zend, Symphony, et cetera, they wouldn't work. There were things that just wouldn't work properly. But over the months, the Facebook team actually did quite a lot of work to make sure that they supported all those frameworks. And that's one of the things that they prided themselves on. So at this stage, I'm living and working in Malaysia. And I started working on a content management system called nuts and bolts. So there's a bit of a story behind this. And I think I have time to explain it a little bit. So it was one weekend and I was actually invited to my boss's house for dinner. And we're both Australian. So we were drinking as you do. And it was quite late at night. And my boss isn't a programmer, but he does dabble. Anyway, he's like, let's build something. We're drunk. Let's write some code. And so it's a great idea. There's this thing I always wanted to do. I wanted to build a CMS on top of nutshell. So yeah, let's do it. So we're drunk. And a few hours later, early morning, I've written this content management system. And yeah, so then Monday comes around. And I look at, oh, what did I write? It's this Mammoth code base. And it works. It inputs content and outputs content. You can manage pages, you can pretty rapidly develop something. But it was hideous. The code was terrible. Yeah, very bad. So anyway, a few days later, we won a big project. And we were sober at this stage and we said, okay, let's use the content management system for this. And so we used it. And we thought it's only going to take a couple of weeks to finish this project. So no big deal. So two months went by. And we finished the project. So it was over budget. It's terrible. But we'd actually filled out the content management system with quite a lot of features. And at this stage, we were invested. Right? So we'd already put the time and effort and money into building this thing. So we thought, oh, we'll keep going. We'll use it on the next project. It's fine. We had a repeat of the same issue, blew our timeline considerably. All right? So that was not great. Eventually, you know, we filled it out with so many features that it did stabilize and it was useful. But I guess one of the morals of the story is, oh, this has been going without me. Sorry about that. Auto progress. So don't drunk on your code. So yeah, we used it for a lot of projects. But it was a CMS. It wasn't actually architected to be anything more than that. And what we were actually doing it, using it for, was quite a lot of e-commerce stuff and a lot of big data. And we really were running into massive performance defects. Okay? So it wasn't, it wasn't handling high traffic. It wasn't really handling big data very well. Hacks were written on top of hacks, patches on top of patches. And it became something that we realized we needed something new. So it's 2015. We had large projects coming up. We knew we needed a new solution, because we'd reached the point where it was too hard to move on. Now, we knew that we were going to still have to support this for the next year or year and a half while we built something new. Okay? So we knew we didn't want to build another CMS because the software that we were writing for clients was well beyond what a content management system should be or should be capable of. So we created a new development team. We had new goals and new methodologies and practices. All right? So what we wanted to do is we wanted to focus on writing code. We didn't want to worry about chasing our tails with bugs and issues that come up. And in fairness, in development, we all make mistakes. Okay? So we wanted to do that and we wanted better insight into the code. We wanted to be able to look at it at a glance and understand what was going on without having to dig too deeply into the code. We wanted something that was strongly typed. Now, we're a PHP shop. So the problem was that we didn't really want to move to something like .NET or Java or any other strongly typed language. We wanted to stay as close as possible to PHP so that we could reuse everybody's skill set. So HAC was just released by Facebook at that time. It runs on HHVM. It's basically PHP with a lot more features. So that alone was enough to convince us that using HAC was the right choice. Okay? So from there, it's now 2016. Our new framework has a 1.0 pre-release and the application platform is almost there. Okay? But I'm not actually here to talk about building frameworks. I'm not here to talk about our new platform, but I hope to come back next year and talk about that. So what I am here to talk about is some of the successes that we've had as a company moving to HAC, some of the pitfalls that we've fallen into, some of the traps and how you can get around those and avoid those. And I want to show you some of the great features of HAC and what it has to offer. So we'll start off with some successes. So without a doubt, every member of our team has become a better programmer. HAC has what we call a type checker and just that alone, when you're running it, it type checks all your code and it digs deep into your code and lets you know if you're doing nonsense things, right? It teaches you to be a better programmer. If you're constantly following it, you'll notice your mistakes and eventually you won't make those mistakes. And now this is the result of our team. We don't write many mistakes anymore. We still do, but not so many as we used to. Because of that, our products are more solid, they're more robust. It's easier to maintain our code, mostly because it is strongly typed. The inference that we get from analyzing our code is very easy so we can look at it, we understand what's going on. And yeah, this isn't a presentation about frameworks, but with our framework, we can do a lot more with writing less code. But even so, without a framework, we can generally achieve the same goal with HAC. So in the end, we have a great framework and amazing platform and I hope to show you that next year. So you can get started with HHVM by using any of the pre-baked images or scripts. Any of these are supported. And there's others as well, of course. Otherwise, if you have a pre-existing virtual machine or a server, you can use one of the pre-existing packages. For example, Ubuntu is as simple as sudo apket install HHVM. Alternatively, if you're brave, you can build from source. I've got to say that building from source for HHVM and HAC is one of the easiest build experiences I've had. We use a lot of MongoDB, and they do have a MongoDB driver, but you have to compile it whenever you upgrade your HHVM. But that's fine because it itself is actually really easy to compile as well. It's quite a good experience. So I mentioned the type checker earlier. So it basically analyzes source code before run time. So you're able to see what errors you get before they actually become bugs. So you can see in a console or it also supports various editors as well, and that will connect straight in and give you inference on your code. So it's run with a program called HH Client, which comes with HHVM, and it looks something like this when you run it. Now, so I've created something and intentionally created an issue here. So it's basically saying that I'm using a string somewhere where it should be an integer. So you can have this running in a console because I'm on windows and HAC isn't very friendly with windows, but I have this running and immediately I can spot I've made a mistake and fix it up. So the code for that looks something like this. So you can see here that the run method is expecting a string as a key and a mixed value, but I've actually just given it a pretty flat, numerically indexed array. It doesn't like that. But we'll have a look more at what all this means in a bit. So learning, how do you learn HHVM? How do you learn HAC? Read the manual. Yeah, there are some languages or a lot of projects that have terrible documentation, but they have great documentation. So check out the docs. It's really easy to get everything you need to know there. Otherwise, NGNAT has a really great three-part article that you can go through if you're getting started and that'll teach you everything you need to know to kick-start your HAC experience. So what's the difference? Differences between PHP and HAC. So HAC looks like PHP, feels like PHP and the problem is it's not PHP. So there's a number of differences and I'm going to go through them with you today. Have a look at some minor differences first. Then we're going to tap into what's not supported because it being a very strict and strongly typed language, they've had to make some exceptions and they've had to remove a few features and a few things that you guys probably like to do. And then we'll get into having a look at some of the great new features that it offers. So the opening tag has changed. So we're using HH instead of PHP and there is a special rule around this. If the first four characters of your file does not match that, it will not be interpreted as a HAC file. You could even get an error. So you're not allowed to use closing tags. You can in PHP but it's not recommended and in HAC they've just said you can't do a period. You can't possibly close the tag. So the other thing is we use .hh instead of PHP for our files. Okay. So top level code. Who understands what top level code means? So it's probably more commonly known as your procedural code. It's the code that lives on the initial execution, the top execution level. Typically not in a class. Okay. All right. So this is not permitted and this is an example of top level code. So I've got a function that's acceptable but calling foo from the top level is not acceptable. You can't do this. So this leads to an issue and that is that we strive to have 100% strict code. So there is a strict mode and a partial mode and a decimal mode. You should only be concerned with strict and partial. We strive to get full strict but due to this rule it's actually not possible to have 100% strict code because you need a boot strapping file to kickstart your application. So that's typically a partial mode file which initializes your application. So sometimes it's unavoidable because you might be migrating code. You might be migrating it from PHP to hack and you don't want to rewrite everything initially. What you can do is you can do some tricks here which isn't really to trick the type checker, it's just to make it happy and allow it to continue to optimize your code responsibly. So what we can do is we have a file called toplevel.hh and we have our toplevel code in it. We can actually then require it in another file and execute it in that context which is allowed. It's acceptable. So you might also notice that I use require once there. That is one of the few things that is allowed on the top level. There are some others. So we have require require once, include once, namespace use, class, trait, interface, function. Those are all allowed. So everybody here uses references in PHP, right? It's mostly used to optimize your arrays but it can be used for other things as well. PHP passes all the objects around by reference anyway. This is not supported in hack. If you try and pass something by reference you will get a runtime error. You'll even get a type checker. It doesn't like it. That's because the type checker cannot figure out what's going on if you use that. It's not designed to use references in the engine whatsoever. That's mostly because it doesn't need to. Because it does such deep analysis of your code to optimize it. It already knows what's going on. If you're passing one array to somewhere else it's going to know that and it's going to optimize it for you efficiently. That's something you have to worry about as a programmer. Okay? So another thing is HTML and PHP being mixed together. This is a no-go in hack. It's not supported at all. One reason aside from the obvious performance issues is the rule that I mentioned at the beginning where you need to open with HH that if you have HTML before it's violating the rule. And we're not allowed to use a closing tag to put HTML after it. So it's impossible. But there is a way to do it. It's called XHP. Who's heard of XHP? So who's heard of React? Yeah? Great. So React was made by Facebook too. So they thought, well, let's add this ability to put HTML as native code in hack. So actually it's an XML-like syntax that it allows. In React, those who you are unfamiliar with it, it transforms them into components, which are essentially first-classes. And you can use them in much the same way you use HTML. So this is something that they've built in. It's called XHP. It looks something like this. So I don't have any string quotation marks around this at all. This will run. It's perfectly valid. XHP is a really large topic. And I can't get into it today because we'll definitely run over time. I could do a whole couple presentations on that. But it's really great. I recommend you guys check it out yourselves. Okay. So intrinsics. Okay. So certain language constructs aren't supported. You cannot use them. And this is actually the biggest thing that caught my team off guard the most. Like, the most type areas that we have still getting pushed into the system are because of this. Okay. It's become such a habit that we use IsSet, Empty, and Unset that we don't think otherwise. Okay. But with Hack, there is actually ways to get around it. So with IsSet, you can test if it's null or not. But essentially, you don't always really need to do it because the type checker and the engine already knows if something's set or not. So it will warn you if you try and use something irresponsibly. Most commonly used in arrays, though. So you want to check if an array key exists, particularly if you have, like, a bit of a dynamic array going on. You can do that with, like, a array key exists, or if you're using maps or vectors, which is new in Hack, you can actually call the, you know, does key exist method. Okay. With Empty, well, you can just test if something's an empty string. It's pretty easy. Unset, not needed. You just set something to null. It's the same thing. Okay. So here's the big one. And this threw me the most. So when I was trying to migrate the nutshell framework to our new framework in Hack, this threw me off guard quite a bit. You can't write dynamic code with Hack. So the obvious one, which I think is, anyway, eval and pre-function. They're not supported. They're out of the engine. And if you're using them now, bad. All right. They create a lot of problems. And it's actually impossible for the type checker to infer what's going on with that because it can't do it until runtime. So what's got me the most was the dynamic syntax. So stuff like this, right, you can't do it. There are ways around this. And if you have a look at the source code for our new framework, which by the way is called Nucleo. Nucleo has some partial files which expose some functions which you know, rack this kind of functionality to allow you to make these dynamic calls. But yeah, essentially variable methods, variable properties cannot. They're not supported. So a couple other ones, quick mentions. Who remembers PHP 4 style constructors? Yeah? Not allowed. You can't even put the function in there anymore. For those who don't remember, if you name the method in your class the same as the class name, that's a PHP 4 constructor. You can't do that now. You'll get an error. The type checker will say no. And at runtime, it'll also say no. Template style syntax. So I used this quite a bit back when I was doing PHP because I quite liked using very light. I considered it as view style PHP where you wouldn't put any kind of business logic or anything like that in your code, in your HTML code. But things like conditionals like this was great and it was very easy to use the PHP tags to achieve this in your HTML. But they're not supported at all anymore. So if and if all those family of structures you can't use. So incrementing and decrementing strings with plus plus minus minus, that's not allowed anymore. So a lot of people in their code still use and or XOR as literal words. You can't do that anymore. You need to use the symbols. You used to be able to break number in your code if you had like deeply nested switches or loops. So you could break multiple levels up in one go. Or you can continue or what not. You can't do that anymore. It's been removed. Hack is case sensitive. So you cannot, for example, use uppercase class foo and then try and initialize it with lowercase class foo. It won't find it. So you can be a little bit loose with PHP in terms of how you access various methods in a class. You can't with hack. You have to use the appropriate wording at the appropriate place or you'll have issues. Okay, so there's a lot of new stuff. Now what I'm going to do is I'm going to start with types. We touch on a lot of other features as we're walking through types. Just simply because the type system in hack is so ingrained into everything that we will see most of the features as we go along. After that, we'll have a look at some other things and some worthwhile mentions at the end. Hopefully we have time. So I'm almost out of time already. When I tested this presentation last night, it went for an hour. So I'm trying to... Three minutes? No, I've got eight minutes. Okay, so we rush through this then. Okay, so as you know, PHP 7 has some new typing stuff is getting better and better. Unfortunately, it's not able to get to the level of hack due to some limitations with BC breaks. So moving on, you can define type annotations on class properties, methods and function parameters, method and function returns, constants, and you can type types and some other types of types you can type. You need to understand recursion before you understand recursion. So what's the difference with this? So let's have a quick example. This is some basic PHP. So it's an upset function. It's an imaginary method I've come up with. Let's say, for example, it can insert, update a record in a database. Pretty straightforward. Everyone should understand this. Now, PHP 5, they introduced the arrays and object sort of thing and you could do that to get some more information about your function here. So that's good. It's an improvement. PHP 7 gets even more creative so arrays are actually a type and you can have return types as well. PHP 7.1 slightly improves that. We can say, well, we might want to actually return null if there was a problem, like if we didn't insert the record correctly or whatever. So here we go to hack though and we get a bit more detail. So here we're saying, okay, we want to have an array and we want its keys to be string and its values can be anything. So this touches on another new feature of hack. This is generics. So type generics and it allows a lot more power and flexibility to be implemented into various things in the language namely arrays and collections as you'll see soon. But they're essentially like a way of defining a placeholder type. So when you create your method or your class, you don't know what the type is going to be until somebody initializes it. So it gives you that kind of dynamic flexibility. Okay, we can make this a bit easier to read though and that's by using type aliases. So here I've created common string key array which is an array, the same thing as we saw in the previous slide but now we can use it down here. So we can see that it's a common string key array. I know what that is throughout my code. That's great. Okay, so we're not repeating the signature everywhere. So if we want to change it later, we can but obviously you've got to be careful with something like that. Now what if we want to make this even more readable? We can, by aliasing aliases. So now I know, oh, this is a DB record. This is a DB query. This is a DB query options. Okay, so it no longer matters what these are called. If you have terrible variable names, then yeah, that alleviates that for you. Now what if the DB query options was specifically shaped in some sort of way and you didn't remember what they were? Here you can just define what the shape should be. So what this says is the DB query options type must have an order, must have a limit, must have an offset and they're all integers. You cannot add or remove any more from this. It's a shape. You must conform to that when you're using the upsert method. Okay, so what I like to do is I like to actually include a types.hh file with all my custom types in and then it just makes it available to everything. But you can also type your properties. So here we've got like a DB connection which could be nullable and we have a boolean. So it's connected to real false and we might store the last query and we know that's a DB query. We know what that looks like. Okay, so there are quite a few types in hack. So there's the common ones that you know of. All right, but there's some new ones. So we've got void, no return, mixed. You already know of object that's in PHP. This num is a union type which mixes integer and float together and we have array key, which is quite common in array keys and it mixes an integer and a string, okay? Another union type. Okay, so most things can be prefixed with the question mark. You know this already is in PHP now. Can't use that with void or no return and mixed already includes that so you don't use it with mixed either. I have two minutes according to this. All right, so, sorry, sorry, sorry. Are you all interested? Yeah, yeah, yeah, yeah, yeah, all right. So callable is gone. This is something that was introduced recently in the PHP but it's a type that doesn't make sense in hack because when you're introducing a callable or a closure, the type checker doesn't know what it looks like. It must know the signature, all right? So what you gotta do is you actually gotta shape it out like this, all right? So you need to give it exactly what it's gonna expect and then the type checker is able to deal with that. Okay, tuples are supported and they're like arrays. They have a few restrictions, fixed size and type. Values may change but they must be the same type. I'm just gonna skip through these quite quickly. We've got enums, collections are new. I personally use collections everywhere so they're basically specialized classes for replacing arrays. They use very specific patterns to help you optimize your code, okay? So we've got map, we've got vector, we've got set, we've got pair. Map is like your standard array that you use quite commonly in PHP. Indexed with both keys and both strings and integers whereas a vector is just integers. A set is a special collection. It's key list and it only supports integers and strings. And when you think about it, this is actually a common thing that you do in your code, right? So then we have a pair which only has two keys, two values and it's immutable, all right? So once you set the values, you can't change them. Everything has an immutable counterpart except pair because it's already immutable. So we have in map, in vector, in set. And they all have literal syntaxes like this. It's a little bit more verbose than the array syntax but that's because there's only so many brackets, right? So they just prefix it all. All right, so there are many other features worth mentioning. We got class attributes. This is just basically a way to add some metadata to methods or classes. And this is reflectable so you can do a lot with it. Now here's an example of some real code that I have in my framework. And basically this is a command line tool. So it defines what the command is and what arguments it accepts. And so it's this argument or it's an alias. And then the method. That's how attributes work. So one of the greatest new features that I've just added is the pipe operator and I really hope it gets added into PHP because it's fantastic. So this is the old way you would do something. Nest all these methods together. With piping, you can break it out. And your code is readable. It's amazing, amazing. All right, so some other quick features. Constructor promotion, tracing interface requirements. There's asynchronous code. It's lambda's and a lot of other small ones which we don't have time to go into. Would you like me to wrap up now? Okay, so I'm being kicked off stage. If you wanna come and talk to me about some of the issues we faced and how to get around it, please do. I'll be here all day and night. Thank you all for your attention today. I hope you enjoyed it. If you have any questions about anything in general hack or the company I work for, whatever, please come see me. Thank you. Thank you, Timothy. Okay, if you guys have any questions, please ask right now or there are mics at the back or you can wait until tea, which is coming up next. So anyone has any questions? Yeah? All right, you can use the mic at the back. To what sort of websites do you recommend HIPHOP-PSP? So is there any, to what sort of websites do you recommend HIPHOP-PSP? What kind of websites? Yeah, it's like any benchmark or criteria like it should handle some, this much amount of traffic or if it's handle some big data like that. Well, I mean, you get the obvious immediate speed improvements on using anything with hack so it's a benefit in that sense. There are benchmarks which were showing that that PHP was faster, that was true for about a week. I might want, I just want to put that out there. But yeah, if you're using everything I've just shown you, you will produce faster code in general. But if you're just using PHP with HHVM, you're gonna get a small improvement, but it's not gonna be that noticeable. It's probably not worth changing at this stage because the difference between PHP 7 and HHVM is quite minimal right now. Oh, okay, yeah, that makes sense. Okay, thank you. For anyone else that has any questions, you can ask Timothy during tea. We'll have tea until 11.45 today. Is there anything else? Okay, let's all head out for tea. I think the food is here.