 printed hello world on its screen and it gave me I did it with either Java, Python, Hadoop or Ruby on Rails recently and there's one more thing I want you to know about me recently I applied for a deal I was damn sure I would be getting the deal but it so happened that they rejected my application I realized one thing even after a lot of preparation and a lot of confidence sometimes things can go wrong even though I've been practicing speaking at Toastmasters this is my first tech talk at a tech conference so please don't shoot me if at all I paint or I freeze in between the talk. Talk is a series of incidents that made me go that definitely this is not my style of presentation for the talk this style of presentation is taken from this awesome talk given by Giri Ben Hadid if you have already watched it please don't kill me if I'm not doing justice to the presentation and if you haven't actually watched it please do watch it it's because definitely you will have team runs of loads of laughter okay moving on how many of you know Rails please be humble to raise the hands how many of you know ActiveRecord how many of you know ActiveRecord callbacks the thing is I was told I must be asking the questions to include the to get the audience focused and to get their attention I hope I did it and then okay there was my my friend he called me and then he asked me can you can you see any difference in this code I was like dude I know I wear specs but still I can make a difference that is custom customer control controller and another is comments controller is like no can you tell me which model is using callbacks and which model is not using callbacks I thought for a moment and then I gave him an awesome game I was like dude you don't have to think so much to use callbacks all that you have to do is just use it and forget it and that awesome is come back and I just love it and moving on I was made believable and that was my first and it was the spring time in the year I was able to do my first production code and we got this requirement for this class account to activate the account only when the password matches like any good developer I don't expect to test it should activate the account only when the password matches and then I went to my code and then I added this method which returns either true or false and then was that awesome moment of adding the callback to the code first I callback I was adding to the production code I just did do activate the account when the password matches like before you create you make sure that you're activating the account whenever the password matches I went and then I ran the spec bingo it ran successfully intelligent as I consider myself to be and I added another test to test it should not activate the account when the password doesn't matches simple and as each and every one of you I was expecting the co-test to did not the test did not pass or that should be my setup error I thought that should be some error in the world but that definitely not my code definitely not my code which is like rock and even after you come out of that moment of your like my code is the perfect time took a lot of time like it actually took me a couple of hours to figure out it was that callback which was making which was making that test to fail if you already got the reason why it is failing please help please please leave me do that hundred of telling the reason why the spec was failing due to that active record callback it was failing because as each and every one of us know Ruby method returns the value of the last statement and though I have read it I've ignored the point that before callbacks fails and rolls back the transaction if it returns false so the assignment I was assigning false to a way people and it so happened that it was returning false from the before callback and it was making the road a transaction to fail and so was my test was failing I was like okay one error can happen but still contacts and it was like the summertime and I was on another project and and in that project what happened was the test sweet time it suddenly got spiked up by 10 minutes frankly speaking we did not know why was happening and honestly speaking will live with it for a month we ignore it because we did not know where to look at and up but like if you're like waiting 10 extra minutes for your test you to run every time definitely it will irritates you and when we found that commit which actually made the spike to happen we were like like the person who found like I found it and we were like we want to see it and he was like this innocent looking code which is what caused your test youth time to spike up by 10 minutes we were like what dude do you make sense that is this don't don't play pranks like this and then and then he explained see the user object is is object which is mostly used in our test here it's like you know of a the login and other stuff this is a most usually used object and it's usually created in each and every testing your test you and when you are creating your user object it's also calling your after callback and it's also creating your delayed job added in that creating one delayed job a synchronous job really doesn't hams you but if you're creating if you're calling after callback thousand time like it's just a number like that many number of tests that you have that many delayed jobs you're creating and then that when that time multiplies that would cost you we actually knew it we actually knew it but we did not realize that after callback would not after callbacks the callbacks would harm us like this and after all this definitely the time moved on and then it was the autumn time and I was like very I became more little more of discipline and discipline discipline and then I went through the documentation and I write that after commit suppresses the exceptions I was like okay like I haven't seen any dev who has written a code which doesn't have work like if at all you write a buggy code and then it doesn't throw exceptions where to go and then when I was googling like where to use the after commit I found this great best practices use the after commit instead of the after create to create your notifications or to create batch process or to create anything you want to create after the transaction how does it make sense like if there is a exception thrown in your after commit and there is some notification not sent to your user your user is not getting amazed but you're not notified about it your cash is not updating but you're not notified about it you would you would know it only when it's like too late so please be careful if at all you are thinking of using after commit after seeing such kind of a reference or you should be aware that after the commit suppresses the exceptions but the good the good news is but the good news is after race 4.2 after commit and also after rollback would be throwing the exceptions instead of suppressing the exceptions like that's a good news actually like yeah after all this I was I was thinking like okay like when the spring was started I was like okay by the time of the winter I would be like the master of the callback and I would be like this no one smiling all the time but it so happened that I was like I don't know I don't know when to use callbacks now everywhere it's troubling me everywhere it's cooking it's not and then I asked a lot of people and I did a lot and boom I found that secret sauce when to use the callback like before I give you the secret sauce let me ask you one question can you send parameters to callbacks now please don't tell me there are a lot of hacky ways to send parameters to callback I know you're all very very smart but this was never designed or never meant to be used like that you can actually send the parameters because your of the callbacks should deal with okay let me give the secret sauce like callbacks like should deal with it callbacks should be used only when the logic refers to the internal state of the object so now it makes sense like you want actually send the parameter like some something something from outside because callbacks they think that they already have everything that a callback should know the internal state of the object so yes like if at all you're using a callbacks use it only when it's referring to the internal state of the object the the problem with the callbacks is like it is like very easy to use and then it will it will make you couple a lot of things a couple of couple multiple things to get out and when this becomes like when you couple a lot of things like you definitely know what would happen if you have not listened to my talk till now it's okay but if at all if your codebacks has the callbacks and you are thinking of running some migrations please do take care of migrations because there's a lot of scenarios where it has just sent a mail and then a dev is not even like knowing that it's sending the mail