 Yeah, so for today's talk again, it's called what the heck is side fact and Initially, so this is actually a German word. It's really hard to pronounce. I'm pretty sure I'm not pronouncing correctly So I included the official pronunciation provided by the by the the jam or the Okay, so like Jess. I'm just gonna play Sidefag I I don't know whether you guys heard it Yeah, so so it's pronounced as side fact Yeah, then So before we start talking about this Ruby Jam Let's first talk about loading in Ruby. So I'm sure like cold loading is Every language has cold loading because you you hardly write all all the things in one file, right? It's not your house gonna be like more than a thousand lines definitely if you have everything in one file so then so then if you are if you have done a Ruby project and then you'll have More than one file to keep things like modular or things easy to be easy to follow Then you will definitely Run into this thing. How do I look cool? It will be so the the most common way Usually it's just used to require relative because you want to you just load a code Relative from where your file is the file that you are the entry point is and then you just From there, it's like the it's like how our file system is you just thought then slash the dot it go up or just put a Folder name and then or a file name that you would just look the file relative from where your file is however in in Ruby because Ruby is object oriented so that we have Classes we have modules that access namespacing Then you can nest multiple module you can nest as many as you want Then the look order in Ruby becomes very important So in that case in this case if you want to do a a column column B Pattern right and you immediately just try and load that file right Ruby will just throw you a name error you'll tell you that oh, I cannot find a then Then why are you loading a a column column B? It's as if that you you tell me a is already there So then you would just throw your name name So if you want to load something like that, it's either you do you load a file that contains the module a first Then you load the file that contains the class a column column B If not, then you you have to do it like what I have in this example here is to explicitly Nest the modules in your file. So instead of like in this case, I have demo one Singapore food Instead you have to do this instead of doing class demo one column colon Singapore colon colon Yeah, so that will not work and Another thing about following is that Ruby doesn't care about naming convention So you you just tell Ruby to load the file. You just look whatever is in the file It doesn't it doesn't care whether like your file has the class that you That you expect to be there or not It just loads the file is on the programmer to make sure that the correct code is loaded into the file So So then okay, then there's the normal normal code loading, right? Then in Ruby, there's actually something called module autoload. So there's this Autoload method that is provided by the Ruby language itself. Okay, so it's native to the Ruby language So how this autoload works is that you do you call this method autoload? For example in the in the first image on the top left Yeah, for demo do you call autoload Singapore and then you put a file path there so how it works is that now you are creating a sort of creating a constant Singapore under the namespace of demo do and the moment demo do Singapore is reference, right? Ruby will load that out load that Singapore the RB file for you and And if you just compare the number of lines that you have to write Between these and require a right. It's actually probably the same long Because you have to require all the files now. Thank you. You have to also autoload then Tell tell Ruby like what are the files that you need to write and then But the only plus point here is that probably is the ego loading so you only load when it's needed and then your your your good time of your app or your your Yeah, your app or your code can be faster. So but the Amount of code that you write is still still an amount number of lines of code you write still the same And then also another thing is that you put autoload Singapore then you put a file there, right? So all it does is demo do Singapore you call them a demo to Singapore is reference You will just load that file, but it doesn't care whether your file has that pass or not Why if you load that file but then the file doesn't even have the pass They were then then you were just fresh there. So for this autoload method. He also doesn't care So it's quite like quite stupid one. Ah, oh All it all it does is like do the oh the the ego loading twice on the programmer to do to do to make sure that the correct classes are loaded So this is module autoload So then like I said just now There's this like name error thing like we want we all want to look like right Okay, not okay. I cannot say we all want to like to me It feels like cleaner to just write class demo three color colon Singapore color food instead of do the triple nesting of the Body body then a class right, but if you try and write it like that, but you don't have demo three or you don't have Singapore loaded Ruby will just call throw you a name error like I mentioned just now and then and then this is the same for the The the the two code loading method that I mentioned before So it's really really at the end of the day on the programmer to make sure that the namespace are loaded already in memory before they can use such way to declare their Class names So then we talk about all Loading or auto loading, right? But what about file reloading? So I think this is maybe a bit same for Every language is that you load the the file into memory ready Then if you go and edit the code a bit Then you have to control C to cancel the running instance Then you have to rerun reload rerun a code which loads the new code into memory and then run and then then you will see the new behavior so then How reloading is not something that is supported out of the box for Ruby Then it might become very frustrating if you have like huge Huge project and then you are like doing development right like into the into the flow and then you are just like having a lot of code Then you have to keep constantly cancel and rerun, cancel, rerun, cancel, rerun all the time So then so so at the end of the day like code loading can become very complicated Especially when your project becomes very big you edit your files a lot It creates a lot of files and then you are constantly trying to Build feature on the fly so it becomes very complicated So here comes like this gem called flagpack which can alleviate all this for you and is Essentially a code loader for Ruby and it supports auto loading and reloading of the box and and one more extra thing that it gives to you is the file name to pass module name convention that that many Ruby people follow and Especially so in Rails So the convention is that the file name should be the Snack case of the class and module name. Yeah so so and then One interesting point to note which even made me like try and find out what what what is this gem is Is that it because it became the default auto loader in Rails 6 So in Rails, we always we know the files are always automatically loaded and automatically reloaded right and side side pack gives you this thing for For that you can use in your own project as well So so essentially like problems that is solved You don't need to worry that you're forgetting to require files Now if you have huge projects you constantly creating and deleting files You don't have to forget to add that one require at the correct place Or you don't have to forget to delete that extra require at at some places that you That the file that has been deleted so you don't need to worry about this You also don't need to worry that you are requiring requiring files in the correct order So like I said just now that the load order is important, especially when you're testing of namespaces, right? So in this case later, I would Talk about it that side-pack magically just Create the module the namespace if you if it does not already exist So it magically solves this for you and then because of the file name conventions You can find code easily I think if you have been working on rails for basic understand like how Because of the convention how sometimes how easy is to just find code Of course that when there's meta programming that things might get a bit complicated But then for basic use cases pretty straightforward to find find code so So then how to use this so side-pack is Although like most famously Famously used in like rails like but you actually can just use this very easily in your own Ruby projects It's actually just for lines of code essentially So in here if you look at the code demo that I have you just require side-pack You create a new loader instance. You just push the directory Into like the loader and then you just call setup And what it does is it will just load all the files inside the directory and you can configure loader to like to do Reloading eager loading like some of the options that side-pack gives to you Then then it will just do everything In that folder and you have multiple folders that you want to watch and load you can just Call multiple push directory and then actually that's just about it. It's like super simple to set up And you you almost have like all the magic in rails Or actually you will have all the magic that you that you have in rails in your normal project and you just Yeah, you can just get into the flow and put away just did it false create files Hey, no, actually created it false pretty probably not but yeah You can just edit files and then you see your feature magic be turned up So and then you also get the file name and class name convention. So For me at least when I try and write my own code without not in rails I try to keep the convention as much as possible Like this is like discipline of my part But then in this case you you can just lean on the Ruby gem to let you know long weather things are in order So using it is like super easy so So so when you use this gem all the namespace are They call it automatically VV pipe, which was an English word that I didn't know until I started like Researching this this thing. So VV pipe actually means just like bring a life something like that So meaning to say that all the namespaces. They are not there, right? You just auto create for you So so you can so in this example if you see below I I just have like demo for Singapore place I don't need to have a file or somewhere that creates the demo for Namespace to create a Singapore namespace every you will just automatically create for you So you can feel very safe and feel free to just like write class names like this So yeah, so all namespace are automatically vilified Then you can option to configure inflections or so. So the inflections will be the The transformation between foul names to Class name the the relationship for the conventions, right? Like sometimes you you don't want like the the snackcase relationship so you you can configure this or so and Yeah Then another thing is there's an option to Eagle look everything on boot if you want to so Eagle look meaning that you just look every file Like into memory on boot. Don't even wait for like the auto loop auto loop thing So if you are not worried about Like performance about boot time and you You want to just look everything into memory at one go then you there's a very simple option to to just configure this Then you also have the option to enable reloading. So like I think this reloading is like the it's like super awesome. So It will automatically like do a file watcher and then if you did detect that your Your file has changed. Then you will just Reload that out for you So so yeah, there's also an option to enable reloading So these four are like some of the super easy and probably the most useful Useful options and but there's still a bunch of other options that you can look up and so then I I would think that a very common question would be like, oh, okay rails move from Rails auto loader to side fact right then like what what what should we expect? So in in essence, I feel that If you still want to use the normal rails auto loader, you can just configure it rails real six The the change not actually tells you how you can set it back if you don't want to use the new auto loader And in normal use cases, you really should not expect any differences To be to be honest like that fact is closer to the to the Ruby like correct way of building namespace and etc So I purposely am not talking about the pitfalls of the original rails auto loader in this talk because like is There's like Things that there's like enough things to talk about in a talk by itself So so then like I want to focus on like side fact and how we can bring this rails magic directly into our own project Uh, maybe to even just our normal ruby Just like plain old ruby projects, so no freeball or nothing. Maybe then you you can we can easily just bring all this magic over So so I do have a link here that this actually this person The incredible job like even giving examples about like the pitfalls of the old rails auto loader So if you are interested you can Get the link from me or you can just like copy out the You are pretty easy to follow So then for this I I reference quite a few sites I'm just trying to find out about different different things in in this topic Yeah, so there are the references here and actually there's there's just the end of my talk So I hope like You I think that like bringing this like rails magic into into your own code or your own project Will be very helpful and hopefully You can speed up your development and less less things to worry about and focus more on just writing Writing features and yeah and writing Yeah, awesome stuff Okay, so That's it. Oh my god That's it. Oh my god