What?!? C# Could Do That?!?
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Title of Series | ||
Number of Parts | 110 | |
Author | ||
License | CC Attribution - NonCommercial - ShareAlike 3.0 Unported: You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this | |
Identifiers | 10.5446/50989 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
00:00
Software developerWeightImage resolutionRun time (program lifecycle phase)Symbol tableFunction (mathematics)Task (computing)Visual systemError messageWindowSpacetimeInterface (computing)Generic programmingRight angleCompilation albumFormal languageConstraint (mathematics)Video game consoleCAN busKeyboard shortcutObject (grammar)Dynamical systemMereologyReal numberType theoryWave packetSocial classSystem callAuthorizationView (database)Information technology consultingImage resolutionCategory of beingDemo (music)Term (mathematics)CompilerRun time (program lifecycle phase)CodeWeightMetropolitan area networkPoint (geometry)Goodness of fitString (computer science)Inheritance (object-oriented programming)Software developerNatural languageField (computer science)Line (geometry)Forcing (mathematics)MathematicsProduct (business)Instance (computer science).NET FrameworkOpen setTwitterClosed setEmailForestVisualization (computer graphics)Interior (topology)Extreme programmingComputer animation
08:04
SpacetimeFunction (mathematics)Error messageTask (computing)AerodynamicsSoftware developerSymbol tableWindowView (database)String (computer science)Operator (mathematics)Computer virusOvalProgrammable logic arrayGeneric programmingRight angleSocial classForcing (mathematics)Flow separationSystem callVapor barrierHand fanObject (grammar)Category of beingReal numberOperator (mathematics)String (computer science)Computer animation
09:19
Software developerAerodynamicsWindowSymbol tableFunction (mathematics)Task (computing)Error messageReduction of orderSpacetimeMessage passingPhysical systemGeneric programmingObject (grammar)View (database)Category of beingMessage passingDemo (music)Application service providerState of matterRight angleExpandierender GraphDot productCASE <Informatik>Dynamical systemComputer animation
11:33
Software developerPhysical systemSpacetimeAerodynamicsMessage passingEquals signData typeCausalityElectronic mailing listSymbol tableFunction (mathematics)String (computer science)Letterpress printingVideo game consoleCAN busPrice indexOvalStreaming mediaDialectFile formatWindowData bufferMIDIObject (grammar)Parameter (computer programming)View (database)Standard deviationMenu (computing)ACIDManufacturing execution systemLie groupTask (computing)Error messageDefault (computer science)Line (geometry)Letterpress printingMessage passingCoefficient of determinationGroup actionClosed setString (computer science)Right angleComputer animation
12:28
Software developerEwe languageLetterpress printingSpacetimeMessage passingPhysical systemWindowView (database)Metropolitan area networkMaxima and minimaVideo game consoleSymbol tableTask (computing)Function (mathematics)Computer programElectronic mailing listDiscrete element methodDemo (music)String (computer science)Elasticity (physics)ParsingAerodynamicsUnicodeSeries (mathematics)Error messageMusical ensembleLengthElement (mathematics)Object (grammar)Social classMusical ensembleView (database)Category of beingElement (mathematics)Function (mathematics)Inheritance (object-oriented programming)Open sourceRun time (program lifecycle phase)Attribute grammarLink (knot theory)Dot productDynamical systemConstructor (object-oriented programming)Extension (kinesiology)PlastikkarteSoftware frameworkExpert systemSymbol tableReading (process)Game controllerRight angleConnectivity (graph theory)LengthElasticity (physics)Projective planeBlogTwitterWritingRootFrame problemProcess (computing)Computer fileLine (geometry)Data dictionaryMilitary baseIterationFormal languageRoutingMoment (mathematics)Computer animation
18:59
Software developerMusical ensembleElement (mathematics)WindowAerodynamicsLengthFunction (mathematics)Electronic mailing listSymbol tableTask (computing)Object (grammar)Electric currentEquals signConvex hullFile formatData typeSoftware frameworkElasticity (physics)Attribute grammarObject (grammar)LengthBit rateSocial classDatabaseComputer animation
19:45
Musical ensembleElement (mathematics)AerodynamicsLengthTask (computing)Video game consoleSymbol tableFunction (mathematics)Software developerCantor setPhysical systemSpacetimeAnalogyElectric currentEquals signObject (grammar)Inheritance (object-oriented programming)Variable (mathematics)DatabaseMassComputer clusterObject (grammar)Software frameworkLoginType theoryObject-relational mappingSystem callComputer animation
21:18
DreizehnSoftware developerNetwork topologyWindowSubject indexingEquals signHidden surface determinationVideo game consoleSymbol tableFunction (mathematics)Task (computing)OvalSpacetimeAerodynamicsInheritance (object-oriented programming)Row (database)Row (database)Table (information)Right angleDemo (music)Dynamical systemObject (grammar)WeightParameter (computer programming)ResultantDatabaseException handlingCodeSystem callAddress spaceSocial classOperator (mathematics)LoginQuery languageBinary codeSet (mathematics)Inheritance (object-oriented programming)Object-relational mappingMetadataComputer animation
26:19
Software developerAnalogyMaxima and minimaObject (grammar)String (computer science)Data typeInheritance (object-oriented programming)WindowSymbol tableFunction (mathematics)Task (computing)CausalityAreaRow (database)SpacetimeOvalResultantConstructor (object-oriented programming)CodeDifferent (Kate Ryan album)Multiplication signSocial classCASE <Informatik>Dynamical systemTable (information)Row (database)Line (geometry)Query languageParameter (computer programming)Extension (kinesiology)Right angleSystem callException handlingObject (grammar)Computer animation
28:43
Dylan <Programmiersprache>Run time (program lifecycle phase)Regulärer Ausdruck <Textverarbeitung>WebsiteCache (computing)System callAerodynamicsLoop (music)CAN busEquivalence relationSoftware developerCodeComputer programSpacetimeMultiplication signMechanism designRight angleInterpreter (computing)Line (geometry)Heat transferField (computer science)CodePoint (geometry)Formal languageDynamical systemBridging (networking)ImplementationSyntaxbaumDemosceneCASE <Informatik>Open sourceNumbering schemeService (economics)Different (Kate Ryan album).NET FrameworkObject (grammar)Uniform resource locatorRun time (program lifecycle phase)FingerprintSystem callWebsiteSoftware framework1 (number)Network topologyWeightProcess (computing)EmailMereologyProduct (business)Context awarenessCartesian coordinate systemLatent heatReal numberLoop (music)Coma BerenicesVideo game consoleInternet service providerComputer animation
35:01
Maxima and minimaVisual systemWindowView (database)Symbol tableFunction (mathematics)Error messageTask (computing)Software developerRule of inferenceFloating pointData typeNumberoutputText editorVideo game consoleCAN busElectronic mailing listOvalElectronic program guideNP-completePartial derivativePRINCE2Run time (program lifecycle phase)CodeDew pointCodeRule of inferenceCivil engineeringFormal languageScripting languageMaxima and minimaLine (geometry)Right angleCASE <Informatik>CuboidExtension (kinesiology)Software frameworkAreaLengthMultiplication signMetropolitan area networkPower (physics)Interface (computing)Value-added networkInterpreter (computing)FreewareLie groupMathematicsValidity (statistics)Boolean algebra.NET FrameworkComputer clusterWritingCartesian coordinate systemComputer animation
40:46
Range (statistics)Computer programRun time (program lifecycle phase)Software developerWindowVisual systemTemplate (C++)Windows FormsGame theoryFunction (mathematics)Task (computing)Symbol tableComputer iconComputer fileCursor (computers)View (database)VisualBASICSocial classSource codeScripting languagePhysical systemCompilerProjective planeMereologyMathematicsMoment (mathematics)Right angleVideoconferencingCompilation albumProcess (computing)Descriptive statisticsAbstract syntax treeScripting languageSystem callCodeFormal languageDifferent (Kate Ryan album)Multiplication signComputer fileComplete metric spaceNeuroinformatikSpacetimeDegree (graph theory)Forcing (mathematics)Visualization (computer graphics)Social classCoefficient of determinationContext awarenessDemosceneWritingDivisorComputer to plateIntegrated development environmentDot productPlug-in (computing).NET FrameworkVideo game consoleCode refactoringLine (geometry)Service (economics)Computer animation
46:57
Gamma functionManufacturing execution systemSoftware developerScripting languageRight angleProcess (computing)CompilerCoefficient of determinationComputer animation
47:56
Function (mathematics)Electronic mailing listTask (computing)Visual systemPhysical systemSoftware developerService (economics)CodeLine (geometry)Software developerScripting languageRepetitionComputer clusterVolume (thermodynamics)Formal languageLetterpress printingLoop (music)Dynamical systemPerformance appraisalReading (process)Cartesian coordinate systemComputer animation
48:45
Software developerVideo game consoleWindowCalculationSocial classUniform boundedness principleLetterpress printingRight anglePhysical systemOvalLine (geometry)Multiplication signDot productStructural loadAssembly languageCoefficient of determinationComputer animation
50:18
RepetitionReading (process)String (computer science)Maxima and minimaSoftware developerScripting languageWindowFunction (mathematics)Video game consoleSymbol tableTask (computing)Physical systemError messageMassCodeCodeSocial classScripting languageNeuroinformatikLine (geometry)Function (mathematics)Descriptive statisticsResultantStatement (computer science)Assembly languageoutputCompilation albumComputer animation
51:56
Software developerCodeHierarchyView (database)WindowWeb browserObject (grammar)Error messageWeb pageElectronic mailing listCompilerRevision controlData typeInformationFunction (mathematics)Streaming mediaVisual systemMaxima and minimaVideo game consoleSymbol tableTask (computing)SpacetimeVideo game consoleWindowInteractive televisionError messageLine (geometry)Parameter (computer programming)View (database)Visualization (computer graphics)Dot productCompilation albumAssembly languageRight angleVideo gameResultantInheritance (object-oriented programming)Computer animation
53:37
Demo (music)Physical systemComputer programSpacetimeSymbol tableFunction (mathematics)CausalityTask (computing)Electronic mailing listRule of inferenceSoftware developerMaxima and minimaWindowDemonCAN busCompilerDiscrete element methodDemo (music)Visualization (computer graphics)Projective planeWebsiteMultiplication signResultant1 (number)AverageMereologyComputer programmingTrigonometric functionsSystem callComputer animation
55:37
Software developerTask (computing)Symbol tableWindowCAN busElectronic mailing listError messageFunction (mathematics)Video game consoleView (database)Maxima and minimaMultiplication signInterpreter (computing)Goodness of fitWindowLine (geometry)Cartesian coordinate systemContext awarenessExtreme programmingState of matterLimit (category theory)Asynchronous Transfer ModeSoftware bugRight angleShared memoryComputer animation
57:33
Elasticity (physics)Goodness of fit.NET FrameworkDynamical systemElasticity (physics)Prisoner's dilemmaVideo gameMetaprogrammierungMereologyObject (grammar)TwitterEmailMathematicsComa BerenicesWeightSpacetimeWordComputer programmingDot productPhysical lawBlock (periodic table)Software frameworkComputer animation
Transcript: English(auto-generated)
00:01
How was the party yesterday? Wake up people, wake up. The party is over. Are you ready for some C-shop super magic? Yeah, I need a yeah, I need to wake up too. Yeah. Oh
00:23
Cool, that's good. That's good. Okay, okay Welcome to the C-shop or what? C-shop could do that talk and I hope that by the end of this talk you'll say oh cool. I am a C-shop developer, and I like it so
00:41
That's the target My name is Che Friedman. I am a co-founder and a co-founder in a company named code value Consultancy firm training as well. I'm a Microsoft MVP and the author of iron Ruby unleashed She's the best book ever created. I have big big competition from Harry Potter
01:06
They took all my readers But we'll be fine. We'll be fine. If you want to contact me. These are the ways the email and Twitter account blog everything So now you know me Um
01:22
Let me see how many of you are C-shop developers Of course and and VB Yeah, no one by the way okay, I never met someone who actually writes me but They say they exist
01:42
Okay Let's let I'll just tell you what we're gonna see today because there are three parts for this session The first one is the dynamic keyword and what we can actually do with that because a lot of people just know they exist But never actually used it. So we'll see what we can actually do that with that
02:02
then we'll move forward and see some cool stuff we can do with the DLR and iron languages like iron Ruby and We'll end up with some Rosalind which we'll talk about it when we get there Okay, so how many of you have heard about dynamic
02:22
Almost all of you right and how many of you used it in production? Wow Please like seven people That's that's the most that I've got in this talk. So good for you, Norwegians So this is the thing a dynamic keyword has been around since dotnet forest has been released
02:45
so it's about I guess two years something like that and Not a lot of people have actually used it because it seems like Everything is changing right once you go dynamic like you're all world just collapsing like
03:02
The compiler is not here what I'm gonna do. So It's kind of under I don't know extreme side of dotnet and I do hope to Make it more mainstream the thing about dynamic is really that the compiler won't save you here because everything is done during runtime once you
03:26
assign a variable and it's a dynamic variable all the method resolution and Access to our fields and properties would be done during runtime Now this is just a definition, but you can do so much stuff with that
03:44
really cool stuff magic some would say and Why not it's right there. It's right there for you to use it. So let's dive in into the demo Close that and open Visual Studio and the first demo
04:05
Is about generics how many of you use generics, right? I Have a problem with generics in c-shop, especially with just the term generics because think about it
04:21
Generics in c-shop Yes, thank you Generics in c-shop when you want like to create a new new instance of the generic type You need to have a constraint, right? And maybe you have neither have a constraint about an interface or a class
04:42
and generics and Constraints these are like the opposites, right? So How do you say it's a generic method if it has constraints? So I want to have a real generic method that once that I call something
05:04
On the object on the generic object. I can pass any object whatsoever That has this Method or field that I'm accessing. I don't want to have a base class. I don't want to have an interface or whatever I don't want to have constraints. I just want to do a generic method that would work everywhere
05:27
And this is why dynamic also call it generics on steroids Because you can do generics in dotnet in a real generic way Okay, so let's let's see that
05:44
Let's go here and do public T okay Return a T and add T now. I'll just show you this TA and TB Now I'm just putting a comment so you won't see if it can compile or not
06:03
So can I do that with generics today? Would it be okay? How many of you think I can remove the comment and compile and everything would be good? Okay, how many think how many of you think it's not going to be good? Yeah, well, you know your stuff in origins good for you for you
06:23
Can't say Norwegians, right? Probably most of you not from here. Okay, so good. Well good for you So yes generics doesn't allow me to do that. You see that the red Line there it says. Oh, no, I cannot apply an operator. But well, I want it to be a generic thing
06:42
I want it to pass whatever I want here and I want to add these two objects So What do I do to solve that? Just change this to dynamic and I'm done okay, it compiles and
07:04
and Not just compiles so I can go let's do console write line add an Int and then I pass it one and two and I'll get an int back. I can do Add I don't know double and pass six dot seventy eight and nine point twenty one. I don't know
07:26
And I'll get a double back and I can do even Crazier stuff like hello and world, right again, because I
07:40
can add two strings so It would work I can Well, let's do that and one and hello this would how many think this will work You're right Dotnet allows you to do that. Let's run that so you can believe me
08:04
So you see you just get just adds all this stuff see that now you can see that no Okay, that's good so you see one method fits all which is exactly what generics is about and
08:24
I can even go farther because now I can add any two objects that support the plus operator Right, and even if I add a new object this would feed this as well So I have here a class called it's a fun class because it's very fun
08:41
It has data just a property a string and it supports a class operator between two fun classes So you have double the fun and double the data, okay So this is just a fun class and then you go and and I can just use it on my add method because It's real generic. So I didn't have to implement anything just needed to have the plus operator there so I can do new
09:07
fun class and Something like that a new fun class And I can run that and and it still works. Um, yeah, you see that
09:22
uh, so you see this is this is what I call generics because it's really generic and You can see that I didn't need to use dynamic all over the place I just Have it where I need it just inside this method because it makes sense right, so
09:41
Why not? Why not, right? moving forward to another demo Now how many of you um, um know expando object? Okay, how many of you have used it?
10:00
Cool, right. How many of you use ASP.NET MVC 3 or 4? Okay, so you you guys if you have ever used view bag View bag is an expando object Okay, so you don't maybe you don't even know that you use an expando object So this because of MVC 3 and 4 uh expando object is probably the most popular dynamic object out there
10:26
um expand object is also called a I think a state bag the idea because you just put stuff in it And you put it in like properties And you use it like there were properties, but you don't you never have to actually declare and define these properties
10:47
Okay, so and you see once you go that new expando object You return and you get back a dynamic object, right? And now I can do something like that expando dot message
11:02
equals uh yo Um and um I've never Created this message property, but it looks like a property. It feels like a property. So who cares, right? It's a property for me and I can just go ahead and and print it expando dot message
11:25
um And it would work like let's go here. Just change this to two and So you see you get a yo there Now you can even uh add Let's delete that you can even add methods. So like expando dot
11:45
print And let's do action that takes a string And then do Uh msg in it would go to uh console dot Right line and we'll print the message close
12:06
Dog Yeah Um And now I can use this print message, um sprint Method, let's do print and let's pass
12:22
Yo Right because this is what we do Um, let's run that and we get yo dog It's cool, right? Um So it's kind of construct A kind of way to construct classes during runtime. Um
12:42
If it helps you, uh do stuff, uh, that's great. It's great for mvc because you have this Controller and a view that they don't rely on each other and this dynamic object just makes it Not coupled so it's a cool thing
13:00
And it makes sense in in these kind of scenarios when you have uh, two different components and They don't know about each other and you might change the objects that go between them So this is a good way to do that um Okay, so this is expando object
13:22
Let's continue To another demo, um, by the way, uh expando object is a dynamic object it just um Expands a class named dynamic object which which we will just see how we can take advantage of that So microsoft just created this uh class
13:41
Uh and and took over all the dynamic capabilities of this dynamic object base class Um, by the way underneath it just a dictionary. Okay a dictionary with the name And this object that you pass it. That's it um Okay, so now if we can actually create classes that return dynamic objects
14:05
And we can take advantage of the dynamic capabilities of these objects We can do this ourselves, right? So one step before we do it ourselves. I want to see to show you Uh a framework that someone else did uh, and it's an open source project. It's called elastic object
14:25
And it's a way to handle xml files, okay now, um How many of you have ever parsed an xml file? How many of you like the experience Yes You right there you should be an xml expert if you like that you'd be you'll have tons of money tons
14:49
Anyway, um, yeah, so, uh, you know, uh, xml is not the nicest thing in the world. Um And this elastic object, um
15:00
Framework what are they doing back there? um Read and write xml in a more class-like way, which is great for me Um, you see this is my uh simple xml It has a people root Element and then it has a child element person which has a name twitter handle and a blog
15:26
Okay, that that's it very simple for me Now I do uh x element which is just a link to xml object I parse the xml and then I use this extension method called to elastic
15:41
And I get back a dynamic object Okay, and this dynamic object these people here represent these people Element here. Okay, you just uh one two one And then I can go over all the child nodes of people named person
16:01
And get a dynamic object over each iteration, okay, so this is how I get the child elements of the people element And now in each iteration, I have this person class and it's a dynamic object And then what's cool about it is that I can use the attributes
16:22
Just like there were real properties. Okay. I didn't need to create this class Like a person class and then serialize this realize this this stuff It just works as it is and you just because it uses the dynamic keyword right so I use this
16:41
element this the attributes as Properties it looks like class a class that I did it feels like properties so Great win-win, right? Now reading xml is all is nice but writing xml is even nicer, right?
17:01
Of course, um, so Here again, we can do something more class like, uh when we write xml This is writing xml Okay, so we create a new elastic object and give it the name of the root element and this returns me a dynamic object
17:22
And now I can have uh, like bend dot name Looks like a property but this actually would be an attribute in the output xml, right? And then I want to add child elements named songs And in these songs, I want to have a song and a song and a song. Okay
17:43
So this is the way, uh, you do this here in this framework. You just go band songs Dot song this is creating a new node named song And then you give it the attributes and you use them like properties name and length and then I have another song and name and length
18:01
And it looks like a class. I never created this class Because it's just dynamic now. Um The guy who created this framework, uh, he's called anoop super smart guy uh, but um I don't know why he chose this way to output the xml the from the dynamic object. It's totally legit
18:24
Uh, it's a legit. Um Syntax is c-shop syntax. He just uh overloaded this um greater than Uh symbol and this is how you do it. Um, it's just like calling a method just um synthetic sugar
18:41
Um So this as you can see returns you an x element, which is a link to xml Um element object and then you can go ahead and do whatever you want with that Uh, so here I just print it and let's uh, let's see how it looks like So you see these the two lines, uh that I read so just outputting them
19:05
This is what happens when you create the object the xml using the elastic object framework Which is just banned and the name and songs and then we have a song and a song and an attribute And it just goes on and on and now and now if tomorrow someone comes to me and says this song has to have
19:22
Something else like I don't know song two. Um, I don't know rating And I want it just here. I can just go ahead and do something like that and run it again And now it has name length and rating, right? Very simple, no, we don't need to go and change the class and then serialize all this stuff very simple straightforward, right?
19:45
There are more frameworks, uh that have been created using dynamic a lot of orms mini orms Like massive and simple data if you want to Just connect to a database and you don't want to use anti-firm and hibernate which are huge frameworks
20:05
Check it out. Okay. It's called one of them called massive Rob conroy did that actually and one of them called simple data. They're both very similar. So Just go and look for them Okay
20:20
So this is it now another thing Now we've seen how we use frameworks that Take advantage of the dynamic keyword now. We want to write them Ourselves, right? So i've created this crazy crazy um super magic
20:42
Uh object and you see it's called Log method calls and it returns my dynamic Uh variable and then I can do my objects out. Yo Of course and I can even go ahead and do I don't know I can type here Whatever I want and you can't stop me
21:05
Yeah I can go all day like yeah Let's save that and see what happens So you see, uh, crazy crazy magic, uh goes on
21:21
It just says trying to invoke yo when trying to invoke I can time Over Kind of cool and it gives you the idea that you can actually intercept here Once a method is called you can do whatever you want with that, right? So, let's see how we do that Um, this is the class this is it right the name is log method calls
21:46
and it extends a dynamic object class Okay Now the dynamic object class if we try to overwrite stuff you see that it has all these try things Try binary operation try a convert try try try try try this actually represents
22:02
All the things that you can do on a class in dotnet, okay So anything that you can do on a class you can intercept and and with your code and do something else Okay So what I did try invoke member is just when you uh invoke and a method
22:21
I just wrote the name of the method and If you if you look just on the on the arguments you have a binder which just says the name of the method and some more metadata Uh, you get all your arguments passed to this method and you can send back a result okay, so
22:41
What I did I just put null in the result because I don't want to return anything and then I returned true Because if I uh had returned false I would have gotten an exception like method was not found blah blah blah blah okay, so, um This is uh, you see this is very simple, right? It's not like
23:02
only for uh People who talk to you and you don't know what they're saying, but they're saying smart stuff, right? So many people like that here um so As a regular person I can do this as well, so it's good. Um So this is one thing now. I I want to show you a cool just a cool thing that I did with that because
23:26
log method calls Object is a great Thing, but i'm not sure you really want to use this Um, so i've created something called a super finder, right? Because it finds thing in a super way
23:42
um How many of you have um seen active record? Right, okay active record is an orm in the ruby on rails world and they've got like cool methods They call them magic methods, uh that you can go ahead and do like if you have a user
24:00
Object for example, you can go ahead and do user dot find by And then the column name Okay, so if you have like, uh an address for example an address column You can go find by address and do something like this is the value and this would go and query the database according to the address column and the
24:21
Sdfd value right and if you had another column, uh, which is I don't know Age you could just write find by age and then put something like that. Okay, so kind of cool kind of um Very explicit and you can read it read through the code. You don't need to be to do these
24:41
weird queries So I wanted this in dotnet, right? So what I did let's remove the return here, let's remove all of that because you've seen that already And what I did I created data table now, don't kill me. I know data tables are evil and data sets are
25:01
Thing that need to be dead and done but it just works good for the demo so don't kill me, please So I have a data table you can see how it looks like it just is very simple data table It has a one table and two columns id and name and each column has
25:21
These records like one in norway to sweden, okay So this is the date table And then I can create a new super finder and pass this the data table and I get a dynamic object in return Then I can go on and do finder dot find by name This is the column name and this is the value right and if I wanted to do
25:45
Uh with to query by id I could go ahead and do for find by id and do free. Okay And this would work as well So kind of like um Active record I could go ahead and like if I had another column I could go I don't know find by a continent
26:05
Okay, and this would work as well So, uh, let's return that Find by id would be cool. Uh, so just so you can see that, uh, it actually works Uh, yeah demo five is good. So let's run that so you see it gives you free dermark. So
26:22
Um, it works Just tell you that Let's see how I did that because again, it was very easy Um, this is my super finder class. It extends the dynamic object, right? and I have a constructor it receives the data table and then I again over reading the try invoke member method
26:46
and then only if The name of the method that is called Starts with find by because this is what I want to allow Uh, i'm going ahead i'm going ahead and do something. Otherwise, it just returned a base
27:00
Try invoke member which here would throw an exception, but you can do other stuff as well So once I have this, uh if here what i'm inside I just Remove the find by from the method name and then I have the column name, right? And so I have the column name I have the value from the first argument
27:23
This is just for the query. So I have this ampersand there And then I do the select On this, uh data table just a query, right? Um And return the result. This is the result that is being returned And that's it super easy
27:41
um Like I don't know six seven lines of code And I have this super method that I can just put the name of the the column And find it by that um, so it's you see that you can give uh c-sharp superpowers using that like
28:02
You can't do that. Otherwise Right, it would be a crazy thing to do that in a different way It's so easy and you see that the result also returns a data row So again, once you go dynamic, you don't need to change your entire code to be dynamic, right?
28:20
so Um again, this is a really cool use case And you would see actually something like that in a massive and simple data, which have these kind of methods as well Okay Um Cool now, um Let's continue well that that was dynamic if I have more time after that i'll i'll show you some more stuff about it
28:48
Now moving on To the dlr, um, how many of you have Used one of the dlr languages like on ruby or on python
29:01
I'll raise all really raise your hand all of you just to make me feel better Thank you, thank you Okay, so the dlr is actually a part of the dotnet framework, uh dotnet 4 and um Iron ruby and iron python were written on top of that and c-sharp and vb actually take advantage of that
29:26
of the dlr And the idea of the dlr is just to provide services to dynamic language implementers Just like see the clr Um Provide services to static languages, right?
29:40
It's the same idea and the dlr just uh written on top of the clr, right? So they have clr and dlr and next they will have elr and then flr and who knows? yes, um, so Uh, let's just see how it's written right? So the first thing it has is expression trees
30:01
and the idea here expression trees just Represent your data Not your data your syntax In a tree, right the syntax gets translated To a bunch of objects which represent your syntax, okay Now so if you're a dynamic language implementer you would want to take the syntax write an interpreter that takes the syntax
30:26
Translates that to an expression tree. Okay. This is what you do And then you have this expression tree You give it to the dlr and now once once the code starts executing It gets to a point where there is a call to something method field, whatever
30:45
Which is not inside the context Right and it needs to go out of context to find and call whatever it needs to be It asks to be called So this is what why they have this thing called dynamic dispatch we just go out of context and try to
31:03
Execute what you want And it this uses binders Okay, so once like for example iron ruby tries to execute something from the dotnet framework It would go and use this object binder, right? and maybe uh python iron python code tries to
31:23
Tries to execute an iron ruby code so it would go and use a binder and ruby binder from python Okay, so you can see that all of these Different worlds by the way, you can see object binder for dotnet javascript and python ruby com different worlds can now interact
31:43
Thanks to this dynamic dispatch Feature, okay, so it's kind of cool So Last but not least here is what's called call side caching, which is just a caching mechanism So once you run code You interpreter you interpret the code and then you execute it
32:05
You Next time you execute it, you will not have to interpret it again and again and again So the idea is that once you run your dynamic Application It would run faster As time goes by okay, because the all the things would be cached
32:24
Okay. So these are the three main stuff of the dynamic language runtime the dlr And on top of the dlr as I said, we're written iron ruby and iron python They started as a microsoft thing now, they're open source if you want to contribute Go ahead. We need you
32:42
Um, do you want to buy a book about iron ruby It's down there Now c-shop and vb.net Take advantage of the dlr when you use the dynamic keyword right all the binders and dynamic dispatch stuff They use it once you go ahead and use the dynamic object in in dotnet
33:05
Now other languages were written on top of that as well. For example, uh one Created iron js, which is a javascript implementation on top of that, uh, someone tried to do iron scheme for scheme Um, someone did nuwa which is an implementation of the lua language
33:25
um and also this It runs This is lol code It runs really. Um, so high is code start I has a fish. It's yummy. It's just fish equals yummy
33:44
Visible high world is just console right line I'm in your loop It's loop start K. Thanks is loop n And k thanks bias code So this this actually runs someone from the dlr team created, uh some kind of a poc with that
34:04
Uh it if you go and look for lol code online, they have a specification for the language. So it's a real language Um haven't met anyone using in production But Uh, you never know
34:22
If you do send me an email so I can uh, once I do these talks, I just can show your name or something um So i'm going to show you not this But what you can actually do with the dynamic, uh with the dlr in your applications And I know you're not going going to transfer and now write all your your code in um
34:44
Iron ruby or iron python, but I think there are several different cases where you can take these um These languages and corporate them into your application And they will make perfect sense there. So, uh, let's close all of these
35:02
And go to uh this thing here Let's run it. Okay. This is my great great awesome rule engine, right? thousand of man hours spent on the design of this thing Now I can go and click here and I have these validation rules, right?
35:23
And I can go like let's see Go textual and let's say the max length can be three Okay, and save it and now once I do aa it would be Happy, right? And when I do aa bbbbbbb it would be sad
35:42
um, you see how many uh design hours spent when you have this, uh, uh, white background, but yeah, well, um I'm not good at designing things um, anyway now what's wrong with that right
36:00
It's cool But once it goes out and it gets to the customer Right and don't get me wrong. I love customers, right? We all love customers But customers tend to have weird requirements uh from time to time now What do you do when a customer comes and say to you? Well your rule engine rocks, but
36:26
I need Now I want this the value to start with the letter c Otherwise I want it to fail Well, they say okay cool and you go and add this feature here
36:41
So now you have like I don't know checkboxes and you can choose this first letter as c rule, right? And now comes another customer And you love them too, right? But they have another weird requirement and then you have another customer and another and it goes on and on and on
37:00
so I say Give power to the people Let them write the rules and You just count the money right so You can you can do that today like with a map for some extensibility Um frameworks, but I think for something like that, which is just simple rule engine
37:24
You need a simpler solution, right? So what i'm going to do i'm going to close this i'm going to open this Um change this to true And i'm kind of done crazy crazy thing
37:41
Um, and now I have this thing here. Okay custom rules and this is actually an iron ruby text box Okay, I can write iron ruby code um Which interacts with my dotnet code? and This is where I write my custom rules
38:00
So if the these customer comes and say I want this first letter I see he can go just go here and say if value the first letter equals c then we turn True and else return false and then this you don't need
38:21
And that's it. We click save let's put textual here click save And now we see something The validate is happy but if we start with something else It's sad Okay so Now we gave power to our customers to write
38:41
This um custom rules. It's very easy because it's very simple Not just they don't need to create a dll and assembly, uh, I don't know implement some interface They just need to write their simple rule right there And that's it, okay, this is iron ruby you can do this with python as well
39:00
um Now and you probably think well, it probably would have been Crazy to write that like one thousand million gazillion hours, right? No Actually, no um I just needed to download iron ruby use their dlls reference them and then
39:23
Add Three lines of code That's it. Nothing more. Let's do that See, let's even do that. Now. It really seems like three lines of code. Um, this is it, right? The first line just creates the ruby engine
39:42
Right, which is just where all the uh language, uh interpreter lies Then I need to expose something to this script right I want to expose Uh that value of the text box So I just expose it to the script with a value a variable named value
40:03
And then I execute the code from this text box and get a boolean in return That's it done finito, right? um So this is very simple This is this is a really big use case in my opinion for all the dlr languages because it just makes so much sense to use
40:23
it right so Yeah, this is this is just one, uh example I have more but I don't have time for that But this is really a big big example of how you can take advantage of the dlr in your current applications for these simple, uh solutions
40:43
Okay, so uh, yeah, you can see this again Moving forward to the last part which is rosalyn Uh, how many of you uh came to my session about rosalyn? Oh, thank you, sir
41:01
uh It was fun. It was fun. You should look at the video. Anyway, how many of you heard about rosalyn? Okay, cool. So, uh rosalyn is the New c-sharp and vb compiler. Okay, it's not yet the compiler. It's still in ctp
41:20
Uh, but it it will be the next compiler It's written in c-sharp and vb.net, right? They write the c-sharp compiler in c-sharp and the vb.net compiler in vb Uh, it's the largest vb.net project inside microsoft at the moment by the way They don't use it either
41:43
Um Anyway, uh rosalyn has four parts. It's not just the compiler, right? What I like about rosalyn is that it just not just the compiler. They took the compiler the idea of compilation And took it and expanded it all over the related things to compiler to compilation
42:03
For example, think about it the compiler compiles code, right? And code is written inside an ide and in dotnet the ide is visual studio so they took the experience of writing visual studio add-ins and Enhanced it. Okay, and they took the idea of using
42:24
The solution files And make it better. Okay, so everything that is related to code Uh is inside rosalyn and they try to make it better the better experience So the first one the first part here is the compiler, right? You can compile code you can um
42:42
Get the syntax the syntax tree and you can intercept your code inside before You have the compile Process so you can get the syntax tree change the syntax tree and then um Execute the compilation process. So it's kind of cool. There are so many things that you can do with that
43:04
um I'm not going to show you compilers today. Uh, but Look at the video, right? Um Scripting is cool. And i'm going to show you scripting because it kind of allows you to use c-sharp as a scripting language Which opens again a bunch of new uh opportunities, which is kind of cool
43:26
workspace um How many of you needed to open a solution file in a text editor? And change it by hand Right, okay, and how many of you liked it?
43:41
I know uh, so Why did they took the entire thing created an api for that and now you can go through the solution file the The projects the files inside add remove update files can do this all via an api
44:00
and An api that makes sense, right? It's not like you need to have a Fair degree or something like that So it's really nice and probably would You wouldn't need to go and change stuff manually in solution files anymore In the future, um, so, uh, thank you the rosalind team for that
44:25
um now Service is the last part and it's just a way to write visual studio add-ins okay, and um in in in context of syntax, right So you can write refactoring tools very easy Okay, so, uh, this is the idea and and and again right in visual studio add-ins
44:46
if you have tried that it's not a nice thing Okay um And nice is you know, it's it. Well, you don't want to go there anyway um, so so services try to make it better and they actually use meth
45:01
and it looks nicer and You can watch the code and understand it which is good Okay, so these are the parts of frozen and Let me show you the scripting part, uh, how much time I have? Okay, cool. So, um first one
45:23
I can um, let's go over here And i'm gonna add a new item Okay, maybe I shouldn't have done this here, but let's see um, yeah Oh I'll go here and add a new item
45:44
And now once you install the rosalind ctp You have a visual c shop script Okay Script c shop that didn't work. Well together before um, let's edit
46:02
Okay And what you can see that the difference now you don't have classes you don't have methods you just write your code right away Okay So all the ceremony of c-sharp goes away just write what you need
46:20
So just like a script so you can do console dot write line um Of course because this is what you also always need and that's uh, uh, of course Yo dog, yeah No, I don't need a semicolon Yes um, so you can you can actually write classes and methods here, but um, you can also do that
46:48
And now you save it. Okay, let's copy. Um the full path of this thing And let's open cmd And You have something that is called
47:03
rcsi Let's see if this joke works miami And rcsi new york I'm going down So you have rcsi and rcsi just a compiler and then it executes. Um
47:24
this this Um Script c-sharp scripts, right? So let's just do that. This is my c-sharp script. It ends with csx Okay, so I start with rcsi and end with scscx And I click enter and you see oh dog
47:42
Okay, so you now have scripts in c-sharp Okay, which is kind of cool. You can just have it right to what's something you need and just Executed wherever you want. So this is a cool thing now Another thing that you can do, um with the services not the services the um scripting api
48:05
Is writing a repl how many of you know what repl is? Okay, cool. Um Repl is a read evaluate print loop application, which means that it is it's just an application that gets lines of of code You write the code you click enter and the code gets executed
48:24
Okay And then you write another line of code click enter and it gets executed again, right? so, um Just like dynamic language developers have had for many years, right? So, uh 2012 and
48:40
We now have these two Let's run my roslene fun code And now we have a c-sharp repl console Okay, and now I can go ahead and do a public class yo Public void print
49:01
Uh system dot console dot right line And Click enter and now I have this pub this class and now I can do var y equals new yo
49:26
Y dot print and you see it says you And it's kind of cool you can actually Move away from calculator and use it instead. Okay, so
49:43
it does that and It's crazy crazy calculations Um, so you see you can just interact with c-sharp in just this cool repl window And you can load your assemblies for example and write Just try them out like load an assembly try some methods or something like that
50:04
Uh, it would be a good example for that now, uh, this this thing here has the craziest best feature of all times right bye-bye And it quits um Now, how did I do that?
50:21
Let's go here Very simple actually, I just I have this scripting host class. I will show it you that in just a minute And this just takes care of all the uh input and output for the user So until you get a bye-bye just execute the code line and output the result. Okay. This is the entire idea here
50:42
Now, let's see the scripting host this uses the roslene scripting api's and you see uh script I have a script engine And a session, okay, the session is here Just just so you can save uh, the lines of code that were interpreted already So once I wrote the class definition the next line would save you I can actually use this line
51:06
Okay, so this is why I need the session here. So I have like an interactive compilation And I have the session I have this script engine and if you um, remember the iron ruby example Kind of the same. This is the engine for c sharp now
51:24
These are the assemblies that I load. Okay, just like add reference just from code And this is the uh usings using statements that I want to have Okay, so I just use that for description then so now I have the engine and the session and all I need to do
51:42
Is just call execute. We just calls engine dot execute and passes the code line and the session That's it Okay, it's very simple uh, very very simple very cool, uh for this, um this ripple example Which is not that but anyway, you know what I mean
52:01
Um now another really cool thing in roslene is that once you install the cdp you can go to view C sharp interactive window And you got the interactive window the ripple thing inside visual studio
52:21
So you can go ahead and do our console Console dot right line and I don't know if you noticed but I have intellisense here, which is kind of cool Um, and I can go ahead and do this stuff and I get immediate result Okay, so again, you can load your assemblies here try it out and and just see what happens
52:44
Okay, so, um, and also if you're not sure about the method how it reacts to different Different Parameters you can put it here. Just write it see what happens and go on with your life Okay, so it's cool. And of course, of course, you don't need to calculate it anymore. You have it here inside visual studio
53:04
You don't need to ever leave visual studio again Um So, um, yeah, it's very cool. However, uh, this interactive console does not support bye-bye It just doesn't know what to do with that like error and stuff Um, so this is uh roslene
53:23
Uh, this is just the compilation the scripting apis. Of course roslene has much more than that But you see how cool it is and where it's going um Okay, so I think we'll just uh uh have questions now because we have not a long time left and then i'll summarize and
53:44
so questions Yes Okay, the question was will rosalen be part of uh visual studio 2012 and I don't think so Uh because they've just released another cdp
54:02
And they're not in an rc or rp or whatever they call it now Um, so i'm not sure I'm, pretty sure that on visual studio v next this would be the compiler The csc.exe would go away Okay more questions
54:20
Yes Uh, the question was about the the performance of the dynamic keyword, which is a great one because I can show you that
54:42
So thanks Let's do that Uh, let's go back to uh this and for example the first demo, okay, so let's just uh remove that I told you that there is this call site caching thing. So once you call the method once again and again
55:03
You get better results. So let's do that and I have this thing here um Yeah, it came prepared. Um, okay So, uh add So I just use stopwatch. Okay, just to show you how much time did it take now, let's run it one time
55:26
Um, let's go to uh program demo, uh one And starting project and run Okay, so this took five milliseconds once okay
55:42
Cool this took five milliseconds now, let's do this for um a thousand times Let's run that Took five milliseconds Okay 100 000
56:05
Okay, uh, did I answer your question? Okay, I can I can go on and on Yeah I can okay. I saw um So you see the performance you do have like a small amount of time at the beginning to to do the interpretation
56:23
Uh, but uh, once you go through that line You're kind of good. Okay More question. Yes
56:41
No, um, no, uh, the question was what are the Interactive window for us in uh, once you you are in debug mode Would it load with the state and the context of your application it makes a lot of sense, but no Right now, uh city the cdp actually doesn't um, it has some limitations like it doesn't support a dynamic and some other
57:06
extreme stuff Uh, so it might um not work for some stuff but uh once it out it would support everything and I It sounds like a good idea so i'm sure someone would do that but right now it's not
57:23
One more question Or not That's it. You're all shocked What happened? What just happened? Okay. Okay, so let me summarize. Um So Cool, so we started with the dynamic keyword Uh, I showed you some uh different things that you can do with that
57:42
Um, I really believe the dynamic keyword has a place in the dotnet world Like I know a lot of people don't use it But you see that there are uses just you can just go ahead and use it and it makes your life easier So why not right if you can why not you can do something in one minute instead of 10
58:03
I don't see the problem The dlr again Has a space in the dotnet world where it fits right where it fits the most to you if what I showed you made sense Go ahead and use it if other things that you can think of make sense go ahead and use it It's right there for you. It's not going away. It's not going away
58:23
uh I'm, not sure what I said before, uh The dlr is a part of the dotnet framework and I don't know if you know the dotnet framework is like um Alcatraz prison for stuff one is to go in never go out
58:40
Okay, so, uh, the dlr is there it will be will be there forever, okay, so you can take advantage of that And last but not least is rosalyn, which I believe is gonna Change a lot of stuff in the dotnet world because you will see meta programming in dotnet new keywords come to life
59:03
uh stuff like stuff like that uh, which will make your Experience with c-sharp, uh much more interesting and on the same thing on the same side Much more easier, I think okay so, um, yeah rosalyn is something to expect and
59:23
I uh, I definitely uh wait to see when when it gets out and what happens when the community takes over And starts to use it and um do great stuff with that Resources on ruby.com on python.net if you want to download this stuff
59:40
Uh msdn.com slash rosalyn for rosalyn everything is there documentation download everything is there Um amaze saint.com, uh is the guy who wrote a elastic object Uh, he's a super smart guy. So just go and look at this blog and get your mind blown
01:00:01
Yeah um That's it. So if you have any more questions, just come to me afterwards find me in the conference. Um Send me an email tweet me. I don't know something like that Um, I will be glad to help. I hope you have a good day today Thank you very much for being here