Slack is an application for team communication. Users chat across mobile devices, web browsers, and a desktop application, which means that Slack has three places to deploy on, rather than the more traditional two places where you just have a mobile device and a web browser. And the desktop apps on Windows and Mac and Linux are not identical, so Slack has even more places to deploy with all the variation in operating systems. With so many different runtime environments, Slack needs to make technology choices that reduce the chance of errors.
TypeScript allows for static typing of JavaScript. The extra compilation step checks the types of variables being passed between different places, so the errors will be discovered at compile time. In an untyped world, these errors might occur at runtime. TypeScript also unlocks the ability to put JavaScript code in an IDE, allowing for more efficient development.
Felix Ryserberg is a desktop engineer at Slack, and in today's episode he explains the unique challenges of building Slack and why the team moved from JavaScript to TypeScript. Felix Ryserberg is a desktop engineer at Slack. Felix, welcome to Software Engineering Daily. Hey, how are you doing?
I'm doing quite well, and I've been using Slack all morning. It's one of my favorite products. And the Slack desktop app is entirely written in JavaScript. And today we're going to be talking about TypeScript.
But before we get into TypeScript, let's motivate that discussion and talk about programming within a large JavaScript codebase. What is difficult about managing a large JavaScript codebase? So I think Slack might be one of the more unique cases. What is going on is that Slack is using a framework called anectron, which allows us to do all the easy parts of JavaScript and HTML, and then we have a thick layer of C++ around it that is responsible for the quote-unquote difficult part.
So for the things that you will consider to be a little bit more advanced, something like the video calls that are available in Slack today, there is a C++, and then we have a thick layer between those two worlds that combines those two worlds. And even if you do not call into something native, even if you don't call into C++ regularly, I personally feel like managing large JavaScript code bases has always been troublesome because the distance between your code and the code that you might be directing with increases over time and with the complexity of the codebase. So if you have just one file and you're calling a certain function, it's very easy for you to see immediately where the function goes. It's either immediately above or below your code.
But as applications become more serious and as applications grow in size and complexity, the location of that code that you're interacting with might just be further from your location. And that makes things pretty difficult sooner or later, right? Because in so many cases today, if you have dependencies, if you have various dependencies, you don't even know what the code looks like, you don't really know how the code behaves. And it's very hard to make sure it's about what the code is going to do every time, right?
And I think that is really something that the community has been grappling and that's something that we can be able to do at all with for a long time at this point. We had JSTALK and various other solutions to try to help us with that, but it has never really been a good solution that was like, it's a function that I can guarantee to you that this function will always return X. And if it goes, it will always throw X. Yeah.
So just as we're talking about the architecture of Slack, we actually did a show about Slack's architecture. And I think I remember much of it being in PHP. Is there still much of Slack that's written in PHP? Also the backend is completely in PHP.
I mean, I'm a majority of it. So the Slack application that you have in the desktop, it basically is something very akin to Visual Studio Code or WordPress or WhatsApp. It's this HTML application built into Chromium that gets to make full use of Chromium at the same of corgues. And that application then interacts with the backend.
And so this is the one that you interact with daily. That one is pretty much a highly react type script. And then as a set is pretty quickly, obviously, plus I've found it. But most visual elements they interact with and most of the lifecycle events, you know, what the application does at start and how it shuts out and how it saves data.
We can write all that in JavaScript, which gives us that, you know, easy ability to write a cross-platform app with what we consider to be a pretty small team. But that's about team at Slack is working for people at this point. Wow. So if I'm using the Slack application on Windows or Mac or Linux, is the backend the same as it or sorry, the front end for the front end, the C++ layer that's sitting on my desktop and doing some of the lower level desktop work, are those applications all the same?
The C++ part? Yeah, excellent question. So the C++ part is not the same. That really depends on your platform.
A good example would be notifications. The way we send notifications on Windows, we do it natively, right? So it shows up in the action center and you get those like little, beautiful windows notifications that you expect are completely different from the ones we send on Mac OS, but we use Objective-C. But everything else that could be cross-platform, right?
Like the input menu or the channel list or your team selector on the left if you have multiple Slack teams, all of that is cross-platform. So everything that is TypeScript is cross-platform and we just write it once and it runs on all platforms that we support. It's pretty amazing. The consequence here is you've got JavaScript that is interacting with native code.
So on Mac OS, it's Objective-C, if you have these platform specific things, there's desktop platform specific things, for example. What are some best practices when you're writing code that's going to pass, because you've got to pass objects between JavaScript and the native desktop client. If you get a notification in Slack and you want to see that notification in your whatever your native notification panel is, there's got to be an object hand-off between the JavaScript code and the native code. So what are some best practices when you're writing code that's passing objects between languages?
Yeah, that's an excellent point. That's something we thought about for a very long time. And I want to say this is probably the main motivator for us to ultimately go with TypeScript. Operating systems, especially on a lower level, an Objective-C plus plus, are pretty unforgiving if you give them wrong stuff, right?
And VA does doing a very good job. VA being the JavaScript engine that is built into Chrome and Node.js And it's also built into a Slack. The best app is extremely good at bridging that transition, moving from the JavaScript world into the native world. It's very good at that.
But still, if you're given a broken object, the operating systems are usually pretty unforgiving. And what I mean by pretty unforgiving is that it's not that you just wouldn't get a notification. In most cases, all applications would just crash, right? And if you're doing some even lower level stuff in the Chrome world and Windows, if you write and create JavaScript that eventually ends up in pure memory, you can absolutely blue screen your computer, right?
That is something that nobody's interested in. So in the past, what we've done is we just triple and quadruple tested our code. Despite our team being very small, we have an equally science quality assurance team, and we have people that, in addition to our unit tests, basically tested out of our application. And then we also used JSTOCK in the past.
But with all these practices, I think as long as you have human error involved, it's very likely to still make a mistake, right? Because if you use JSTOCK, which I think is pretty much the next best thing to guarantee in how it behaves, you really rely on the form of developer to have made good JSTOCK comments and have not made mistakes, right? And casting mistakes, I think it does give a big comment. There's some solutions in the aerospace industry usually applied to CNC++, which are pretty strict, right?
They're basically saying, like, a function should always fit on one computer screen, it should not be longer than 100 screens, it should not make any mutations, parameters, one input, one output, right? There's some pretty hardcore rules you can employ if you want to make guarantees about your code. But I think JavaScript, not having a compiler, makes it pretty hard to not shoot yourself in the foot eventually. Yeah.
Well, let's get into that. Some people are probably unfamiliar with this idea of adding a static typing layer to JavaScript. So that's what TypeScript does. TypeScript is a language where it's statically typed.
So in JavaScript, you don't have to give a type to your variable. It's a dynamically typed language. TypeScript adds static typing. So it forces you to add, or I guess I think it's optional to add types.
Why is it useful to have a type system introduced to an untyped language? Yeah. I think that's an excellent point of this question. I keep getting quite a bit, especially when we introduce TypeScript to newcomers, they come to stack or when I talk about TypeScript at conferences.
And the very basic layer of JavaScript already has something that is akin to types, right? You all have used to type off at some point, and it's broken in various ways, but in theory, JavaScript has some very basic and primitive types. And you constantly do some basic checks where you see if something is an array, or if it's an object and you perform certain operations and you expect certain properties to be present on an object that you receive. What TypeScript really does is, very basic layer, if you just activate TypeScript on your existing JavaScript code, which by the way, is something you can do, and that was a huge benefit.
We should get it to that later. But TypeScript, if you can activate it on a naked JavaScript file, vanilla JavaScript, ES6 is five, it doesn't really matter. And it will immediately try to be ducked types as it understands them from vanilla JavaScript, right? If you have a function that accepts an array, and it will understand that you're trying to accept an array because maybe later on, you're trying to call for each parameter, you try to call that method with, let's say, a number.
TypeScript will eventually tell you, hey, by the way, just so you know, you're trying to pass a number into this function, and then the function will later take the number and try to call for each on it, that's not going to work. Right? So there's like very basic layer without you describing your own types, and tries to use JavaScript's internal types to help you make basic mistakes between strings, numbers, arrays, objects. And once you start playing with that, once you start enjoying that, right?
So you know, later, you will have an object. And in theory, and JavaScript, all objects are more or less equal, right? Passing in an empty object is basically the same as passing in a different object, but sooner than that, you want to define some things. If you stick with our notification example, right, we absolutely need a notification object to have a buddy filled with a string that needs to be there.
So then you enter the great world where you can tell TypeScript, hey, TypeScript, just so you know, in this parameter, I'm always expecting an object that contains the buddy property, and that buddy property should not be empty and should be a string. And once you define that, you don't really have to worry about making mistakes ever again, because TypeScript will warn you, should you ever try to pass something in that doesn't have that property. Then going one step beyond that, and then I'm going to shut up. By going one step beyond that, I think one of the most common mistakes is actually not that you have a string that you have to string and be passing a number.
One of the most common mistakes is that people assume that properties are present, that may or may not be present on an object. So if you stick with our notification example, let's actually stay within the stack world and the notification example. Somebody passing an object that doesn't have a buddy seems extremely unlikely, but we have all these extra properties that we may not use, right, we have something like images, or like an avatar, or maybe local or maybe remote. So the most common mistake is that somebody's passing something in that doesn't have all the properties, and then in the end, somebody in the actual method, the person who implemented the method, did not make clean assurances to check whether or not certain properties are present.
And then I think everybody has run into the error at least once we try to access a property on an object that is undefined. Right. That was good. That was good.
blows up. Right. Absolutely. And you know, like one example would be if you pass a user object from one place to another, a user obviously is going to have a name, but does it have first name and last name, or does it just have name?
And if you try to access the wrong one, like if you try to pass a user variable somewhere, and you try to access first name when it just has a name property, then you're going to blow up. And oops, like it would have been much better to catch that mistake at compile time rather than at runtime. Yeah, exactly. Or even better, that's my recommendation.
I feel like that's going to actually allow me to stop thinking as much. Once you add TypeScript to your editor of choice, right, visuals for your code, supply them out of whatever you use your editor will just know if you did the right thing or not. And we'll give you this like nice comforting, sweetie red lines to tell you you made a mistake. Right.
I can write that's pretty nice. So my evolution as a programmer was I started programming in college. And the introductory language for us was Java. I know a lot of people don't come in through Java, but for me that was it was Java.
And it was a type of it's a type language. You know, you say int x equals five, you have to you declare as an int and then you compile it and in that compilation step, it makes sure that all of your operations are being done correctly because it has types. So it makes it type guarantees. And in fact, you know, since you're working in an IDE with Java from the beginning, you know, most people working in an IDE interactive development environment, you catch these mistakes before you even compile.
So by the time you compile, you know that your code is actually going to work. And in some sense, it's really nice. But then maybe a year or two into programming, you get introduced to a dynamic language like JavaScript or Python and it's interpreted. And you're like, wow, this is much faster to work with.
It's much more fun. You know, it fails sometimes in ways that are not very graceful, but at least at least a compile, at least it ran. And at least I got to see it partially fail. I saw my web page load and like oops, that image didn't load, but it was cool to see my web page load.
It's fun. And it's probably why people fell in love with JavaScript, I think. It's like, oh, it's just it runs. You know, sometimes it doesn't completely run properly, but it runs.
And then, you know, you work in the industry for a little bit and then you learn some hard lessons about interpreted languages. And you start to realize, oh, you know, that compilation step that I hated about Java, it turns out that's actually kind of useful. Yeah. I'm with you, right?
I feel like Python is the same boat where many people who enter the development world today stop at JavaScript of Python just because it is so much more snappy and easy, right? But I think, uh, I think I'm perfectly right. You're perfectly right. We really enjoy JavaScript, right?
That's not making a mistake. I think we really enjoy using JavaScript to stack mostly because it does allow us to have a very small team very fast and very quickly quickly deploy things, be cross-platform. Let's not forget that JavaScript has gotten wicked fast over the last two years. I met some of the Google V8 folks a few months ago and inquired how the heck they managed to make reg X arrays so fast.
If you do reg X today in Chrome, it's amazingly fast. And they were like, oh, I'm really happy that you noticed about like half a yoga, we stopped turning it into, um, we stopped turning it into whatever the intermediary code was. And we're now turning reg X directly to assembly, which is very, very impressive, right? So yeah, we really liked that was good.
But I think you probably have a point where at some point just start shitting slack, in my case, right? I give slack to my customers and there's a decent amount of trust going on, right? Like people type in their stuff. They have messages there.
They deeply care about what they put in a stack. And it's really on me to make sure that I didn't mess something up. And the more guarantees I can get for a very low effort to say, oh, I'm not going to mess this up. I'm going to take them all.
Right. Right. Okay. So we've got a number of reasons that we're touching on here.
Why TypeScript is useful? Why it is useful to have a compile time step and a typed language. So we've got the IDE becoming possible because the reason you can't have a great IDE for just raw JavaScript, at least that I know of is because it's on type. So the IDE can't really give you great guarantees about what's going on because it can't analyze the code super well.
It can't do great static analysis, whatever you want to call it. And then you've also got this, this issue at slack where you're handing off variables from one language to another and you want to enforce certain guarantees about those variables. And it's useful to do that with a typed language. And then you've also, I guess just got the fact that this is a giant codebase and you're sharing it with lots of different developers.
So you want a stricter, just a stricter set of rules, a stricter set of variable typing. Are there any more subtle reasons why TypeScript has gotten adopted by Slack? I would say there are a few that all come down to just, I'm delighted as a developer. Let me just write them off real quick.
The first one is, and I think we underestimate this as developers that have moved away from Java, right? And I look down on those people that can't really do anything without Autocomplete. Autocomplete is pretty amazing. It is fantastic.
The fact that my editor knows what kind of properties are available on the object and don't really need to check everything on time, but they're not something like web preferences, right? Let's say that I have a property called my preferences. Is that camel case? Is it snake case?
Does it have an underscore somewhere? I don't care anymore because my editor knows. And that's, I'm probably going to get a bunch of tweets about like, you know, only real developers don't need autocomplete, but it's so convenient. And then there are two other reasons that I've really enjoyed TypeScript.
One is, I think we're sort of observing a beta max versus VHS fight between the various type systems. And TypeScript seems like the one that has been adopted the most widely, right? With Google adopting it and various other companies. If you heavily rely on what models your chances of finding typings for a node model that is not written in JavaScript are extremely high.
Excuse me, not written in TypeScript, right? So let's say something like React, which is famously not written in TypeScript. You can still find types for that. And it's very easy.
And that also gets down to some of the less unknown modules. So it's very easy to get TypeScript with a typical npm world. And then the third reason is that TypeScript by itself is just extremely cross-platform. It doesn't make many assumptions about your device.
It's transparently fine with all editors. It's just fine on all operating systems. Then it's Windows, Mac OS. And as a company that is building a cross-platform app and has developers on all kinds of machines, that was pretty important to us.
So in summary, we're pretty big fans of TypeScript. I do feel like there are a few downsides, but in summary, it's pretty amazing. I will heavily recommend it to anyone who's going to listen to me. Yeah.
So we've now motivated why TypeScript is useful. And I think we can now get into talking about the process of migrating Slack's code base to TypeScript because it was not originally in TypeScript. That is true. And you were mentioning this earlier, but that basically it's easy to port a JavaScript code base to TypeScript gradually.
So let's start to talk about migrating that code base to TypeScript. Give me an overview for how that narrative got started within Slack when people started to say, you know, maybe let's just try to migrate this and then how that caught on. I think for us, it was maybe we were in a situation that maybe many people find themselves in with a bunch of bugs. A lot of features we wanted to build, no time, no people hiring is impossible, the typical story.
But we always ended up on my set. We would like more guarantees and shortances about our code. And especially about that layer between JavaScript and native world. And we were getting a few options.
But it was very clear to us that a rewrite would not be possible. Like there's no rewrite going on. We can't just drop everything for a month and completely reread the application. And I think most developers will find themselves in a situation where they can't just take a break from what they are normally doing to go off and rewrite the application as something else.
And we keep seeing these drugs on Twitter, but people are like, oh, you should just rewrite it in Rust. I think most people don't have the luxury of being able to just rewrite things completely. So it was extremely important to us that we could just start with a little bit. So TypeScript makes it very easy because as I mentioned earlier, you can just activate it and change nothing.
I think it's also important to point out that TypeScript, unless you specifically ask it to, doesn't do anything to your code runtime. So if you have a JavaScript file and you turn that JavaScript file into a complete TypeScript, the output is still going to be normal in the JavaScript. Like a person will not be able to tell that you were using TypeScript. And this is important to us because we are pretty sensitive about our code and it's important to our code.
It looks on the other side roughly like a local document that came in. And the way we started is we started with just the compiler. We just through the compiler and our codebase made it one of the build steps. And the first step we did nothing.
And TypeScript immediately found a few subtle bugs, which is fantastic. That's exactly the effect we want to do. We gave TypeScript nothing and it immediately started paying off from second zero. I was like, deep down in this code, every now and then, you're accessing some properties that may or may not be there just so you know.
So that was pretty cool. So those small bugs, were they actually problematic or was it just you were glad to find them because you said, well, let's just iron these out and remove them? Yeah, those were actual bugs. They were just too esoteric for any human to ever find.
They were one of those cases where we use RxJS and a bunch of other libraries. And then you have promises everywhere. And I think especially when you have these very rich libraries that pass your code through 50 different methods and if you look at the sector, you never know where things came from, it's pretty easy to lose track of what kind of properties you can expect to be there and what it can't expect to be there. And that was pretty forgiving.
Every now and then it's fine. Good example is if you have an object where the keys are numbers, so you have an object and there's key one key, two key three. You're supposed to access those as strings, but if you use a number, it's fine. It will try to fix mistakes for you.
So those were real bugs. Like stuff we actually wanted to fix. So just turning it on immediately found like two or three little things. That was fantastic.
And from that point of view, we just did some experiments just to see how it goes. We had a few new modules. We wanted to write, so very much like any other JavaScript base is a little bit of all these individual little modules that you can use. So we just started with like single files and it's sort of catches on like fire because once you have one file that gives you all these nice experiences, touching any other files that feel sturdy.
I'll look right away. Interesting. So Slack, I'm sorry, TypeScript adds this compilation step. So whenever you're gonna build a JavaScript file or a TypeScript file into JavaScript, you have the compilation step where the TypeScript is turned into JavaScript.
Does that change the build pipeline at Slack at all? Not for us, but we might be especially kind. So I think for most people it would. If you're using something like Babel today, it's perfectly easy to just like make it another step in there, right?
In our case, we have something called electron compile and we don't have to go too much into it, but it's like this magical thing that Slack released at some point which allows you to just give an electron a bunch of code and whatever language you prefer, a coffee script, a last SAS, and we'll figure it out and we'll just compile it for you. So now, okay, it's pretty easy because we can give electron compile this TypeScript and it will do the right thing. What kinds of testing do you have around the JavaScript? Like if somebody submits a change to some random node module, where is testing taking place?
Oh boy, we have a few places. I think the most important one at the very beginning of your talk with TypeScript is just TSC, which is the TypeScript compiler, and you just run there. And type people immediately complain if you have stuff being undefined or you know your code is structurally not sound, as people like to say. It's structurally not sound, human mistakes.
And then in addition to that, we have something called TS-Lint, which is made by Palantir. TS-Lint in my very personal opinion, it's a very good tool, but ES-Lint is maybe just amazing at this point. You can define anything in ES-Lint, right? If you work at a company in UKDP about how it does, it's written, ES-Lint is the answer.
So the Swiss Army knife that allows you to do anything. TS-Lint is not. TS-Lint is pretty good. It's really just an intro.
It's not a magic wand, whereas ES-Lint really feels like a magic wand. So we run TS-Lint, and then we have some testing suites, the same way you would expect them in any JavaScript app. We have Mocha and Jest, and we just run some unit testing. And then at the very end, and at this point it's pretty far removed from whatever language we used at the very end, we have a very extensive manual testing operation.
Because as I said, we give you care about all kinds of environments, and somebody's taking a slow Windows 7 machine and running Slack there just to make sure that as many customers as possible have a decent experience. Right. And this manual testing, there's a certain contingency of people who are opposed to manual testing. I'm of the opinion that particularly when you're looking at a really complicated app with a lot of usability like Slack, you really have no choice.
Because you can't enumerate all of the possible tests that somebody could do. All you can really do is give it to some users and have them actually test it. Can you talk about your philosophy or Slack's philosophy around manual testing? Oh, I'm not sure.
I'm not sure that I'm going to speak for the whole company. I'm pretty sure I've tried to do that. Somebody's going to be like, I don't think we have a codified philosophy at this point, but I'm talking about why we do it and how we do it. I worked at Microsoft before, and coming to Slack, having such an extensive manual testing team is pretty blissful.
It feels like luxury, right? Because you just gain so much more confidence. You sleep more soundly at night. You know that it worked in all these different devices.
We probably don't do as much unit testing in the desktop app only as we should. We have extremely extensive testing on the back end and the front end. It's super extensive, has every possible testing case defined. But for the desktop world, the one that I work in, and the desktop world unit testing only gets you so far, because once your application reaches a certain majority stage, you will just run into bugs that you couldn't think of possibly.
My favorite ticket that I ever received was somebody who sent me an email saying that if you were named a Windows folder, apparently, Slack doesn't work as he expected it to. Oh. The developer wants to think, why in the world would you rename the Windows folder? Like, why would you do that?
That's a very instinctive reaction. I'm fairly certain that it would have never done a test case for that. We now have our manual testers who are extremely empathetic people and have amazing patients. They now have an additional testing set where they try Slack if you rename certain system folders and just make sure that that's all works.
Wow. Because users will do that sometimes. Yeah, exactly. I think it's also with manual testing, it's just easier to test some of the special cases that are really hard to codify.
What happens if you open up a design other machine? What happens if you start on the internet? What does actually happen? Because in the data world, it's supposed to the luxury of a sometimes book with envy on our iOS team.
Their target is pretty sim. They know pretty exactly what the operating system looks like they're building for. Okay, we don't really know. Let's forget that Slack is also available for Linux where people can pretty much do whatever they want.
That's why they're running Linux. So manual testing, I feel like, is extremely important if you care about those last 5% of quality in your application, but granted, it's also pretty expensive. Do you think this interferes with the popularized idea of the continuous delivery, continuous deployment? I remember talking to somebody who was a continuous delivery advocate and they were saying, oh, if you have a manual testing step, then you can't do continuous delivery.
And I was like, well, I've never worked at a place that takes itself seriously that doesn't have significant manual testing. Yeah, good question. I'm not sure. I think you can do both.
Yeah, because I think ideally what makes what makes continuous delivery with manual testing hard is that you don't know how much stuff you're going to find in manual testing. Right. That's what makes this hard. But I think if you have manual testing, not as your primary testing method, but as your method that allows you to make sure that this last polish is there, and ideally manual testing doesn't find stuff, right?
Ideally, just everything works. Then I think you can absolutely have continuous delivery. But I also got to say that in the past, we have, we in the best of team only have some decent travel with continuous delivery just because we do run into banks all the time that are pretty esoteric that you contradict. Typically, for example, we knew Windows releases, right?
Thanks to the inside of build now, we can we can start testing this like fairly early. But every now and then we run into a bug that was a focus back to the multi-cranus update where the Windows granus update had some trouble focusing windows. And that was not specific to stack at all, which is the update is general travel focusing and we found some work around to make to protect stack against that to a decent degree. But those are things I personally think you really only find the manual testing.
You just have real users, like real human beings trying the things that we try right, they wake up in the morning and the Windows receive an update. So I think that's really important. I want to talk some about electron because Slack is a wide user of electron and this is a technology I haven't done a show on. I absolutely need to do a show on it because this is how a lot of desktop applications are being built today.
And I want to understand more about the difference between an electron app and a browser window because if I electron is this thing that basically lets you build desktop apps out of the same tools that you would use to build a web app, maybe you could just start us off by talking about what are the notable differences between an electron app and a browser window? Oh yeah, I'm extremely excited about electron. So the difference between a browser and electron is very important when you talk about all the time. And I think it's one that the electron team or we in the electron team need to talk about much more often because electron is not the benefit of electron is really that you can do 90% of your work and combine that with the last 10% that you really want to write natively.
You want to do you know the native different parts in C++. And I think very often electron gets mistaken for a solution where people just want to take a web application as a browser and make sure that it gets on an icon in the taskbar and the macOS doc. But that would really not be the right approach. So electron is at the very basic combination of Chromium to take care of a lot of cross-platform work that uses Node.js and then it has this thick layer of C++ around it to do typical operating system accessibility.
So you find it funny that like, so for example, I use a Mac and sometimes I look into the, you know, what is it called? What's the thing that tells you what's running? The activity monitor. Yeah, exactly.
Activity monitor. So look at activity monitor. And I'm looking at what's taking up all my CPU cycles and my memory and it's all browsers and electron apps. And I'm sometimes wondering like why am I on a Mac again?
So what's going on there fundamentally? Like what are we using a Mac for? And that kind of context. Yeah, you know the whole CPU and memory thing comes from all the time.
And I think it's a very legit concern. I think, I think, I think, actually, sort of like becoming a victim of its own success or JavaScript is becoming a victim of its own success in the sense that the old mentor was always that you write the best JavaScript if you pretend that you're writing C. But as it turns out, most people write JavaScript today don't know how to write C. It's like included by the way, right?
So Slack, if you look at your activity monitor memory and CPU is one of our number one concerns. And it's not that we can't do anything about it. In fact, we're working pretty hard on it right now. It's one of our biggest projects this year because there's a lot you can do.
It's like a little startup, which is three years old. And if you move quickly and you just build a good web application as quickly as possible, you do leave a lot of things on the side of the road so you can easily pick up. If you start doing things again and start thinking about your architecture, maybe throw some things out and build some things. And a good example would be the visual DOM, right?
Everybody has been done with the visual DOM for a while, but many parts of Slack currently don't have that. And the second part would be that if you have a lot of teams, Slack will end up using a decent amount of memory. And that is also something we can work around, right? We can, instead of giving you one connection for each team, we can combine those connections and be a little bit smarter about how we send your notifications and your messages.
So there's a lot of V-way there. And I think if you're trying to find an application that does a very good job, I always look up to a visual studio code. I think if you just open it up, use it like 30-max memory. Wow.
Extremely impressive. Very optimized application. I think JavaScript, it's sort of like CGI. If it's done badly, you will notice.
You know what I mean? How people always complain about CGI, not realizing how much CGI there actually is. It's hilarious analogy. Yeah.
And like my favorite examples for when Node.js is running today primarily is Photoshop, which comes with Node.js, right? Most people do not complain about Photoshop being a shitty web app or the NVIDIA drivers on Windows, which also ship with Node.js. But those are places where people don't really notice that it's there. It just works, right?
And every single time, every single time somebody complains about slack using too much memory as CPU, I just go say, me, I call that. That is not an electron that's just us. And also we'll work on it. You know?
Yeah. Okay. You mentioned some really interesting things there. So the first thing, did you say that you wanted to do some stuff in C to improve the efficiency of the Slack Electron app specifically?
Oh, no. This is like an old rule that when you write JavaScript, as if you were writing C, you pretend to be writing C, but you're actually doing JavaScript without actually knowing what kind of optimizations it will take, you could end up being a lot faster. I see. So what kind of memory or I assume you're talking about like memory, like freeing and allocating memory more in a more Spartan fashion?
Yeah, exactly. So basically whenever you run JavaScript today, right, V8 or the various other browsers that run in JavaScript, they will all try to optimize the hell out of it as much as they can. And you as a developer, your main objective as a developer wants to write perform it, obviously, to make that optimization as easy as possible. And there are some basic rules that apply to all all compilers.
But I guess the most two most notable ones are that you declare functions that you reuse every single time. That's a typical mistake people make a lot, right? So let's say you have a four, or a better save a four loop, or for each loop, right? And then set it for each loop, you declare a function.
So what happens inside the compiler? And by the way, V8 has made this a lot better. But I'm taking the same example for recent years because it's the easiest one. But if you define your function inside that for each loop, the compiler will not be able to define the function once it does reuse it, will create and optimize a new function every single time it runs to that feature.
Whereas if you write C, what you would do is you would define the function first, and then you would say, for each, you know, for each item in this array, run this function. So the compiler of JavaScript, the JavaScript engine, can go ahead and see this function, turn that into a machine code. And the next time you call that function, it will immediately go to the machine code. It won't have to interpret the JavaScript again.
It doesn't reuse the same thing. Oh, that, by the way, I know we're talking about electron right now, but I think that is also one of the, one of the weaknesses of TypeScript is that we have so many people today coming out of that schools who learn JavaScript and Python, and why shouldn't they, right? Those are the two, two extremely popular languages that can fully understand why nobody wants to sit down and see again, see Sharafur Java. But if you do have, if you don't have a type language background, or like, is that, you know, a strong, strongly type language background, TypeScript can be pretty scary.
Really? Yeah, because you have interfaces in there, you have Enums, you have class extension, right? And to you and me, and I assume many people are listening to this podcast, if you're a little bit older, you went to school and you had to learn Java and C Sharp, right? Yeah.
Oh, an interface, easy. Abstract class, who cares? Yeah, but you can absolutely be a fantastic JavaScript developer who never had to define an interface, right? Or never had to define class inheritance, or never think about public accessors and private gatherings or something, right?
And those are all excellent developers. But if you, if you employ TypeScript in your company and you really want to like juice everything out of it, you should be prepared to willing to sit some of those much you develop a sound for half a day and say, hey, maybe take a day off and just learn about interface that's an Enums and those type things. Well, if you can teach them in a day or a week, object oriented programming works, there's certainly getting a faster education in that than the academic education. I mean, like this is interesting because I didn't expect to discuss the trade-offs between a computer science education and a hacker school education.
But that's, this is like a prime example. And one I have not discussed before, but it's just like the object oriented stuff that you learn in a computer science education, you really get that stuff drilled into you and maybe that, yeah, it doesn't happen so much at the hacker school where it's like, look, just get this game working or get this like, you know, CMS tool that we're trying to build working, which is fantastic. And that's a philosophy I love. And probably if you do that a little bit, maybe you can start to understand the penalties of moving fast and having an untyped codebase.
And you may understand more easily after those trials and tribulations. Okay, here are some values in interfaces or abstract classes if somebody sits you down and explains them to you. So does it, does it take significant onboarding when you're talking to these newer developers that are coming to slack and you have to explain, okay, here's what we're doing with TypeScript. And this is an interface and this is why we're defining it.
This is how it's going to help us. I think it really depends on how you define significant. I think there's real value in growing those people anyway in that direction, right? Because I think it makes them also better JavaScript developers for a time to perform moment.
But I think it makes people better developers. I think if there's like one magic one that could fix one of the downsides of type, it would be that it would be this notion that TypeScript is wonderful to any person who is maybe coming from C Sharp and is saying, Oh, wow, if only if only JavaScript will be as smart as each other, right? And here comes TypeScript and it's exactly that. But the flip side of the call, and of course, you mentioned abstract classes, right?
Like, that's an excellent example of something that is not immediately where to get to a JavaScript developer. It's certainly something that you do spend some time on. What we do with the philosophy that I follow is that you can sort of define, I'm going to say like multiple levels, right? You can say, okay, maybe this file, we don't use every single feature of TypeScript, right?
Maybe we'll just be fine with like the basic types. But then you can look some of our abstract classes that we have, right? We have like deep class inheritance and you see like a lot of angle brackets and IT extends K and where we do dynamic typing, but still statically typed. That's the stuff that most people doesn't even necessarily look like that was good anymore.
It's going to be turned into JavaScript, but just really looks like C Sharp. If you squint a little bit, you talk this quick a little bit, it looks like C Sharp. So I think if you define those rearms and you say, okay, maybe if you want to touch this block of code, go and take a quick course on abstract classes, right? Yeah.
I think that's real downside. So this suite of Facebook technologies, the React, React Native, GraphQL, Flow, Relay, the this series of technologies has really impacted the JavaScript ecosystem. Which of those technologies is Slack using? More broadly, what do you think of this suite of Facebook open source technologies?
We love React. I think React is pretty amazing. I think React might also be one of the biggest booms to JavaScript. They need this because they made it so much easier and so much more performant without forcing people to think about how to perform stuff.
Right? We previously, you for a second touched upon garbage collection, right? But the sole notion that React is like pretty smart about this throwing stuff away that it knows it's not rendering anymore, that by itself is amazing. Were you pretty much only used React?
We don't use anything else? No, GraphQL. Not at least not the desktop app. Not that I'm aware.
So like obviously this day almost a thousand people at this point. So surely somebody somewhere has played with it. But we in the desktop team are the desktop app. We are really only using React.
We played with React Native for a while. We also played with Flow. But yeah, I'm extremely thankful to Facebook for the gigantic amount of community service that they do. Obviously a lot of the stuff that they release is tailored to what Facebook needs.
But as it turns out, what Facebook needs is also about many other people need, including us. So it's quite amazing. So when I look at Slack, I see some extremely unique application development. Sort of like Netflix had its own unique issues and then they built their own stuff and open source it.
And it was really useful. And same thing is starting to become true with Facebook. Are you seeing some things in the Slack world where you're like, wow, this looks like a fledgling open source project that a lot of people could take advantage of. Is there anything like that that you're starting to see?
I think the biggest one is probably Electron, right? We are co-maintaining Electron with two other with GitHub. Two with GitHub is needing it, the project. And the main engineer is using Bens, the one who invented Electron also works with GitHub.
But we have engineers that work exclusively on Electron and we open source pretty much anything that involves Electron. So Electron Compile is a thing. There's a new node foundation project that we recently started called the Node.js installer. So I think there are things that we try to give back.
We try to give back pretty extensively, especially in the desktop app because sharing things on the end is between easy. And if you ever see anything in Slack and you're wondering, I wonder how they did that, chances are extremely high that you can find it in one of our GitHub repos, right? So we talked about the notifications. You can just check out my Electron Windows notifications implementation.
If you wonder how we use JavaScript to call eventually Windows C++ code, it's automatically done. So yeah, I think we try to give back probably not with the same success as Facebook because hey, Facebook seems to be like currently the king on the hill when it comes to open source source and extremely successful projects, right? We are extremely thankful. If you come from any other development world, let's just say you come from C Sharp.
People do not open source stuff. In general, that is not the default. Most people, I think my assumption is that the very best C Sharp code sits somewhere in some bank behind the wall that's written in front of me for fiscal services. And the people that truly write the best JavaScript, Twitter, Facebook, they all seem to be very active in the community, Google, very heavily open sourcing stuff.
The fact that we have Angular and React fighting each other is to anyone in the JavaScript was amazing, right? It's free and fantastic. Yeah. Okay.
Well, so I know we're nearing the end of our time. I just want to ask one, I guess one more question. We should have touched a little bit more on this earlier, but you mentioned RxJS and we've done some shows about RxJS. And I think this is an important topic that we should do more coverage of could do just briefly touch on why RxJS is useful to Slack.
Oh, yeah, for sure. So the very, the very basic idea being that if you look at the chess system and you look at application, you're really dealing with a lot of streams, right? dealing with a lot of streams that you want to do transformations on. And RxJS makes it easy for us to be a bit more functional about our code.
And being more functional about our code makes it easier for us to reason about it. And that usually the way this can be expressed is that we just have less code, like overall, we just have less code, which is pretty nice. If anyone has ever heard about a thing called the observable, which has been proposed to JavaScript many times, right? RxJS has many cool things, but the core thing that we really like is really the observable.
We also have the big benefit that one of the quarantiners that RxJS works in the desktop team, so that makes things a lot easier for us. Because let me be honest, anyone is out there, the RxJS learning code is steep. It is very steep. But once you get behind it, it just allows you to express transformations we do on events with a lot less code.
And typical examples will be something like mouse clicks, right? It just makes it a lot easier to reason about those things in code in a way that seems to make sense. The same way, I think one of the easiest implementations are examples that I've ever seen is if you compare to the array, how the array has all those really convenient methods that you can just call in the array itself, right? Something like for each or map, imagine you could do a dot map on an event.
And if you find that at the RxJS might make you very happy. Yeah. Are you open to start with one more question? Yeah, sure.
Go for it. Okay. Okay. Is there anything that excites you particularly about WebAssembly and Wasm.js?
We've done some shows around this topic. This is the basically getting to a place where there's more interoperability between other language, like you can compile C++ to WebAssembly, or you can basically, you have an assembly language for the web. What appeals to you about that? I think it's super attractive, right?
Because many of the cases where we currently have to compile C++, maybe we don't have to in the future. So our build currently takes a lot of time. Compiling is like from the bottom up, it takes almost 30 minutes. Just because we have so much C++ that needs to be compiled and it's like many different projects and this build like spins up every single time, make and see, make, right?
But a colleague of mine, OJKwan, ran an extremely interesting experiment. One of the hardest things to do if you were a chat app that wants to be as good as possible is spell checking. Spell checking is one of those things that is extremely difficult because if you sit down with the product person for a person, it says, well, ideally, the spell checker will just detect the language and everything will just work, right? It turns out the technique is pretty difficult.
Even humans have a very hard time distinguishing Canadian English from American English, right? Like, how do you teach computer to distinguish those things? We do all of that in C++, but we also do have some trouble because the native module is really big. When you run into trouble, as we talked about earlier, if you run into trouble in the native world, you're probably shooting a seven foot.
Bad things happen. Anyway, OJKwan took CLD, which is a very popular spell checking library and language detection library and just compiled it down to Wasm. It seems to work just fine. It's just an experiment at this point, but performance is great.
The resulting amount of code that we have is a little bit smaller. So I'm super excited about it. Yeah. Okay.
Well, Felix, thanks for coming to the opportunity. It's been really enjoyable talking to you about all aspects of the desktop development, its Slack and TypeScript and everything we've talked about. Yeah, thank you so much. This was pretty nice.