فشرف بالشتغالي بالعلم ولا تبغي به ما عشت يا دا دا دا لا وياله من شراف عظيمي الحمد لله رب العالمين والعاقبة للمتقين ولا عدوان إلا على الظالمين وأصلي وأصلموا على من أرسله الله رحمة للعالمين سيدنا ونبينا محمد وعلى آله وأصحابه والتابعين لهم إحسان إلى يوم الدين أما بعد وإنه وكتاب الورقات بايمام أبي معالي الجوين رحمه الله إمام الحرمين وقد نأخذوا أصول الفق مفرديه ونأخذوا أصول ورقمان باعتمال مفرديه ونأخذوا أصول ورقمان باعتمال فق ونأخذوا باعتمال لقاقبا لهذا الفن ونأخذوا أصول الفق معاً وما يقومون وما نتكلمه أيضاً ما هو أصول الفق المفرديه؟ ونكلمه أنه يكون 23 مفرديه ونكلمه أنه يقوم باعتمال فق 21 ونكلمه أعضاء أصول المفرديه جيد أول من المفرديه هو أقسام القلام والطبخ أول هو المفرديه هذا هو ما نتكلم إن شاء الله تعالى في هذا المفردي ونكلمه أنه يقوم باعتمال وما أقسام القلام وما يقومون باعتمال وما يتركب منه القلام وما يقومون باعتمال الكتربة ينطرق visited today the minimum a speech can consist of is two nouns أو اسمنuju وفعلون أو that's the third one which is فعلون وجرفان verb in a particle أنهم يتحدث عنها. ولكن الغرماريين والسكولات الذين يتحدثون مع رتوريكس والألوكوانسي ، الآنجل في الذي ينظرون في الوصول ، يختلف من الآنجل الذي يتحدث عن أصول يون ، السكولات من أصول الفق ، ينظروا بها. المعطق يتحدث عن كلام ، لأصول الناس يهم جداً. لهم يهم جداً ، الأولاماء الأصول الفق ، كلام يهم جداً لهم. لماذا؟ لأنهم يجب أن يعرفون كلام الله وكلام المسجر صلى الله عليه وسلم. يجب أن يعرفونه. لذلك ما يفعله هو أنهم ينظرون at the speech of Allah and the speeches of the Messenger صلى الله عليه وسلم. ماذا يجب أن يجب؟ المسجر الله والمسجر are what language? They are in the Arabic language. They are in clear, pure Arabic language. عبد الله يبني صلى الله عليه وسلم يقول ومن لا يعرفون اللغة. أحد who doesn't know the Arabic language لا يمكنه it is impossible for him. استمباطل أحكامي to extract rulings. من الكتابي from the book of Allah والصولة from the sunnah استمباطل صحيحاً a correct extraction. He can't do a correct extraction. He will cause a lot of confusion and misguidance. What does kalam linguistically mean according to the علماء of أصول؟ What do they consider linguistically? What does it mean? Speech linguistically means what? اللفضو الموضوع الي بعدن. It is utterance. That is placed to have a meaning. It is utterance. That is placed to have a meaning. That is placed according to the Arabic language which has a meaning. Why do we say utterance? Because we want to leave the filthy view of the أشاعر who believe that speech is what? It is not utterance. They believe speech is what is inside you even if it comes out as a sign language they still consider that speech. And so what are they trying to negate from that our goal? They are trying to negate that Allah's speech doesn't have sound or a voice. And they want to follow the speech of a disbeliever who said The speech is what is inside you and the tongue is only evidence to bring out what is inside you. So they want to say Because the speech is of Allah is what is inside him. So when they were asked if that's the case then how did this Quran come to us? They said that That's the call of the أشاعر one. The second view that the أشاعر have no they believe Allah created this speech in the air. The third one is the Quran is from the messenger. And the fourth one is Allah placed this Quran on the trees Those are the four views that أشاعر have. So the أشاعر when it comes to the issue of Allah's speech they have the belief of the جهمية from الأنجل and they are not far-fetched from the view of the جهمية and the معتزلة They say the Quran that we have is a the usage of it is the messenger's usage or created in the wind or placed on the trees So they said when Musa when Allah was speaking to him where did the speech come from? When we called him from the angle of the tree they said the tree was speaking أهل السنة refuted them by saying Can the tree say Can the tree say The one who is worthy of worship worship me alone Can it say it? No. So then It just came from that direction Not from the tree Good And the speech of the أشاعر in this matter is It's utterance and a speech which is disbelief Like as you all are aware of أهل السنة They have what? They say تقعادة يم allen أهل السنة Not everybody who falls into a court Does the court fall to him Not everybody who falls in a matter of a court Does it necessitate that a court falls to him Meaning? He becomes a disbeliever Now a person may يجب أن يفعل شيء ما يفهم ، لكن هنا are obstacles that are standing between him becoming a disbeliever and those matters are It is knowledge that negates ignorance in the first condition and willingly intending which negates mistake and error the third one which is willingly choosing which negates duress and the fourth one is not having a permitted interpretation these are called موالع التكفير they are excuses from a person to be made a كافر they are called موالع التكفير they are obstacles from a person to be labelled as a كافر و لذلك أهل صنا بليف وجود الشروط و أنتفاء الموالع these conditions have to be present and the obstacles have to be absent and when we were studying أحكام الوضعية when we were studying the two types of أحكام الوضعية we mentioned the conditions of أحكام الوضعية was what صحيحة فاسد and we talked about the شروط and the سبب and the مانع when we were speaking about it we spoke about the details over there that is what الكلام means linguistically what does it technically mean كلام technically means اللفض المفيد it's utterance which benefits such as الله ربنا الله is our load و محمد صلى الله عليه وسلم النبيون and محمد is our messenger that is the technical definition according to the أصول يون according to the scholars of أصول he said he said that أبيب عالي الجويني he didn't mention the technical definition of أصول الفق nor did he mention the linguistic definition of أصول الفق he hasn't mentioned the linguistic nor the technical definition of a speech كلام أبيب عالي الجويني رحمه الله he didn't give the definition of كلام speech linguistically nor technically but what did he suffice himself with بالكتفة rather he sufficed himself by choosing what by choosing what the minimum a speech can be by the minimum of what a speech can be and he mentioned that the minimum a speech can be is what the minimum is two nouns the minimum it can be number one is two nouns and the example for that is الله which is a noun ربنا is also another noun الله ربنا الله is our lord this is what this is two nouns as the minimum a speech can be one or a noun عالي and a verb a noun and a verb a noun or a verb such as what جاء الحق the حق a came جاء is a فعل and الحق is a noun وزهق الباطل which is again the same example for a noun and a verb are you with me and all of these جاء الحق and also زهق الباطل all of them are what فعلنا فعل and of course it has to be لازم it has to be a transitive verb it can't be an intransitive verb because if it's an intransitive verb then it would be three that'd be a verb and it would be the subject and it would be the object we just want the minimum which is a verb and a subject good ومثلو like also قوضية الأمر the matter has been judged قوضية الأمر which is the verb الأمر which is the noun this is called what it's a فعل ونائم فاعل that's finished so that is the verb the second time it can be a فعل or a verb or it can be a what it can be a فعل or a verb or it can be a فعل ونائم فاعل the third one which is a verb and a particle such as ما قاما he never stood ما which is a particle قاما which is what is the verb ما which is the particle قاما which is the verb أو لم يقم لم which is the particle يقم which is the verb لكن this this is what أبي معالي الجواني he mentioned this and also الجرجاني أما الجرجاني أمام الجرجاني رحم الله أمام أبي معالي الجواني they are the ones who mention that a speech can consist of minimum a what it can consist of the minimum that it can consist of is a verb and a particle and that is not right according to the grammarians according to the grammarians it's not right because لم ما قاما he didn't stand what is hidden there نضمير the pronoun is hidden because the word قاما there's a pronoun hidden which is for example he didn't stand he's talking about زيد مثال an example so for example when you say ما قاما he didn't stand it's really meant to be what ما قاما زيد so it's not true that's why but why did he bring it he is saying to you he is saying to you that whether it's there or not we're basing on what what we can see we can see ما قاما as for the issue of the تحقيق and analyzing the matter leave that for who leave that for the نحن that's for the grammarians they're the ones who are تحقيق who detail the matter pay attention good good so as I said to you this is the view of إمام أم إمعالي الجويني he took and also the view that was taken by ألجر جاني رحمه الله أو أئسم على حرف and أئسم على حرف is also another view that he took which is not correct which is like the word يا الله are you with me the word يا الله what is it الله is a noun and يا is a harf so and it's also فيه لغة there's a look to it it's not as he made it look like which is what the speech هي which is the word يا the يا is a مقدر it is taking the position of a what a verb and an object subject the word يا by itself has taken the position of what of a فعل على فعل the word يا by itself and what is it that it's taking its position it took the position of you saying أدع الله you see أدعو we can see there's the verb where is the subject the subject is أمير المستطر تقديره أنا me so the word أدع الله I call unto Allah is حرفو لداء which is that took the position of the word أدعو الله so when the person says يا الله he's trying to say أدعو الله I am calling unto Allah أم أنادي الله or I call unto Allah whichever so from that I call the only two that we would give him is two nouns or a noun and a verb that's it the extra two that he mentioned is not correct which is the فعل and the حرث and the اسم and the حرث that all according to the grammarians they are the people of تحقيق they do not see that correct so the مينم وأقلوا ما يتألفوا منه الكلام is what اسماني أو اسم مفعلون that's all we can say والكلام with the word كلام the word كلام is the plural of what the word كلام is a plural is a plural and it's a جمع تكسير and it's a plural of what كلام it's a plural of what is the plural of كلام and the كلام which is speech in the Arabic language is three types it's a noun a verb and a particle those are the three and according to those three the noun is what that noun is what indicates meaning مدل على معنى في نفسه it is what indicates meaning in and within itself ولم يقترن بأحدين أزميرتي ثلاثة and it doesn't show any of that any of the three times past present or future it doesn't indicate it the second one is called فعل فعل is what مدل على معنى في نفسه it is something that indicates meaning shows a meaning وقترن بأحدين أزميرتي ثلاثة and it shows it shows what it shows one of the three times the last one is called حرف particle and the particle is what مالا يدل على معنى في نفسه the heart is that which does not show you meaning in and within itself وإنما يضعروا معنى في غيره it's meaning becomes clear when you put it into a into a context good pay attention how do the أصول يون how do the scholars of أصول how do they analyze the اسم the فعل and the حرف in وقانجوا did they look at it please pay attention please الأسماء nouns والأفعال and verbs والحروف and particles تبسوا الحجة إلى معرفاتها to know them there are a lot of need there is a lot of there is a lot of need for it so أكسسيب شخص so so إنما تقولmpre已經 وقت إذن تون القيم اتفق نوع وقت وقت وقت وقت وقت وقت وقت هذا عنوات هو من ثلاثة تواrie عندما ينظم الانجليزية ، ينظمها من أجل آس of إسم مظهر ، إسم مهم ، وإسم مظمر يرى أن الانجليزية تفعلها. كما يفعلون أسوليون ، ينظم الانجليزية ، عندما ينظم الانجليزية ، يتقلق إلى 3 لكن 3 مختلفين من الانجليزية. ما هو it؟ first one is ... that which benefits generalization. so the first type of noun according to the grammar according to the Osulion the people of Osul the first type of noun that they have is now that benefit generalization. and they are like the connectives.거든요؟ أنت معرفني أنت معرفتهم كالاتي مالخرافة أو مجتمع في عالم الانتغار ممتاز في عالم الانتغار ممتاز أنت the first type. they show generalization. يعني معرفني أنه يظهر معرط أنت. That's the first type of nouns. The second type is called Mayufid al-Itlak. That which shows Itlak means what? Open. That which shows that it's open. The meaning of this word is open. And it is the noun that comes in what? The noun which is indefinite in the context of affirmation. It is the indefinite pay attention, which is in the context of affirmation. The third type is called Mayufid al-Khusus. That which shows specification. It shows exclusivity. And that is what? كل أعلام like names. Names. If I say Ahmed, all of you guys don't enter it. It's exclusively him I'm referring to. And أعلام means what? Names. So the nouns according to the أصوليون. That's the three types it is for them. Mayufid al-Umam. Mayufid al-Itlak. And Mayufid al-Khusus. And all of these matters in details, in details where it is going to come to us. And we there's no need for us to hasten for it. And also what is connected to the verbs are going to come to us. We're not going to speak about it now. What is connected to the verbs is going to come to us. هه? Not now. As for the particles. As for the particles. The person who needs it is not the أصوليون. The فقهة I need of that. Such as the و. And the ف. This is now this topic that insha'Allah we're going to conclude here. It talks about the types of speech and that and the minimum that it can consist of. And we've taken that. And we conclude there insha'Allah.


As I noted in my video on bone mineral density, vegetarians had slightly lower bone mineral density in their spines. Although the difference was basically within the margin of error for the test, if the bone quality really is compromised it could lead to collapse vertebra, increased spinal fracture risk, there's no evidence for this. The incidence of vertebral fracture was ascertained in older women who had been vegan for most of their lives, 34 years on average. And despite their calcium intake being terrible, about half that of the non-vegans, and a quarter of them vitamin D deficient, the incidence of vertebral fractures was not significantly different. Although the vegans had a higher prevalence of vitamin D deficiency and lower dietary calcium intakes, the two factors were not associated with bone loss. In fact, the annual loss in bone mineral density in the hips of vegans was less than half that of the meat eaters, although the difference did not reach statistical significance. Vegetarian women had not been found to be at higher risk of any kind of fractures, including wrist fractures in this case, though among vegetarians, those who consumed the least vegetable protein intake were at the highest risk for fracture. Those who ate beans every day, or nuts, or like veggie burgers, only had a third of the wrist fractures compared to vegetarians who only ate beans or other higher protein foods less than three times a week. So those who consume a vegan or vegetarian diet may be at increased risk of fracture unless care is taken to ensure an adequate quantity and variety of foods high in protein, such as whole grains, nuts, and beans, split peas, chickpeas, or lentils, or in the diet. That's one of the reasons my free daily dozen app I recommend whole grains and legumes every day. Hip fractures are even more serious. Those eating legumes, like beans every day, reduce their risk of hip fracture by more than 60% compared to 40% lower risk for meat protein with plant-based meats coming in in between with about 50% lower risk of hip fractures. What's the bottom line on plant-based diets and bone health according to this 2020 review? Theoretically, a long-term plant-based diet may reduce the risk of osteoporosis, but that has yet to be demonstrated. What we do know is that plant-based diets, when ensuring adequate calcium and vitamin D levels, don't appear to have any detrimental effects on bone health. But this was published August 2020. In November 2020, the 12-year follow-up to the study I talked about in my last video on comparative fracture risk in vegetarians versus non-vegetarians was published, finding that non-meat eaters, especially vegans, had higher risk of total bone fractures, including at sites associated with osteoporosis, such as hip fractures. It comes out to be about 20 more cases in vegans for every 1,000 people over 10 years. So if indeed this is cause and effect, eating vegan, there would be an annual 1 in 500 chance of having a bone fracture that you otherwise might not have had. Was it because they weren't eating enough beans? Apparently not, since vegans getting more protein still apparently had higher risk. Maybe it was because they weren't getting enough calcium? Apparently not, since vegans getting more calcium still, apparently, had higher risk. What about bone and vitamin B12? If you remember, Epic Oxford, where the bone data comes from, is the same group of British vegans who had rampant B12 deficiency. More than half the vegans were B12 deficient because they weren't adequately supplementing with B12 or B12 fortified foods. This can lead to high homocysteine levels which not only increase stroke risk, but may increase the activity of bone-eating cells. This was in a petri dish, but you do indeed see low bone mineral density in those born with a birth defect, at least at high homocysteine levels in the blood. Therefore, high serum homocysteine may be regarded as a factor that can reduce both bone mass and quality, but you don't know until you put it to the test. And homocysteine lowering treatment failed to reduce the risk of bone fracture. So in the end, the effect of B12 deficiency in bone health remains to be established. OK, so how do we explain the higher fracture rates found among vegans? The investigators conclude that their findings suggest that bone health and vegans requires further research, but there were some clues. The elevated fracture risk, both for total fractures and for hip fractures specifically, was only significant for those under a BMI of 22.5, which is like under about 130 pounds for a woman of average height. So part of the problem is that vegans tend to be so slender on average. Why are overweight and obese individuals protected from fractures? Think about it. They have cushioning during a fall. There's more of a cushion on your hips. Also, there's an enzyme in fatty tissue that churns out estrogen, which is why women increase their breast cancer risk, a percentage point for every pound they gain in adulthood. But estrogen can also have a bone-preserving effect. Now, you can get the best of both worlds consuming soy foods, preventing bone loss while at the same time associated with lessening breast cancer risk for both estrogen receptor-positive tumors and estrogen receptor-negative tumors. Finally, overweight and obese individuals may also have stronger bones just from the increased weight-bearing, carrying 100 extra pounds. I mean, you're doing major weight-bearing exercise just walking across the room. So the risk difference they saw between vegans and meat-eaters were likely at least partially due to the difference in BMI. My money, however, is on vitamin D. Great Britain is at Canadian latitudes. The sun's rays are at such an angle during the winter months up there that the vitamin D levels among British vegans in the wintertime drops down to suboptimal levels. Ideally we should be up around 75 nanomoles per liter, or 30 nanograms per milliliter, depending on what units you're using, which the vegans nail in the summer. It is the sunshine vitamin after all, but in the winter, not getting the vitamin D added to dairy or found naturally in oily fish, if vegans aren't supplementing, that'll add it to. During the winter, their vitamin D levels may drop too low. Now, randomized controlled trials show that vitamin D alone does not seem to reduce fracture rates, boosting people's DN calcium at the same time does, so maybe it was a combination of the relatively low DN calcium intakes among the vegans that led to their higher fracture rates. We won't know for sure until it's actually put to the test, and when it is, you can be sure I'll do a video about it.


Hi everyone, I'm Joe for jazby's case breaks calm and I'm gonna give away Six spots at the end of this break in that three blaster case break. Check that out. That's a really good deal That's this premium stock blah blah one pack sell a pack 35 So we need the break first and then we'll re-randomize every day's name everybody's names blah blah blah You know the drill these people know the drill. I think right you guys know the drill Thanks boys and girls. All right. They're the teams right there. Let's roll it Let's randomize names and teams first six into two eight times one All right, Andrew down to Martin after eight eight times for the teams and Even final time after a we got Golden State Warriors down to the 76ers So here's the first half of the list right here and this group of people right here and teams let's sort by column B and Let's print and Rick some rookies there Diallo Darius Garland rookie Is not too bad. No Zion. No jaw Unless they're in the exclusive packs Landry shaman bogdan bogdanovich and Kevin Durant. All right, nothing too crazy there Cleveland did get the Darius Garland, which is not so bad. That'll be for dawn last spot mojo striking again Now let's see who's gonna win at those spots. We got John down to Martin and everyone in between Let's get that let's roll it. Let's randomize it Four and a two six times so top six after six will be in that blaster that triple blaster case break, which is gonna be a lot of fun one two Three and six then final time after six seven on down It's gonna be sad times, but I appreciate you giving this shop. Thank you Happy times for the top six. We got Martin Jeremy 33 Eastwood Simon Jeremy 33 and Barry Roberts in that triple case break There you go. I'm Joe for jasby's case breaks calm. I think we have to do one more of these filler packs. Maybe two That should sell out get close to sign out the triple K. Anyway, we'll probably get that done on Sunday. Thanks for watching I'm Joe. I'll see you next time for the next one


Oh, my goodness. This is really turning into an annual video, huh? I'm recording this on June 2nd. I posted my last one on June 10th. I really hope that a year from now, we're not making the same video. I'll cut right to the point. It was no mystery that me and Bailey were definitely more than just friends. It was a hilarious meme. We had to keep it going. But we also never formally dated. And that's kind of what today's video is about. I started talking to Bailey relatively soon after I was done talking to Kaylee. Yes, I know the names are very similar. And I was very forward with Bailey about this. I let her know that I had just gotten out of a relationship. I was not interested in getting back into one. But if she wanted to spend time with me and we were gonna have fun, let's go for it. She was awesome with Luna. She loved being on camera. We made some awesome videos, as you guys know. And we actually technically were friends. So the meme wasn't a total lie. But as you guys could probably tell from the videos, we were spending a lot of time together and it was clear that it was getting towards a relationship. And roughly three months ago, a lot of things were happening. I made the decision to split my time between Michigan and Arizona. Honestly, a lot of you might not know this. I purchased the house in Michigan and then I also purchased the house in Arizona. And I know that sounds like kind of a flex, but trust me, it's not. The only reason I can do any of that is because of you guys. So you can pat yourselves on the back for that. Additionally, I decided that I was gonna up and go to Hawaii for about two months. Now the reason I tell you this is you can probably understand that if I'm very close to dating someone in Michigan, while also determining for my career that I'm gonna be spending an indefinite amount of months in Michigan and then an indefinite amount of months in Arizona, and Anna Daim will be deciding to go to an island, how that might not be very conducive for a healthy relationship. So to continue to paint this picture, me and Bailey were spending a lot of time together. It was very clear that she wanted a relationship and it's just not something that I was comfortable with. I was pretty damn scared of fully committing to someone, knowing that there'd be massive lengths of time where I couldn't see them. I am a firm believer that I can make anything work, but the timeline of all of it just scared the hell out of me. I'm gonna be totally honest with you. And I feel comfortable saying this because I was equally honest with Bailey and she fully understands. Bailey was an excellent friend. She was so kind to me, so generous, so helpful, very supportive, but I'm just not ready to commit to something like that right now. So if when I'm 30, I realize that I made a poor decision, I will accept those consequences. But for now, I continue to be ready to pour my heart and soul into this channel, into the work that I do for you guys. And I can only hope that I made the right decision. The only reason I feel so comfortable sharing this with you guys is because me and Bailey really are on good terms. We still casually text. She sometimes sits for Luna, which is so cute. And hopefully we remain friends. But you guys can also probably understand that obviously Bailey's not gonna need videos. You guys are very good at starting the rumor mill and I could see the wheels churning on it a little too fast, so I just wanted to step in. I like my drama, that's for sure. But I'm very happy with me and Bailey still talk and I'll maintain that I will never have anything bad to say about her ever. I just don't, so I couldn't really start drama even if I wanted to. It is what it is. I appreciate your guys' support as always. This actually happened roughly three months ago. I just wanted to let the dust settle and I just wanted to make sure that I would make a respectful video that wasn't too construed by my emotions. I think it's funny when I watch YouTubers videos where they're clearly so agitated or something just happened to them and they're all over the place. The video's horrible, it's just rambling and ranting. I didn't wanna do that. I hope you guys didn't get that impression from this video. So from my end of things, I'm gonna continue to put out as good of content as humanly possible for me. And from Bailey's end of things, I hope you guys can be respectful as well. And since this is an annual video for me now, I might as well end it off with something good. I usually end these off with something good. I do have a big announcement that I've sort of talked about, but never formally. Next year, at the start of the NFL season, I will be doing a full-fledged live podcast. Ever since I went on the Pat McAfee show around this time last year, actually, it's all I could think about. I loved going live on Twitch, but I was not scheduled and I hated playing Madden. Obviously I love talking about the NFL and I'm watching all the games anyway. My little brother is going to be running tech on it, which is awesome, so he'll be on the podcast too. And it will be live on its own YouTube channel. I'm so excited. It's gonna be incredible. I very much look forward to it. It's really all I can think about, actually. So I know for a lot of you who really like Bailey, myself included, this video is kind of a bummer. So I thought I'd leave you guys off with something to look forward to. Honestly, if you watch my channel in June anyway, I love you because this is the deadest of the dead of the NFL season. And it's an incredible blessing that I get to continue to do this year and year out. So I appreciate you guys so much. I love you. Please be respectful. That would make me so happy. And I hope you guys have an awesome day. Peace out, boys.


Welcome to this course on data structures and algorithms. Last time, we saw the basics of implementing Q using standard template library. In this session, we will take a simple example of a bus queue and try to understand how the queues are formed and what is the important information about bus queues that we need to find out. First, let us do a quick overview of a bus queue. People will arrive and stand in a queue at the bus stop. They will wait for the bus to arrive. Please note that in actual practice, people will arrive at random times. Similarly, buses will arrive at around the scheduled time, not necessarily exactly at the scheduled time. So, again there is some randomness involved. In this particular illustration, we are not going to use any random number generator, etcetera to simulate the actual bus queue. We are just trying to illustrate how bus queues are handled in a C++ program. So, to recapitulate, people will arrive and stand in a queue at the bus stop. We will note an arbitrary time of arrival of each person. Similarly, buses will arrive at the scheduled time or around it. There will be limited available seats in every bus. Again, we will arbitrarily assign the number of seats available in any bus or the actual bus arrival time. The most important thing about bus queues in which both the bus company and the passengers are interested is how long a passenger has to wait in a queue to get a bus. So, we define the waiting time of a person as time of boarding the bus minus arrival time of person at the bus stop. Of course, if we do these calculations over a long period, accounting for a large number of people arriving and boarding, etcetera, we will be able to find out the average waiting time in the bus queue. So, let us demonstrate this entire process of people standing in a bus queue. Here is a sample bus stop. People will come and the buses will come from this side. So, here is the first person who comes in. We arbitrarily assign a tag to that person say 1001 and arbitrarily assign an arrival time. Let us say 1450. Please note that in real life, when we simulate a bus queue, we will have to generate this number randomly. We shall speak about it in a practice problem later. Here is another person who comes in. Let us assume that he arrives at 14 hours 19 minutes. Here is a third person arrives at 1421. Note that we are giving an arbitrary increasing tag to each person who arrives at the queue. Here is the fourth person and here is the fifth person. Note that so far no bus has come. All of them are waiting for bus to arrive. Next comes a bus. This arrives at 1430 again an arbitrary time. Let us again arbitrarily assume that there are only two available seats in this bus. So, what will happen? Only the first two people in the queue will be able to board the bus. This is depicted here. When the first two people board the bus, we will have to remove them from the queue and we have to remember for later usage for how long did they wait. This person arrived at 1415. The bus arrived at 1430. So, he waited for 15 minutes. The next person similarly waited for 11 minutes. Next another bus comes. All the three people are waiting for the next bus to arrive and let us assume that this bus arrives at 1440. Let us assume that there are seven available seats in this bus. Of course, there are only three people remaining in the queue. All three of them will be able to board the bus. Once again we calculate the actual waiting time for each person individually. Now we know when bus arrived and we know when the people arrived. So, the difference between these two will be the waiting time. In a nutshell, we have simulated a queue, giving of course, arbitrary arrival times for both the bus and the passengers, arbitrary number of seats available in the bus, etcetera. But we are able to calculate the waiting time for each person and consequently the average waiting time. So, in our example with assumed hypothetical timings, we have person one waited for 15 minutes, person two for 11 minutes and so on. Totally five persons waited for a sum of 76 minutes. The average wait time is thus 15.06 minutes. In practice, in real life, these are the timings which are most important which will permit the bus company to schedule more buses during peak hours. For example, or for people to estimate at what time they should appear at the bus stop so that they are more likely to get a bus. So, what we note in this example is that although we will be illustrating programming of a bus queue using these arbitrary numbers which are illustrated in this example, in actual practice passengers will arrive randomly. Buses will also arrive randomly. They may arrive around their schedule time, but there will be some random. And finally, even the number of available seats will have to be generated randomly. In one of the practice problems, we will illustrate how the random number generator function of C plus plus can be utilized to simulate this. These are some of the references. First of all, all images which are used in this particular slide deck are from openclipper.org. Those of you are interested can look at it and will note that all images available are under creative commons license and therefore, they can be freely used. These are all released in public domain. To conclude, in this session, we have taken our discussion in the queues further and we have illustrated a practical problem, namely people waiting for a bus in a queue. We have demonstrated using arbitrary numbers to represent the arrival time of people and arrival time of the bus, etcetera, to demonstrate that we can actually calculate the waiting time for each person and the average waiting time for that particular bus stop when people arrive. Later on, as I said in a practice problem, you will look at the random numbers to be generated to represent arrival times, etcetera. But in the next session, we will simply look at a C plus plus program which implements this particular illustration of the bus queue. Thank you.


So let's talk about good object-oriented programming. Short, good. So my journey started during my studies. I learned C++ and then Java. Those were two first object-oriented languages that I learned. And it was really great. It was great because I learned about objects, and interfaces, and messages, and encapsulation. And I started learning programming during my study. So we started with some basics using languages like trubopascal or C. So when I learned object orientation, it was great because we started using classes. And we started using normal words, like person or a group. And we started working on projects with small teams. And we started discussing classes, and roles, and responsibilities. And it was just great. It felt really, really magical for me. Truth is that during my first years of studies, I wasn't even sure if I'm going to be a programmer. I thought that it's not for me. But once I saw object orientation, I was like, yeah, that's it. This is nice. I can do that. And then I got my first job. That was a bummer. But well, I was still a student, so it was cool. I got my first job. So OK. And I started working with code like that. If you've done any PHP, you've probably seen it. But I'm showing this to you because I was seeing functions, I was seeing functions everywhere. And after my studies, I wasn't even sure what functional programming is. Everybody was talking about object orientation. And I started using PHP, and I started seeing those functions and function and function and function. I was like, functional programming is ugly. It's just ugly. I want objects. I want classes because it's beautiful. I can organize my code into classes and objects and interfaces, and it's going to be great. And then I discovered that PHP has object-oriented features. So I was like, yes, I can do that. It's going to be awesome, right? So I started working with object-oriented PHP. And it took me about a year to say, well, it's great. But there are some issues like a lot of boilerplate, some very early PHP overams, very nasty, and inconsistency everywhere. So I was like, well, that's not good object-oriented design. I don't want to do that. So what choices I had? Java? Well, we already had this opinion. It was, I think, 2006. People were already talking about, well, Java, it's just nasty object-oriented language. Enterprisey, very bloated, abstract factory, factory, all those common jokes. So not good object-oriented design. I'm not going to do that. It's going to be boring. C++? Not really. I wasn't experienced enough, and it would be very hard to find Java as a C++ programmer. So I started looking for something that's better. So I started learning Python, and I kind of liked it. But then I was introduced to Ruby on Rails. And that was great. That was great, because after my experience with PHP, which I use mostly to build web applications, when I learned about Ruby on Rails, it was great because the boilerplate, I could just write very little code, and it would just work. And that was fantastic, especially when I've seen Active Record for the first time. I was like, wow, two lines of code, and so much functionality. This is it. Now I'm going to write great object-oriented code. I have great features, and it's going to be great. It's good object-oriented design, right? It's great because I can work with the data very easily because Active Record is very powerful. It has convenient interfaces, so I can just access my data, and then I can add some behavior, and it's going to be super awesome, because I have all those ridiculously powerful interfaces that are just there for me. I can use them. It's great. And then you know the story, probably. I think you do. Then we started seeing things like that, right? So repository Active Record object, right? It's from Gittori's project, by the way. It's a real thing. So I realized that, okay, so this is a data structure that's connected to a database. That's already pretty complicated. And then we use Mixins in Ruby for everything, and Mixins is just multiple inheritance, so what can go wrong? Well, we are adding more and more and more, and then we are defining 14 associations. So that's a lot of complexity. And then we add some behavior on top of it, so we end up with this, right? And you know, you've seen that, right? We've seen that.  We've been discussing that for five years, I think. So that's kind of boring. And I realized that that's not good object-oriented design either. I was like, okay, what's the reason for using object-oriented design? I want to use it because it's gonna help me with dealing with complexity, but it didn't work like that, at least not for me. So this talk is about blending functional and object-oriented programming in Ruby. It's probably not a typical Ruby talk, although I want to make one thing clear that it's not one of those talks where I was bored during the weekend and I decided to do some crazy stuff with Ruby, and now I'm like, yeah, I'm gonna talk about that because it's crazy and it's kind of cool. It's a bit different. This is based on fewer years of experience. I've been experimenting a lot with different styles of Ruby, and that's basically my conclusion. So my name is Piazzolica, as you've seen. You can find me on the internet. I'm typically known as Solnik. So I tried to blog about Ruby and open source projects on my blog, follow me on Twitter, find my stuff on GitHub. I've been working on a project called Ruby Object Mapper, and the things I'm gonna show you are pretty much taken from this project. They were born while we were working on this very project, so it's a pretty important project for me because of that. So my path to good object-oriented design leads through functional programming, and it was an accident. It's not like I've learned functional programming, and then I was like, now I want to write Haskell, but I will use Ruby syntax, or now I will write Elixir with Ruby syntax because this didn't work like that. I just started applying certain concepts to my code, and it turned out that they are functional, and then I started learning about functional languages, and I was like, wow, wow, it's the same thing. So that's interesting. So the first thing that I wanna talk about are functional objects. So functional objects have a lot of common concepts. They follow common conventions, or even rules, I should say. And the first rule is that they are immutable. And when I say immutable, I mean immutable, because in Ruby it's kind of difficult to have truly immutable objects. To have a truly immutable object in Ruby, you would have to deeply freeze it, which means that you're gonna have some code that is very, very slow. On a larger scale, it would be too slow. So there are gems that do that for you, but I stopped using them because of the performance issues. But they helped me to understand how to design my systems in a way where objects don't have to change. So the second thing is that the functional objects have common interface, which is method call. It's the only method, the primary interface, that is used to trigger some behavior of a given object. Now, I'm not saying that this is the only method that I implement. That would be kind of stupid, but there are many other methods that I can implement, but the primary method, the method that triggers the behavior is call. And it always receives an input, and it has no side effects. It means that if call method received a hash, it will not change it. Please don't change hashes that you receive. Don't assume that you own them because you don't. So no side effects also mean that the object itself will not change. So that's important. And they always return some output. And it's also important because when something receives an input and returns some output, you can continue with the processing. You can apply more and more functionality. So you probably notice that we're talking about objects that work like functions, which is pretty cool. So the first thing is to get rid of immutable objects. As I mentioned, immutability is the first rule, the first convention. And it's really important, and even though the implementation and the kind of technique that I use is very simple, the effect of applying this technique is pretty mind shifting. And it's a long process to actually understand how to design your system in a way that your objects won't have to change. Because it means that once you instantiated something, it must be ready because you will not be able to change it later on. So it must be ready to be used. And that's a big change. So immutability-oriented design is quite simple. So here's a class, or a typical class in Ruby, some user query. It receives some dependency. It's injected into the constructor, and then we call it, right? So it's typical to define interfaces that allow you to change an object, which means that when we use this object, we instantiate it with some query, then we call it, and then it's possible to change it. It's a very common thing to do in Ruby. And for many people, it's absolutely okay. It's even idiomatic. For me, it's very bad. When I seek out like this, I'm like, no, no, I wanna go. This is something that I cannot rely on because when something can change, some other thing might depend on it, on its initial state, and then the state will change, so the thing will break, which happens a lot. And this is the source of complexity and a source of bugs, so I stopped doing that. So this is the design that I prefer these days. And as you can see, it's a pretty simple concept. I still have a constructor that receives a dependency, and then I just return a new instance if I want some different context for this object. It's a very, very simple technique. Even though it's simple, applying that to your entire application is not simple, because we are used to the fact that things do change. We rely on the fact that something can be changed, and it means that we often instantiate an object which will change in order to be able to use it. So we need to do more work before we instantiate objects, and that part is difficult. So when we have this object, we just instantiate it just like we did before, then we call it, and then we just ask for a different query, and we call it again. And the cool part is that the initial object will not change, so we can safely, for example, store it in some registry and make other objects depend on it, and it will just work. So the second topic is what about the state? When I say state, I'm talking about data, you know, the attributes. We love attributes, right? We love to define attributes and define types and have coercion, and we love with objects that are bags of attributes. And that is already complex, but we typically add behavior to it. It's also a very typical object-oriented idea to have data combined with behavior. And now I'm gonna say something heretical because I prefer stateless objects. I prefer objects that only have behavior. They receive some input, some data, some state to the call method, but they don't include any kind of state. They don't encapsulate any kind of state, especially if it's mutable. So that's heretical.  I mean, we have objects with state everywhere and it's object-oriented, right? Now it's okay. I mean, it might be surprising, but it's okay. So here's a typical class in Ruby. Let's say we wanna persist a person. So a typical thing to do is to pass the person to the constructor, assign it to the instance variable, and then have a method that will use some external dependency to save this person. Now there are a couple of problems here. So the first one is that we pass the state to the constructor, which means that we turn this object into a safe object which also has functionality which is persisting the person, which means that we coupled this object to a specific kind of person, which means that it's not flexible. It's not reusable because we can use it just once. And then we do a common mistake of coupling this object with a specific class. We didn't use dependency injection and that's just more coupling and it's also less flexible. So when we use this object, we can instantiate it with the hash for the sake of simplicity. And then we call it and then what? Then we can't do anything about it. It's just a throw away object because we use it once and we cannot reuse it anymore. And it's a problem because if we want to do something else with this person, it's not that simple because now it's the part of the internal state of this object. So composing more functionality, it's not that simple anymore. So the design that I prefer is to use constructor just for one thing and it's dependency injection. I'm no longer discussing things like what should go to the constructor. I decided to always use it just to inject the dependencies if there are any. So this means less coupling because this object is now coupled to the idea of user repository but not to a specific class and it simply uses its interface. So it's definitely less coupling. It's more flexible. And then we pass in the input to the call method which is nice because we can do this. We can instantiate the object. We can call it and we can use it many times. Now it's a small change. It's a small difference but it has big impact because we can instantiate objects just once and then reuse them many times. So the outcome of this design is that you separate the structures that your application is working with with the behavior which is kind of against object orientation. It means that suddenly all the data that you receive or extract from some database becomes something that's first class. It should be a concept in your application. It should be well-defined. And there are libraries that do that but it's like a separate subject for a separate talk. So I just want to mention that. The nice aspect of this design is that once you have those data structures you can easily add more functionality implemented inside small objects that will rely on those structures. And it's absolutely simple to do that. It's way simpler than having objects with state and then trying to figure out whether you should use inheritance or include a module or whatever because you just simply compose functionality together and the data structures are just passed in from one object to another. It simplifies your code. When you don't mutate anything and when you use immutable objects it's really simple to compose functionality. You have objects that don't change so you can safely rely on them. Nothing will break because nothing changes. So if you want to compose some more complicated functionality we can use a couple of objects and just call them like that. And it looks pretty much like calling functions, right? So the downside of it is that Ruby doesn't have any built-in interfaces for this kind of object composition. But it's okay, we can implement our own, right? So I'm gonna talk about a couple of functional interfaces that I implemented inside Ruby ObjectMapper and now they are being extracted into separate gems. I found them to be really powerful, surprisingly powerful. So the first one is out to curry. Sorry you were hungry, so. I forgot that you were hungry. That was a mistake, sorry. So out to curry is a simple idea. So let's say we have a class log event. It uses a logger to write some logs and it has an interface where the call method can receive a type and a payload. So we can use a small extension. It's called out to curry. It's not released yet but I will do that like tomorrow I think. It allows us to include a small extension and then say that the call method will be lazy. What it means is that we can create the instance of this object and then call this object with just the first argument and it's gonna be partially applied. Which means that we can call it again with the remaining argument and it's gonna work. Now I know it's weird, like what is this? That's confusing. Well, it's not that weird. In Haskell language, every function is lazy. You can partially apply arguments to any function. You can compose them and things will just work. So it's not a really crazy idea. It's something that is pretty fundamental in some languages. It's also a very small, I would say, lower level building block for some high level functionality that gives you a lot of flexibility. So the second thing is functional composition. I'm gonna show you one type of functional composition that I've been using in Ruby Object Mapper and I started using it in other projects as well. It's called pipeline. So if we have a class, an object that persists to user, we can add this thing and it's gonna add a pipeline operator. An idea is really simple. It means that if we have some other object that, as you've seen before, logs some events, we can create those objects and then we can do this. This means that we're composing a pipeline, which means that create user will persist the user and then the output of this operation will be passed to the log event. The log event is partially applied, which is cool because it will do what we expect it to do. We don't need extra classes. We don't need extra abstractions. It's a simple idea. And when you look at the implementation of this operator, it's actually pretty object-oriented because it's object composition under the hood. We have a left side and a right side and then we call the results from one side with the other one, so that's pretty simple. So yeah, that's also confusing, right? I mean, pipeline operator, what are you talking about? That's just crazy. But it turns out that in Elixir language, you have exactly the same thing. You have pipeline operator, which looks a bit different, but it's the same concept. You're composing some functionality from small pieces to get some more high-level concept back and then you can just use it. And it's extremely powerful. So what happens when we combine those techniques, those functional techniques, functional ideas, and some functional rules like immutability with object orientation? So first of all, when we start treating immutability as a virtue, as something that is actually beneficial, when we start having objects where mutation is just not possible or discouraged, at least, we have consistent and side-effectless interfaces and that leads to great composability. It turns out that you can implement a lot of functionality in very small objects and combine them however you want and it's very, very simple. Now, I've been spending quite a lot of time learning about all kinds of object-oriented rules and principles and code-smells and refactoring techniques and everything and over time I realized that I'm moving towards objects that are like functions, like singular responsibility principles, a great example, like if you start to follow this principle, you will end up with an object that is like a function, pretty much. And the nice part of this is that consistency allows you to do this and it's a really, really nice thing to have. And on top of it, with functional interfaces, you can build high-level object-oriented abstractions and that's like my latest discovery and I was really happy to see that because it turns out that to build some high-level, more object-oriented abstractions, when I have small functional components under the hood, things become so much simpler. So I'm gonna show one example. It's a library that I wrote, I think, a couple of weeks ago. It's called TransFlow. It's for composing business transactions. It means that when you have a bunch of things that need to happen inside a transaction, you can do that with a DSL. So it's very simple. You just define steps and it will execute first step and take the result from the first ones and do the next one until you get the final result, which I've shown you already, right? It's this thing, right? Under the hood it uses the simple concept of object composition just like function composition in functional programming languages. So it's the same thing under the hood. So the nice part was that I was able to add some additional features to that without much complexity. So I realized that I have some use cases where I would like to use publish, subscribe. So I added a feature called publish. It uses a jam called whisper under the hood which is really nice, check it out. And the idea is that each of the steps can publish some messages, some events. And then we can define an event listener. And then this event listener can have methods that will be triggered by a specific event. So we have persist step and we have persist success and of course persist failure. So this is a very common thing to do and I refactored a lot of really nasty code with this approach in my Rails app. But then it turned out that I have some use cases where I cannot use that because I have some information only inside controller and I cannot easily pass that to an event listener. It would be just too messy, it would be more complexity. So I realized that I can use some underlying pieces. So if we're using event listener, we subscribe it and then we call it. But what if in the moment of defining the transaction we have some information that we want to just pass in to some step. And it turned out that I can use the outer curry that I showed you. So we define the translator without publishing, we define the log event step as the last one and then we say, okay, log event should use the create user event type. And then we call it and things just worked. So this is built on top of functional interfaces and I didn't have to add any kind of additional abstractions. I just reused existing functionality and I was really, really happy to see that because under the hood it uses the same kind of stuff, just the pipeline and the partial application and we're calling the input and that's it. So what happens when we start treating functional programming as something that we can take inspiration from and combine them with object orientation? So it's kind of difficult to discuss it because this is the kind of feedback I typically get. So it seems like that would much rather be programming in a statically typed functional language. And yeah, that's true, right?  That's pretty obvious. But the truth is that I program in Ruby and I'm gonna do that for quite a while and the things that I've discovered are really easy to implement in Ruby and they are not crazy. This is pretty simple stuff. And with all the things that we have in huge projects like Rails, which provides a ton of additional abstractions with a ton of complexity, I don't think that those simple functional concepts are more crazy than anything else that we already have in Ruby. So why not try it? Especially that I want to write the best Ruby that's possible. And for me, good functional programming combined with object orientation means good object-oriented design. And that's it. It's wow, it's great. Thank you.